Skip to Content.
Sympa Menu

notify-dpml - r1114 - in trunk/main: central/src/docs/metro/tasks/components/context metro/runtime/src/main/net/dpml/metro/runtime metro/test metro/test/src/main/net/dpml/test metro/test/src/main/net/dpml/test/array metro/test/src/test/net/dpml/metro/runtime/test metro/tools/src/main/net/dpml/metro/tools transit/core/src/main/net/dpml/transit transit/core/src/test/net/dpml/transit/test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1114 - in trunk/main: central/src/docs/metro/tasks/components/context metro/runtime/src/main/net/dpml/metro/runtime metro/test metro/test/src/main/net/dpml/test metro/test/src/main/net/dpml/test/array metro/test/src/test/net/dpml/metro/runtime/test metro/tools/src/main/net/dpml/metro/tools transit/core/src/main/net/dpml/transit transit/core/src/test/net/dpml/transit/test
  • Date: Fri, 17 Feb 2006 07:24:33 +0100

Author: mcconnell
Date: 2006-02-17 07:24:14 +0100 (Fri, 17 Feb 2006)
New Revision: 1114

Added:
trunk/main/metro/test/src/main/net/dpml/test/array/
trunk/main/metro/test/src/main/net/dpml/test/array/ArrayTestComponent.java

trunk/main/metro/test/src/test/net/dpml/metro/runtime/test/ArrayTestCase.java
Removed:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ArrayDataType.java
trunk/main/transit/core/src/test/net/dpml/transit/test/ArrayTestCase.java
Modified:
trunk/main/central/src/docs/metro/tasks/components/context/entries.xml
trunk/main/central/src/docs/metro/tasks/components/context/values.xml

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
trunk/main/metro/test/build.xml
trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueDataType.java
trunk/main/transit/core/src/main/net/dpml/transit/Construct.java

trunk/main/transit/core/src/test/net/dpml/transit/test/ConstructTestCase.java
Log:
1. update transit construct class to fully support array types
2. update metro tools and runtime to support array types in context

Modified:
trunk/main/central/src/docs/metro/tasks/components/context/entries.xml
===================================================================
--- trunk/main/central/src/docs/metro/tasks/components/context/entries.xml
2006-02-15 18:16:12 UTC (rev 1113)
+++ trunk/main/central/src/docs/metro/tasks/components/context/entries.xml
2006-02-17 06:24:14 UTC (rev 1114)
@@ -20,8 +20,7 @@

</subsection>

- <subsection name="Entry Attributes (Reference)">
-
+ <subsection name="Entry Attributes (Common)">
<table>
<tr>
<td><tt>key</tt></td>
@@ -30,6 +29,11 @@
<tt>totalWidth</tt>. (refer
java.beans.Introspector#decapitalize
for additional details concerning method to key
transformation).</td>
</tr>
+ </table>
+ </subsection>
+
+ <subsection name="Entry Attributes (for non-array entries)">
+ <table>
<tr>
<td><tt>class</tt></td>
<td>
@@ -67,7 +71,6 @@
</td>
</tr>
</table>
-
</subsection>

<subsection name="Nested Elements">
@@ -76,8 +79,8 @@
<tr>
<td><tt><a href="values.html">value</a></tt></td>
<td>The entry element may contain 0..n nested &lt;value&gt;
directives.
- A value directive allows in-line construction of operation
- or constructor arguments. Nested values may not be used in
+ A value directive allows in-line construction of operation
parameters,
+ array entries, or constructor arguments. Nested values may
not be used in
conjunction with the entry <tt>lookup</tt> or <tt>value</tt>
attributes.</td>
</tr>

Modified:
trunk/main/central/src/docs/metro/tasks/components/context/values.xml
===================================================================
--- trunk/main/central/src/docs/metro/tasks/components/context/values.xml
2006-02-15 18:16:12 UTC (rev 1113)
+++ trunk/main/central/src/docs/metro/tasks/components/context/values.xml
2006-02-17 06:24:14 UTC (rev 1114)
@@ -59,9 +59,10 @@
<tr>
<td><tt><a href="values.html">value</a></tt></td>
<td>The value element may contain 0..n nested &lt;value&gt;
directives.
- A value directive allows in-line construction of operation
- or constructor arguments. Nested values may not be used in
- cnjuntion with the <tt>value</tt> attribute.</td>
+ If the value class is an array class the nested values are
+ interprited as array entries otherwise nested values are
interprited
+ as constructor parameter values. Nested values may not be used
in
+ conjuntion with the <tt>value</tt> attribute.</td>
</tr>
</table>

