Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2125 - in development/main/metro/composition/builder/src/main/net/dpml/composition/builder: . datatypes

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: r2125 - in development/main/metro/composition/builder/src/main/net/dpml/composition/builder: . datatypes
  • Date: Thu, 24 Mar 2005 16:12:04 -0500

Author: mcconnell AT dpml.net
Date: Thu Mar 24 16:12:03 2005
New Revision: 2125

Added:

development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/

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

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

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

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

development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/ParametersDataType.java
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/TypeBuilderTask.java
Log:
separate out the respective builder datatypes

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
Thu Mar 24 16:12:03 2005
@@ -23,10 +23,12 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URI;
+import java.net.URL;
import java.net.URISyntaxException;
import java.rmi.MarshalledObject;
import java.util.Arrays;
@@ -42,6 +44,7 @@
import net.dpml.logging.data.CategoryDirective;
import net.dpml.logging.data.CategoriesDirective;

+import net.dpml.composition.data.TypeNotFoundException;
import net.dpml.composition.data.EntryDirective;
import net.dpml.composition.data.DeploymentProfile;
import net.dpml.composition.data.ConstructorDirective;
@@ -51,6 +54,12 @@
import net.dpml.composition.data.ComponentProfile;
import net.dpml.composition.data.Mode;

+import net.dpml.composition.builder.datatypes.CategoriesDataType;
+import net.dpml.composition.builder.datatypes.ContextDataType;
+import net.dpml.composition.builder.datatypes.DependenciesDataType;
+import net.dpml.composition.builder.datatypes.ParametersDataType;
+import net.dpml.composition.builder.datatypes.ConfigurationDataType;
+
import net.dpml.part.Part;
import net.dpml.part.PartHolder;

@@ -60,6 +69,7 @@
import net.dpml.configuration.Configuration;
import net.dpml.configuration.impl.DefaultConfiguration;

+import net.dpml.meta.info.Type;
import net.dpml.meta.info.InfoDescriptor;

import net.dpml.parameters.Parameters;
@@ -102,6 +112,8 @@
private DependenciesDataType m_dependencies;
private PartsDataType m_parts;

+ private Type m_type;
+
public void setKey( String key )
{
m_key = key;
@@ -330,12 +342,14 @@
log( "building component: " + getName() );

//
- // setup clasname and type
+ // setup classname and type
//

String name = getName();
String classname = getClassname();
- String lifestyle = getLifestylePolicy(); // need to update
ComponentProfile to handle this
+ Type type = loadType( classloader, classname );
+
+ String lifestyle = getLifestylePolicy( type ); // need to update
ComponentProfile to handle this
int collection = getCollectionPolicy();
int activation = getActivationPolicy();
Mode mode = Mode.EXPLICIT;
@@ -349,8 +363,34 @@
// return the component profile
//

- return new ComponentProfile( name, activation, collection,
classname, categories, context, dependencies, parameters, configuration, mode
);
+ return new ComponentProfile(
+ name, activation, collection, classname, categories, context,
+ dependencies, parameters, configuration, mode );
+ }

+ private Type loadType( ClassLoader classloader, String classname )
+ {
+ String path = classname.replace( '.', '/' ) + ".type";
+ try
+ {
+ URL url = classloader.getResource( path );
+ System.out.println( "# resource url: " + url );
+ InputStream input = url.openStream();
+ if( null == input )
+ {
+ throw new TypeNotFoundException( url.toString() );
+ }
+ ObjectInputStream stream = new ObjectInputStream( input );
+ return (Type) stream.readObject();
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error occured while attempting to load the type
from the path ["
+ + path
+ + "]";
+ throw new BuildException( error, e, getLocation() );
+ }
}

protected String getName()
@@ -375,11 +415,31 @@
return m_classname;
}

