Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2210 - in development/main/metro: automation/builder/src/main/net/dpml/automation/builder automation/control/src/main/net/dpml/automation/part composition/api/src/main/net/dpml/composition/data composition/api/src/test/net/dpml/composition/data/test composition/builder/src/main/net/dpml/composition/builder composition/builder/src/main/net/dpml/composition/builder/datatypes composition/control/src/main/net/dpml/composition/models composition/impl/src/main/net/dpml/composition/data/builder meta/api/src/main/net/dpml/meta/info meta/api/src/test/net/dpml/meta/info/test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2210 - in development/main/metro: automation/builder/src/main/net/dpml/automation/builder automation/control/src/main/net/dpml/automation/part composition/api/src/main/net/dpml/composition/data composition/api/src/test/net/dpml/composition/data/test composition/builder/src/main/net/dpml/composition/builder composition/builder/src/main/net/dpml/composition/builder/datatypes composition/control/src/main/net/dpml/composition/models composition/impl/src/main/net/dpml/composition/data/builder meta/api/src/main/net/dpml/meta/info meta/api/src/test/net/dpml/meta/info/test
  • Date: Tue, 05 Apr 2005 13:12:01 -0400

Author: mcconnell AT dpml.net
Date: Tue Apr 5 13:11:57 2005
New Revision: 2210

Added:

development/main/metro/automation/builder/src/main/net/dpml/automation/builder/PartReferenceBuilder.java

development/main/metro/automation/control/src/main/net/dpml/automation/part/PartReference.java
Modified:

development/main/metro/automation/builder/src/main/net/dpml/automation/builder/PartBuilder.java

development/main/metro/composition/api/src/main/net/dpml/composition/data/ComponentProfile.java

development/main/metro/composition/api/src/test/net/dpml/composition/data/test/ComponentProfileTestCase.java

development/main/metro/composition/api/src/test/net/dpml/composition/data/test/ContainmentProfileTestCase.java

development/main/metro/composition/builder/src/main/net/dpml/composition/builder/ComponentBuilderTask.java

development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypeBuilderTask.java

development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypesTask.java

development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/PartsDataType.java

development/main/metro/composition/control/src/main/net/dpml/composition/models/StandardComponentModel.java

development/main/metro/composition/impl/src/main/net/dpml/composition/data/builder/XMLComponentProfileCreator.java

development/main/metro/meta/api/src/main/net/dpml/meta/info/PartDescriptor.java
development/main/metro/meta/api/src/main/net/dpml/meta/info/Type.java

development/main/metro/meta/api/src/test/net/dpml/meta/info/test/PartDescriptorTestCase.java

development/main/metro/meta/api/src/test/net/dpml/meta/info/test/TypeTestCase.java
Log:
Update the codebase to add support for distinct part references (a reference
to a part together with the key that the container uses to refernce the
part). This is needed when handling parts as nested elements within a
composite part. Also cleaned up the PartDescriptor to aggregate the
operations performed per part. This results in a cleaner maping of the
aggregated set of part references held by a type - and for each part
reference we can access all of the operations relevant for that part (thereby
allowing validation of the assmbly time assignment of a part into a composite
component).

Modified:
development/main/metro/automation/builder/src/main/net/dpml/automation/builder/PartBuilder.java
==============================================================================
---
development/main/metro/automation/builder/src/main/net/dpml/automation/builder/PartBuilder.java
(original)
+++
development/main/metro/automation/builder/src/main/net/dpml/automation/builder/PartBuilder.java
Tue Apr 5 13:11:57 2005
@@ -22,6 +22,7 @@
import java.io.IOException;

import net.dpml.automation.part.Part;
+import net.dpml.automation.part.PartReference;
import net.dpml.automation.control.BadStrategyException;

/**
@@ -40,11 +41,6 @@
URI getPartHandlerURI();

/**
- * Return the key identifying the part that this builder is building.
- */
- String getKey();
-
- /**
* Build the part.
* @param classloader the classloader to use if type creation is required
* @return the serializable part

Added:
development/main/metro/automation/builder/src/main/net/dpml/automation/builder/PartReferenceBuilder.java
==============================================================================
--- (empty file)
+++
development/main/metro/automation/builder/src/main/net/dpml/automation/builder/PartReferenceBuilder.java
Tue Apr 5 13:11:57 2005
@@ -0,0 +1,49 @@
+/*
+ * 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.automation.builder;
+
+import java.net.URI;
+import java.io.IOException;
+
+import net.dpml.automation.part.Part;
+import net.dpml.automation.part.PartReference;
+import net.dpml.automation.control.BadStrategyException;
+
+/**
+ * The contract for builders that create component part.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public interface PartReferenceBuilder extends PartBuilder
+{
+ /**
+ * Return the key identifying the part that this builder is building.
+ */
+ String getKey();
+
+ /**
+ * Build the part.
+ * @param classloader the classloader to use if type creation is required
+ * @return the serializable part
+ * @exception Exception if a construction error occurs
+ */
+ PartReference buildPartReference( ClassLoader classloader )
+ throws IntrospectionException, IOException, ClassNotFoundException;
+}