@@ -97,7 +98,7 @@

</subsection>

- <subsection name="Construct Example">
+ <subsection name="Constructor Example">

<p>
Example of the creation of an instance of <tt>java.awt.Color</tt>

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
2006-02-15 18:16:12 UTC (rev 1113)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -95,7 +95,6 @@
Directive part = controller.loadDirective( uri );
Context context = controller.createContext( part ); // management info
Component handler = controller.createComponent( context ); // runtime
controller
- handler.activate();
Provider instance = handler.getProvider(); // instance controller
Object value = instance.getValue( true ); // service instance
* </pre>
@@ -108,7 +107,7 @@
* @see ComponentModel
* @see Provider
*/
-public class DefaultComponentHandler extends UnicastEventSource
+class DefaultComponentHandler extends UnicastEventSource
implements Component, ComponentHandler, Disposable, ModelListener
{

//--------------------------------------------------------------------------

Modified: trunk/main/metro/test/build.xml
===================================================================
--- trunk/main/metro/test/build.xml 2006-02-15 18:16:12 UTC (rev 1113)
+++ trunk/main/metro/test/build.xml 2006-02-17 06:24:14 UTC (rev 1114)
@@ -270,6 +270,19 @@
<c:component dest="target/test/state.part" test="true"
activation="STARTUP"
type="net.dpml.test.state.ManagedComponent" collection="hard"/>

+ <!-- array test -->
+
+ <c:type class="net.dpml.test.array.ArrayTestComponent" name="array"/>
+ <c:component dest="target/test/array.part" test="true"
+ type="net.dpml.test.array.ArrayTestComponent">
+ <context>
+ <entry key="values">
+ <value value="Hello"/>
+ <value value="World"/>
+ </entry>
+ </context>
+ </c:component>
+
</target>

<target name="install" depends="standard.install">

Added:
trunk/main/metro/test/src/main/net/dpml/test/array/ArrayTestComponent.java
===================================================================
---
trunk/main/metro/test/src/main/net/dpml/test/array/ArrayTestComponent.java
2006-02-15 18:16:12 UTC (rev 1113)
+++
trunk/main/metro/test/src/main/net/dpml/test/array/ArrayTestComponent.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.test.array;
+
+/**
+ * Test the supply of a string array as a context value.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ArrayTestComponent
+{
+ //------------------------------------------------------------------
+ // concerns
+ //------------------------------------------------------------------
+
+ /**
+ * The construction criteria.
+ */
+ public interface Context
+ {
+ /**
+ * Return the assigned values
+ * @return the values array
+ */
+ String[] getValues();
+ }
+
+ //------------------------------------------------------------------
+ // state
+ //------------------------------------------------------------------
+
+ /**
+ * The assigned context instance.
+ */
+ private final Context m_context;
+
+ //------------------------------------------------------------------
+ // constructor
+ //------------------------------------------------------------------
+
+ /**
+ * Creation of a new test component instance.
+ * @param context a component context
+ */
+ public ArrayTestComponent( final Context context )
+ {
+ m_context = context;
+ }
+
+ //------------------------------------------------------------------
+ // Example
+ //------------------------------------------------------------------
+
+ /**
+ * Return the string array assigned to the context.
+ * @return the color value
+ */
+ public String[] getValues()
+ {
+ return m_context.getValues();
+ }
+}