- public String getLifestylePolicy()
+ /**
+ * Return the lifestyle policy declared relative to usage.
+ * If undefined then default to the lifestyle declared by the component
type.
+ * Lifestyle policies that may be declared under the 'lifestyle'
attribute of
+ * a component are 'request', 'thread' or 'shared'. If 'request' is
supplied
+ * the assigned lefestyle policy is InfoDescriptor.TRANSIENT resulting in
the
+ * creation of a new instance per request. If 'thread' is declared the
assigned
+ * lifestyle policy shall be InfoDescriptor.THREAD in which case a
supplied
+ * instance will be reused for all requests within the same thread of
execution.
+ * If the supplied policy is 'shared' then the established instance will
be
+ * shared across consumers referencing the component.
+ *
+ * TODO - delcare in a component implementation class if the
implementation
+ * is thread-safe or not. If not thread-safe then a request for a shared
+ * usage policy should raise an error.
+ *
+ * @param type the component type
+ * @return the lifestyle policy
+ */
+ public String getLifestylePolicy( Type type )
{
+ String typeLifestylePolicy = type.getInfo().getLifestyle();
if( null == m_lifestyle )
{
- return InfoDescriptor.TRANSIENT;
+ return typeLifestylePolicy; //
}
else
{
@@ -392,7 +452,7 @@
{
return InfoDescriptor.THREAD;
}
- else if( "singleton".equals( spec ) )
+ else if( "shared".equals( spec ) )
{
return InfoDescriptor.SINGLETON;
}
@@ -511,596 +571,6 @@
}
}

