mcconnell 2003/11/24 01:11:43
Modified: repository/main/src/java/org/apache/avalon/repository/main
InitialRepositoryFactory.java
repository/test/src/test/org/apache/avalon/repository/main
InitialRepositoryFactoryTest.java LoaderTest.java
Added: repository/spi/src/java/org/apache/avalon/repository/criteria
AbstractCriteria.java
repository/spi/src/java/org/apache/avalon/repository/meta
ApplicationDescriptor.java ArtifactDescriptor.java
Removed: repository/spi/src/java/org/apache/avalon/repository/criteria
Template.java
repository/spi/src/java/org/apache/avalon/repository/meta
Meta.java TargetMeta.java
Log:
Naming improvements.
Revision Changes Path
1.2 +8 -7
avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/main/InitialRepositoryFactory.java
Index: InitialRepositoryFactory.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/main/InitialRepositoryFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InitialRepositoryFactory.java 24 Nov 2003 08:22:08 -0000 1.1
+++ InitialRepositoryFactory.java 24 Nov 2003 09:11:43 -0000 1.2
@@ -79,7 +79,7 @@
import org.apache.avalon.repository.util.RepositoryUtils ;
import org.apache.avalon.repository.criteria.Factory ;
import org.apache.avalon.repository.criteria.Criteria ;
-import org.apache.avalon.repository.meta.TargetMeta ;
+import org.apache.avalon.repository.meta.ApplicationDescriptor ;
/**
* Sets up the environment to create repositories by downloading the required
@@ -172,19 +172,20 @@
// which is default mechanism dependent.
//
- TargetMeta target =
- new TargetMeta(
+ ApplicationDescriptor app =
+ new ApplicationDescriptor(
RepositoryUtils.getAttributes( repositories, reference ) );
- Artifact implementation = target.getImplementation();
- String factory = target.getFactoryClassname();
+ Artifact implementation = app.getImplementation();
+ String factory = app.getFactoryClassname();
//
// Download every dependency referenced by the implementation into the
// temporary cache to build the repository classloader with.
//
- Attributes attributes = RepositoryUtils.getAttributes( repositories,
implementation ) ;
+ Attributes attributes =
+ RepositoryUtils.getAttributes( repositories, implementation ) ;
ArrayList list = new ArrayList() ;
Artifact dependency = null;
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/AbstractCriteria.java
Index: AbstractCriteria.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.criteria;
import java.io.IOException;
import java.io.File;
import java.io.InputStream;
import java.util.Properties;
import java.util.Hashtable;
import java.util.Map;
import java.net.URL;
import java.net.MalformedURLException;
import java.lang.reflect.Constructor;
import org.apache.avalon.repository.criteria.Criteria;
import org.apache.avalon.repository.criteria.Parameter;
import org.apache.avalon.repository.criteria.ValidationException;
/**
* A abstract utility class that can be used to simplfy the
* creation of domain specific criteria handlers.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public abstract class AbstractCriteria implements Criteria
{
//--------------------------------------------------------------
// state
//--------------------------------------------------------------
private final Hashtable m_bindings = new Hashtable();
//--------------------------------------------------------------
// Criteria
//--------------------------------------------------------------
/**
* Return the parameter associated to the criteria.
* @return the parameters
*/
public abstract Parameter[] getParameters();
/**
* Set a named parameter of the criteria to a value.
* @param key the parameter key
* @param value the value to assign to the key
* @exception ValidationException if the supplied value fails
* the validation test for its associated parameter
*/
public void setValue( final String key, final Object value )
throws ValidationException
{
final Parameter p = getParameter( key );
final Object v = resolveValue( p, value );
m_bindings.put( key, v );
}
/**
* Return the currently assigned value for a key.
* @return the assigned value
*/
public Object getValue( final String key )
{
getParameter( key ); // verify key
return m_bindings.get( key );
}
/**
* Return the current state of the criteria as a map.
* @return the criteria as a map
*/
public Map getMap()
{
Hashtable map = new Hashtable();
Parameter[] params = getParameters();
for( int i=0; i<params.length; i++ )
{
final String key = params[i].getKey();
Object value = m_bindings.get( key );
if( value != null )
{
map.put( key, value );
}
}
return map;
}
public String toString()
{
return "[criteria: " + getMap() + "]";
}
//--------------------------------------------------------------
// private
//--------------------------------------------------------------
/**
* Verify a value relative to the parameter constraints.
* @param value the value to verify
* @exception ValidationException if the value is invalid
*/
public Object resolveValue( Parameter param, Object value )
throws ValidationException
{
if( value == null ) return null;
Class c = getParameterClass( param );
if( c.isInstance( value ) )
{
return value;
}
else
{
Constructor constructor = null;
try
{
constructor = c.getConstructor( new Class[]{ value.getClass() } );
}
catch( NoSuchMethodException nsme )
{
final String error =
"Value of class: ["
+ value.getClass().getName()
+ "] supplied for key ["
+ param.getKey()
+ "] is not an instance of type: ["
+ param.getClassname()
+ "].";
throw new ValidationException( error );
}
try
{
return constructor.newInstance( new Object[]{ value } );
}
catch( Throwable e )
{
final String error =
"Value of class: ["
+ value.getClass().getName()
+ "] supplied for key ["
+ param.getKey()
+ "] is not an instance of or was not resolvable to the type: ["
+ param.getClassname()
+ "].";
throw new ValidationException( error, e );
}
}
}
private Class getParameterClass( Parameter param )
throws ValidationException
{
try
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
return loader.loadClass( param.getClassname() );
}
catch( Throwable e )
{
final String error =
"Unable to resolve parameter class: "
+ param.getClassname();
throw new ValidationException( error, e );
}
}
public Parameter getParameter( final String key )
{
Parameter[] params = getParameters();
for( int i=0; i<params.length; i++ )
{
Parameter parameter = params[i];
if( parameter.getKey().equals( key ) ) return parameter;
}
final String error =
"Unknown key: [" + key + "].";
throw new IllegalArgumentException( error );
}
}
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/meta/ApplicationDescriptor.java
Index: ApplicationDescriptor.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.meta;
import java.io.Serializable;
import java.util.NoSuchElementException;
import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute;
import javax.naming.NamingException;
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.repository.ClassicArtifact;
/**
* An application descriptor associates a target artifact and
* factory enabling the creation of a potential application context.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public class ApplicationDescriptor extends ArtifactDescriptor
{
//-----------------------------------------------------------
// static
//-----------------------------------------------------------
public static final String GROUP_KEY =
"avalon.target.group";
public static final String NAME_KEY =
"avalon.target.name";
public static final String VERSION_KEY =
"avalon.target.version";
public static final String FACTORY_KEY =
"avalon.target.factory";
//-----------------------------------------------------------
// immutable state
//-----------------------------------------------------------
private final Artifact c_implementation;
private final String c_factory;
//-----------------------------------------------------------
// constructor
//-----------------------------------------------------------
/**
* Creates a new TargetMeta descriptor.
*
* @param domain the domain value
* @param classifier the classifier value
* @param version the meta data version
*/
public ApplicationDescriptor( final Attributes attributes )
throws MetaException
{
super( attributes );
try
{
c_factory = getValue( attributes, FACTORY_KEY );
if( null == c_factory )
{
final String error =
"Missing attribute: " + FACTORY_KEY;
throw new MetaException( error );
}
}
catch( NamingException ne )
{
final String error =
"Unexpected naming exception during target metadata creation.";
throw new MetaException( error, ne );
}
catch( NoSuchElementException nee )
{
final String error =
"Unexpected exception during target metadata creation.";
throw new MetaException( error, nee );
}
try
{
c_implementation = createImplementationArtifact( attributes );
}
catch( Throwable e )
{
final String error =
"Unable to construct target implementation artifact "
+ "reference from attributes: " + attributes;
throw new MetaException( error, e );
}
}
//-----------------------------------------------------------
// public
//-----------------------------------------------------------
/**
* Return the implementation artifact
* @return the artifact
*/
public Artifact getImplementation()
{
return c_implementation;
}
/**
* Return the factory classname.
* @return the classname
*/
public String getFactoryClassname()
{
return c_factory;
}
/**
* Test is the supplied object is equal to this object.
* @return true if the object are equivalent
*/
public boolean equals( Object other )
{
boolean isEqual = other instanceof TargetMeta;
if ( isEqual )
{
TargetMeta meta = (TargetMeta) other;
isEqual = isEqual && c_implementation.equals( meta.c_implementation );
isEqual = isEqual && c_factory.equals( meta.c_factory );
isEqual = isEqual && super.equals( meta );
}
return isEqual;
}
/**
* Return the hashcode for the object.
* @return the hashcode value
*/
public int hashCode()
{
int hash = super.hashCode();
hash >>>= 13;
hash ^= c_implementation.hashCode();
hash >>>= 13;
hash ^= c_factory.hashCode();
hash >>>= 13;
return hash;
}
//-----------------------------------------------------------
// private
//-----------------------------------------------------------
private Artifact createImplementationArtifact( Attributes attributes )
throws NamingException, NoSuchElementException
{
final String group = getValue( attributes, GROUP_KEY );
final String name = getValue( attributes, NAME_KEY );
final String version = getValue( attributes, VERSION_KEY );
return ClassicArtifact.createJarArtifact( group, name, version );
}
}
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/meta/ArtifactDescriptor.java
Index: ArtifactDescriptor.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.meta;
import java.io.Serializable;
import java.util.NoSuchElementException;
import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute;
import javax.naming.NamingException;
/**
* An artifact descriptor holds attributes about an artifact.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class ArtifactDescriptor implements Serializable
{
//-----------------------------------------------------------
// static
//-----------------------------------------------------------
public static final String DOMAIN_KEY = "meta.domain";
public static final String CLASSIFIER_KEY = "meta.classifier";
public static final String VERSION_KEY = "meta.version";
//-----------------------------------------------------------
// immutable state
//-----------------------------------------------------------
private final String c_domain;
private final String c_classifier;
private final String c_version;
//-----------------------------------------------------------
// constructor
//-----------------------------------------------------------
/**
* Creates a new Meta descriptor.
*
* @param domain the domain value
* @param classifier the classifier value
* @param version the meta data version
* @exception NullPointerException if the domain, classifier
* or version attribute is undefined
*/
public Meta( Attributes attributes )
throws MetaException
{
if( null == attributes )
throw new NullPointerException( "attributes" );
try
{
c_domain = getValue( attributes, DOMAIN_KEY );
if( null == c_domain )
{
final String error =
"Missing attribute: " + DOMAIN_KEY;
throw new MetaException( error );
}
c_classifier = getValue( attributes, CLASSIFIER_KEY );
if( null == c_classifier )
{
final String error =
"Missing attribute: " + CLASSIFIER_KEY;
throw new MetaException( error );
}
c_version = getValue( attributes, VERSION_KEY );
if( null == c_version )
{
final String error =
"Missing attribute: " + VERSION_KEY;
throw new MetaException( error );
}
}
catch( NamingException e )
{
final String error =
"Unexpected naming exception during metadata creation.";
throw new MetaException( error, e );
}
catch( NoSuchElementException e )
{
final String error =
"Unexpected exception during metadata creation.";
throw new MetaException( error, e );
}
}
//-----------------------------------------------------------
// public
//-----------------------------------------------------------
/**
* Return the meta data domain value.
* @return the domain
*/
public String getDomain()
{
return c_domain;
}
/**
* Return the meta data classifier value.
* @return the classifier
*/
public String getClassifier()
{
return c_classifier;
}
/**
* Return the meta data version
* @return the version
*/
public String getVersion()
{
return c_version;
}
/**
* Test is the supplied object is equal to this object.
* @return true if the object are equivalent
*/
public boolean equals( Object other )
{
boolean isEqual = other instanceof Meta;
if ( isEqual )
{
Meta meta = (Meta) other;
isEqual = isEqual && c_domain.equals( meta.c_domain );
isEqual = isEqual && c_classifier.equals( meta.c_classifier );
isEqual = isEqual && c_version.equals( meta.c_version );
}
return isEqual;
}
/**
* Return the hashcode for the object.
* @return the hashcode value
*/
public int hashCode()
{
int hash = 1;
hash >>>= 13;
hash ^= c_domain.hashCode();
hash >>>= 13;
hash ^= c_classifier.hashCode();
hash >>>= 13;
hash ^= c_version.hashCode();
hash >>>= 13;
return hash;
}
/**
* Return a stringified representation of the instance.
* @return the string representation
*/
public String toString()
{
return "[meta " + getDomain()
+ ":" + getClassifier()
+ ":" + getVersion() + "]";
}
//-----------------------------------------------------------
// utilities
//-----------------------------------------------------------
protected String getValue( Attributes attributes, String key )
throws NamingException, NoSuchElementException
{
Attribute attribute = attributes.get( key );
if( null == attribute ) return null;
Object object = attribute.get();
if( null == object ) return null;
return object.toString();
}
}
1.2 +1 -2
avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/main/InitialRepositoryFactoryTest.java
Index: InitialRepositoryFactoryTest.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/main/InitialRepositoryFactoryTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InitialRepositoryFactoryTest.java 24 Nov 2003 05:30:08 -0000 1.1
+++ InitialRepositoryFactoryTest.java 24 Nov 2003 09:11:43 -0000 1.2
@@ -61,7 +61,6 @@
import org.apache.avalon.repository.RepositoryException ;
import org.apache.avalon.repository.criteria.Criteria ;
import org.apache.avalon.repository.criteria.Factory ;
-import org.apache.avalon.repository.meta.TargetMeta ;
/**
1.2 +3 -3
avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/main/LoaderTest.java
Index: LoaderTest.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/main/LoaderTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LoaderTest.java 24 Nov 2003 05:30:08 -0000 1.1
+++ LoaderTest.java 24 Nov 2003 09:11:43 -0000 1.2
@@ -63,7 +63,7 @@
import org.apache.avalon.repository.RepositoryException ;
import org.apache.avalon.repository.criteria.Criteria ;
import org.apache.avalon.repository.criteria.Factory ;
-import org.apache.avalon.repository.meta.TargetMeta ;
+import org.apache.avalon.repository.meta.ApplicationDescriptor ;
/**
*
@@ -105,7 +105,7 @@
Attributes attributes = m_repository.getArtifactAttributes( spec );
assertNotNull( "attributes-not-null", attributes );
- TargetMeta target = new TargetMeta( attributes );
+ ApplicationDescriptor target = new ApplicationDescriptor( attributes );
Artifact implementation = target.getImplementation();
assertNotNull( "implementation", implementation );
String classname = target.getFactoryClassname();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]