Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2958 - in development/main: metro metro/composition/builder/src/main/net/dpml/composition/builder metro/composition/control/src/main/net/dpml/composition/data metro/composition/control/src/main/net/dpml/composition/info metro/composition/control/src/main/net/dpml/composition/runtime metro/composition/control/src/test/net/dpml/composition/info/test metro/part/src/main/net/dpml/part/state metro/part/src/test/net/dpml/part/state test/components/plus/src/main/net/dpml/test/acme/plus

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: r2958 - in development/main: metro metro/composition/builder/src/main/net/dpml/composition/builder metro/composition/control/src/main/net/dpml/composition/data metro/composition/control/src/main/net/dpml/composition/info metro/composition/control/src/main/net/dpml/composition/runtime metro/composition/control/src/test/net/dpml/composition/info/test metro/part/src/main/net/dpml/part/state metro/part/src/test/net/dpml/part/state test/components/plus/src/main/net/dpml/test/acme/plus
  • Date: Sun, 03 Jul 2005 04:11:08 -0400

Author: mcconnell AT dpml.net
Date: Sun Jul 3 04:11:07 2005
New Revision: 2958

Added:

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

development/main/test/components/plus/src/main/net/dpml/test/acme/plus/ManagedComponent.xgraph
Removed:

development/main/metro/composition/control/src/main/net/dpml/composition/data/DependencyDirective.java
Modified:

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

development/main/metro/composition/control/src/main/net/dpml/composition/info/Type.java

development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ComponentHandler.java

development/main/metro/composition/control/src/test/net/dpml/composition/info/test/TypeTestCase.java
development/main/metro/index.xml
development/main/metro/part/src/main/net/dpml/part/state/State.java
development/main/metro/part/src/test/net/dpml/part/state/StateTestCase.java

development/main/test/components/plus/src/main/net/dpml/test/acme/plus/ManagedComponent.java
Log:
o Move state model construction out of the runtime and into the type builder.
o Update the example components to reflect build based strategy.

