donaldp 02/04/27 22:51:00
Modified: container/src/java/org/apache/myrmidon/components/embeddor
DefaultEmbeddor.java
container/src/java/org/apache/myrmidon/components/property
Resources.properties
container/src/test/org/apache/myrmidon/components
AbstractComponentTest.java
container/src/test/org/apache/myrmidon/components/property/test
DefaultPropertyResolverTestCase.java
Added: container/src/java/org/apache/myrmidon/components/property
DefaultPropertyStore.java MapPropertyStore.java
Removed: container/src/java/org/apache/myrmidon/components/store
DefaultPropertyStore.java Resources.properties
container/src/java/org/apache/myrmidon/interfaces/property
MapPropertyStore.java
Log:
Move PropertyStore implementations into property package.
Revision Changes Path
1.55 +2 -2
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
Index: DefaultEmbeddor.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- DefaultEmbeddor.java 28 Apr 2002 05:04:49 -0000 1.54
+++ DefaultEmbeddor.java 28 Apr 2002 05:51:00 -0000 1.55
@@ -33,7 +33,7 @@
import org.apache.avalon.framework.service.Serviceable;
import org.apache.myrmidon.Constants;
import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.components.store.DefaultPropertyStore;
+import org.apache.myrmidon.components.property.DefaultPropertyStore;
import org.apache.myrmidon.components.workspace.DefaultExecutionFrame;
import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
@@ -64,7 +64,7 @@
* Instantiate this to embed inside other applications.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.54 $ $Date: 2002/04/28 05:04:49 $
+ * @version $Revision: 1.55 $ $Date: 2002/04/28 05:51:00 $
*/
public class DefaultEmbeddor
extends AbstractLogEnabled
1.3 +7 -0
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/property/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/property/Resources.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Resources.properties 9 Apr 2002 02:26:34 -0000 1.2
+++ Resources.properties 28 Apr 2002 05:51:00 -0000 1.3
@@ -1,3 +1,10 @@
#AbstractPropertyResolver
prop.mismatched-braces.error=Malformed property with mismatched }'s.
prop.missing-value.error=Unknown property "{0}".
+
+#DefaultPropertyStore
+unknown-prop.error=Unknown property "{0}".
+bad-property.error=Property "{0}" must have a value of type {1}.
+bad-property-name.error=Invalid property name "{0}".
+null-resolved-value.error=Value "{0}" resolved to null.
+bad-resolve.error=Unable to resolve value "{0}".
1.1
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/property/DefaultPropertyStore.java
Index: DefaultPropertyStore.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.property;
import java.io.File;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.oldmodel.DefaultNameValidator;
import org.apache.myrmidon.interfaces.oldmodel.NameValidator;
import org.apache.myrmidon.interfaces.property.PropertyStore;
/**
* This is the Default implementation of PropertyStore. It follows
* the following rules;
*
* <ul>
* <li>The property names must pass DefaultNameValidator checks</li>
* <li>The store is mutable</li>
* <li>If the key is TaskContext.NAME then value must be a string.</li>
* <li>If the key is TaskContext.BASE_DIRECTORY then value must be a
key.</li>
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/04/28 05:51:00 $
* @see org.apache.myrmidon.interfaces.property.PropertyStore
*/
public class DefaultPropertyStore
implements PropertyStore
{
private final static Resources REZ =
ResourceManager.getPackageResources( DefaultPropertyStore.class );
/**
* The parent store (may be null).
*/
private final PropertyStore m_parent;
/**
* The name validator to check property names against.
*/
private final NameValidator m_validator;
/**
* The underlying map where propertys are actually stored.
*/
private final Map m_contextData = new Hashtable();
/**
* Construct a PropertyStore with no parent and
* default name-validator.
*/
public DefaultPropertyStore()
{
this( "", null, null );
}
/**
* Construct a PropertyStore with specified parent.
*
* @param parent the parent PropertyStore (may be null).
* @param validator the validator to use to check property names (may be
null).
*/
public DefaultPropertyStore( final String name,
final PropertyStore parent,
final NameValidator validator )
{
m_parent = parent;
NameValidator candidateValidator = validator;
if( null == candidateValidator )
{
candidateValidator = createDefaultNameValidator();
}
m_validator = candidateValidator;
m_contextData.put( TaskContext.NAME, name );
}
/**
* Set the property with specified name to specified value.
* The specific implementation will apply various rules
* before setting the property.
*
* @param name the name of property
* @param value the value of property
* @throws org.apache.myrmidon.api.TaskException if property can not be
set
*/
public void setProperty( final String name, final Object value )
throws TaskException
{
checkPropertyName( name );
checkPropertyValid( name, value );
if ( value == null )
{
m_contextData.remove( name );
}
else
{
m_contextData.put( name, value );
}
}
/**
* Return <code>true</code> if the specified property is set.
*
* @param name the name of property
*/
public boolean isPropertySet( final String name )
{
try
{
getProperty( name );
return true;
}
catch( Exception e )
{
}
return false;
}
/**
* Retrieve the value of specified property.
* Will return null if no such property exists.
*
* @param name the name of the property
* @return the value of the property, or null if no such property
* @throws org.apache.myrmidon.api.TaskException if theres an error
retrieving property, such
* as an invalid property name
*/
public Object getProperty( final String name )
throws TaskException
{
Object value = m_contextData.get( name );
if( value != null )
{
return value;
}
if( m_parent != null )
{
return m_parent.getProperty( name );
}
final String message = REZ.getString( "unknown-prop.error", name );
throw new TaskException( message );
}
/**
* Retrieve a copy of all the properties that are "in-scope"
* for store.
*
* @return a copy of all the properties that are "in-scope"
* for store.
* @throws org.apache.myrmidon.api.TaskException if theres an error
retrieving propertys
*/
public Map getProperties()
throws TaskException
{
final Map properties = new HashMap();
if( m_parent != null )
{
properties.putAll( m_parent.getProperties() );
}
properties.putAll( m_contextData );
return properties;
}
/**
* Return a child PropertyStore with specified name.
* This is to allow support for scoped stores. However a
* store may choose to be unscoped and just return a
* reference to itself.
*
* @param name the name of child store
* @return the child store
*/
public PropertyStore createChildStore( final String name )
{
// Build the name for the new store
final String thisName = (String)m_contextData.get( TaskContext.NAME );
final String newName;
if( name == null || name.length() == 0 )
{
newName = thisName;
}
else if( thisName.length() == 0 )
{
newName = name;
}
else
{
newName = thisName + "." + name;
}
return new DefaultPropertyStore( newName, this, m_validator );
}
/**
* Checks that the supplied property name is valid.
*/
private void checkPropertyName( final String name )
throws TaskException
{
try
{
m_validator.validate( name );
}
catch( Exception e )
{
String message = REZ.getString( "bad-property-name.error", name );
throw new TaskException( message, e );
}
}
/**
* Make sure property is valid if it is one of the "magic" properties.
*
* @param name the name of property
* @param value the value of proeprty
* @exception org.apache.myrmidon.api.TaskException if an error occurs
*/
private void checkPropertyValid( final String name, final Object value )
throws TaskException
{
if( TaskContext.BASE_DIRECTORY.equals( name ) && !( value instanceof
File ) )
{
final String message =
REZ.getString( "bad-property.error",
TaskContext.BASE_DIRECTORY,
File.class.getName() );
throw new TaskException( message );
}
else if( TaskContext.NAME.equals( name ) && !( value instanceof
String ) )
{
final String message =
REZ.getString( "bad-property.error",
TaskContext.NAME,
String.class.getName() );
throw new TaskException( message );
}
}
/**
* Create an instance of the default the name validator.
*
* @return the default NameValidator
*/
private static NameValidator createDefaultNameValidator()
{
final DefaultNameValidator defaultValidator = new
DefaultNameValidator();
defaultValidator.setAllowInternalWhitespace( false );
defaultValidator.setAdditionalInternalCharacters( "_-.+" );
return defaultValidator;
}
}
1.1
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/property/MapPropertyStore.java
Index: MapPropertyStore.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.property;
import java.util.Map;
import java.util.HashMap;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.property.PropertyStore;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
/**
* A simple unscoped, unsynchronized property store which is backed by a Map.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/28 05:51:00 $
*/
public class MapPropertyStore
implements PropertyStore
{
private static final Resources REZ =
ResourceManager.getPackageResources( MapPropertyStore.class );
private final Map m_properties = new HashMap();
/**
* Creates an empty store.
*/
public MapPropertyStore()
{
}
/**
* Creates a store containing the given properties.
*/
public MapPropertyStore( final Map properties )
{
m_properties.putAll( properties );
}
/**
* Return <code>true</code> if the specified property is set.
*
* @param name the name of property
*/
public boolean isPropertySet( final String name )
{
return m_properties.containsKey( name );
}
/**
* Retrieve the value of specified property.
*
* @param name the name of the property
* @return the value of the property. Never returns null.
* @throws org.apache.myrmidon.api.TaskException if there is no such
property, or on error
* retrieving property, such as an invalid property name.
*/
public Object getProperty( final String name )
throws TaskException
{
final Object value = m_properties.get( name );
if( value == null )
{
final String message = REZ.getString( "unknown-property.error",
name );
throw new TaskException( message );
}
return value;
}
/**
* Retrieve a copy of all the properties that are "in-scope"
* for store.
*
* @return a copy of all the properties that are "in-scope"
* for store.
* @throws org.apache.myrmidon.api.TaskException if theres an error
retrieving propertys
*/
public Map getProperties()
throws TaskException
{
return new HashMap( m_properties );
}
/**
* Set the property with specified name to specified value.
* The specific implementation will apply various rules
* before setting the property.
*
* @param name the name of property
* @param value the value of property
* @throws org.apache.myrmidon.api.TaskException if property can not be
set
*/
public void setProperty( String name, Object value )
throws TaskException
{
m_properties.put( name, value );
}
/**
* Return a child PropertyStore with specified name.
* This is to allow support for scoped stores. However a
* store may choose to be unscoped and just return a
* reference to itself.
*
* @param name the name of child store
* @return the child store
*/
public PropertyStore createChildStore( String name )
{
return this;
}
}
1.29 +2 -2
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/AbstractComponentTest.java
Index: AbstractComponentTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/AbstractComponentTest.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- AbstractComponentTest.java 26 Apr 2002 03:12:50 -0000 1.28
+++ AbstractComponentTest.java 28 Apr 2002 05:51:00 -0000 1.29
@@ -35,7 +35,7 @@
import org.apache.myrmidon.components.role.DefaultRoleManager;
import org.apache.myrmidon.components.type.DefaultTypeManager;
import org.apache.myrmidon.components.event.DefaultTaskEventManager;
-import org.apache.myrmidon.components.store.DefaultPropertyStore;
+import org.apache.myrmidon.components.property.DefaultPropertyStore;
import org.apache.myrmidon.components.workspace.DefaultExecutionFrame;
import org.apache.myrmidon.components.workspace.DefaultTaskContext;
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
@@ -58,7 +58,7 @@
* A base class for tests for the default components.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.28 $ $Date: 2002/04/26 03:12:50 $
+ * @version $Revision: 1.29 $ $Date: 2002/04/28 05:51:00 $
*/
public abstract class AbstractComponentTest
extends AbstractContainerTestCase
1.4 +2 -2
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/property/test/DefaultPropertyResolverTestCase.java
Index: DefaultPropertyResolverTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/property/test/DefaultPropertyResolverTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultPropertyResolverTestCase.java 9 Apr 2002 02:26:34 -0000
1.3
+++ DefaultPropertyResolverTestCase.java 28 Apr 2002 05:51:00 -0000
1.4
@@ -10,14 +10,14 @@
import org.apache.myrmidon.interfaces.property.PropertyResolver;
import
org.apache.myrmidon.components.property.test.AbstractPropertyResolverTestCase;
import org.apache.myrmidon.components.property.DefaultPropertyResolver;
-import org.apache.myrmidon.components.store.DefaultPropertyStore;
+import org.apache.myrmidon.components.property.DefaultPropertyStore;
import org.apache.avalon.excalibur.i18n.Resources;
/**
* Functional tests for [EMAIL PROTECTED]
org.apache.myrmidon.components.property.DefaultPropertyResolver}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
- * @version $Revision: 1.3 $ $Date: 2002/04/09 02:26:34 $
+ * @version $Revision: 1.4 $ $Date: 2002/04/28 05:51:00 $
*/
public class DefaultPropertyResolverTestCase
extends AbstractPropertyResolverTestCase
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>