Added:
trunk/main/metro/test/src/test/net/dpml/metro/runtime/test/ArrayTestCase.java
===================================================================
---
trunk/main/metro/test/src/test/net/dpml/metro/runtime/test/ArrayTestCase.java
2006-02-15 18:16:12 UTC (rev 1113)
+++
trunk/main/metro/test/src/test/net/dpml/metro/runtime/test/ArrayTestCase.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.runtime.test;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import net.dpml.part.Controller;
+import net.dpml.part.Component;
+import net.dpml.part.Provider;
+
+import net.dpml.test.array.ArrayTestComponent;
+
+/**
+ * Test dealing with arrays in context entries.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ArrayTestCase extends TestCase
+{
+ private static final Controller CONTROLLER = Controller.STANDARD;
+
+ private URI m_uri;
+
+ /**
+ * Test case setup.
+ * @exception Exception if an error occurs
+ */
+ public void setUp() throws Exception
+ {
+ final String path = "array.part";
+ final File test = new File( System.getProperty( "project.test.dir" )
);
+ m_uri = new File( test, path ).toURI();
+ }
+
+ /**
+ * Validate composite instantiation and in particular that the color
+ * assigned to the child component has been overriden by the parent.
+ * @exception Exception if an error occurs
+ */
+ public void testComponent() throws Exception
+ {
+ Component component = CONTROLLER.createComponent( m_uri );
+ Provider provider = component.getProvider();
+ ArrayTestComponent object = (ArrayTestComponent) provider.getValue(
false );
+ String[] values = object.getValues();
+ boolean flag = Arrays.equals( new String[]{"Hello", "World"}, values
);
+ assertTrue( "array-return-value", flag );
+ }
+
+ static
+ {
+ System.setProperty(
+ "java.util.logging.config.class",
+ System.getProperty(
+ "java.util.logging.config.class",
+ "net.dpml.transit.util.ConfigurationHandler" ) );
+ }
+}

Deleted:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ArrayDataType.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/ArrayDataType.java
2006-02-15 18:16:12 UTC (rev 1113)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/ArrayDataType.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -1,170 +0,0 @@
-/*
- * Copyright (c) 2005 Stephen J. McConnell
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.dpml.metro.tools;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import net.dpml.transit.Value;
-import net.dpml.transit.Construct.Array;
-
-import org.apache.tools.ant.BuildException;
-
-/**
- * Defintion of a context entry parameter directive.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class ArrayDataType implements ValueBuilder
-{
- private String m_classname;
- private List m_params = new ArrayList();
-
- /**
- * Set the context entry classname.
- * @param classname the context entry classname
- */
- public void setClass( final String classname )
- {
- m_classname = classname;
- }
-
- /**
- * Return the context entry parameter classname.
- * @return the classname
- */
- public String getClassname()
- {
- return m_classname;
- }
-
- /**
- * Create, assign and return a new nested entry constructor parameter.
- * @param param the configured value data type
- */
- public void addConfiguredValue( ValueDataType param )
- {
- if( null == param.getClassname() )
- {
- param.setClass( m_classname );
- }
- m_params.add( param );
- }
-
- /**
- * Create, assign and return a new nested entry constructor parameter.
- * @param param the configured array data type
- */
- public void addConfiguredArray( ArrayDataType param )
- {
- if( null == param.getClassname() )
- {
- param.setClass( m_classname );
- }
- m_params.add( param );
- }
-
- /**
- * Return the set of nested param directives.
- * @return the params
- */
- private ValueBuilder[] getValueBuilders()
- {
- return (ValueBuilder[]) m_params.toArray( new ValueBuilder[0] );
- }
-
- /**
- * Build a value datastructure.
- * @param classloader the working classloader
- * @return the serializable value descriptor
- */
- public Value buildValue( ClassLoader classloader )
- {
- String classname = getClassname();
- Class base = getBaseClass( classloader, classname );
- try
- {
- ValueBuilder[] params = getValueBuilders();
- Value[] values = new Value[ params.length ];
- for( int i=0; i<values.length; i++ )
- {
- ValueBuilder p = params[i];
- Class target = p.getTargetClass( classloader );
- if( base.isAssignableFrom( target ) )
- {
- values[i] = p.buildValue( classloader );
- }
- else
- {
- final String error =
- "A value entry of the type ["
- + target.getName()
- + "] is not assignable to the array class ["
- + base.getName()
- + "].";
- throw new BuildException( error );
- }
- }
- return new Array( classname, values );
- }
- catch( BuildException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- final String error =
- "An error occured while building array datatype.";
- throw new BuildException( error, e );
- }
- }
-
- /**
- * Return the base classname.
- * @param classloader the working classloader
- * @return the target class
- */
- public Class getTargetClass( ClassLoader classloader )
- {
- String classname = getClassname();
- return getBaseClass( classloader, classname );
- }
-
- private Class getBaseClass( ClassLoader classloader, String classname )
- {
- if( null == classname )
- {
- return Object.class;
- }
- else
- {
- try
- {
- return classloader.loadClass( classname );
- }
- catch( ClassNotFoundException e )
- {
- final String error =
- "The array type [" + classname + "] is unknown.";
- throw new BuildException( error, e );
- }
- }
- }
-}

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
2006-02-15 18:16:12 UTC (rev 1113)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -563,7 +563,7 @@
//