Added:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/StateBuilder.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/StateBuilder.java
Sun Jul 3 04:11:07 2005
@@ -0,0 +1,353 @@
+/*
+ * 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;
+
+import java.net.URI;
+
+import net.dpml.configuration.Configuration;
+
+import net.dpml.part.state.State;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+/**
+ * Build a state module from an .xgraph resource.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ */
+public class StateBuilder
+{
+ private final Task m_task;
+
+ public StateBuilder( Task task )
+ {
+ m_task = task;
+ }
+
+ public State build( Configuration config )
+ {
+ final String name = config.getName();
+ if( false == "state".equals( name ) )
+ {
+ final String error =
+ "Root element in the state graph is not a 'state' element.";
+ throw new BuildException( error );
+ }
+
+ return buildStateGraph( config );
+ }
+
+ private State buildStateGraph( Configuration config )
+ {
+ boolean terminal = config.getAttributeAsBoolean( "terminal", false );
+ State state = new State( terminal );
+ if( false == terminal )
+ {
+ addSubStates( state, config );
+ addTransitions( state, config );
+ addInitialization( state, config );
+ addOperations( state, config );
+ addTermination( state, config );
+ }
+ return state;
+ }
+
+ private void addSubStates( State state, Configuration config )
+ {
+ Configuration[] configs = config.getChildren( "state" );
+ for( int i=0; i<configs.length; i++ )
+ {
+ Configuration conf = configs[i];
+ addState( state, conf );
+ }
+ }
+
+ private void addState( State parent, Configuration config )
+ {
+ String name = config.getAttribute( "name", null );
+ if( null == name )
+ {
+ final String error =
+ "State declaration inside [" + parent.getName() + "] does not
declare a name.";
+ throw new BuildException( error );
+ }
+ boolean terminal = config.getAttributeAsBoolean( "terminal", false );
+ if( terminal )
+ {
+ log( "adding terminal state [" + name + "] to [" +
parent.getName() + "]" );
+ parent.addTerminalState( name );
+ }
+ else
+ {
+ log( "adding sub-state [" + name + "] to [" + parent.getName() +
"]" );
+ State state = parent.addState( name );
+ addSubStates( state, config );
+ }
+ }
+
+ private void addInitialization( State state, Configuration config )
+ {
+ Configuration child = config.getChild( "initialization", false );
+ if( null != child )
+ {
+ String target = child.getAttribute( "target", null );
+ Configuration method = child.getChild( "method", false );
+ if( null == target )
+ {
+ if( null == method )
+ {
+ final String error =
+ "Initialization element inside state [" +
state.getName()
+ + "] does not declare a target attribute or
alternative nested method.";
+ throw new BuildException( error );
+ }
+ else
+ {
+ URI uri = getExecutionURI( state, "initialization",
method );
+ state.setInitialization( uri );
+ log( "set initialization [" + uri + "] on [" +
state.getName() + "]" );
+ }
+ }
+ else
+ {
+ if( null == method )
+ {
+ state.setInitialization( target );
+ log( "set initialization target [" + target + "] on [" +
state.getName() + "]" );
+ }
+ else
+ {
+ URI uri = getExecutionURI( state, "initialization",
method );
+ state.setInitialization( uri, target );
+ log( "set initialization target [" + target + "] on ["
+ + state.getName()
+ + "] using ["
+ + uri
+ + "]." );
+ }
+ }
+ }
+ Configuration[] states = config.getChildren( "state" );
+ for( int i=0; i<states.length; i++ )
+ {
+ Configuration c = states[i];
+ State s = state.getState( c.getAttribute( "name", null ) );
+ addInitialization( s, c );
+ }
+ }
+
+ private void addTermination( State state, Configuration config )
+ {
+ Configuration child = config.getChild( "termination", false );
+ if( null != child )
+ {
+ String target = child.getAttribute( "target", null );
+ Configuration method = child.getChild( "method", false );
+ if( null == target )
+ {
+ if( null == method )
+ {
+ final String error =
+ "Termination element inside state [" + state.getName()
+ + "] does not declare a target attribute or
alternative nested method.";
+ throw new BuildException( error );
+ }
+ else
+ {
+ URI uri = getExecutionURI( state, "termination", method
);
+ state.setTerminator( uri, state );
+ log( "set termination [" + uri + "] on [" +
state.getName() + "]" );
+ }
+ }
+ else
+ {
+ if( null == method )
+ {
+ state.setTerminator( target );
+ log( "set termination target [" + target + "] on [" +
state.getName() + "]" );
+ }
+ else
+ {
+ URI uri = getExecutionURI( state, "termination", method
);
+ state.setTerminator( uri, target );
+ log( "set termination target [" + target + "] on ["
+ + state.getName()
+ + "] using ["
+ + uri
+ + "]." );
+ }
+ }
+ }
+ Configuration[] states = config.getChildren( "state" );
+ for( int i=0; i<states.length; i++ )
+ {
+ Configuration c = states[i];
+ State s = state.getState( c.getAttribute( "name", null ) );
+ addTermination( s, c );
+ }
+ }
+
+ private URI getExecutionURI( State state, String role, Configuration
config )
+ {
+ String element = config.getName();
+ if( "method".equals( element ) )
+ {
+ String name = config.getAttribute( "name", null );
+ if( null == name )
+ {
+ final String error =
+ "A method declaration within the ["
+ + role
+ + "] element under the state ["
+ + state.getName()
+ + "] does not declare a name.";
+ throw new BuildException( error );
+ }
+ return createURI( "method:" + name );
+ }
+ else
+ {
+ final String error =
+ "Don't know how to construct execution semantics using an
element named ["
+ + element
+ + "] declared within the an ["
+ + role
+ + "] element under the state ["
+ + state.getName()
+ + "].";
+ throw new BuildException( error );
+ }
+ }
+
+ private void addTransitions( State state, Configuration config )
+ {
+ Configuration[] configs = config.getChildren( "transition" );
+ for( int i=0; i<configs.length; i++ )
+ {
+ Configuration conf = configs[i];
+ addTransition( state, conf );
+ }
+ Configuration[] states = config.getChildren( "state" );
+ for( int i=0; i<states.length; i++ )
+ {
+ Configuration c = states[i];
+ State s = state.getState( c.getAttribute( "name", null ) );
+ addTransitions( s, c );
+ }
+ }
+
+ private void addTransition( State state, Configuration config )
+ {
+ String name = config.getAttribute( "name", null );
+ if( null == name )
+ {
+ final String error =
+ "A transition declaration inside ["
+ + state.getName()
+ + "] does not declare a name.";
+ throw new BuildException( error );
+ }
+ String target = config.getAttribute( "target", null );
+ if( null == target )
+ {
+ final String error =
+ "A transition declaration inside [" + state.getName() + "]
does not declare a target.";
+ throw new BuildException( error );
+ }
+ Configuration child = config.getChild( "method", false );
+ if( null == child )
+ {
+ state.addTransition( name, target );
+ log( "transition [" + name + "] added to [" + state.getName() +
"] with target [" + target + "]" );
+ }
+ else
+ {
+ URI uri = getExecutionURI( state, "transition", child );
+ state.addTransition( name, uri, target );
+ log(
+ "transition [" + name + "] added to [" + state.getName()
+ + "] with target [" + target + "] and urn [" + uri + "]" );
+ }
+ }
+
+ private void addOperations( State state, Configuration config )
+ {
+ Configuration[] configs = config.getChildren( "operation" );
+ for( int i=0; i<configs.length; i++ )
+ {
+ Configuration conf = configs[i];
+ addOperation( state, conf );
+ }
+ Configuration[] states = config.getChildren( "state" );
+ for( int i=0; i<states.length; i++ )
+ {
+ Configuration c = states[i];
+ State s = state.getState( c.getAttribute( "name", null ) );
+ addOperations( s, c );
+ }
+ }
+
+ private void addOperation( State state, Configuration config )
+ {
+ String name = config.getAttribute( "name", null );
+ if( null == name )
+ {
+ final String error =
+ "An operation declaration inside ["
+ + state.getName()
+ + "] does not declare a name.";
+ throw new BuildException( error );
+ }
+ Configuration child = config.getChild( "method", false );
+ if( null == child )
+ {
+ final String error =
+ "An operation element in the state [" + state.getName()
+ + "] does not include a nested method.";
+ throw new BuildException( error );
+ }
+ else
+ {
+ URI uri = getExecutionURI( state, "operation", child );
+ state.addOperation( name, uri );
+ log(
+ "operation [" + name + "] added to [" + state.getName()
+ + "] with urn [" + uri + "]" );
+ }
+ }
+
+ private URI createURI( String path )
+ {
+ try
+ {
+ return new URI( path );
+ }
+ catch( Throwable e )
+ {
+ throw new BuildException( e );
+ }
+ }
+
+ private void log( String message )
+ {
+ m_task.log( message );
+ }
+}
+

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
Sun Jul 3 04:11:07 2005
@@ -30,6 +30,9 @@
import java.util.Map;
import java.util.Properties;

+import net.dpml.activity.Startable;
+import net.dpml.activity.Executable;
+
import net.dpml.composition.info.CategoryDescriptor;
import net.dpml.composition.info.ContextDescriptor;
import net.dpml.composition.info.DependencyDescriptor;
@@ -39,10 +42,14 @@
import net.dpml.composition.info.ServiceDescriptor;
import net.dpml.composition.info.Type;
import net.dpml.composition.info.PartDescriptor.Operation;
+
import net.dpml.configuration.Configuration;
import net.dpml.configuration.impl.DefaultConfigurationBuilder;
+
import net.dpml.magic.tasks.ProjectTask;

+import net.dpml.part.state.State;
+
import org.apache.tools.ant.BuildException;

/**
@@ -163,17 +170,18 @@
throws IntrospectionException, IOException
{
log( "creating: " + subject.getName() );
+
InfoDescriptor info = createInfoDescriptor( subject );
ServiceDescriptor[] services = createServiceDescriptors( subject );
- DependencyDescriptor[] dependencies = new DependencyDescriptor[0];
// TODO: remove this
CategoryDescriptor[] categories = new CategoryDescriptor[0];
ContextDescriptor context = createContextDescriptor( subject );
PartDescriptor[] parts = createPartDescriptors( subject );
Configuration config = createDefaultConfiguration( subject );
+ State graph = resolveStateGraph( subject );

// TODO: add state model

- return new Type( info, categories, context, services, dependencies,
config, parts );
+ return new Type( graph, info, categories, context, services, config,
parts );
}

//---------------------------------------------------------------
@@ -301,7 +309,8 @@
catch( Exception e )
{
final String error =
- "An unexpected error occured while resolving the static
TYPE_CONFIGURATION_SCHEMA field on the type ["
+ "An unexpected error occured while resolving the static "
+ + "TYPE_CONFIGURATION_SCHEMA field on the type ["
+ subject.getName()
+ "].";
throw new IntrospectionException( error );
@@ -310,8 +319,6 @@

private Configuration createDefaultConfiguration( Class subject )
{
- // TODO: change this to a nested element in the <type>
-
final String classname = subject.getName();
final ClassLoader classloader = subject.getClassLoader();
final String xdefaults = classname.replace( '.', '/' ) + ".xconfig";
@@ -340,7 +347,7 @@

private Properties getTypeProperties( Class subject ) throws
IntrospectionException
{
- // TODO: change this to a nested element in the <type>
+ // TODO: change this to a .xproperties
try
{
Field field = subject.getDeclaredField( "TYPE_INFO_PROPERTIES" );
@@ -385,7 +392,8 @@
catch( Exception e )
{
final String error =
- "An unexpected error occured while resolving the static
TYPE_INFO_PROPERTIES field on the type ["
+ "An unexpected error occured while resolving the static "
+ + "TYPE_INFO_PROPERTIES field on the type ["
+ subject.getName()
+ "].";
throw new IntrospectionException( error );
@@ -926,6 +934,36 @@
}
}

+ private State resolveStateGraph( Class subject )
+ {
+ final String classname = subject.getName();
+ final ClassLoader classloader = subject.getClassLoader();
+ final String xgraph = classname.replace( '.', '/' ) + ".xgraph";
+ final InputStream input = classloader.getResourceAsStream( xgraph );
+ if( null == input )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
+ Configuration config = builder.build( input );
+ StateBuilder stateBuilder = new StateBuilder( this );
+ return stateBuilder.build( config );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "An unexpected error occured while resolving the state
model ["
+ + xgraph
+ + "]: " + e.toString();
+ throw new BuildException( error, e, getLocation() );
+ }
+ }
+ }
+
private static URI TYPE_HANDLER_URI = setupURI( "@TYPE-HANDLER-URI@" );
private static URI TYPE_BUILDER_URI = setupURI( "@TYPE-BUILDER-URI@" );


Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/info/Type.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/info/Type.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/info/Type.java
Sun Jul 3 04:11:07 2005
@@ -27,6 +27,7 @@

import net.dpml.configuration.Configuration;

+import net.dpml.part.state.State;
import net.dpml.part.manager.ComponentException;

/**
@@ -80,17 +81,19 @@
}
}

+ private final State m_graph;
private final InfoDescriptor m_descriptor;
private final ContextDescriptor m_context;
private final Configuration m_configuration;
private final ServiceDescriptor[] m_services;
- private final DependencyDescriptor[] m_dependencies;
private final CategoryDescriptor[] m_loggers;
private final PartDescriptor[] m_parts;

/**
* Creation of a new Type instance using a supplied component descriptor,
- * logging, cotext, services, depedencies, stages and extension
descriptors.
+ * logging, cotext, services, and part descriptors.
+ *
+ * @param graph the component state graph
* @param descriptor a component descriptor that contains information
about
* the component type
* @param loggers a set of logger descriptors the declare the logging
channels
@@ -99,18 +102,16 @@
* and context entry key and value classnames
* @param services a set of service descriprors that detail the service
that
* this component type is capable of supplying
- * @param dependencies a set of depedency descriprors that detail the
service
- * that this component type is depedent on
* @param defaults the static configuration defaults
* @param parts an array of part descriptors
- * @exception NullPointerException if the descriptor, loggers, context,
services,
- * or dependencies argument are null
+ * @exception NullPointerException if the graph, descriptor, loggers,
context, services
+ * or part argument are null
*/
- public Type( final InfoDescriptor descriptor,
+ public Type( final State graph,
+ final InfoDescriptor descriptor,
final CategoryDescriptor[] loggers,
final ContextDescriptor context,
final ServiceDescriptor[] services,
- final DependencyDescriptor[] dependencies,
final Configuration defaults,
final PartDescriptor[] parts )
throws NullPointerException
@@ -131,16 +132,12 @@
{
throw new NullPointerException( "services" );
}
- if ( null == dependencies )
- {
- throw new NullPointerException( "dependencies" );
- }

+ m_graph = graph;
m_descriptor = descriptor;
m_loggers = loggers;
m_context = context;
m_services = services;
- m_dependencies = dependencies;
m_configuration = defaults;

if( null == parts )
@@ -164,6 +161,16 @@
}

/**
+ * Return the Component descriptor.
+ *
+ * @return the Component descriptor.
+ */
+ public State getStateGraph()
+ {
+ return m_graph;
+ }
+
+ /**
* Return the set of Logger that this Component will use.
*
* @return the set of Logger that this Component will use.
@@ -253,34 +260,6 @@
}

/**
- * Return the set of Dependencies that this component requires to
operate.
- *
- * @return the set of Dependencies that this component requires to
operate.
- */
- public DependencyDescriptor[] getDependencies()
- {
- return m_dependencies;
- }
-
- /**
- * Retrieve a dependency with a particular role.
- *
- * @param key the service key
- * @return the dependency or null if it does not exist
- */
- public DependencyDescriptor getDependency( final String key )
- {
- for ( int i = 0; i < m_dependencies.length; i++ )
- {
- if ( m_dependencies[i].getKey().equals( key ) )
- {
- return m_dependencies[i];
- }
- }
- return null;
- }
-
- /**
* Returns the default configuration supplied with the type.
*
* @return the default configuration or null if no packaged defaults
@@ -291,7 +270,7 @@
}

/**
- * Returns the part dependencies declared by this compoent type.
+ * Returns the parts declared by this compoent type.
*
* @return the part descriptors
*/
@@ -301,10 +280,10 @@
}