- //
- // Logging category handlers.
- //
-
- public static class CategoriesDataType
- {
- private List m_list = new LinkedList();
-
- public CategoryDataType createCategory()
- {
- CategoryDataType category = new CategoryDataType();
- m_list.add( category );
- return category;
- }
-
- CategoriesDirective getCategoriesDirective()
- {
-
- CategoryDataType[] types = (CategoryDataType[])
m_list.toArray( new CategoryDataType[0] );
- CategoryDirective[] directives = new CategoryDirective[
types.length ];
- for( int i=0; i<types.length; i++ )
- {
- CategoryDataType type = types[i];
- CategoryDirective directive = type.getCategoryDirective();
- }
- return new CategoriesDirective( directives );
- }
-
- public class CategoryDataType
- {
- private String m_name;
- private String m_priority;
- private String m_target;
-
- public void setName( String name )
- {
- m_name = name;
- }
-
- public void setPriority( String priority )
- {
- m_priority = priority;
- }
-
- public void setTarget( String target )
- {
- m_target = target;
- }
-
- public CategoryDirective getCategoryDirective()
- {
- return new CategoryDirective( m_name, m_priority, m_target
);
- }
- }
- }
-
- //
- // context handler
- //
-
- /**
- * A context directive class.
- */
- public static class ContextDataType
- {
- private String m_class;
- private List m_entries = new ArrayList();
-
- /**
- * Declare a custom context implementation classname.
- * @param classname the classname of an optional context
implementation class
- */
- public void setClass( final String classname )
- {
- m_class = classname ;
- }
-
- /**
- * Return the optional context implementation classname.
- * @return the classname
- */
- public String getClassname()
- {
- return m_class;
- }
-
- /**
- * Create, add and return a new entry directive to the context.
- * @return a new context entry directive
- */
- public Entry createEntry()
- {
- final Entry entry = new Entry();
- m_entries.add( entry );
- return entry;
- }
-
- /**
- * Return all of the context entries within the context directive.
- * @return the set of context entries
- */
- public Entry[] getEntries()
- {
- return (Entry[]) m_entries.toArray( new Entry[0] );
- }
-
- protected ContextDirective getContextDirective()
- {
- Entry[] entries = getEntries();
- EntryDirective[] entryDirectives = new EntryDirective[
entries.length ];
- for( int i=0; i<entries.length; i++ )
- {
- Entry entry = entries[i];
- entryDirectives[i] = entry.getEntryDirective();
- }
- String classname = getClassname();
- return new ContextDirective( classname, entryDirectives );
- }
- }
-
- /**
- * Defintion of a context entry directive.
- */
- public static class Entry extends Param
- {
- private String m_key;
-
- /**
- * Set the context enty key that this directive qualifies.
- * @param key the context entry key
- */
- public void setKey( final String key )
- {
- m_key = key ;
- }
-
- /**
- * Return the context entry key.
- * @return the entry key
- */
- public String getKey()
- {
- return m_key;
- }
-
- public EntryDirective getEntryDirective()
- {
- String key = getKey();
- String classname = getClassname();
- String value = getValue();
- if( null != value )
- {
- return new ConstructorDirective( key, classname, value );
- }
- else
- {
- Param[] params = getParams();
- Parameter[] parameters = new Parameter[ params.length ];
- for( int i=0; i<parameters.length; i++ )
- {
- Param p = params[i];
- parameters[i] = p.getParameter();
- }
- return new ConstructorDirective( key, classname, parameters
);
- }
- }
- }
-
- /**
- * Defintion of a context entry parameter directive.
- */
- public static class Param
- {
- private String m_classname;
- private String m_value;
- 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;
- }
-
- /**
- * Set the value of the context entry parameter.
- * @param value the param value
- */
- public void setValue( final String value )
- {
- m_value = value;
- }
-
- /**
- * Return the value of the context entry param.
- * @return the value
- */
- public String getValue()
- {
- return m_value;
- }
-
- /**
- * Create, assign and return a new nested entry constructor parameter.
- * @return the new context entry param
- */
- public Param createParam()
- {
- final Param param = new Param();
- m_params.add( param );
- return param;
- }
-
- /**
- * Return the set of nested param directives.
- * @return the params
- */
- public Param[] getParams()
- {
- return (Param[]) m_params.toArray( new Param[0] );
- }
-
- public Parameter getParameter()
- {
- String classname = getClassname();
- String value = getValue();
- if( null != value )
- {
- return new Parameter( classname, value );
- }
- else
- {
- Param[] params = getParams();
- Parameter[] parameters = new Parameter[ params.length ];
- for( int i=0; i<parameters.length; i++ )
- {
- Param p = params[i];
- parameters[i] = p.getParameter();
- }
- return new Parameter( classname, parameters );
- }
- }
- }
-
- //
- // Dependecies data type
- //
-
- public static class DependenciesDataType
- {
- private List m_dependencies = new ArrayList();
-
- /**
- * Create, assiciate and return a new dependency within this set of
dependencies.
- * @return the new dependnecy directive
- */
- public DependencyDataType createDependency()
- {
- final DependencyDataType dep = new DependencyDataType ();
- m_dependencies.add( dep );
- return dep;
- }
-
- /**
- * Return the set of dependency directives within this dependencies
directive.
- * @return the dependency directives
- */
- public DependencyDataType[] getDependencies()
- {
- return (DependencyDataType[]) m_dependencies.toArray( new
DependencyDataType[0] );
- }
-
- protected DependencyDirective[] getDependencyDirectives()
- {
- DependencyDataType[] deps = getDependencies();
- DependencyDirective[] dependencies = new DependencyDirective[
deps.length ];
- for( int i=0; i<dependencies.length; i++ )
- {
- DependencyDataType dep = deps[i];
- dependencies[i] = dep.getDependencyDirective();
- }
- return dependencies;
- }
- }
-
- /**
- * A dependency directive.
- */
- public static class DependencyDataType
- {
- private String m_source;
-
- private String m_key;
-
- /**
- * Set the key that this depedency directive qualifies.
- * @param key the dependency key
- */
- public void setKey( final String key )
- {
- m_key = key;
- }
-
- /**
- * Get the dependency directive key.
- */
- public String getKey()
- {
- return m_key;
- }
-
- /**
- * Set the address of the source component to fulofill the dependency.
- * @param source the source component address
- */
- public void setSource( final String source )
- {
- m_source = source;
- }
-
- /**
- * Return the address of the source component to use to fulfill this
dependency.
- * @return the source component address
- */
- public String getSource()
- {
- return m_source;
- }
-
- protected DependencyDirective getDependencyDirective()
- {
- String key = getKey();
- String source = getSource();
- return new DependencyDirective( key, source );
- }
- }
-
- /**
- * A parameters directive declares a set of n parameters.
- */
- public static class ParametersDataType
- {
- private final List m_parameters = new ArrayList();
- private final Project m_project;
-
- public ParametersDataType( Project project )
- {
- m_project = project;
- }
-
- /**
- * Create, allocate and return a new parameter with this set of
parameters.
- * @return a new parameter directive
- */
- public ParameterDataType createParameter()
- {
- final ParameterDataType parameter = new ParameterDataType(
m_project );
- m_parameters.add( parameter );
- return parameter;
- }
-
- /**
- * Return the set of parameter directives declarared within this
parameters directives.
- * @return the set of parameter directives
- */
- public ParameterDataType[] getParameterDataTypes()
- {
- return (ParameterDataType[]) m_parameters.toArray( new
ParameterDataType[0] );
- }
-
- protected Parameters getParameters()
- {
- DefaultParameters parameters = new DefaultParameters();
- ParameterDataType[] params = getParameterDataTypes();
- for( int i=0; i<params.length; i++ )
- {
- ParameterDataType p = params[i];
- String name = p.getName();
- String value = p.getValue();
- parameters.setParameter( name, value );
- }
- return parameters;
- }
- }
-
- /**
- * A parameter directive.
- */
- public static class ParameterDataType
- {
- private final Project m_project;
-
- private String m_name;
- private String m_value;
-
- public ParameterDataType( Project project )
- {
- m_project = project;
- }
-
- /**
- * Set the parameter name.
- * @param name the parameter name
- */
- public void setName( final String name )
- {
- m_name = name;
- }
-
- /**
- * Set the value assigned to the named parameter.
- * @param value the parameter value
- */
- public void setValue( final String value )
- {
- m_value = m_project.replaceProperties( value );
- }
-
- /**
- * Return the parameter name.
- * @return the parameter name
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * Return the value assigned to the parameter.
- * @return the parameter value
- */
- public String getValue()
- {
- return m_value;
- }
- }
-
- //
- // Configuration data type
- //
-
- /**
- * A configuration directive.
- */
- public static class ConfigurationDataType implements
DynamicConfiguratorNS
- {
- private final Project m_project;
-
- private String m_value;
- private Map m_attributes = new Hashtable();
- private List m_children = new LinkedList();
- private String m_name;
-
- /**
- * Creation of a root configuration directive.
- */
- public ConfigurationDataType( Project project )
- {
- this( project, "configuration" );
- }
-
- /**
- * Creation of a named configuration element.
- * @param name the element name
- */
- public ConfigurationDataType( Project project, String name )
- {
- m_name = name;
- m_project = project;
- }
-
- /**
- * Add nested text.
- * @param value the test value
- */
- public void addText(String value )
- {
- String s = value.trim();
- if( s.length() > 0 )
- {
- String parsedValue = m_project.replaceProperties( s );
- m_value = parsedValue;
- }
- }
-
- /**
- * Set a named attribute to the given value
- *
- * @param uri The namespace uri for this attribute, "" is
- * used if there is no namespace uri.
- * @param localName The localname of this attribute.
- * @param qName The qualified name for this attribute
- * @param value The value of this attribute.
- * @throws BuildException when any error occurs
- */
- public void setDynamicAttribute(
- String uri, String localName, String qName, String value)
- throws BuildException
- {
- String parsedValue = m_project.replaceProperties( value );
- m_attributes.put( qName, parsedValue );
- }
-
- /**
- * Create an element with the given name
- *
- * @param qName the element nbame
- * @throws BuildException when any error occurs
- * @return the element created
- */
- public Object createDynamicElement(
- String uri, String localName, String qName) throws BuildException
- {
- ConfigurationDataType conf = new ConfigurationDataType(
m_project, qName );
- m_children.add( conf );
- return conf;
- }
-
- /**
- * Return the name of the configuration element.
- * @return the node name
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * Return a value associated with the element.
- * @return the assigned value
- */
- public String getValue()
- {
- return m_value;
- }
-
- /**
- * Return the map of the assigned attributes.
- * @return the attribute name value map
- */
- public Map getAttributes()
- {
- return m_attributes;
- }
-
- /**
- * Return he set of nest child configuration directives.
- * @return the configuration directives within this directive
- */
- public ConfigurationDataType[] getChildren()
- {
- return (ConfigurationDataType[]) m_children.toArray( new
ConfigurationDataType[m_children.size()] );
- }
-
- protected Configuration getConfiguration()
- {
- String name = getName();
- DefaultConfiguration config = new DefaultConfiguration( name );
- config.setValue( getValue() );
- Map attributes = getAttributes();
- String[] keys = (String[]) attributes.keySet().toArray( new
String[0] );
- for( int i=0; i<keys.length; i++ )
- {
- String key = keys[i];
- String value = (String) attributes.get( key );
- config.setAttribute( key, value );
- }
- ConfigurationDataType[] nodes = getChildren();
- Configuration[] children = new Configuration[ nodes.length ];
- for( int i=0; i<nodes.length; i++ )
- {
- ConfigurationDataType data = nodes[i];
- Configuration conf = data.getConfiguration();
- config.addChild( conf );
- }
- return config;
- }
- }
-
private static URI PART_HANDLER_URI = setupURI( "@PART-HANDLER-URI@" );
private static URI PART_BUILDER_URI = setupURI( "@PART-BUILDER-URI@" );


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
Thu Mar 24 16:12:03 2005
@@ -90,18 +90,6 @@
m_classname = classname;
}

