leosutic 2004/01/30 02:43:09
Modified: framework/impl/src/java/org/apache/avalon/framework/configuration
DefaultConfiguration.java
framework/impl/src/test/org/apache/avalon/framework/configuration/test
DefaultConfigurationTestCase.java
Removed: framework/api/src/java/org/apache/avalon/framework/configuration
MutableConfiguration.java
Log:
Rolling back changes.
Revision Changes Path
1.41 +4 -120
avalon/framework/impl/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java
Index: DefaultConfiguration.java
===================================================================
RCS file:
/home/cvs/avalon/framework/impl/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- DefaultConfiguration.java 29 Jan 2004 16:27:12 -0000 1.40
+++ DefaultConfiguration.java 30 Jan 2004 10:43:09 -0000 1.41
@@ -27,7 +27,7 @@
*/
public class DefaultConfiguration
extends AbstractConfiguration
- implements MutableConfiguration, Serializable
+ implements Serializable
{
/**
* An empty (length zero) array of configuration objects.
@@ -595,9 +595,9 @@
}
/**
- * Check if this configuration is writeable.
+ * heck if this configuration is writeable.
*
- * @throws IllegalStateException if this configuration is read-only
+ * @throws IllegalStateException if this configuration s read-only
*/
protected final void checkWriteable()
throws IllegalStateException
@@ -606,122 +606,6 @@
{
throw new IllegalStateException
( "Configuration is read only and can not be modified" );
- }
- }
-
- /**
- * Returns true iff this DefaultConfiguration has been made read-only.
- */
- protected final boolean isReadOnly()
- {
- return m_readOnly;
- }
-
- /**
- * Convenience function to convert a child to a mutable configuration.
- * If the child is-a MutableConfiguration, and it isn't a read-only
DefaultConfiguration
- * (which isn't really mutable), the child is cast to MutableConfiguration and
returned.
- * If not, the child is replaced in the m_children array with a new writable
DefaultConfiguration
- * that is a shallow copy of the child, and the new child is returned.
- */
- private MutableConfiguration toMutable( Configuration child ) throws
ConfigurationException
- {
- if (child instanceof MutableConfiguration &&
- !( child instanceof DefaultConfiguration && ((DefaultConfiguration)
child).isReadOnly() ))
- {
- // Child is already mutable - return it.
- return (MutableConfiguration) child;
- }
-
- // Child isn't mutable. (This is a mutating operation, so let's check
- // if we're writable.)
- checkWriteable();
-
- DefaultConfiguration config = new DefaultConfiguration( child );
-
- // Replace the old child.
- for( int i = 0; i < m_children.size(); i++)
- {
- if( m_children.get(i) == child )
- {
- m_children.set( i, config );
- break;
- }
- }
-
- return config;
- }
-
- public MutableConfiguration getMutableChild( final String name ) throws
ConfigurationException
- {
- return getMutableChild( name, true );
- }
-
- public MutableConfiguration getMutableChild( final String name, boolean
autoCreate ) throws ConfigurationException
- {
- Configuration child = getChild( name, false );
- if( child == null )
- {
- // No child. Create?
-
- if( autoCreate )
- {
- DefaultConfiguration config = new DefaultConfiguration( name, "-" );
- addChild( config );
- return config;
- }
- else
- {
- return null;
- }
- }
-
- // Child exists
- return toMutable( child );
- }
-
- public MutableConfiguration[] getMutableChildren() throws ConfigurationException
- {
- if( null == m_children )
- {
- return new MutableConfiguration[ 0 ];
- }
- else
- {
- final ArrayList children = new ArrayList();
- final int size = m_children.size();
-
- for( int i = 0; i < size; i++ )
- {
- final Configuration configuration = (Configuration)m_children.get(
i );
- children.add( toMutable( configuration ) );
- }
-
- return (MutableConfiguration[])children.toArray( new
MutableConfiguration[ 0 ] );
- }
- }
-
- public MutableConfiguration[] getMutableChildren( final String name ) throws
ConfigurationException
- {
- if( null == m_children )
- {
- return new MutableConfiguration[ 0 ];
- }
- else
- {
- final ArrayList children = new ArrayList();
- final int size = m_children.size();
-
- for( int i = 0; i < size; i++ )
- {
- final Configuration configuration = (Configuration)m_children.get(
i );
- if( name.equals( configuration.getName() ) )
- {
- children.add( toMutable( configuration ) );
- }
- }
-
- return (MutableConfiguration[])children.toArray( new
MutableConfiguration[ 0 ] );
}
}
1.13 +15 -69
avalon/framework/impl/src/test/org/apache/avalon/framework/configuration/test/DefaultConfigurationTestCase.java
Index: DefaultConfigurationTestCase.java
===================================================================
RCS file:
/home/cvs/avalon/framework/impl/src/test/org/apache/avalon/framework/configuration/test/DefaultConfigurationTestCase.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DefaultConfigurationTestCase.java 29 Jan 2004 16:28:21 -0000 1.12
+++ DefaultConfigurationTestCase.java 30 Jan 2004 10:43:09 -0000 1.13
@@ -21,7 +21,6 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.ConfigurationUtil;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.configuration.MutableConfiguration;
/**
* Test the basic public methods of DefaultConfiguration.
@@ -31,27 +30,27 @@
public final class DefaultConfigurationTestCase extends TestCase
{
private DefaultConfiguration m_configuration;
-
+
public DefaultConfigurationTestCase()
{
this("DefaultConfiguration Test Case");
}
-
+
public DefaultConfigurationTestCase( String name )
{
super( name );
}
-
+
public void setUp()
{
m_configuration = new DefaultConfiguration( "a", "b" );
}
-
+
public void tearDowm()
{
m_configuration = null;
}
-
+
public void testGetValue()
throws Exception
{
@@ -59,7 +58,7 @@
m_configuration.setValue( orgValue );
assertEquals( orgValue, m_configuration.getValue() );
}
-
+
public void testGetValueAsInteger()
throws Exception
{
@@ -68,7 +67,7 @@
m_configuration.setValue( "0x" + strValue );
assertEquals( orgValue, m_configuration.getValueAsInteger() );
}
-
+
public void testGetValueAsBoolen()
throws Exception
{
@@ -76,7 +75,7 @@
m_configuration.setValue("TrUe");
assertEquals( b, m_configuration.getValueAsBoolean() );
}
-
+
public void testGetAttribute()
throws Exception
{
@@ -87,7 +86,7 @@
assertEquals( value, m_configuration.getAttribute( key, defaultStr ) );
assertEquals(defaultStr , m_configuration.getAttribute( "newKey",
defaultStr ) );
}
-
+
public void testMakeReadOnly()
{
final String key = "key";
@@ -95,7 +94,7 @@
String exception = "exception not thrown";
final String exceptionStr ="Configuration is read only";
m_configuration.makeReadOnly();
-
+
try
{
m_configuration.setAttribute( key, value );
@@ -104,18 +103,18 @@
{
exception = exceptionStr;
}
-
+
assertEquals( exception, exceptionStr );
}
-
+
public void testAddRemoveChild()
{
final String childName = "child";
final Configuration child = new DefaultConfiguration( childName, "child
location" );
-
+
m_configuration.addChild( child );
assertEquals( child, m_configuration.getChild( childName ) );
-
+
m_configuration.removeChild( child );
assertEquals( null, m_configuration.getChild( childName, false ) );
}
@@ -125,7 +124,7 @@
DefaultConfiguration root = new DefaultConfiguration( "root", "0:0",
"http://root", "root" );
root.setAttribute( "attr1", "1" );
root.setAttribute( "attr2", "2" );
-
+
DefaultConfiguration child1 = new DefaultConfiguration( "child1", "0:1",
"http://root/child1", "child1" );
DefaultConfiguration child2 = new DefaultConfiguration( "child2", "0:2",
"http://root/child2", "child2" );
@@ -188,58 +187,5 @@
// OK, this is what we expect - the attribute wasn't found.
}
}
-
- public void testMutability() throws Exception
- {
- MutableConfiguration root = new DefaultConfiguration( "root", "-" );
- root.setAttribute( "root1", "root1" );
- root.setAttribute( "root2", "root2" );
- root.getMutableChild( "child1" ).setAttribute( "child1-attr1",
"child1-attr1" );
- root.getMutableChild( "child1" ).setAttribute( "child1-attr2",
"child1-attr2" );
- root.getMutableChild( "child2" ).setAttribute( "child2-attr1",
"child2-attr1" );
- root.getMutableChild( "child2" ).setAttribute( "child2-attr2",
"child2-attr2" );
-
- assertEquals( "root1", root.getAttribute( "root1" ) );
- assertEquals( "root2", root.getAttribute( "root2" ) );
- assertEquals( "child1-attr1", root.getChild( "child1" ).getAttribute(
"child1-attr1" ) );
- assertEquals( "child1-attr2", root.getChild( "child1" ).getAttribute(
"child1-attr2" ) );
- assertEquals( "child2-attr1", root.getChild( "child2" ).getAttribute(
"child2-attr1" ) );
- assertEquals( "child2-attr2", root.getChild( "child2" ).getAttribute(
"child2-attr2" ) );
-
- assertEquals( null, root.getMutableChild( "child3", false ) );
-
- assertEquals( 2, root.getChildren().length );
-
- assertEquals( 2, root.getMutableChildren().length );
- assertEquals( 1, root.getMutableChildren( "child1" ).length );
- assertEquals( 1, root.getMutableChildren( "child2" ).length );
- assertTrue( root.getMutableChildren( "child1" )[0] == root.getChild(
"child1" ) );
-
- // Add an immutable child.
- DefaultConfiguration immutableChild = new DefaultConfiguration(
"immutable-child", "-" );
- immutableChild.makeReadOnly();
-
- try
- {
- immutableChild.setAttribute( "attr", "attr" );
- fail( "Read-only DefaultConfiguration wasn't read-only!" );
- }
- catch (IllegalStateException ise)
- {
- // expected
- }
-
- root.addChild( immutableChild );
-
- // OK, ask to have it back.
- root.getMutableChild( "immutable-child" ).setAttribute( "attr", "attr" );
-
- assertEquals( 1, root.getChildren( "immutable-child" ).length );
- assertEquals( "attr", root.getChild( "immutable-child" ).getAttribute(
"attr" ) );
- }
}
-
-
-
-
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]