/**
- * Retrieve a dependency with a particular role.
+ * Retrieve an identified part.
*
- * @param key the service key
- * @return the dependency or null if it does not exist
+ * @param key the part key
+ * @return the part (possibly null)
*/
public PartDescriptor getPartDescriptor( final String key )
{
@@ -343,19 +322,37 @@
Type t = (Type) other;

if( ! m_descriptor.equals( t.m_descriptor ) )
+ {
return false;
-
+ }
+ if( null == m_graph )
+ {
+ if( ! ( null == t.m_graph ) )
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if( ! m_graph.equals( t.m_graph ) )
+ {
+ return false;
+ }
+ }
if( null == m_configuration )
{
if( ! ( null == t.m_configuration ) )
+ {
return false;
+ }
}
else
{
if( ! m_configuration.equals( t.m_configuration ) )
- return false;
+ {
+ return false;
+ }
}
-
if( m_parts.length != t.m_parts.length )
{
return false;
@@ -372,22 +369,22 @@
}

if( ! m_context.equals( t.m_context ) )
+ {
return false;
-
+ }
for( int i=0; i<m_loggers.length; i++ )
{
if( ! m_loggers[i].equals( t.m_loggers[i] ) )
+ {
return false;
+ }
}
for( int i=0; i<m_services.length; i++ )
{
if( ! m_services[i].equals( t.m_services[i] ) )
+ {
return false;
- }
- for( int i=0; i<m_dependencies.length; i++ )
- {
- if( ! m_dependencies[i].equals( t.m_dependencies[i] ) )
- return false;
+ }
}
return true;
}
@@ -399,6 +396,10 @@
public int hashCode()
{
int hash = m_descriptor.hashCode();
+ if( m_graph != null )
+ {
+ hash ^= m_graph.hashCode();
+ }
hash ^= m_context.hashCode();
if( m_configuration != null )
{
@@ -414,11 +415,6 @@
hash ^= m_services[i].hashCode();
hash = hash - 163611323;
}
- for( int i = 0; i < m_dependencies.length; i++ )
- {
- hash ^= m_dependencies[i].hashCode();
- hash = hash - 912361372;
- }
for( int i = 0; i < m_loggers.length; i++ )
{
hash ^= m_loggers[i].hashCode();

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ComponentHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ComponentHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ComponentHandler.java
Sun Jul 3 04:11:07 2005
@@ -181,40 +181,6 @@
getContextMap().addEntry( key, part );
}
}
-
- //
- // If this component has been asserted as a root component then it
cannot
- // have any non-optional dependencies. If the component is nested
within another
- // component then we can attempt to resolve dependencies using the
supplied enclosing
- // component and dependency directives declared in this component's
profile. If a
- // dependency directive is not available and the dependency is
required
- // (non-optional) then we flag the model as unresolved.
- //
-
- DependencyDescriptor[] dependencies = m_type.getDependencies();
- for( int i=0; i<dependencies.length; i++ )
- {
- DependencyDescriptor dependency = dependencies[i];
- String key = dependency.getKey();
- boolean required = dependency.isRequired();
- PartReference reference = context.getPartReference( key );
- if( null == reference )
- {
- if( dependency.isRequired() )
- {
- final String error =
- "Unresolved dependency."
- + "\nComponent: " + getURI()
- + "\nKey: " + key;
- throw new ComponentException( error );
- }
- }
- else
- {
- Part part = reference.getPart();
- getContextMap().addEntry( key, part );
- }
- }
}