- /*
- public PartsDataType createParts()
- {
- if( null == m_parts )
- {
- System.out.println( "## creating parts element" );
- m_parts = new PartsDataType( this );
- }
- return m_parts;
- }
- */
-
//---------------------------------------------------------------
// Builder
//---------------------------------------------------------------
@@ -150,7 +138,6 @@
Configuration config = null;
ParameterDescriptor[] params = createParameterDescriptors( subject );
PartDescriptor[] parts = createPartDescriptors( subject );
- //PartDescriptor[] parts = createPartDescriptors( subject );
return new Type( info, categories, context, services, dependencies,
config, params, parts );
}


Added:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/CategoriesDataType.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/CategoriesDataType.java
Thu Mar 24 16:12:03 2005
@@ -0,0 +1,95 @@
+/*
+ * 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.composition.builder.datatypes;
+
+import java.util.List;
+import java.util.LinkedList;
+
+import net.dpml.logging.data.CategoryDirective;
+import net.dpml.logging.data.CategoriesDirective;
+
+/**
+ * Build datatype used to construct a categories descriptor.
+ */
+public class CategoriesDataType
+{
+ private List m_list = new LinkedList();
+
+ /**
+ * CategoryDataType creation function incvolved by the ant builder
+ * for all nested 'category' elements.
+ *
+ * @return a datatype used to construct a category descriptor
+ */
+ public CategoryDataType createCategory()
+ {
+ CategoryDataType category = new CategoryDataType();
+ m_list.add( category );
+ return category;
+ }
+
+ /**
+ * Utility method used to construct a CategoriesDirective based on
+ * build time features assigned by ant.
+ * @return the CategoriesDirective containing zero or more
CategoryDirective instances
+ */
+ public CategoriesDirective getCategoriesDirective()
+ {
+
+ CategoryDataType[] types = (CategoryDataType[]) m_list.toArray( new
CategoryDataType[0] );
+ CategoryDirective[] directives = new CategoryDirective[
types.length ];
+ for( int i=0; i<types.length; i++ )
+ {
+ CategoryDataType type = types[i];
+ CategoryDirective directive = type.getCategoryDirective();
+ }
+ return new CategoriesDirective( directives );
+ }
+
+ /**
+ * Build datatype used to construct a categories descriptor.
+ */
+ public class CategoryDataType
+ {
+ private String m_name;
+ private String m_priority;
+ private String m_target;
+
+ public void setName( String name )
+ {
+ m_name = name;
+ }
+
+ public void setPriority( String priority )
+ {
+ m_priority = priority;
+ }
+
+ public void setTarget( String target )
+ {
+ m_target = target;
+ }
+
+ public CategoryDirective getCategoryDirective()
+ {
+ return new CategoryDirective( m_name, m_priority, m_target );
+ }
+ }
+}
+