Added:
development/main/metro/automation/control/src/main/net/dpml/automation/part/PartReference.java
==============================================================================
--- (empty file)
+++
development/main/metro/automation/control/src/main/net/dpml/automation/part/PartReference.java
Tue Apr 5 13:11:57 2005
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2004 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.automation.part;
+
+import java.io.Serializable;
+
+
+/**
+ * A <code>PartReference</code> is a serializable object that contains a key
and
+ * an associated part.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id: Parameter.java 2119 2005-03-23 02:04:46Z mcconnell AT dpml.net
$
+ */
+public class PartReference implements Serializable
+{
+ /**
+ * The key.
+ */
+ private final String m_key;
+
+ /**
+ * The supplied argument.
+ */
+ private Part m_part;
+
+ /**
+ * Creation of a new parameter using the default
<code>java.lang.String</code>
+ * type and a supplied value.
+ *
+ * @param value the string value
+ */
+ public PartReference( final String key, Part part )
+ {
+ if( null == key )
+ {
+ throw new NullPointerException( "key" );
+ }
+ if( null == part )
+ {
+ throw new NullPointerException( "part" );
+ }
+ m_key = key;
+ m_part = part;
+ }
+
+ /**
+ * Return the key.
+ * @return the key
+ */
+ public String getKey()
+ {
+ return m_key;
+ }
+
+ /**
+ * Return the part.
+ */
+ public Part getPart()
+ {
+ return m_part;
+ }
+
+ /**
+ * 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;
+ }
+ else
+ {
+ if( false == ( other instanceof PartReference ) )
+ {
+ return false;
+ }
+ else
+ {
+ PartReference reference = (PartReference) other;
+ if( false == m_key.equals( reference.getKey() ) )
+ {
+ return false;
+ }
+ else
+ {
+ return m_part.equals( reference.getPart() );
+ }
+ }
+ }
+ }
+
+ /**
+ * Return the hashcode for the instance.
+ * @return the instance hashcode
+ */
+ public int hashCode()
+ {
+ int hash = m_key.hashCode();
+ hash ^= m_part.hashCode();
+ return hash;
+ }
+}

Modified:
development/main/metro/composition/api/src/main/net/dpml/composition/data/ComponentProfile.java
==============================================================================
---
development/main/metro/composition/api/src/main/net/dpml/composition/data/ComponentProfile.java
(original)
+++
development/main/metro/composition/api/src/main/net/dpml/composition/data/ComponentProfile.java
Tue Apr 5 13:11:57 2005
@@ -19,6 +19,7 @@
package net.dpml.composition.data;

import net.dpml.automation.part.Part;
+import net.dpml.automation.part.PartReference;

import net.dpml.configuration.Configuration;
import net.dpml.parameters.Parameters;
@@ -141,7 +142,7 @@
/**
* The internal parts.
*/
- private final Part[] m_parts;
+ private final PartReference[] m_parts;


//--------------------------------------------------------------------------
// constructor
@@ -195,7 +196,7 @@
final CategoriesDirective categories,
final ContextDirective context,
final DependencyDirective[] dependencies,
- final Part[] parts,
+ final PartReference[] parts,
final Parameters parameters,
final Configuration config,
final ClassLoaderDirective classloader,
@@ -242,7 +243,7 @@
}
if( null == parts )
{
- m_parts = new Part[0];
+ m_parts = new PartReference[0];
}
else
{
@@ -310,7 +311,7 @@
*
* @return the array of internal parts.
*/
- public Part[] getParts()
+ public PartReference[] getParts()
{
return m_parts;
}
@@ -409,15 +410,36 @@
{
return false;
}
- DependencyDirective[] mine = getDependencyDirectives();
- DependencyDirective[] yours = profile.getDependencyDirectives();
- for( int i=0; i<mine.length; i++ )
- {
- DependencyDirective a = mine[i];
- DependencyDirective b = yours[i];
- if( false == a.equals( b ) )
+ else
+ {
+ DependencyDirective[] mine = getDependencyDirectives();
+ DependencyDirective[] yours = profile.getDependencyDirectives();
+ for( int i=0; i<mine.length; i++ )
{
- return false;
+ DependencyDirective a = mine[i];
+ DependencyDirective b = yours[i];
+ if( false == a.equals( b ) )
+ {
+ return false;
+ }
+ }
+ }
+ if( getParts().length != profile.getParts().length )
+ {
+ return false;
+ }
+ else
+ {
+ PartReference[] mine = getParts();
+ PartReference[] yours = profile.getParts();
+ for( int i=0; i<mine.length; i++ )
+ {
+ PartReference a = mine[i];
+ PartReference b = yours[i];
+ if( false == a.equals( b ) )
+ {
+ return false;
+ }
}
}
return true;
@@ -457,7 +479,10 @@
{
hash ^= m_dependencies[i].hashCode();
}
+ for( int i=0; i<m_parts.length; i++ )
+ {
+ hash ^= m_parts[i].hashCode();
+ }
return hash;
}
-
}