public ClassLoader getClassLoader()
@@ -673,40 +639,23 @@
// the composition builder upgraded to handle the state graph
// generation into the component type descriptor.

- try
+ State graph = m_type.getStateGraph();
+
+ if( graph != null )
{
- Field field = subject.getField( "STATE_GRAPH" );
- return (State) field.get( null );
+ return graph;
}
- catch( NoSuchFieldException e )
+ else if( Executable.class.isAssignableFrom( subject ) )
{
- if( Executable.class.isAssignableFrom( subject ) )
- {
- return EXECUTABLE_OBJECT_GRAPH;
- }
- else if( Startable.class.isAssignableFrom( subject ) )
- {
- return STARTABLE_OBJECT_GRAPH;
- }
- else
- {
- return NULL_OBJECT_GRAPH;
- }
+ return EXECUTABLE_OBJECT_GRAPH;
}
- catch( ClassCastException e )
+ else if( Startable.class.isAssignableFrom( subject ) )
{
- final String error =
- "The component is declaring a STATE_GRAPH member "
- + "that is not an instance of net.dpml.part.state.State."
- + "\nObject: " + getURI();
- throw new IllegalArgumentException( error );
+ return STARTABLE_OBJECT_GRAPH;
}
- catch( IllegalAccessException e )
+ else
{
- final String error =
- "Unexpected access exception while resolving class STATE_GRAPH
field."
- + "\nClass: " + subject.getName();
- throw new IllegalStateException( error );
+ return NULL_OBJECT_GRAPH;
}
}