Added:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/ConfigurationDataType.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/ConfigurationDataType.java
Thu Mar 24 16:12:03 2005
@@ -0,0 +1,172 @@
+/*
+ * 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.composition.builder.datatypes;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.Map;
+
+import net.dpml.composition.data.DependencyDirective;
+
+import net.dpml.configuration.Configuration;
+import net.dpml.configuration.impl.DefaultConfiguration;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.DynamicConfiguratorNS;
+import org.apache.tools.ant.BuildException;
+
+
+/**
+ * A configuration directive.
+ */
+public class ConfigurationDataType implements DynamicConfiguratorNS
+{
+ private final Project m_project;
+
+ private String m_value;
+ private Map m_attributes = new Hashtable();
+ private List m_children = new LinkedList();
+ private String m_name;
+
+ /**
+ * Creation of a root configuration directive.
+ */
+ public ConfigurationDataType( Project project )
+ {
+ this( project, "configuration" );
+ }
+
+ /**
+ * Creation of a named configuration element.
+ * @param name the element name
+ */
+ public ConfigurationDataType( Project project, String name )
+ {
+ m_name = name;
+ m_project = project;
+ }
+
+ /**
+ * Add nested text.
+ * @param value the test value
+ */
+ public void addText(String value )
+ {
+ String s = value.trim();
+ if( s.length() > 0 )
+ {
+ String parsedValue = m_project.replaceProperties( s );
+ m_value = parsedValue;
+ }
+ }
+
+ /**
+ * Set a named attribute to the given value
+ *
+ * @param uri The namespace uri for this attribute, "" is
+ * used if there is no namespace uri.
+ * @param localName The localname of this attribute.
+ * @param qName The qualified name for this attribute
+ * @param value The value of this attribute.
+ * @throws BuildException when any error occurs
+ */
+ public void setDynamicAttribute(
+ String uri, String localName, String qName, String value)
+ throws BuildException
+ {
+ String parsedValue = m_project.replaceProperties( value );
+ m_attributes.put( qName, parsedValue );
+ }
+
+ /**
+ * Create an element with the given name
+ *
+ * @param qName the element nbame
+ * @throws BuildException when any error occurs
+ * @return the element created
+ */
+ public Object createDynamicElement(
+ String uri, String localName, String qName) throws BuildException
+ {
+ ConfigurationDataType conf = new ConfigurationDataType( m_project,
qName );
+ m_children.add( conf );
+ return conf;
+ }
+
+ /**
+ * Return the name of the configuration element.
+ * @return the node name
+ */
+ public String getName()
+ {
+ return m_name;
+ }
+
+ /**
+ * Return a value associated with the element.
+ * @return the assigned value
+ */
+ public String getValue()
+ {
+ return m_value;
+ }
+
+ /**
+ * Return the map of the assigned attributes.
+ * @return the attribute name value map
+ */
+ public Map getAttributes()
+ {
+ return m_attributes;
+ }
+
+ /**
+ * Return he set of nest child configuration directives.
+ * @return the configuration directives within this directive
+ */
+ public ConfigurationDataType[] getChildren()
+ {
+ return (ConfigurationDataType[]) m_children.toArray( new
ConfigurationDataType[m_children.size()] );
+ }
+
+ public Configuration getConfiguration()
+ {
+ String name = getName();
+ DefaultConfiguration config = new DefaultConfiguration( name );
+ config.setValue( getValue() );
+ Map attributes = getAttributes();
+ String[] keys = (String[]) attributes.keySet().toArray( new
String[0] );
+ for( int i=0; i<keys.length; i++ )
+ {
+ String key = keys[i];
+ String value = (String) attributes.get( key );
+ config.setAttribute( key, value );
+ }
+ ConfigurationDataType[] nodes = getChildren();
+ Configuration[] children = new Configuration[ nodes.length ];
+ for( int i=0; i<nodes.length; i++ )
+ {
+ ConfigurationDataType data = nodes[i];
+ Configuration conf = data.getConfiguration();
+ config.addChild( conf );
+ }
+ return config;
+ }
+}

