mcconnell 2003/11/23 07:24:13
Modified: repository README.TXT
repository/test/src/test/org/apache/avalon/repository
InitialRepositoryFactoryTest.java
Added: repository/spi/src/java/org/apache/avalon/repository/criteria
Criteria.java Factory.java Parameter.java
Template.java ValidationException.java
repository/spi/src/java/org/apache/avalon/repository/meta
Meta.java MetaException.java TargetMeta.java
repository/spi/src/test/org/apache/avalon/repository/meta
MetaTest.java
Removed: repository/api/src/java/org/apache/avalon/repository/criteria
Criteria.java Factory.java Parameter.java
Template.java ValidationException.java
repository/api/src/java/org/apache/avalon/repository/meta
Meta.java MetaException.java TargetMeta.java
repository/api/src/test/org/apache/avalon/repository/meta
MetaTest.java
Log:
Move criteria and meta subpackages from api to spi.
Revision Changes Path
1.5 +2 -1 avalon-sandbox/repository/README.TXT
Index: README.TXT
===================================================================
RCS file: /home/cvs/avalon-sandbox/repository/README.TXT,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- README.TXT 23 Nov 2003 02:06:23 -0000 1.4
+++ README.TXT 23 Nov 2003 15:24:12 -0000 1.5
@@ -27,10 +27,11 @@
Before building the repository project you need to install the
avalon-repository plugin. A convinience goal is provided:
+ $ cd /avalon-sandbox/repository
$ maven avalon:setup
The test suite in the repo package assumes that the sandbox/kernel
-suporoject has been build and installed. To do this you need to
+suboroject has been build and installed. To do this you need to
do the following:
$ cd ../kernel/impl
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Criteria.java
Index: Criteria.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.util.Map;
/**
* A Criteria is a class holding the values supplied by a user
* for application to a factory.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public interface Criteria
{
/**
* Return the template backing the criteria.
* @return the template
*/
public Template getTemplate();
/**
* 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;
/**
* Return the currently assigned value for a key.
* @return the assigned value
*/
public Object getValue( final String key );
/**
* Return the current state of the criteria as a map.
* @return the criteria as a map
*/
public Map getMap();
}
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Factory.java
Index: Factory.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.util.Map;
/**
* A generic application factory.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public interface Factory
{
/**
* Return a new instance of default criteria for the factory.
* @return a new criteria instance
*/
Criteria createDefaultCriteria();
/**
* Create a new instance of an application.
* @param map the creatiob criteria
* @return the application instance
*/
Object create( Map map );
}
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Parameter.java
Index: Parameter.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 ;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public class Parameter
{
private final String m_key;
private final String m_type;
private final boolean m_required;
private final String m_description;
/**
* Creation of a new parameter constraint.
* @param key the parameter key
* @param type the name of a class constraining assigned values
* @boolean required TRUE if the parameter is required
* @param description a human readable parameter description
*/
public Parameter(
final String key, final String type, boolean required,
String description )
{
m_key = key;
m_type = type;
m_required = required;
m_description = description;
}
/**
* Return the key for the parameter.
* @return the key
*/
public String getKey()
{
return m_key;
}
/**
* Return the classname for the parameter.
* @return the classname
*/
public String getClassname()
{
return m_type;
}
/**
* Return TRUE is the parameter is required.
* @return the required status of the parameter
*/
public boolean isRequired()
{
return m_required;
}
/**
* Return TRUE is the parameter is optional.
* @return the optional status of the parameter
*/
public boolean isOptional()
{
return !isRequired();
}
/**
* Return the human readable description of the parameter.
* @return the description
*/
public String getDescription()
{
return m_description;
}
/**
* Verify a value relative to the parameter constraints.
* @param value the value to verify
* @exception ValidationException if the value is invalid
*/
public void verify( Object value )
throws ValidationException
{
Class c = getParameterClass();
if( !c.isInstance( value ) )
{
final String error =
"Value is not an instance of type: ["
+ getClassname()
+ "].";
throw new ValidationException( error );
}
}
private Class getParameterClass()
throws ValidationException
{
try
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
return loader.loadClass( getClassname() );
}
catch( Throwable e )
{
final String error =
"Unable to resolve parameter class: "
+ getClassname();
throw new ValidationException( error, e );
}
}
}
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Template.java
Index: Template.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 ;
/**
* The Template class holds a set of parameters that are used
* in the validation of factory criteria arguments.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public class Template
{
private final String m_description;
private final Parameter[] m_parameters;
private final String[] m_keys;
/**
* Creation of a new factory template.
* @param description the template description
* @param parameters the template parameters
*/
public Template( final String description, final Parameter[] parameters )
{
if( null == description )
throw new NullPointerException( "description" );
if( null == parameters )
throw new NullPointerException( "parameters" );
m_description = description;
m_parameters = parameters;
m_keys = new String[ parameters.length ];
for( int i=0; i<parameters.length; i++ )
{
Parameter parameter = parameters[i];
if( null == parameter )
throw new NullPointerException( "parameter" );
m_keys[i] = parameter.getKey();
}
}
public String[] getKeys()
{
return m_keys;
}
public Parameter getParameter( final String key )
{
for( int i=0; i<m_parameters.length; i++ )
{
Parameter parameter = m_parameters[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/criteria/ValidationException.java
Index: ValidationException.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 ;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public class ValidationException extends Exception
{
private final Throwable m_cause;
/**
* Creation of a new criteria.
*/
public ValidationException( String message )
{
this( message, null );
}
/**
* Creation of a new criteria.
*/
public ValidationException( String message, Throwable cause )
{
super( message );
m_cause = cause;
}
public Throwable getCause()
{
return m_cause;
}
}
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/meta/Meta.java
Index: Meta.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;
/**
* A meta data descriptor.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class Meta 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.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/meta/MetaException.java
Index: MetaException.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 org.apache.avalon.repository.RepositoryException;
/**
* Exception to indicate that there was a repository related meta error.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/11/23 15:24:12 $
*/
public class MetaException extends RepositoryException
{
/**
* Construct a new <code>MetaException</code> instance.
*
* @param message The detail message for this exception.
*/
public MetaException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>MetaException</code> instance.
*
* @param message The detail message for this exception.
* @param cause the root cause of the exception
*/
public MetaException( final String message, final Throwable cause )
{
super( message, cause );
}
}
1.1
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/meta/TargetMeta.java
Index: TargetMeta.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;
/**
* A target meta data descriptor.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public class TargetMeta extends Meta
{
//-----------------------------------------------------------
// 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 TargetMeta( 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/test/org/apache/avalon/repository/meta/MetaTest.java
Index: MetaTest.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.util.NoSuchElementException;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.Attribute;
import javax.naming.NamingException;
import junit.framework.TestCase;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $
*/
public class MetaTest extends TestCase
{
public static void main(String[] args)
{
junit.textui.TestRunner.run( MetaTest.class );
}
/**
* Constructor for ArtifactReferenceTest.
* @param arg0
*/
public MetaTest( String name )
{
super( name );
}
public void testConstructor() throws Exception
{
try
{
Meta meta = new Meta( null );
fail( "constructor using null should throw an NPE" );
}
catch( NullPointerException e )
{
assertTrue( true );
}
catch( Throwable e )
{
fail( "NPE expected by encountered: " + e );
}
}
public void testEmptyAttribute() throws Exception
{
Attributes attributes = new BasicAttributes();
try
{
Meta meta = new Meta( attributes );
fail( "missing attributes should fail" );
}
catch( MetaException e )
{
assertTrue( true );
}
catch( Throwable e )
{
fail( "Unexpected error: " + e );
}
}
public void testIntegrity() throws Exception
{
String domain = "aaa";
String classifier = "bbb";
String version = "123";
Attributes attributes = new BasicAttributes();
attributes.put( Meta.DOMAIN_KEY, domain );
attributes.put( Meta.CLASSIFIER_KEY, classifier );
attributes.put( Meta.VERSION_KEY, version );
try
{
Meta meta = new Meta( attributes );
assertEquals( "domain", meta.getDomain(), domain );
assertEquals( "classifier", meta.getClassifier(), classifier );
assertEquals( "version", meta.getVersion(), version );
assertEquals( "equals", meta, meta );
}
catch( Throwable e )
{
fail( "unexpected error: " + e );
}
}
}
1.9 +1 -8
avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/InitialRepositoryFactoryTest.java
Index: InitialRepositoryFactoryTest.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/InitialRepositoryFactoryTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- InitialRepositoryFactoryTest.java 23 Nov 2003 14:10:14 -0000 1.8
+++ InitialRepositoryFactoryTest.java 23 Nov 2003 15:24:13 -0000 1.9
@@ -166,11 +166,4 @@
"http://www.ibiblio.org/maven/"
};
}
-
- private String getCacheDir()
- {
- return System.getProperty( "user.dir" )
- + File.separator + ".cache"
- + File.separator + "repository";
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]