Modified:
development/main/metro/composition/api/src/test/net/dpml/composition/data/test/ComponentProfileTestCase.java
==============================================================================
---
development/main/metro/composition/api/src/test/net/dpml/composition/data/test/ComponentProfileTestCase.java
(original)
+++
development/main/metro/composition/api/src/test/net/dpml/composition/data/test/ComponentProfileTestCase.java
Tue Apr 5 13:11:57 2005
@@ -20,6 +20,7 @@
import junit.framework.TestCase;

import net.dpml.automation.part.Part;
+import net.dpml.automation.part.PartReference;

import net.dpml.composition.data.ComponentProfile;
import net.dpml.composition.data.ContextDirective;
@@ -57,7 +58,7 @@
private Configuration m_configuration;
private ContextDirective m_context;
private DependencyDirective[] m_dependencies;
- private Part[] m_parts;
+ private PartReference[] m_parts;
private String m_name;
private String m_classname;
private int m_collection;
@@ -83,7 +84,7 @@
m_categories = new CategoriesDirective( new CategoryDirective[0] );
m_collection = InfoDescriptor.SOFT_COLLECTION;
m_classpath = null;
- m_parts = new Part[0];
+ m_parts = new PartReference[0];
m_lifestyle = "request";
}


Modified:
development/main/metro/composition/api/src/test/net/dpml/composition/data/test/ContainmentProfileTestCase.java
==============================================================================
---
development/main/metro/composition/api/src/test/net/dpml/composition/data/test/ContainmentProfileTestCase.java
(original)
+++
development/main/metro/composition/api/src/test/net/dpml/composition/data/test/ContainmentProfileTestCase.java
Tue Apr 5 13:11:57 2005
@@ -20,6 +20,7 @@
import junit.framework.TestCase;

import net.dpml.automation.part.Part;
+import net.dpml.automation.part.PartReference;