Added:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/ContextDataType.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/ContextDataType.java
Thu Mar 24 16:12:03 2005
@@ -0,0 +1,224 @@
+/*
+ * 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.composition.builder.datatypes;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.ArrayList;
+
+import net.dpml.composition.data.ContextDirective;
+import net.dpml.composition.data.ConstructorDirective;
+import net.dpml.composition.data.EntryDirective;
+import net.dpml.composition.data.Parameter;
+
+/**
+ * A context directive class.
+ */
+public class ContextDataType
+{
+ private String m_class;
+ private List m_entries = new ArrayList();
+
+ /**
+ * Declare a custom context implementation classname.
+ * @param classname the classname of an optional context implementation
class
+ */
+ public void setClass( final String classname )
+ {
+ m_class = classname ;
+ }
+
+ /**
+ * Return the optional context implementation classname.
+ * @return the classname
+ */
+ public String getClassname()
+ {
+ return m_class;
+ }
+
+ /**
+ * Create, add and return a new entry directive to the context.
+ * @return a new context entry directive
+ */
+ public Entry createEntry()
+ {
+ final Entry entry = new Entry();
+ m_entries.add( entry );
+ return entry;
+ }
+
+ /**
+ * Return all of the context entries within the context directive.
+ * @return the set of context entries
+ */
+ public Entry[] getEntries()
+ {
+ return (Entry[]) m_entries.toArray( new Entry[0] );
+ }
+
+ public ContextDirective getContextDirective()
+ {
+ Entry[] entries = getEntries();
+ EntryDirective[] entryDirectives = new EntryDirective[
entries.length ];
+ for( int i=0; i<entries.length; i++ )
+ {
+ Entry entry = entries[i];
+ entryDirectives[i] = entry.getEntryDirective();
+ }
+ String classname = getClassname();
+ return new ContextDirective( classname, entryDirectives );
+ }
+
+ /**
+ * Defintion of a context entry directive.
+ */
+ public static class Entry extends Param
+ {
+ private String m_key;
+
+ /**
+ * Set the context enty key that this directive qualifies.
+ * @param key the context entry key
+ */
+ public void setKey( final String key )
+ {
+ m_key = key ;
+ }
+
+ /**
+ * Return the context entry key.
+ * @return the entry key
+ */
+ public String getKey()
+ {
+ return m_key;
+ }
+
+ public EntryDirective getEntryDirective()
+ {
+ String key = getKey();
+ String classname = getClassname();
+ String value = getValue();
+ if( null != value )
+ {
+ return new ConstructorDirective( key, classname, value );
+ }
+ else
+ {
+ Param[] params = getParams();
+ Parameter[] parameters = new Parameter[ params.length ];
+ for( int i=0; i<parameters.length; i++ )
+ {
+ Param p = params[i];
+ parameters[i] = p.getParameter();
+ }
+ return new ConstructorDirective( key, classname, parameters
);
+ }
+ }
+ }
+
+ /**
+ * Defintion of a context entry parameter directive.
+ */
+ public static class Param
+ {
+ private String m_classname;
+ private String m_value;
+ 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;
+ }
+
+ /**
+ * Set the value of the context entry parameter.
+ * @param value the param value
+ */
+ public void setValue( final String value )
+ {
+ m_value = value;
+ }
+
+ /**
+ * Return the value of the context entry param.
+ * @return the value
+ */
+ public String getValue()
+ {
+ return m_value;
+ }
+
+ /**
+ * Create, assign and return a new nested entry constructor parameter.
+ * @return the new context entry param
+ */
+ public Param createParam()
+ {
+ final Param param = new Param();
+ m_params.add( param );
+ return param;
+ }
+
+ /**
+ * Return the set of nested param directives.
+ * @return the params
+ */
+ public Param[] getParams()
+ {
+ return (Param[]) m_params.toArray( new Param[0] );
+ }
+
+ public Parameter getParameter()
+ {
+ String classname = getClassname();
+ String value = getValue();
+ if( null != value )
+ {
+ return new Parameter( classname, value );
+ }
+ else
+ {
+ Param[] params = getParams();
+ Parameter[] parameters = new Parameter[ params.length ];
+ for( int i=0; i<parameters.length; i++ )
+ {
+ Param p = params[i];
+ parameters[i] = p.getParameter();
+ }
+ return new Parameter( classname, parameters );
+ }
+ }
+ }
+}
+