validateNonNullReturnType( method );
- validateNonArrayReturnType( method, returnType );
+ //validateNonArrayReturnType( method, returnType );
String type = returnType.getName();
return new EntryDescriptor( key, type, EntryDescriptor.REQUIRED
);
}

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueDataType.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueDataType.java
2006-02-15 18:16:12 UTC (rev 1113)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueDataType.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -46,7 +46,16 @@
*/
public void setClass( final String classname )
{
- m_classname = classname;
+ if( classname.endsWith( "[]" ) )
+ {
+ int n = classname.length() - 2;
+ m_classname = "[L" + classname.substring( 0, n ) + ";";
+ System.out.println( "## " + m_classname );
+ }
+ else
+ {
+ m_classname = classname;
+ }
}

/**
@@ -106,17 +115,6 @@
}

/**
- * Create, assign and return a new nested array datatype.
- * @return the new array datatype
- */
- public ArrayDataType createArray()
- {
- final ArrayDataType param = new ArrayDataType();
- m_params.add( param );
- return param;
- }
-
- /**
* Return the set of nested param directives.
* @return the params
*/

Modified: trunk/main/transit/core/src/main/net/dpml/transit/Construct.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/Construct.java
2006-02-15 18:16:12 UTC (rev 1113)
+++ trunk/main/transit/core/src/main/net/dpml/transit/Construct.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -25,6 +25,7 @@
import java.beans.Expression;
import java.io.Serializable;
import java.lang.reflect.Field;
+import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
@@ -414,6 +415,236 @@
Object[] instances = getInstanceValues( map, classloader, args );
String method = getMethodName();
boolean isaClass = ( target.getClass() == Class.class );
+
+ //
+ // check if we are dealing with an array class and if so return and
+ // array created from the array of nested values
+ //
+
+ if( isaClass )
+ {
+ Class c = (Class) target;
+ if( c.isArray() )
+ {
+ Class type = c.getComponentType();
+ if( type.isPrimitive() )
+ {
+ Object result = Array.newInstance( type,
instances.length );
+ if( Integer.TYPE == type )
+ {
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( instance instanceof Integer )
+ {
+ Integer integer = (Integer) instance;
+ int v = integer.intValue();
+ Array.setInt( result, i, v );
+ }
+ else
+ {
+ final String error =
+ "Supplied int array argument class ["
+ + instance.getClass().getName()
+ + "] is not an Integer.";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ else if( Short.TYPE == type )
+ {
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( instance instanceof Short )
+ {
+ Short primitive = (Short) instance;
+ short v = primitive.shortValue();
+ Array.setShort( result, i, v );
+ }
+ else
+ {
+ final String error =
+ "Supplied short array argument class ["
+ + instance.getClass().getName()
+ + "] is not an instance of Short.";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ else if( Long.TYPE == type )
+ {
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( instance instanceof Long )
+ {
+ Long primitive = (Long) instance;
+ long v = primitive.longValue();
+ Array.setLong( result, i, v );
+ }
+ else
+ {
+ final String error =
+ "Supplied long array argument class ["
+ + instance.getClass().getName()
+ + "] is not an instance of Long.";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ else if( Byte.TYPE == type )
+ {
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( instance instanceof Byte )
+ {
+ Byte primitive = (Byte) instance;
+ byte v = primitive.byteValue();
+ Array.setByte( result, i, v );
+ }
+ else
+ {
+ final String error =
+ "Supplied byte array argument class ["
+ + instance.getClass().getName()
+ + "] is not an instance of Byte.";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ else if( Double.TYPE == type )
+ {
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( instance instanceof Double )
+ {
+ Double primitive = (Double) instance;
+ double v = primitive.doubleValue();
+ Array.setDouble( result, i, v );
+ }
+ else
+ {
+ final String error =
+ "Supplied double array argument class ["
+ + instance.getClass().getName()
+ + "] is not an instance of Double.";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ else if( Float.TYPE == type )
+ {
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( instance instanceof Float )
+ {
+ Float primitive = (Float) instance;
+ float v = primitive.floatValue();
+ Array.setFloat( result, i, v );
+ }
+ else
+ {
+ final String error =
+ "Supplied float array argument class ["
+ + instance.getClass().getName()
+ + "] is not an instance of Float.";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ else if( Character.TYPE == type )
+ {
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( instance instanceof Character )
+ {
+ Character primitive = (Character) instance;
+ char v = primitive.charValue();
+ Array.setChar( result, i, v );
+ }
+ else
+ {
+ final String error =
+ "Supplied char array argument class ["
+ + instance.getClass().getName()
+ + "] is not an instance of Character.";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ else if( Boolean.TYPE == type )
+ {
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( instance instanceof Boolean )
+ {
+ Boolean primitive = (Boolean) instance;
+ boolean v = primitive.booleanValue();
+ Array.setBoolean( result, i, v );
+ }
+ else
+ {
+ final String error =
+ "Supplied boolean array argument class ["
+ + instance.getClass().getName()
+ + "] is not an instance of Boolean.";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ else
+ {
+ final String error =
+ "Primitive array class ["
+ + type.getName()
+ + "] is not recognized.";
+ throw new UnsupportedOperationException( error );
+ }
+ }
+ else
+ {
+ Object[] result =
+ (Object[]) Array.newInstance( type, instances.length );
+ for( int i=0; i<instances.length; i++ )
+ {
+ Object instance = instances[i];
+ if( type.isAssignableFrom( instance.getClass() ) )
+ {
+ result[i] = instances[i];
+ }
+ else
+ {
+ final String error =
+ "Array ["
+ + type.getName()
+
+ + "] contains an invalid element ["
+ + instance.getClass().getName()
+ + "].";
+ throw new ValueException( error );
+ }
+ }
+ return result;
+ }
+ }
+ }
+
+ // otherwise its a regular expression
+
if( null == method )
{
if( isaClass )
@@ -537,15 +768,25 @@
*/
private Object getTargetObject( Map map, ClassLoader loader ) throws
ValueException
{
- if( null == m_target )
+ return getTargetObject( map, loader, m_target );
+ }
+
+ /**
+ * Return the instance class using the context classloader.
+ * @return the target object or class
+ * @exception ValueException if target related error occurs
+ */
+ private Object getTargetObject( Map map, ClassLoader loader, String
target ) throws ValueException
+ {
+ if( null == target )
{
return null;
}
- else if( m_target.startsWith( "${" ) )
+ else if( target.startsWith( "${" ) )
{
if( null != map )
{
- String pre = m_target.substring( 2 );
+ String pre = target.substring( 2 );
String key = pre.substring( 0, pre.length() -1 );
if( map.containsKey( key ) )
{
@@ -555,22 +796,33 @@
{
final String error =
"Unresolvable target symbolic expression ["
- + m_target
+ + target
+ "].";
throw new ValueException( error );
}
}
else
{
- return PropertyResolver.resolve( m_target );
+ String resolved = PropertyResolver.resolve( target );
+ return getTargetObject( map, loader, resolved );
}
}
else
{
- return resolveClass( loader, m_target );
+ if( target.endsWith( "[]" ) )
+ {
+ int n = target.length() - 2;
+ String componentClassname = target.substring( 0, n );
+ Class componentClass = resolveType( loader,
componentClassname );
+ return Array.newInstance( componentClass, 0 ).getClass();
+ }
+ else
+ {
+ return resolveClass( loader, target );
+ }
}
}
-
+
/**
* Return the instance class using the context classloader.
* @return the class
@@ -627,6 +879,62 @@
}
}

+ /**
+ * Return the instance class using the context classloader.
+ * @return the class
+ * @exception ComponentException if the parameter class cannot be
resolved
+ */
+ private Class resolveType( ClassLoader loader, String classname ) throws
ValueException
+ {
+ try
+ {
+ return loader.loadClass( classname );
+ }
+ catch( final ClassNotFoundException e )
+ {
+ if( classname.equals( "int" ) )
+ {
+ return Integer.TYPE;
+ }
+ else if( classname.equals( "short" ) )
+ {
+ return Short.TYPE;
+ }
+ else if( classname.equals( "long" ) )
+ {
+ return Long.TYPE;
+ }
+ else if( classname.equals( "byte" ) )
+ {
+ return Byte.TYPE;
+ }
+ else if( classname.equals( "double" ) )
+ {
+ return Double.TYPE;
+ }
+ else if( classname.equals( "float" ) )
+ {
+ return Float.TYPE;
+ }
+ else if( classname.equals( "char" ) )
+ {
+ return Character.TYPE;
+ }
+ else if( classname.equals( "boolean" ) )
+ {
+ return Boolean.TYPE;
+ }
+ else
+ {
+ final String error =
+ "Class not found ["
+ + classname
+ + "].";
+ throw new ValueException( error, e );
+ }
+ }
+ }
+
private ClassLoader resolveClassLoader( ClassLoader classloader )
{
if( null != classloader )
@@ -753,227 +1061,4 @@
return a.equals( b );
}
}
-
-
//--------------------------------------------------------------------------
- // Array
-
//--------------------------------------------------------------------------
-
- /**
- * Array value defintion.
- */
- public static final class Array implements Value
- {
- /**
- * Serial version identifier.
- */
- static final long serialVersionUID = 1L;
-
-
//--------------------------------------------------------------------------
- // state
-
//--------------------------------------------------------------------------
-
- private final String m_classname;
- private final Value[] m_values;
-
-
//--------------------------------------------------------------------------
- // constructors
-
//--------------------------------------------------------------------------
-
- /**
- * Create a new array construct.
- *
- * @param classname the array type
- * @param values the construct values
- */
- public Array( String classname, Value[] values )
- {
- if( null == classname )
- {
- m_classname = Object.class.getName();
- }
- else
- {
- m_classname = classname;
- }
-
- m_values = values;
- }
-
-
//--------------------------------------------------------------------------
- // ArrayDirective
-
//--------------------------------------------------------------------------
-
- /**
- * Return the array classname.
- * @return the classname of the array elements
- */
- public String getClassname()
- {
- return m_classname;
- }
-
- /**
- * Return an array of value element constructor elements.
- * @return the value array
- */
- public Value[] getValues()
- {
- return m_values;
- }
-
-
//--------------------------------------------------------------------------
- // Value
-
//--------------------------------------------------------------------------
-
- /**
- * Resolve an instance from the value using the context classloader.
- * @return the resolved instance
- * @exception Exception if error occurs during instance resolution
- */
- public Object resolve() throws Exception
- {
- return resolve( null, false );
- }
-
- /**
- * Resolve an instance from the value using a supplied context map.
If any
- * target expressions in immediate or nested values contain a symbolic
- * expression the value will be resolved using the supplied map.
- *
- * @param map the context map
- * @return the resolved instance
- * @exception Exception if error occurs during instance resolution
- */
- public Object resolve( Map map ) throws Exception
- {
- return resolve( map, false );
- }
-
- /**
- * Resolve an instance from the value using a supplied isolvation
policy.
- *
- * @param isolate the isolation policy
- * @return the resolved instance
- * @exception Exception if error occurs during instance resolution
- */
- public Object resolve( boolean isolate ) throws Exception
- {
- return resolve( null, isolate );
- }
-
- /**
- * Resolve an instance from the value using a supplied context map.
If any
- * target expressions in immediate or nested values contain a symbolic
- * expression the value will be resolved using the supplied map.
- *
- * @param map the context map
- * @param isolate the isolation policy
- * @return the resolved instance
- * @exception Exception if error occurs during instance resolution
- */
- public Object resolve( Map map, boolean isolate ) throws Exception
- {
- ClassLoader loader =
Thread.currentThread().getContextClassLoader();
- Class c = loader.loadClass( m_classname );
- Object[] instances =
- (Object[]) java.lang.reflect.Array.newInstance( c,
m_values.length );
- for( int i=0; i<m_values.length; i++ )
- {
- Value value = m_values[i];
- instances[i] = value.resolve( map, isolate );
- }
- return instances;
- }
-
- /**
- * Test if the supplied object is equal to this object.
- * @param other the object to compare with this instance
- * @return TRUE if the supplied object is equal to this object
- */
- public boolean equals( Object other )
- {
- if( null == other )
- {
- return false;
- }
- if( !( other instanceof Array ) )
- {
- return false;
- }
- else
- {
- Array directive = (Array) other;
- if( !m_classname.equals( directive.m_classname ) )
- {
- return false;
- }
- else
- {
- return Arrays.equals( m_values, directive.m_values );
- }
- }
- }
-
- /**
- * Return the hashcode for the instance.
- * @return the instance hashcode
- */
- public int hashCode()
- {
- int hash = m_classname.hashCode();
- for( int i=0; i<m_values.length; i++ )
- {
- hash ^= m_values[i].hashCode();
- }
- return hash;
- }
- }
-
- /**
- * Array bean info.
- */
- public static final class ArrayBeanInfo extends SimpleBeanInfo
- {
- private static final BeanDescriptor BEAN_DESCRIPTOR =
setupBeanDescriptor();
-
- /**
- * Return the bean descriptor.
- * @return the descriptor
- */
- public BeanDescriptor getBeanDescriptor()
- {
- return BEAN_DESCRIPTOR;
- }
-
- private static BeanDescriptor setupBeanDescriptor()
- {
- BeanDescriptor descriptor = new BeanDescriptor( Array.class );
- descriptor.setValue(
- "persistenceDelegate",
- new ArrayPersistenceDelegate() );
- return descriptor;
- }
-
- /**
- * Persistence delegate implementation.
- */
- private static class ArrayPersistenceDelegate
- extends DefaultPersistenceDelegate
- {
- /**
- * Return the expression value.
- * @param old the old instance
- * @param encoder the encoder
- * @return the expression
- */
- public Expression instantiate( Object old, Encoder encoder )
- {
- Array construct = (Array) old;
- Object[] args = new Object[2];
- args[0] = construct.getClassname();
- args[1] = construct.getValues();
- return new Expression( old, old.getClass(), "new", args );
- }
- }
- }
}

Deleted:
trunk/main/transit/core/src/test/net/dpml/transit/test/ArrayTestCase.java
===================================================================
--- trunk/main/transit/core/src/test/net/dpml/transit/test/ArrayTestCase.java
2006-02-15 18:16:12 UTC (rev 1113)
+++ trunk/main/transit/core/src/test/net/dpml/transit/test/ArrayTestCase.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -1,94 +0,0 @@
-/*
- * Copyright 2004-2006 Stephen J. McConnell.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.dpml.transit.test;
-
-import net.dpml.transit.Value;
-import net.dpml.transit.Construct;
-import net.dpml.transit.Construct.Array;
-
-/**
- * Construct testcase.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class ArrayTestCase extends AbstractEncodingTestCase
-{
- /**
- * Test creation of a simple construct.
- * @exception Exception if an unexpected error occurs.
- */
- public void testSimpleArray() throws Exception
- {
- Construct a = new Construct( "a" );
- Construct b = new Construct( "b" );
- Value[] args = new Value[]{a, b};
- Array array = new Array( String.class.getName(), args );
- Object value = array.resolve();
- if( null == value )
- {
- throw new NullPointerException( "value" );
- }
- if( value instanceof String[] )
- {
- String[] strings = (String[]) value;
- assertEquals( "length", 2, strings.length );
- }
- else
- {
- throw new IllegalStateException( "result is not an array" );
- }
- }
-
- /**
- * Test creation of a simple construct.
- * @exception Exception if an unexpected error occurs.
- */
- public void testArrayAsCompositeArgument() throws Exception
- {
- Construct a = new Construct( "Hello " );
- Construct b = new Construct( "World!" );
- Value[] args = new Value[]{a, b};
- Array array = new Array( String.class.getName(), args );
-
- Value[] params = new Value[]{array};
- Construct construct = new Construct( Demo.class.getName(), params );
- Demo demo = (Demo) construct.resolve();
- assertNotNull( "demo", demo );
- }
-
- /**
- * Test class.
- */
- public static class Demo
- {
- /**
- * Create a new demo class.
- * @param args the args
- */
- public Demo( String[] args )
- {
- for( int i=0; i<args.length; i++ )
- {
- System.out.print( args[i] );
- }
- System.out.println( "" );
- }
- }
-}

Modified:
trunk/main/transit/core/src/test/net/dpml/transit/test/ConstructTestCase.java
===================================================================
---
trunk/main/transit/core/src/test/net/dpml/transit/test/ConstructTestCase.java
2006-02-15 18:16:12 UTC (rev 1113)
+++
trunk/main/transit/core/src/test/net/dpml/transit/test/ConstructTestCase.java
2006-02-17 06:24:14 UTC (rev 1114)
@@ -23,6 +23,7 @@
import java.util.Date;
import java.util.Map;
import java.util.Hashtable;
+import java.util.Arrays;

import net.dpml.transit.Value;
import net.dpml.transit.Construct;
@@ -197,7 +198,58 @@
}
}

+ public void testSimpleArray() throws Exception
+ {
+ String[] args = new String[]{"aaa", "bbb"};
+ Value s1 = new Construct( "aaa" );
+ Value s2 = new Construct( "bbb" );
+ Value construct = new Construct( args.getClass().getName(), new
Value[]{s1, s2} );
+ String[] result = (String[]) construct.resolve();
+ boolean equal = Arrays.equals( args, result );
+ assertTrue( "simple-array", equal );
+ }
+
+ public void testZeroLengthArray() throws Exception
+ {
+ String[] args = new String[0];
+ Value construct = new Construct( args.getClass().getName(), new
Value[0] );
+ String[] result = (String[]) construct.resolve();
+ boolean equal = Arrays.equals( args, result );
+ assertTrue( "zero-length-array", equal );
+ }
+
/**
+ * Test creation of a simple construct.
+ * @exception Exception if an unexpected error occurs.
+ */
+ public void testArrayAsCompositeArgument() throws Exception
+ {
+ Construct a = new Construct( "Hello " );
+ Construct b = new Construct( "World!" );
+ Construct array = new Construct( String[].class.getName(), new
Value[]{a, b} );
+ Construct construct = new Construct( Demo.class.getName(), new
Value[]{array} );
+ Demo demo = (Demo) construct.resolve();
+ assertNotNull( "demo", demo );
+ }
+
+ /**
+ * Test creation of a simple construct.
+ * @exception Exception if an unexpected error occurs.
+ */
+ public void testPrimitiveArray() throws Exception
+ {
+ int[] args = new int[]{ 1, 2, 3 };
+ Value p1 = new Construct( "int", "1" );
+ Value p2 = new Construct( "int", "2" );
+ Value p3 = new Construct( "int", "3" );
+ Value construct = new Construct( "int[]", new Value[]{p1, p2, p3} );
+ Object result = construct.resolve();
+ int[] array = (int[]) construct.resolve();
+ boolean equal = Arrays.equals( args, array );
+ assertTrue( "primitive-array", equal );
+ }
+
+ /**
* Test construct encoding.
* @exception Exception if an unexpected error occurs.
*/
@@ -211,6 +263,25 @@
}

/**
+ * Test class.
+ */
+ public static class Demo
+ {
+ /**
+ * Create a new demo class.
+ * @param args the args
+ */
+ public Demo( String[] args )
+ {
+ for( int i=0; i<args.length; i++ )
+ {
+ System.out.print( args[i] );
+ }
+ System.out.println( "" );
+ }
+ }
+
+ /**
* Mock class.
*/
public static class Context




  • r1114 - in trunk/main: central/src/docs/metro/tasks/components/context metro/runtime/src/main/net/dpml/metro/runtime metro/test metro/test/src/main/net/dpml/test metro/test/src/main/net/dpml/test/array metro/test/src/test/net/dpml/metro/runtime/test metro/tools/src/main/net/dpml/metro/tools transit/core/src/main/net/dpml/transit transit/core/src/test/net/dpml/transit/test, mcconnell at BerliOS, 02/17/2006

Archive powered by MHonArc 2.6.24.

Top of Page