import net.dpml.composition.data.ServiceDirective;
import net.dpml.composition.data.ClassLoaderDirective;
@@ -53,7 +54,7 @@
public class ContainmentProfileTestCase extends AbstractSerializableTestCase
{
private CategoriesDirective m_categories;
- private Part[] m_parts;
+ private PartReference[] m_parts;
private Mode m_mode;
private int m_activation;
private Parameters m_parameters;
@@ -105,7 +106,7 @@
m_collection = InfoDescriptor.SOFT_COLLECTION;
m_classpath = new ClassLoaderDirective();
m_lifestyle = "model";
- m_parts = new Part[0];
+ m_parts = new PartReference[0];
return new ComponentProfile(
name, m_activation, m_collection, m_lifestyle, m_classname,
m_categories,
m_context, m_dependencies, m_parts, m_parameters,

Modified:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/ComponentBuilderTask.java
==============================================================================
---
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/ComponentBuilderTask.java
(original)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/ComponentBuilderTask.java
Tue Apr 5 13:11:57 2005
@@ -72,7 +72,9 @@
import net.dpml.automation.control.DelegationException;
import net.dpml.automation.part.Part;
import net.dpml.automation.part.PartHolder;
+import net.dpml.automation.part.PartReference;
import net.dpml.automation.builder.PartBuilder;
+import net.dpml.automation.builder.PartReferenceBuilder;
import net.dpml.automation.builder.IntrospectionException;

import net.dpml.configuration.Configuration;
@@ -107,9 +109,10 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
*/
-public class ComponentBuilderTask extends ProjectTask implements PartBuilder
+public class ComponentBuilderTask extends ProjectTask implements
PartReferenceBuilder
{
private URI m_uri;
+ private String m_key;

private String m_name;
private String m_classname;
@@ -141,6 +144,11 @@
m_uri = uri;
}

+ public void setKey( String key )
+ {
+ m_key = key;
+ }
+
public void setName( String name )
{
m_name = name;
@@ -322,6 +330,10 @@
+ "]";
throw new BuildException( error, e, getLocation() );
}
+ catch( BuildException e )
+ {
+ throw e;
+ }
catch( Exception e )
{
final String error =
@@ -418,12 +430,6 @@
// PartBuilder
//---------------------------------------------------------------------

- public Part buildPart( ClassLoader classloader )
- throws IntrospectionException, IOException, ClassNotFoundException
- {
- return buildComponentProfile( classloader );
- }
-
/**
* Return a urn identitifying the part handler for this builder.
*
@@ -434,6 +440,16 @@
return PART_HANDLER_URI;
}

+ public Part buildPart( ClassLoader classloader )
+ throws IntrospectionException, IOException, ClassNotFoundException
+ {
+ return buildComponentProfile( classloader );
+ }
+
+ //---------------------------------------------------------------------
+ // PartReferenceBuilder
+ //---------------------------------------------------------------------
+
/**
* Return the part key.
*
@@ -441,7 +457,22 @@
*/
public String getKey()
{
- return getName();
+ if( null == m_key )
+ {
+ final String message =
+ "Missing key attribute for nested part reference. Using part
name instead.";
+ log( message, Project.MSG_VERBOSE );
+ return m_name;
+ }
+ return m_key;
+ }
+
+ public PartReference buildPartReference( ClassLoader classloader )
+ throws IntrospectionException, IOException, ClassNotFoundException
+ {
+ String key = getKey();
+ Part part = buildComponentProfile( classloader );
+ return new PartReference( key, part );
}

//---------------------------------------------------------------------
@@ -517,7 +548,7 @@
CategoriesDirective categories = getCategoriesDirective();
ContextDirective context = getContextDirective( classloader, type );
DependencyDirective[] dependencies = getDependencyDirectives();
- Part[] parts = getParts( classloader );
+ PartReference[] parts = getParts( classloader );

Parameters parameters = getParameters();
Configuration configuration = getConfiguration();
@@ -792,12 +823,12 @@
}
}

- private Part[] getParts( ClassLoader classloader )
+ private PartReference[] getParts( ClassLoader classloader )
throws IntrospectionException, IOException, ClassNotFoundException
{
if( null == m_parts )
{
- return new Part[0];
+ return new PartReference[0];
}
else
{

Modified:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypeBuilderTask.java
==============================================================================
---
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypeBuilderTask.java
(original)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypeBuilderTask.java
Tue Apr 5 13:11:57 2005
@@ -45,6 +45,7 @@
import net.dpml.meta.info.EntryDescriptor;
import net.dpml.meta.info.CategoryDescriptor;
import net.dpml.meta.info.PartDescriptor;
+import net.dpml.meta.info.PartDescriptor.Operation;

import net.dpml.automation.builder.IntrospectionException;
import net.dpml.automation.control.BadStrategyException;
@@ -231,7 +232,6 @@
+ "].";
throw new IntrospectionException( error );
}
-
}

private String getLifestylePreference( Class subject, boolean threadsafe
) throws IntrospectionException
@@ -497,7 +497,7 @@
validateNoExceptions( method );
validateNoParameters( method );

- String key = getPartKey( method );
+ String key = getPartKey( method, "get" );
String type = returnType.getName();
return new DependencyDescriptor( key, type );
}
@@ -544,8 +544,9 @@
else
{
//
- // For each method in the Parts interface we construct a part
- // descriptor that establishes the part key, type, and semantics.
+ // Based on the method declarations in the parts inner class
+ // we collect a list of the unique keys where each key
represents a
+ // unique part.
//

Method[] methods = parts.getMethods();
@@ -553,10 +554,132 @@
for( int i=0; i<methods.length; i++ )
{
Method method = methods[i];
- PartDescriptor descriptor = createPartDescriptor( method );
- list.add( descriptor );
+ String key = getPartKey( method );
+ if( false == list.contains( key ) )
+ {
+ list.add( key );
+ }
+ }
+
+ String[] keys = (String[]) list.toArray( new String[0] );
+ PartDescriptor[] descriptors = new PartDescriptor[ keys.length ];
+ for( int i=0; i<keys.length; i++ )
+ {
+ String key = keys[i];
+ Operation[] operations = getOperations( key, methods );
+ PartDescriptor descriptor = new PartDescriptor( key,
operations );
+ descriptors[i] = descriptor;
+ }
+
+ return descriptors;
+ }
+ }
+
+ private Operation[] getOperations( String key, Method[] methods ) throws
IntrospectionException
+ {
+ ArrayList list = new ArrayList();
+ for( int i=0; i<methods.length; i++ )
+ {
+ Method method = methods[i];
+ if( key.equals( getPartKey( method ) ) )
+ {
+ Operation operation = getOperation( method );
+ list.add( operation );
}
- return (PartDescriptor[]) list.toArray( new PartDescriptor[0] );
+ }
+ return (Operation[]) list.toArray( new Operation[0] );
+ }
+
+ private Operation getOperation( Method method ) throws
IntrospectionException
+ {
+ final String name = method.getName();
+ if( name.startsWith( PartDescriptor.GET_KEY ) )
+ {
+ validateNoExceptions( method );
+ validateAtMostOneParameter( method );
+ Class returnType = method.getReturnType();
+ validateNonNullReturnType( method, returnType );
+ validateNonArrayReturnType( method, returnType );
+ String type = returnType.getName();
+ return new Operation( PartDescriptor.GET, type );
+ }
+ else if( name.startsWith( PartDescriptor.CREATE_KEY ) )
+ {
+ validateNoParameters( method );
+ Class returnType = method.getReturnType();
+ validateNonNullReturnType( method, returnType );
+ validateNonArrayReturnType( method, returnType );
+ String type = returnType.getName();
+ return new Operation( PartDescriptor.CREATE, type );
+ }
+ else if( name.startsWith( PartDescriptor.RELEASE_KEY ) )
+ {
+ validateNoExceptions( method );
+ Class param = validateSingleParameter( method );
+ validateNonArrayParameter( method, param );
+ validateNonNullParameter( method, param );
+ Class returnType = method.getReturnType();
+ validateNullReturnType( method, returnType );
+ String classname = param.getName();
+ return new Operation( PartDescriptor.RELEASE, classname );
+ }
+ else
+ {
+ final String error =
+ "Unrecognized part accessor method signature ["
+ + name
+ + "]";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private String getPartKey( Method method )
+ {
+ String name = method.getName();
+ if( name.startsWith( PartDescriptor.GET_KEY ) )
+ {
+ return getPartKey( method, PartDescriptor.GET );
+ }
+ else if( name.startsWith( PartDescriptor.CREATE_KEY ) )
+ {
+ return getPartKey( method, PartDescriptor.CREATE );
+ }
+ else if( name.startsWith( PartDescriptor.RELEASE_KEY ) )
+ {
+ return getPartKey( method, PartDescriptor.RELEASE );
+ }
+ else
+ {
+ final String error =
+ "Unrecognized part accessor method signature ["
+ + name
+ + "]";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private String getPartKey( Method method, int semantic )
+ {
+ String name = method.getName();
+ if( PartDescriptor.GET == semantic )
+ {
+ return formatKey( name, 3 );
+ }
+ else if( PartDescriptor.CREATE == semantic )
+ {
+ return formatKey( name, 6 );
+ }
+ else if( PartDescriptor.RELEASE == semantic )
+ {
+ return formatKey( name, 7 );
+ }
+ else
+ {
+ final String error =
+ "Unrecognized part accessor method signature ["
+ + name
+ + "]";
+ throw new IllegalArgumentException( error );
}
}

@@ -566,6 +689,7 @@
* runtime instance. The part builder establishes the deployment
solution for the
* part implementation.
*/
+ /*
private PartDescriptor createPartDescriptor( Method method )
throws IntrospectionException
{
@@ -622,6 +746,7 @@
throw new IntrospectionException( error );
}
}
+ */

private ContextDescriptor createContextDescriptor( Class subject )
throws IntrospectionException
{
@@ -679,7 +804,7 @@
validateMethodName( method );
validateNoExceptions( method );

- String key = getPartKey( method );
+ String key = getPartKey( method, "get" );

Class returnType = method.getReturnType();
if( method.getParameterTypes().length == 0 )
@@ -723,16 +848,17 @@
}
}

- private String getPartKey( Method method )
+ private String getPartKey( Method method, String prefix )
{
- return getPartKey( method, "get" );
+ String name = method.getName();
+ int offset = prefix.length();
+ return formatKey( name, offset );
}

- private String getPartKey( Method method, String prefix )
+ private String formatKey( String key, int offset )
{
- String name = method.getName();
- String key = name.substring( prefix.length() );
- return formatKey( key );
+ String k = key.substring( offset );
+ return formatKey( k );
}

private String formatKey( String key )
@@ -760,6 +886,19 @@
return null;
}

+ private void validateNonNullParameter( Method method, Class type )
throws IntrospectionException
+ {
+ if( Void.TYPE.equals( type ) )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] declares a null parameter.";
+ throw new IntrospectionException( error );
+ }
+ }
+
+
private void validateNonNullReturnType( Method method, Class returnType
) throws IntrospectionException
{
if( Void.TYPE.equals( returnType ) )
@@ -873,6 +1012,33 @@
}
}