Added:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/DependenciesDataType.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/DependenciesDataType.java
Thu Mar 24 16:12:03 2005
@@ -0,0 +1,117 @@
+/*
+ * 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.composition.builder.datatypes;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.ArrayList;
+
+import net.dpml.composition.data.DependencyDirective;
+
+/**
+ * Dependecies data type
+ */
+public class DependenciesDataType
+{
+ private List m_dependencies = new ArrayList();
+
+ /**
+ * Create, assiciate and return a new dependency within this set of
dependencies.
+ * @return the new dependnecy directive
+ */
+ public DependencyDataType createDependency()
+ {
+ final DependencyDataType dep = new DependencyDataType ();
+ m_dependencies.add( dep );
+ return dep;
+ }
+
+ /**
+ * Return the set of dependency directives within this dependencies
directive.
+ * @return the dependency directives
+ */
+ public DependencyDataType[] getDependencies()
+ {
+ return (DependencyDataType[]) m_dependencies.toArray( new
DependencyDataType[0] );
+ }
+
+ public DependencyDirective[] getDependencyDirectives()
+ {
+ DependencyDataType[] deps = getDependencies();
+ DependencyDirective[] dependencies = new DependencyDirective[
deps.length ];
+ for( int i=0; i<dependencies.length; i++ )
+ {
+ DependencyDataType dep = deps[i];
+ dependencies[i] = dep.getDependencyDirective();
+ }
+ return dependencies;
+ }
+
+ /**
+ * A dependency directive.
+ */
+ public static class DependencyDataType
+ {
+ private String m_source;
+
+ private String m_key;
+
+ /**
+ * Set the key that this depedency directive qualifies.
+ * @param key the dependency key
+ */
+ public void setKey( final String key )
+ {
+ m_key = key;
+ }
+
+ /**
+ * Get the dependency directive key.
+ */
+ public String getKey()
+ {
+ return m_key;
+ }
+
+ /**
+ * Set the address of the source component to fulofill the dependency.
+ * @param source the source component address
+ */
+ public void setSource( final String source )
+ {
+ m_source = source;
+ }
+
+ /**
+ * Return the address of the source component to use to fulfill this
dependency.
+ * @return the source component address
+ */
+ public String getSource()
+ {
+ return m_source;
+ }
+
+ public DependencyDirective getDependencyDirective()
+ {
+ String key = getKey();
+ String source = getSource();
+ return new DependencyDirective( key, source );
+ }
+ }
+}