Modified:
development/main/metro/composition/control/src/test/net/dpml/composition/info/test/TypeTestCase.java
==============================================================================
---
development/main/metro/composition/control/src/test/net/dpml/composition/info/test/TypeTestCase.java
(original)
+++
development/main/metro/composition/control/src/test/net/dpml/composition/info/test/TypeTestCase.java
Sun Jul 3 04:11:07 2005
@@ -32,7 +32,6 @@

import net.dpml.composition.info.CategoryDescriptor;
import net.dpml.composition.info.ContextDescriptor;
-import net.dpml.composition.info.DependencyDescriptor;
import net.dpml.composition.info.EntryDescriptor;
import net.dpml.composition.info.InfoDescriptor;
import net.dpml.composition.info.ReferenceDescriptor;
@@ -43,6 +42,8 @@

import net.dpml.configuration.Configuration;

+import net.dpml.part.state.State;
+

/**
* TypeTestCase does XYZ
@@ -52,11 +53,11 @@
*/
public class TypeTestCase extends TestCase
{
+ private State m_graph;
private InfoDescriptor m_descriptor;
private CategoryDescriptor[] m_loggers;
private ContextDescriptor m_context;
private ServiceDescriptor[] m_services;
- private DependencyDescriptor[] m_dependencies;
private PartDescriptor[] m_parts;
private ReferenceDescriptor m_reference;
private String m_key;
@@ -68,6 +69,7 @@

public void setUp()
{
+ m_graph = new State();
m_reference = new ReferenceDescriptor(TypeTestCase.class.getName());
m_key = TypeTestCase.class.getName();
m_descriptor = createSimpleInfo(TypeTestCase.class.getName());
@@ -79,11 +81,11 @@
m_services = new ServiceDescriptor[] {
new ServiceDescriptor(m_reference)
};
- m_dependencies = new DependencyDescriptor[] {
- new DependencyDescriptor("role", m_reference)
- };
m_parts = new PartDescriptor[] {
- new PartDescriptor( "key", new Operation[]{ new Operation(
PartDescriptor.GET, ReferenceDescriptor.class.getName() ) } )
+ new PartDescriptor(
+ "key",
+ new Operation[]{
+ new Operation( PartDescriptor.GET,
ReferenceDescriptor.class.getName() ) } )
};
}

@@ -92,8 +94,6 @@
assertNotNull(type);
checkArray( m_loggers, type.getCategories());
assertEquals( m_context, type.getContext());
- checkArray( m_dependencies, type.getDependencies());
- assertEquals( m_dependencies[0],
type.getDependency(m_dependencies[0].getKey()));
assertEquals( m_descriptor, type.getInfo() );
assertEquals( m_services[0], type.getService(m_reference));
assertEquals( m_services[0], type.getService(
m_services[0].getReference().getClassname()));
@@ -116,7 +116,7 @@
{
Type type =
new Type(
- m_descriptor, m_loggers, m_context, m_services, m_dependencies,
+ m_graph, m_descriptor, m_loggers, m_context, m_services,
null, m_parts );
checkType(type);
}
@@ -125,8 +125,7 @@
{
Type type =
new Type(
- m_descriptor, m_loggers, m_context, m_services, m_dependencies,
- null, m_parts );
+ m_graph, m_descriptor, m_loggers, m_context, m_services, null,
m_parts );

checkType( type );


Modified: development/main/metro/index.xml
==============================================================================
--- development/main/metro/index.xml (original)
+++ development/main/metro/index.xml Sun Jul 3 04:11:07 2005
@@ -120,7 +120,6 @@
<name>dpml-composition-control</name>
<types>
<type>jar</type>
- <!--<type>plugin</type>-->
</types>
</info>
<dependencies>

Modified: development/main/metro/part/src/main/net/dpml/part/state/State.java
==============================================================================
--- development/main/metro/part/src/main/net/dpml/part/state/State.java
(original)
+++ development/main/metro/part/src/main/net/dpml/part/state/State.java Sun
Jul 3 04:11:07 2005
@@ -257,7 +257,7 @@
* @exception NoSuchStateException if the key does not match a state
* within the state graph
*/
- protected State getState( String key )
+ public State getState( String key )
{
if( null == key )
{
@@ -302,6 +302,21 @@
* selecting transitions.
*
* @param key the transition key
+ * @param target the transition target state
+ */
+ public void addTransition( String key, String target )
+ {
+ State state = getState( target );
+ addTransition( key, state );
+ }
+
+ /**
+ * Add a transition to the state. Transition keys are unique within the
scope
+ * of the state under which the transition is assigned. Transitions with
the
+ * same name as a transition within a parent state will take precedence
when
+ * selecting transitions.
+ *
+ * @param key the transition key
* @param uri the uri identifying the handler to be assigned as the
handler
* of the transition action
* @param target the transition target state
@@ -322,6 +337,40 @@
}

/**
+ * Add a transition to the state. Transition keys are unique within the
scope
+ * of the state under which the transition is assigned. Transitions with
the
+ * same name as a transition within a parent state will take precedence
when
+ * selecting transitions.
+ *
+ * @param key the transition key
+ * @param uri the uri identifying the handler to be assigned as the
handler
+ * of the transition action
+ * @param target the transition target state
+ */
+ public void addTransition( String key, URI uri, String target )
+ {
+ State state = getState( target );
+ addTransition( key, uri, state );
+ }
+
+
+ /**
+ * Optionally set the initializer for this state. During the state
manager
+ * initialization phase an initializer declared on the assigned state
model
+ * will be invoked. If the current state is modified as a result of
invocation
+ * of an initializer, any initializer associated with the new state will
be
+ * fired. This process will continue until a state is established that
does not
+ * delcare an initializor.
+ *
+ * @param target the target initialization state
+ */
+ public void setInitialization( String target )
+ {
+ State state = getState( target );
+ setInitialization( state );
+ }
+
+ /**
* Optionally set the initializer for this state. During the state
manager
* initialization phase an initializer declared on the assigned state
model
* will be invoked. If the current state is modified as a result of
invocation
@@ -363,6 +412,24 @@
* of the initialization action
* @param target the target initialization state
*/
+ public void setInitialization( URI uri, String target )
+ {
+ State state = getState( target );
+ setInitialization( uri, state );
+ }
+
+ /**
+ * Optionally set the initializer for this state. During the state
manager
+ * initialization phase an initializer declared on the assigned state
model
+ * will be invoked. If the current state is modified as a result of
invocation
+ * of an initializer, any initializer associated with the new state will
be
+ * fired. This process will continue until a state is established that
does not
+ * delcare an initializor.
+ *
+ * @param uri the uri identifying the handler to be assigned as the
handler
+ * of the initialization action
+ * @param target the target initialization state
+ */
public void setInitialization( URI uri, State target )
{
if( null != m_initialization )
@@ -395,6 +462,22 @@
*
* @param target the transition target state
*/
+ public void setTerminator( String target )
+ {
+ State state = getState( target );
+ setTerminator( null, state );
+ }
+
+ /**
+ * Optionally set the terminator for this state. During the state manager
+ * termination phase a terminator declared on the assigned state model
+ * will be invoked. If the current state is modified as a result of
invocation
+ * of a terminator, a terminator associated with the new state will be
+ * fired (if declared). This process will continue until a terminal
state is
+ * established or no additional terminators can be fired.
+ *
+ * @param target the transition target state
+ */
public void setTerminator( State target )
{
setTerminator( null, target );
@@ -412,6 +495,24 @@
* of the transition action
* @param target the transition target state
*/
+ public void setTerminator( URI uri, String target )
+ {
+ State state = getState( target );
+ setTerminator( uri, state );
+ }
+
+ /**
+ * Optionally set the terminator for this state. During the state manager
+ * termination phase a terminator declared on the assigned state model
+ * will be invoked. If the current state is modified as a result of
invocation
+ * of a terminator, a terminator associated with the new state will be
+ * fired (if declared). This process will continue until a terminal
state is
+ * established or no additional terminators can be fired.
+ *
+ * @param uri the uri identifying the handler to be assigned as the
handler
+ * of the transition action
+ * @param target the transition target state
+ */
public void setTerminator( URI uri, State target )
{
if( null != m_terminator )

Modified:
development/main/metro/part/src/test/net/dpml/part/state/StateTestCase.java
==============================================================================
---
development/main/metro/part/src/test/net/dpml/part/state/StateTestCase.java
(original)
+++
development/main/metro/part/src/test/net/dpml/part/state/StateTestCase.java
Sun Jul 3 04:11:07 2005
@@ -316,7 +316,7 @@
State foo = m_root.addState( "foo" );
try
{
- m_root.addTransition( "to-foo", new URI( "method:null" ), null );
+ m_root.addTransition( "to-foo", new URI( "method:null" ),
(State) null );
fail( "do not throw NPE" );
}
catch( NullPointerException e )
@@ -384,7 +384,7 @@
State foo = m_root.addState( "foo" );
try
{
- m_root.setInitialization( new URI( "system:null" ), null );
+ m_root.setInitialization( new URI( "system:null" ), (State) null
);
fail( "No NPE." );
}
catch( NullPointerException e )
@@ -439,7 +439,7 @@
State foo = m_root.addState( "foo" );
try
{
- m_root.setTerminator( new URI( "system:null" ), null );
+ m_root.setTerminator( new URI( "system:null" ), (State) null );
fail( "do not throw NPE" );
}
catch( NullPointerException e )
@@ -459,7 +459,7 @@
catch( IllegalArgumentException e )
{
// success
- }
+ }
}

public void testSetTerminatorInTerminal() throws Exception

Modified:
development/main/test/components/plus/src/main/net/dpml/test/acme/plus/ManagedComponent.java
==============================================================================
---
development/main/test/components/plus/src/main/net/dpml/test/acme/plus/ManagedComponent.java
(original)
+++
development/main/test/components/plus/src/main/net/dpml/test/acme/plus/ManagedComponent.java
Sun Jul 3 04:11:07 2005
@@ -133,7 +133,7 @@
buffer.append( "\nState Model:" );
buffer.append( "\nCurrent State: " + state.getName() );
buffer.append( "\n-------------------------------------------------"
);
- buffer.append( STATE_GRAPH.list() );
+ buffer.append( state.list() );
buffer.append( "\n-------------------------------------------------"
);
buffer.append( "\nClass Loader Stack" );
buffer.append( "\n-------------------------------------------------"
);
@@ -146,60 +146,6 @@
// static utilities
// ------------------------------------------------------------------

- public static final State STATE_GRAPH = new State();
-
- static
- {
- //
- // construct a state graph
- //
-
- State root = STATE_GRAPH;
- State initialized = root.addState( "initialized" );
- State available = root.addState( "available" );
- State started = available.addState( "started" );
- State stopped = available.addState( "stopped" );
- State terminated = root.addTerminalState( "terminated" );
-
- //
- // create the handler declarations
- //
-
- try
- {
- //
- // add system transitions dealing with initilization and
- // termination - each transition is added to a particular
- // state and is qualified with the uri of the handler to
- // use, and the transitions target state
- //
-
- root.setInitialization( initialized );
- root.setTerminator( new URI( "method:null" ), terminated );
- started.setTerminator( new URI( "method:stop" ), stopped );
-
- //
- // add user (application) transitions
- //
-
- initialized.addTransition( "start", new URI( "method:start" ),
started );
- started.addTransition( "stop", new URI( "method:stop" ), stopped
);
- stopped.addTransition( "start", new URI( "method:start" ),
started );
-
- //
- // add an operations that is only accessible in the active state
chain
- // when the component is in the started state
- //
-
- started.addOperation( "audit", new URI( "method:audit" ) );
-
- }
- catch( URISyntaxException e )
- {
- // will not happen
- }
- }
-
//
// The following class is an example of a transition handler. Instances
// of this class may be registered with the state manager and referenced
in

Added:
development/main/test/components/plus/src/main/net/dpml/test/acme/plus/ManagedComponent.xgraph
==============================================================================
--- (empty file)
+++
development/main/test/components/plus/src/main/net/dpml/test/acme/plus/ManagedComponent.xgraph
Sun Jul 3 04:11:07 2005
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<state>
+
+ <initialization target="initialized"/>
+
+ <termination target="terminated"/>
+
+ <state name="initialized">
+ <transition name="start" target="started">
+ <method name="start"/>
+ </transition>
+ </state>
+
+ <state name="available">
+
+ <state name="started">
+
+ <termination target="stopped">
+ <method name="stop"/>
+ </termination>
+
+ <transition name="stop" target="stopped">
+ <method name="stop"/>
+ </transition>
+
+ <operation name="audit">
+ <method name="audit"/>
+ </operation>
+
+ </state>
+
+ <state name="stopped">
+
+ <transition name="start" target="started">
+ <method name="start"/>
+ </transition>
+
+ </state>
+
+ </state>
+
+ <state name="terminated" terminal="true"/>
+
+</state>
+



  • svn commit: r2958 - in development/main: metro metro/composition/builder/src/main/net/dpml/composition/builder metro/composition/control/src/main/net/dpml/composition/data metro/composition/control/src/main/net/dpml/composition/info metro/composition/control/src/main/net/dpml/composition/runtime metro/composition/control/src/test/net/dpml/composition/info/test metro/part/src/main/net/dpml/part/state metro/part/src/test/net/dpml/part/state test/components/plus/src/main/net/dpml/test/acme/plus, mcconnell, 07/03/2005

Archive powered by MHonArc 2.6.24.

Top of Page