+ private Class validateSingleParameter( Method method ) throws
IntrospectionException
+ {
+ Class[] parameterTypes = method.getParameterTypes();
+ if( parameterTypes.length != 1 )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] does not declare a single parameter argument type.";
+ throw new IntrospectionException( error );
+ }
+ return parameterTypes[0];
+ }
+
+
+ private void validateNonArrayParameter( Method method, Class type )
throws IntrospectionException
+ {
+ if( null != type.getComponentType() )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] declares an array parameter type.";
+ throw new IntrospectionException( error );
+ }
+ }
+
private Class loadSubjectClass( ClassLoader classloader )
{
if( null == m_classname )

Modified:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypesTask.java
==============================================================================
---
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypesTask.java
(original)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypesTask.java
Tue Apr 5 13:11:57 2005
@@ -122,6 +122,11 @@
final TypeHolder holder = new TypeHolder( handler, bytes );
SerializableObjectHelper.write( holder, file );
}
+ catch( IntrospectionException e )
+ {
+ final String error = e.getMessage();
+ throw new BuildException( error, e, getLocation() );
+ }
catch( Exception e )
{
final String error =

Modified:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/PartsDataType.java
==============================================================================
---
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/PartsDataType.java
(original)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/PartsDataType.java
Tue Apr 5 13:11:57 2005
@@ -24,7 +24,9 @@
import java.net.URI;

import net.dpml.automation.part.Part;
+import net.dpml.automation.part.PartReference;
import net.dpml.automation.builder.PartBuilder;
+import net.dpml.automation.builder.PartReferenceBuilder;
import net.dpml.automation.builder.IntrospectionException;

import net.dpml.composition.builder.ComponentBuilderTask;
@@ -68,12 +70,12 @@
* Create a new constructed value builder.
* @return a part builder
*/
- public EntryDataType createValue()
- {
- final EntryDataType builder = new EntryDataType();
- m_builders.add( builder );
- return builder;
- }
+ //public EntryDataType createValue()
+ //{
+ // final EntryDataType builder = new EntryDataType();
+ // m_builders.add( builder );
+ // return builder;
+ //}

/**
* Operation used to construct a custom part type directive.
@@ -84,7 +86,7 @@
public Object createDynamicElement( String uri, String name, String
qualified )
{
String path = getProject().replaceProperties( uri );
- PartBuilder builder = loadPartHandler( path, name );
+ PartReferenceBuilder builder = loadPartHandler( path, name );
if( null != builder )
{
m_builders.add( builder );
@@ -92,11 +94,11 @@
return builder;
}

- private PartBuilder loadPartHandler( String uri, String name ) throws
BuildException
+ private PartReferenceBuilder loadPartHandler( String uri, String name )
throws BuildException
{
String urn = uri + ":" + name;
Object builder = null;
- PartBuilder partBuilder = null;
+ PartReferenceBuilder partBuilder = null;
String target = m_owner.getOwningTarget().getName();
Location location = m_owner.getLocation();
ClassLoader context = Thread.currentThread().getContextClassLoader();
@@ -105,7 +107,7 @@
Thread.currentThread().setContextClassLoader(
getClass().getClassLoader() );
Project project = getProject();
builder = project.createDataType( urn );
- partBuilder = (PartBuilder) builder;
+ partBuilder = (PartReferenceBuilder) builder;
return partBuilder ;
}
catch( ClassCastException e )
@@ -121,7 +123,7 @@
+ m_owner.getTaskName()
+ "><parts> within the target <"
+ target
- + "> does not implement the net.dpml.metro.tools.PartBuilder
interface.";
+ + "> does not implement the
net.dpml.metro.tools.PartReferenceBuilder interface.";
throw new BuildException( error, e );
}
catch( BuildException e )
@@ -162,24 +164,24 @@
* Return the set of parts contained within this container.
* @return the contained parts
*/
- public PartBuilder[] getPartBuilders()
+ public PartReferenceBuilder[] getPartBuilders()
{
- return (PartBuilder[]) m_builders.toArray( new PartBuilder[0] );
+ return (PartReferenceBuilder[]) m_builders.toArray( new
PartReferenceBuilder[0] );
}

/**
* Return the set of parts contained within this container.
* @return the contained parts
*/
- public Part[] getParts( ClassLoader classloader )
+ public PartReference[] getParts( ClassLoader classloader )
throws IntrospectionException, IOException, ClassNotFoundException
{
- PartBuilder[] builders = (PartBuilder[]) m_builders.toArray( new
PartBuilder[0] );
- Part[] parts = new Part[ builders.length ];
+ PartReferenceBuilder[] builders = (PartReferenceBuilder[])
m_builders.toArray( new PartReferenceBuilder[0] );
+ PartReference[] parts = new PartReference[ builders.length ];
for( int i=0; i<builders.length; i++ )
{
- PartBuilder builder = builders[i];
- parts[i] = builder.buildPart( classloader );
+ PartReferenceBuilder builder = builders[i];
+ parts[i] = builder.buildPartReference( classloader );
}
return parts;
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/models/StandardComponentModel.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/models/StandardComponentModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/models/StandardComponentModel.java
Tue Apr 5 13:11:57 2005
@@ -33,6 +33,7 @@
import net.dpml.automation.control.Controller;
import net.dpml.automation.control.DelegationException;
import net.dpml.automation.part.Part;
+import net.dpml.automation.part.PartReference;

import net.dpml.composition.data.ComponentProfile;
import net.dpml.composition.data.ContextDirective;
@@ -148,11 +149,13 @@

String newPartition = getQualifiedName() + "/";
m_parts = new PartsModel( controller, this, newPartition,
classloader );
- Part[] parts = profile.getParts();
+ PartReference[] parts = profile.getParts();
for( int i=0; i<parts.length; i++ )
{
- Part part = parts[i];
- m_parts.addPartToCollection( null, part, false );
+ PartReference reference = parts[i];
+ String key = reference.getKey();
+ Part part = reference.getPart();
+ m_parts.addPartToCollection( key, part, false );
}

//

Modified:
development/main/metro/composition/impl/src/main/net/dpml/composition/data/builder/XMLComponentProfileCreator.java
==============================================================================
---
development/main/metro/composition/impl/src/main/net/dpml/composition/data/builder/XMLComponentProfileCreator.java
(original)
+++
development/main/metro/composition/impl/src/main/net/dpml/composition/data/builder/XMLComponentProfileCreator.java
Tue Apr 5 13:11:57 2005
@@ -20,6 +20,7 @@
import java.util.ArrayList;

import net.dpml.automation.part.Part;
+import net.dpml.automation.part.PartReference;

import net.dpml.logging.data.CategoriesDirective;

@@ -123,7 +124,7 @@
// not supported in XML
//

- final Part[] parts = new Part[0];
+ final PartReference[] parts = new PartReference[0];
final ClassLoaderDirective cld = new ClassLoaderDirective();

//

Modified:
development/main/metro/meta/api/src/main/net/dpml/meta/info/PartDescriptor.java
==============================================================================
---
development/main/metro/meta/api/src/main/net/dpml/meta/info/PartDescriptor.java
(original)
+++
development/main/metro/meta/api/src/main/net/dpml/meta/info/PartDescriptor.java
Tue Apr 5 13:11:57 2005
@@ -32,6 +32,7 @@
* {
* Gizmo createGizmo();
* Gizmo getGizmo();
+ * Gizmo getGizmo( Object id );
* void releaseGizmo( Gizmo gizmo );
* }
*
@@ -87,14 +88,9 @@
private final String m_key;

/**
- * The type classname (normally the return type).
+ * The set of operations applicable to the assigned part.
*/
- private final String m_type;
-
- /**
- * The method semantics flag - one of GET, CREATE or RELEASE.
- */
- private final int m_semantic;
+ private final Operation[] m_operations;

/**
* Construct a part descriptor with the supplied key, type and default
get semantics.
@@ -102,44 +98,21 @@
* @param key the key resolved from the method name
* @param type the argument type corresponding to the method return type
* for get and create methods, and the single parameter for the
release method
- * @exception NullPointerException if key or type is null
+ * @exception NullPointerException if key or operations array is null
*/
- public PartDescriptor( final String key, final String type ) throws
NullPointerException
- {
- this( key, type, GET );
- }
-
- /**
- * Construct a part descriptor with the supplied key, type and semantic.
- *
- * @param key the key resolved from the method name
- * @param type the argument type corresponding to the method return type
- * for get and create methods, and the single parameter for the
release method
- * @param semantic the operation semantics ( GET, CREATE or RELEASE )
- * @exception NullPointerException if key or type is null
- * @exception IllegalArgumentException if the semantic value is invalid
- */
- public PartDescriptor( final String key, final String type, int semantic
)
- throws NullPointerException, IllegalArgumentException
+ public PartDescriptor( final String key, final Operation[] operations )
throws NullPointerException
{
if ( null == key )
{
throw new NullPointerException( "key" );
}
- if ( null == type )
+ if ( null == operations )
{
- throw new NullPointerException( "type" );
- }
- if( ( semantic < RELEASE) || ( semantic > CREATE ) )
- {
- final String error =
- "Semantic argument is out of range.";
- throw new IllegalArgumentException( error );
+ throw new NullPointerException( "operations" );
}

m_key = key;
- m_type = type;
- m_semantic = semantic;
+ m_operations = operations;
}

/**
@@ -153,23 +126,13 @@
}

/**
- * Return the return type.
+ * Return the array of operations.
*
- * @return the type classname
+ * @return the operations array
*/
- public String getType()
+ public Operation[] getOperations()
{
- return m_type;
- }
-
- /**
- * Return the semantics for the part reference.
- *
- * @return the semantic identifier
- */
- public int getSemantic()
- {
- return m_semantic;
+ return m_operations;
}

/**
@@ -192,15 +155,27 @@
{
return false;
}
- else if( false == m_type.equals( part.getType() ) )
+ else
{
- return false;
+ return equals( getOperations(), part.getOperations() );
}
- else
+ }
+ }
+
+ private boolean equals( Operation[] ops1, Operation[] ops2 )
+ {
+ if( ops1.length != ops2.length )
+ {
+ return false;
+ }
+ for( int i=0; i<ops1.length; i++ )
+ {
+ if( false == ops1[i].equals( ops2[i] ) )
{
- return m_semantic == part.getSemantic();
+ return false;
}
}
+ return true;
}

/**
@@ -210,8 +185,60 @@
public int hashCode()
{
int hash = m_key.hashCode();
- hash ^= m_type.hashCode();
- hash ^= m_semantic;
+ for( int i=0; i<m_operations.length; i++ )
+ {
+ Operation operation = m_operations[i];
+ hash ^= operation.hashCode();
+ }
return hash;
}
+
+ public static class Operation implements Serializable
+ {
+ private final String m_type;
+ private int m_semantic;
+
+ public Operation( int semantic, String type )
+ {
+ m_type = type;
+ m_semantic = semantic;
+ }
+
+ public String getType()
+ {
+ return m_type;
+ }
+
+ public int getSemantic()
+ {
+ return m_semantic;
+ }
+
+ public boolean equals( Object other )
+ {
+ if( false == ( other instanceof Operation ) )
+ {
+ return false;
+ }
+ else
+ {
+ Operation a = (Operation) other;
+ if( false == m_type.equals( a.getType() ) )
+ {
+ return false;
+ }
+ else
+ {
+ return ( m_semantic == a.getSemantic() );
+ }
+ }
+ }
+
+ public int hashCode()
+ {
+ int hash = m_semantic;
+ hash ^= m_type.hashCode();
+ return hash;
+ }
+ }
}

Modified:
development/main/metro/meta/api/src/main/net/dpml/meta/info/Type.java
==============================================================================
--- development/main/metro/meta/api/src/main/net/dpml/meta/info/Type.java
(original)
+++ development/main/metro/meta/api/src/main/net/dpml/meta/info/Type.java
Tue Apr 5 13:11:57 2005
@@ -273,18 +273,14 @@
* @param key the service key
* @return the dependency or null if it does not exist
*/
- public PartDescriptor getPartDescriptor( final String key, int semantic )
+ public PartDescriptor getPartDescriptor( final String key )
{
for ( int i = 0; i < m_parts.length; i++ )
{
PartDescriptor part = m_parts[i];
if ( part.getKey().equals( key ) )
{
- int s = part.getSemantic();
- if( semantic == s )
- {
- return part;
- }
+ return part;
}
}
return null;

Modified:
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/PartDescriptorTestCase.java
==============================================================================
---
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/PartDescriptorTestCase.java
(original)
+++
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/PartDescriptorTestCase.java
Tue Apr 5 13:11:57 2005
@@ -29,6 +29,7 @@
import junit.framework.TestCase;

import net.dpml.meta.info.PartDescriptor;
+import net.dpml.meta.info.PartDescriptor.Operation;

/**
* EntryDescriptorTestCase does XYZ
@@ -41,18 +42,19 @@
private static final String m_key = "key";
private static final String m_type = PartDescriptor.class.getName();
private static final int m_semantic = PartDescriptor.GET;
+ private static final Operation m_operation = new Operation( m_semantic,
m_type );
+ private static final Operation[] m_operations = new Operation[]{
m_operation };

public void testDescriptor()
{
- PartDescriptor part = new PartDescriptor( m_key, m_type, m_semantic
);
+ PartDescriptor part = new PartDescriptor( m_key, m_operations );

assertEquals( "key", m_key, part.getKey() );
- assertEquals( "type", m_type, part.getType() );
- assertTrue( "semantic", m_semantic == part.getSemantic() );
+ assertEquals( "operations", m_operations, part.getOperations() );

try
{
- new PartDescriptor( null, m_type );
+ new PartDescriptor( null, m_operations );
fail("Did not throw expected NullPointerException ");
}
catch( NullPointerException npe)
@@ -73,7 +75,7 @@

public void testSerialization() throws IOException,
ClassNotFoundException
{
- PartDescriptor part = new PartDescriptor( m_key, m_type, m_semantic
);
+ PartDescriptor part = new PartDescriptor( m_key, m_operations );

File file = new File( "test.out" );
ObjectOutputStream oos = new ObjectOutputStream( new
FileOutputStream( file ) );

Modified:
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/TypeTestCase.java
==============================================================================
---
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/TypeTestCase.java
(original)
+++
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/TypeTestCase.java
Tue Apr 5 13:11:57 2005
@@ -38,6 +38,7 @@
import net.dpml.meta.info.ReferenceDescriptor;
import net.dpml.meta.info.ServiceDescriptor;
import net.dpml.meta.info.PartDescriptor;
+import net.dpml.meta.info.PartDescriptor.Operation;
import net.dpml.meta.info.Type;

import net.dpml.configuration.Configuration;
@@ -86,7 +87,7 @@
};
m_defaults = new DefaultConfiguration("default");
m_parts = new PartDescriptor[] {
- new PartDescriptor( "key", ReferenceDescriptor.class.getName() )
+ new PartDescriptor( "key", new Operation[]{ new Operation(
PartDescriptor.GET, ReferenceDescriptor.class.getName() ) } )
};
}




  • svn commit: r2210 - in development/main/metro: automation/builder/src/main/net/dpml/automation/builder automation/control/src/main/net/dpml/automation/part composition/api/src/main/net/dpml/composition/data composition/api/src/test/net/dpml/composition/data/test composition/builder/src/main/net/dpml/composition/builder composition/builder/src/main/net/dpml/composition/builder/datatypes composition/control/src/main/net/dpml/composition/models composition/impl/src/main/net/dpml/composition/data/builder meta/api/src/main/net/dpml/meta/info meta/api/src/test/net/dpml/meta/info/test, mcconnell, 04/05/2005

Archive powered by MHonArc 2.6.24.

Top of Page