Added:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/ParametersDataType.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/datatypes/ParametersDataType.java
Thu Mar 24 16:12:03 2005
@@ -0,0 +1,131 @@
+/*
+ * 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.composition.builder.datatypes;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.ArrayList;
+
+import net.dpml.composition.data.DependencyDirective;
+
+import net.dpml.parameters.Parameters;
+import net.dpml.parameters.impl.DefaultParameters;
+
+import org.apache.tools.ant.Project;
+
+
+/**
+ * A datatype supporting the creation of a parameters instance.
+ */
+public class ParametersDataType
+{
+ private final List m_parameters = new ArrayList();
+ private final Project m_project;
+
+ public ParametersDataType( Project project )
+ {
+ m_project = project;
+ }
+
+ /**
+ * Create, allocate and return a new parameter with this set of
parameters.
+ * @return a new parameter directive
+ */
+ public ParameterDataType createParameter()
+ {
+ final ParameterDataType parameter = new ParameterDataType( m_project
);
+ m_parameters.add( parameter );
+ return parameter;
+ }
+
+ /**
+ * Return the set of parameter directives declarared within this
parameters directives.
+ * @return the set of parameter directives
+ */
+ public ParameterDataType[] getParameterDataTypes()
+ {
+ return (ParameterDataType[]) m_parameters.toArray( new
ParameterDataType[0] );
+ }
+
+ public Parameters getParameters()
+ {
+ DefaultParameters parameters = new DefaultParameters();
+ ParameterDataType[] params = getParameterDataTypes();
+ for( int i=0; i<params.length; i++ )
+ {
+ ParameterDataType p = params[i];
+ String name = p.getName();
+ String value = p.getValue();
+ parameters.setParameter( name, value );
+ }
+ return parameters;
+ }
+
+ /**
+ * A parameter directive.
+ */
+ public static class ParameterDataType
+ {
+ private final Project m_project;
+
+ private String m_name;
+ private String m_value;
+
+ public ParameterDataType( Project project )
+ {
+ m_project = project;
+ }
+
+ /**
+ * Set the parameter name.
+ * @param name the parameter name
+ */
+ public void setName( final String name )
+ {
+ m_name = name;
+ }
+
+ /**
+ * Set the value assigned to the named parameter.
+ * @param value the parameter value
+ */
+ public void setValue( final String value )
+ {
+ m_value = m_project.replaceProperties( value );
+ }
+
+ /**
+ * Return the parameter name.
+ * @return the parameter name
+ */
+ public String getName()
+ {
+ return m_name;
+ }
+
+ /**
+ * Return the value assigned to the parameter.
+ * @return the parameter value
+ */
+ public String getValue()
+ {
+ return m_value;
+ }
+ }
+}



  • svn commit: r2125 - in development/main/metro/composition/builder/src/main/net/dpml/composition/builder: . datatypes, mcconnell, 03/24/2005

Archive powered by MHonArc 2.6.24.

Top of Page