akarasulu 2003/11/06 17:54:17
Modified: repository/spi/src/java/org/apache/avalon/repository
ArtifactDatabaseImpl.java
Added: repository/spi/src/java/org/apache/avalon/repository
RepositoryUtils.java
Log:
Centralizing some utility functions and documenting some
more now that the picture is becoming more clear.
Revision Changes Path
1.2 +14 -111
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/ArtifactDatabaseImpl.java
Index: ArtifactDatabaseImpl.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/ArtifactDatabaseImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArtifactDatabaseImpl.java 6 Nov 2003 23:53:06 -0000 1.1
+++ ArtifactDatabaseImpl.java 7 Nov 2003 01:54:16 -0000 1.2
@@ -51,21 +51,25 @@
package org.apache.avalon.repository ;
-import java.net.MalformedURLException;
import java.net.URL ;
+import java.net.MalformedURLException ;
+import java.util.HashMap ;
import java.io.IOException ;
-import java.io.InputStream ;
-
-import java.util.HashMap;
-import java.util.Properties ;
-import java.util.Enumeration ;
import javax.naming.directory.Attributes ;
-import javax.naming.directory.BasicAttributes ;
/**
+ * A simple implementation which depends on properties type artifacts within the
+ * repository. Every artifact has a properties file with a set of application
+ * dependent properties in the file. The properties file is the full name
+ * of the artifact with its type (file) extention however '.properties' is
+ * appended to the name to denote the fact that the properties file is in fact a
+ * properties file. Here's an example:
+ *
+ * artifact: avalon-repository-spi-1.1-dev.jar
+ * artifact attributes: avalon-repository-spi-1.1-dev.jar.properties
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author$
@@ -103,7 +107,7 @@
try
{
l_url = new URL( a_descriptor.getUrl( m_remoteRepoBase ) ) ;
- l_attrs = getAsAttributes( getProperties( l_url ) ) ;
+ l_attrs = RepositoryUtils.getAsAttributes(
RepositoryUtils.getProperties( l_url ) ) ;
}
catch ( MalformedURLException e )
{
@@ -117,106 +121,5 @@
}
return l_attrs ;
- }
-
-
- public static Attributes getAsAttributes( Properties a_props )
- {
- Attributes l_attrs = new BasicAttributes( false ) ;
- Enumeration l_list = a_props.propertyNames() ;
-
- while ( l_list.hasMoreElements() )
- {
- String l_key = ( String ) l_list.nextElement() ;
-
- if ( isEnumerated( l_key ) )
- {
- String l_keyBase = getEnumeratedBase( l_key ) ;
- l_attrs.put( l_keyBase, a_props.getProperty( l_key ) ) ;
- }
-
- l_attrs.put( l_key, a_props.getProperty( l_key ) ) ;
- }
-
- return l_attrs ;
- }
-
-
- /**
- * Gets the Properties in a remote properties file.
- *
- * @param a_url the url to the properties file
- * @return the loaded properties for the file
- * @throws IOException if there is any problem loading the properties
- */
- public static Properties getProperties( URL a_url ) throws IOException
- {
- InputStream l_in = null ;
- Properties l_props = new Properties() ;
- l_in = a_url.openStream() ;
- l_props.load( l_in ) ;
-
- if ( l_in != null )
- {
- l_in.close() ;
- }
-
- return l_props ;
- }
-
-
- /**
- * Detects whether or not a property key is of the multivalued enumeration
- * kind. A multivalued key simply enumerates values by appending a '.' and
- * a number after the dot: i.e. artifact.dependency.2 and artifact.alias.23
- * et. cetera.
- *
- * @param a_key the property name or key
- * @return true if the property conforms to the enumerated property
- * convention, false otherwise
- */
- public static boolean isEnumerated( String a_key )
- {
- int l_lastDot = a_key.lastIndexOf( '.' ) ;
- String l_lastComponent = null ;
-
- if ( -1 == l_lastDot )
- {
- return false ;
- }
-
- l_lastComponent = a_key.substring( l_lastDot + 1 ) ;
-
- try
- {
- Integer.parseInt( l_lastComponent ) ;
- }
- catch ( NumberFormatException e )
- {
- return false ;
- }
-
- return true ;
- }
-
-
- /**
- * Gets the key base of an enumerated property using the multivalued
- * property key naming convention.
- *
- * @param a_key the enumerated key whose last name component is a number
- * @return the base name of the enumerated property
- */
- public static String getEnumeratedBase( String a_key )
- {
- int l_lastDot = a_key.lastIndexOf( '.' ) ;
- String l_base = null ;
-
- if ( -1 == l_lastDot )
- {
- return a_key ;
- }
-
- return a_key.substring( 0, l_lastDot ) ;
}
}
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/RepositoryUtils.java
Index: RepositoryUtils.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.repository ;
import java.net.URL ;
import java.io.IOException ;
import java.io.InputStream ;
import java.util.Properties ;
import java.util.Enumeration ;
import javax.naming.directory.Attributes ;
import javax.naming.directory.BasicAttributes ;
/**
* Various static utility methods used throughout repository related programing
* interfaces.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: akarasulu $
* @version $Revision: 1.1 $
*/
public class RepositoryUtils
{
/**
* Transforms a Properties into a Attributes using a simple enumeration
* convention for property names which appends a numeric enumeration name
* component to the dotted property key. Note that changes to the
* Attributes object do not have any effect on the Properties object and
* vice versa. All values are copied.
*
* @param a_props the properties to be transformed
* @return the Attributes representing the properties
*/
public static Attributes getAsAttributes( Properties a_props )
{
Attributes l_attrs = new BasicAttributes( false ) ;
Enumeration l_list = a_props.propertyNames() ;
while ( l_list.hasMoreElements() )
{
String l_key = ( String ) l_list.nextElement() ;
if ( isEnumerated( l_key ) )
{
String l_keyBase = getEnumeratedBase( l_key ) ;
l_attrs.put( l_keyBase, a_props.getProperty( l_key ) ) ;
}
l_attrs.put( l_key, a_props.getProperty( l_key ) ) ;
}
return l_attrs ;
}
/**
* Gets the Properties in a remote properties file.
*
* @param a_url the url to the properties file
* @return the loaded properties for the file
* @throws IOException if there is any problem loading the properties
*/
public static Properties getProperties( URL a_url ) throws IOException
{
InputStream l_in = null ;
Properties l_props = new Properties() ;
l_in = a_url.openStream() ;
l_props.load( l_in ) ;
if ( l_in != null )
{
l_in.close() ;
}
return l_props ;
}
/**
* Detects whether or not a property key is of the multivalued enumeration
* kind. A multivalued key simply enumerates values by appending a '.' and
* a number after the dot: i.e. artifact.dependency.2 and artifact.alias.23
* et. cetera.
*
* @param a_key the property name or key
* @return true if the property conforms to the enumerated property
* convention, false otherwise
*/
public static boolean isEnumerated( String a_key )
{
int l_lastDot = a_key.lastIndexOf( '.' ) ;
String l_lastComponent = null ;
if ( -1 == l_lastDot )
{
return false ;
}
l_lastComponent = a_key.substring( l_lastDot + 1 ) ;
try
{
Integer.parseInt( l_lastComponent ) ;
}
catch ( NumberFormatException e )
{
return false ;
}
return true ;
}
/**
* Gets the key base of an enumerated property using the multivalued
* property key naming convention.
*
* @param a_key the enumerated key whose last name component is a number
* @return the base name of the enumerated property
*/
public static String getEnumeratedBase( String a_key )
{
int l_lastDot = a_key.lastIndexOf( '.' ) ;
String l_base = null ;
if ( -1 == l_lastDot )
{
return a_key ;
}
return a_key.substring( 0, l_lastDot ) ;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]