Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2462 - in development/main/metro: . composition/builder/src/main/net/dpml/composition/builder composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/event composition/control/src/main/net/dpml/composition/model composition/part/src/main/net/dpml/composition/info composition/testing/test/src/main/net/dpml/test/config composition/testing/test/src/main/net/dpml/test/state composition/testing/test/src/test/net/dpml/composition/testing composition/testing/test/src/test/net/dpml/test/config composition/testing/test/src/test/net/dpml/test/state composition/testing/workshop composition/testing/workshop/src composition/testing/workshop/src/main composition/testing/workshop/src/main/net composition/testing/workshop/src/main/net/dpml composition/testing/workshop/src/main/net/dpml/test composition/testing/workshop/src/test composition/testing/workshop/src/test/net composition/testing/workshop/src/test/net/dpml composition/testing/workshop/src/test/net/dpml/test composition/unit/src/main/net/dpml/composition/unit parts/src/main/net/dpml/parts/control parts/src/main/net/dpml/parts/model

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: r2462 - in development/main/metro: . composition/builder/src/main/net/dpml/composition/builder composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/event composition/control/src/main/net/dpml/composition/model composition/part/src/main/net/dpml/composition/info composition/testing/test/src/main/net/dpml/test/config composition/testing/test/src/main/net/dpml/test/state composition/testing/test/src/test/net/dpml/composition/testing composition/testing/test/src/test/net/dpml/test/config composition/testing/test/src/test/net/dpml/test/state composition/testing/workshop composition/testing/workshop/src composition/testing/workshop/src/main composition/testing/workshop/src/main/net composition/testing/workshop/src/main/net/dpml composition/testing/workshop/src/main/net/dpml/test composition/testing/workshop/src/test composition/testing/workshop/src/test/net composition/testing/workshop/src/test/net/dpml composition/testing/workshop/src/test/net/dpml/test composition/unit/src/main/net/dpml/composition/unit parts/src/main/net/dpml/parts/control parts/src/main/net/dpml/parts/model
  • Date: Thu, 05 May 2005 08:13:30 -0400

Author: mcconnell AT dpml.net
Date: Thu May 5 08:13:26 2005
New Revision: 2462

Added:

development/main/metro/composition/control/src/main/net/dpml/composition/model/AbstractComponent.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/Appliance.java
- copied, changed from r2460,
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ApplianceException.java
- copied, changed from r2453,
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceException.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentTable.java
- copied, changed from r2453,
development/main/metro/composition/control/src/main/net/dpml/composition/control/InstanceTable.java
development/main/metro/composition/testing/workshop/ (props changed)
development/main/metro/composition/testing/workshop/build.properties
development/main/metro/composition/testing/workshop/build.xml
development/main/metro/composition/testing/workshop/src/
development/main/metro/composition/testing/workshop/src/main/
development/main/metro/composition/testing/workshop/src/main/net/
development/main/metro/composition/testing/workshop/src/main/net/dpml/
development/main/metro/composition/testing/workshop/src/main/net/dpml/test/

development/main/metro/composition/testing/workshop/src/main/net/dpml/test/WorkshopComponent.java
development/main/metro/composition/testing/workshop/src/test/
development/main/metro/composition/testing/workshop/src/test/net/
development/main/metro/composition/testing/workshop/src/test/net/dpml/
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/

development/main/metro/composition/testing/workshop/src/test/net/dpml/test/WorkshopTestCase.java

development/main/metro/parts/src/main/net/dpml/parts/model/AvailabilityEvent.java

development/main/metro/parts/src/main/net/dpml/parts/model/AvailabilityListener.java
development/main/metro/parts/src/main/net/dpml/parts/model/Provider.java
Removed:

development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceException.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/InstanceTable.java

development/main/metro/composition/control/src/main/net/dpml/composition/event/AvailabilityEvent.java

development/main/metro/composition/control/src/main/net/dpml/composition/event/AvailabilityListener.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/control/ComponentController.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionClassLoader.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/LifestyleHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/PartsInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ValueController.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentEntry.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/CompositionModel.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ContextTable.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceEntry.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueEntry.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueModel.java

development/main/metro/composition/part/src/main/net/dpml/composition/info/PartDescriptor.java

development/main/metro/composition/testing/test/src/main/net/dpml/test/config/ConfigurableContainer.java

development/main/metro/composition/testing/test/src/main/net/dpml/test/state/ManagingContainer.java

development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/ExampleTestCase.java

development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/SimpleTestCase.java

development/main/metro/composition/testing/test/src/test/net/dpml/test/config/ConfigurationTestCase.java

development/main/metro/composition/testing/test/src/test/net/dpml/test/state/ManagementTestCase.java

development/main/metro/composition/unit/src/main/net/dpml/composition/unit/CompositionHelper.java
development/main/metro/index.xml

development/main/metro/parts/src/main/net/dpml/parts/control/Controller.java
development/main/metro/parts/src/main/net/dpml/parts/model/Component.java
development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
Log:
improving the structure with the relocation of appliance under the model
package (appliance is actually a view of a component model); adding Provider
a sub-type of Component (which is a step towards isolating Component to the
owner of the model in which it is contained); improved memory management via
a weak event provider model; and validation of classloader garbage
collection; also improved/rationalized naming

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 May 5 08:13:26 2005
@@ -547,6 +547,11 @@
validateNonNullReturnType( method );
validateAtMostOneParameter( method );
}
+ else if( PartDescriptor.PROVIDER_KEY.equals( postfix ) )
+ {
+ validateNonNullReturnType( method );
+ validateAtMostOneParameter( method );
+ }
else if( PartDescriptor.MODEL_KEY.equals( postfix ) )
{
validateNonNullReturnType( method );

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ComponentController.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ComponentController.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ComponentController.java
Thu May 5 08:13:26 2005
@@ -117,11 +117,11 @@
{
if( component instanceof ComponentEntry )
{
+
ComponentEntry entry = (ComponentEntry) component;
if( policy )
{
- InvocationHandler handler = new ApplianceInvocationHandler(
entry );
- return entry.getProxy( handler );
+ return entry.getProxy();
}
else
{
@@ -145,29 +145,25 @@
}

/**
- * Release a reference to an object managed by the instance.
+ * Release a proxy reference to a component.
*
- * @param instance the instance to release
+ * @param proxy the proxy to release
*/
- public void release( Object instance )
+ public void release( Object proxy )
{
- if( null == instance )
+ if( null == proxy )
{
return;
}
- if( Proxy.isProxyClass( instance.getClass() ) )
+ if( Proxy.isProxyClass( proxy.getClass() ) )
{
- Object handler = Proxy.getInvocationHandler( instance );
+ Object handler = Proxy.getInvocationHandler( proxy );
if( handler instanceof Disposable )
{
Disposable disposable = (Disposable) handler;
disposable.dispose();
}
}
- else
- {
- m_lifecycleHandler.etherialize( instance );
- }
}

/**

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionClassLoader.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionClassLoader.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionClassLoader.java
Thu May 5 08:13:26 2005
@@ -23,6 +23,7 @@
import java.net.URLClassLoader;

import net.dpml.parts.control.ControlRuntimeException;
+import net.dpml.parts.control.Monitor;

import net.dpml.transit.repository.StandardClassLoader;

@@ -38,6 +39,7 @@
// state
//--------------------------------------------------------------------

+ private final Monitor m_monitor;
private final URI m_partition;
private final int m_index;

@@ -45,16 +47,17 @@
// constructor
//--------------------------------------------------------------------

- public CompositionClassLoader( URI partition, ClassLoader parent )
+ public CompositionClassLoader( Monitor monitor, URI partition,
ClassLoader parent )
{
- this( partition, 0, new URI[0], parent );
+ this( monitor, partition, 0, new URI[0], parent );
}

- public CompositionClassLoader( URI partition, int index, URI[] uris,
ClassLoader parent )
+ public CompositionClassLoader( Monitor monitor, URI partition, int
index, URI[] uris, ClassLoader parent )
{
super( partition, urisToURLs( uris ), parent );
m_partition = partition;
m_index = index;
+ m_monitor = monitor;
}

//--------------------------------------------------------------------
@@ -148,7 +151,12 @@

protected void finalize()
{
-System.out.println( "## CLASSLOADER finalization: " + m_partition );
+ if( m_monitor.isDebugEnabled() )
+ {
+ final String message =
+ "classloader finalization: " + m_partition;
+ m_monitor.debug( message );
+ }
}

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

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
Thu May 5 08:13:26 2005
@@ -55,6 +55,7 @@
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.Component;
+import net.dpml.parts.model.Provider;

import net.dpml.parts.part.Part;

@@ -83,7 +84,6 @@
private final LifestyleHandler m_lifestyleHandler;
private final URI m_partition;
private final ValueController m_valueController;
- private final InstanceTable m_instances;

//--------------------------------------------------------------------
// constructor
@@ -98,12 +98,6 @@
m_valueController = new ValueController( this );
ComponentController manager = new ComponentController( monitor,
system, this );
m_lifestyleHandler = new LifestyleHandler( monitor, manager );
- m_instances = new InstanceTable( this );
- }
-
- public InstanceTable getInstanceTable()
- {
- return m_instances;
}

//--------------------------------------------------------------------
@@ -217,7 +211,7 @@
return model.getPartsTable().getModel( key );
}

- public Entry getContextEntry( CompositionModel model, String key )
+ public Provider getContextEntry( CompositionModel model, String key )
{
return model.getContextTable().getEntry( key );
}
@@ -312,7 +306,7 @@
final ValueDirective directive = (ValueDirective) part;
getMonitor().debug( "creating nested value model using " +
directive );
URI partition = getPartition( model );
- return new ValueModel( key, this, partition, m_valueController,
classloader, directive, model );
+ return new ValueModel( m_monitor, key, this, partition,
m_valueController, classloader, directive, model );
}
else
{
@@ -325,6 +319,29 @@
}

/**
+ * Return a default service provider.
+ *
+ * @param model the reference model
+ * @return the service provider
+ */
+ public Provider getProvider( Model model )
+ {
+ return getComponent( (Component) null, model );
+ }
+
+ /**
+ * Return an identified service provider.
+ *
+ * @param model the reference model
+ * @param identity the privider identity
+ * @return the service provider
+ */
+ public Provider getProvider( Model model, Object identity )
+ {
+ return getComponent( (Component) null, model, identity );
+ }
+
+ /**
* Return a nested component for a supplied part.
*
* @param model the enclosing model
@@ -333,10 +350,10 @@
* @param key the key to assign to the model
* @return the model
*/
- public Component getComponent( ClassLoader classloader, Part part,
String key )
+ public Component getComponent( Component owner, ClassLoader classloader,
Part part, String key )
throws ModelException, HandlerNotFoundException, DelegationException
{
- return getComponent( null, classloader, part, key );
+ return getComponent( owner, null, classloader, part, key );
}

/**
@@ -349,18 +366,18 @@
* @return the model
*/
public Component getComponent(
- CompositionModel model, ClassLoader classloader, Part part, String key
)
+ Component owner, CompositionModel model, ClassLoader classloader, Part
part, String key )
throws ModelException, HandlerNotFoundException, DelegationException
{
if( isRecognizedPart( part ) )
{
Model componentModel = getModel( model, classloader, part, key );
- return getComponent( componentModel );
+ return getComponent( owner, componentModel );
}
else
{
Controller controller = getPartHandler( part );
- return controller.getComponent( classloader, part, key );
+ return controller.getComponent( owner, classloader, part, key );
}
}

@@ -371,8 +388,7 @@
* @param identity the instance identity
* @return the model
*/
- public Component getComponent( Model model )
- throws ModelException
+ public Component getComponent( Component owner, Model model )
{
if( model instanceof ValueModel )
{
@@ -381,7 +397,7 @@
}
else
{
- return getComponentEntry( model, null );
+ return getComponentEntry( owner, model, null );
}
}

@@ -392,10 +408,9 @@
* @param identity the instance identity
* @return the model
*/
- public Component getComponent( Model model, Object key )
- throws ModelException
+ public Component getComponent( Component owner, Model model, Object key
)
{
- return getComponentEntry( model, key );
+ return getComponentEntry( owner, model, key );
}

/**
@@ -405,8 +420,7 @@
* @param identity the instance identity
* @return the model
*/
- public ComponentEntry getComponentEntry( Model model, Object key )
- throws ModelException
+ public ComponentEntry getComponentEntry( Component owner, Model model,
Object key )
{
if( null == model )
{
@@ -417,11 +431,11 @@
CompositionModel m = (CompositionModel) model;
if( null == key )
{
- return m_lifestyleHandler.aquire( m, null );
+ return m_lifestyleHandler.aquire( m, owner );
}
else
{
- return m_lifestyleHandler.aquire( m, key, null );
+ return m_lifestyleHandler.aquire( m, key, owner );
}
}
else
@@ -515,7 +529,7 @@
URI[] uris = filter( cpd.getURIs(), parent );
if( uris.length > 0 )
{
- parent = new CompositionClassLoader( partition, i, uris,
parent );
+ parent = new CompositionClassLoader( m_monitor, partition,
i, uris, parent );
}
}
return parent;

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
Thu May 5 08:13:26 2005
@@ -155,7 +155,7 @@
throws IOException, DelegationException, ModelException,
PartNotFoundException, HandlerNotFoundException
{
Model model = getModel( uri, key );
- Component component = model.getComponent();
+ Component component = model.getController().getComponent(
(Component) null, model );
addComponent( component );
return component;
}
@@ -171,7 +171,7 @@
throws IOException, DelegationException, ModelException,
PartNotFoundException, HandlerNotFoundException
{
Model model = getModel( uri, key );
- Component component = model.getComponent( id );
+ Component component = model.getController().getComponent(
(Component) null, model, id );
addComponent( component );
return component;
}
@@ -207,7 +207,7 @@
Component component = components[i];
getMonitor().debug( "stopping " + component.getURI() );
Object instance = m_instances.get( component );
- component.getManager().release( instance );
+ component.release( instance );
m_instances.remove( component );
}
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextInvocationHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextInvocationHandler.java
Thu May 5 08:13:26 2005
@@ -24,11 +24,11 @@

import net.dpml.parts.control.LifecycleException;
import net.dpml.parts.model.ModelException;
+import net.dpml.parts.model.AvailabilityListener;
import net.dpml.parts.state.StateListener;

import net.dpml.composition.model.ComponentEntry;
import net.dpml.composition.model.CompositionModel;
-import net.dpml.composition.event.AvailabilityListener;

import net.dpml.system.SystemContext;


Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifestyleHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifestyleHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifestyleHandler.java
Thu May 5 08:13:26 2005
@@ -65,18 +65,18 @@
{
synchronized( model )
{
- ComponentEntry holder = new ComponentEntry( m_monitor,
m_controller, model, null, owner );
- Object key = holder.getKey();
+ ComponentEntry entry = new ComponentEntry( m_monitor,
m_controller, model, null, owner );
+ Object key = entry.getKey();
if( getMonitor().isDebugEnabled() )
{
final String message =
"Established key ["
- + holder.getURI()
+ + entry.getURI()
+ "].";
getMonitor().debug( message );
}
- model.getCompositionController().getInstanceTable().add(
holder );
- return holder;
+ model.getComponentTable().add( entry );
+ return entry;
}
}
else if( "model".equals( lifestyle ) || "singleton".equals(
lifestyle ) )
@@ -120,9 +120,9 @@
{
throw new NullPointerException( "key" );
}
- ComponentEntry holder =
model.getCompositionController().getInstanceTable().get( model, key );
+ ComponentEntry entry = model.getComponentTable().get( key );

- if( null == holder )
+ if( null == entry )
{
if( getMonitor().isDebugEnabled() )
{
@@ -132,29 +132,29 @@
+ "].";
getMonitor().debug( message );
}
- holder = new ComponentEntry( m_monitor, m_controller, model,
key, owner );
+ entry = new ComponentEntry( m_monitor, m_controller, model, key,
owner );
if( getMonitor().isDebugEnabled() )
{
final String message =
- "Adding holder ["
- + holder.getURI()
+ "Adding component entry ["
+ + entry.getURI()
+ "].";
getMonitor().debug( message );
}
- model.getCompositionController().getInstanceTable().add( holder
);
+ model.getComponentTable().add( entry );
}
else
{
if( getMonitor().isDebugEnabled() )
{
final String message =
- "Using existing holder ["
- + holder.getURI()
+ "Using existing component entry ["
+ + entry.getURI()
+ "].";
getMonitor().debug( message );
}
}
- return holder;
+ return entry;
}

public void release( CompositionModel model, Object key )
@@ -170,7 +170,7 @@
+ "].";
getMonitor().debug( message );
}
- model.getCompositionController().getInstanceTable().remove( model,
key );
+ model.getComponentTable().remove( key );
}

private Monitor getMonitor()

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/PartsInvocationHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/PartsInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/PartsInvocationHandler.java
Thu May 5 08:13:26 2005
@@ -156,7 +156,7 @@
Controller controller = provider.getController();
if( null == args )
{
- return controller.getComponent( provider ).resolve();
+ return controller.getComponent( m_holder, provider
).resolve();
}
else if( args.length == 1 )
{
@@ -164,18 +164,18 @@
if( arg.getClass() == Boolean.TYPE )
{
boolean policy = getBooleanValue( args[1] );
- return controller.getComponent( provider ).resolve(
policy );
+ return controller.getComponent( m_holder, provider
).resolve( policy );
}
else
{
- return controller.getComponent( provider, arg
).resolve();
+ return controller.getComponent( m_holder, provider,
arg ).resolve();
}
}
else if( args.length == 2 )
{
Object arg = args[0];
boolean policy = getBooleanValue( args[1] );
- return controller.getComponent( provider, arg ).resolve(
policy );
+ return controller.getComponent( m_holder, provider, arg
).resolve( policy );
}
else
{
@@ -233,6 +233,10 @@
new ContextManagerInvocationHandler( system, component );
return Proxy.newProxyInstance( classloader, new Class[]{
clazz }, handler );
}
+ else if( PartDescriptor.PROVIDER_KEY.equals( postfix ) )
+ {
+ return getComponent( provider, args );
+ }
else if( PartDescriptor.COMPONENT_KEY.equals( postfix ) )
{
return getComponent( provider, args );
@@ -352,15 +356,15 @@
{
if( null == args )
{
- return model.getComponent();
+ return model.getController().getComponent( m_holder, model );
}
else if( args.length == 0 )
{
- return model.getComponent();
+ return model.getController().getComponent( m_holder, model );
}
else
{
- return model.getComponent( args[0] );
+ return model.getController().getComponent( m_holder, model,
args[0] );
}
}

@@ -369,15 +373,15 @@
CompositionController controller = model.getCompositionController();
if( null == args )
{
- return controller.getComponentEntry( model, null );
+ return controller.getComponentEntry( m_holder, model, null );
}
else if( args.length == 0 )
{
- return controller.getComponentEntry( model, null );
+ return controller.getComponentEntry( m_holder, model, null );
}
else
{
- return controller.getComponentEntry( model, args[0] );
+ return controller.getComponentEntry( m_holder, model, args[0] );
}
}


Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ValueController.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ValueController.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ValueController.java
Thu May 5 08:13:26 2005
@@ -67,7 +67,7 @@
*/
public Object resolve( Component entry, boolean policy )
{
- return entry.getValue();
+ return ((ValueEntry)entry).getInstance();
}

public void release( Object instance )

Added:
development/main/metro/composition/control/src/main/net/dpml/composition/model/AbstractComponent.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/AbstractComponent.java
Thu May 5 08:13:26 2005
@@ -0,0 +1,218 @@
+/*
+ * 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.composition.model;
+
+import java.util.EventObject;
+import java.util.EventListener;
+
+import net.dpml.composition.event.WeakEventProducer;
+import net.dpml.composition.state.DefaultState;
+
+import net.dpml.parts.control.Monitor;
+import net.dpml.parts.control.Manager;
+import net.dpml.parts.model.Component;
+import net.dpml.parts.model.AvailabilityEvent;
+import net.dpml.parts.model.AvailabilityListener;
+import net.dpml.parts.state.StateEvent;
+import net.dpml.parts.state.StateListener;
+import net.dpml.parts.state.State;
+
+/**
+ * A lifestyle handler provides support for the aquisition and release
+ * of component instances. An implementation is responsible for the
+ * handling of new instance creation based on lifestyle policy declared
+ * in a component model.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id: LifestyleManager.java 259 2004-10-30 07:24:40Z mcconnell $
+ */
+public abstract class AbstractComponent extends WeakEventProducer implements
Component
+{
+ private static final State NULL_STATE = new DefaultState( true );
+
+ private final Monitor m_monitor;
+
+ private boolean m_initialized = false;
+
+ public AbstractComponent( Monitor monitor )
+ {
+ m_monitor = monitor;
+ }
+
+ /**
+ * Return the availability status of the model.
+ * @return the availability status
+ */
+ public abstract boolean isOperational();
+
+ public void addAvailabilityListener( AvailabilityListener listener )
+ {
+ super.addListener( listener );
+ }
+
+ public void removeAvailabilityListener( AvailabilityListener listener )
+ {
+ super.removeListener( listener );
+ }
+
+ /**
+ * Return the current state of the component.
+ * @return the current state
+ */
+ public State getState()
+ {
+ return NULL_STATE;
+ }
+
+ public void addStateListener( StateListener listener )
+ {
+ super.addListener( listener );
+ }
+
+ public void removeStateListener( StateListener listener )
+ {
+ super.removeListener( listener );
+ }
+
+ protected void processEvent( EventObject event )
+ {
+ if( event instanceof AvailabilityEvent )
+ {
+ AvailabilityEvent e = (AvailabilityEvent) event;
+ EventListener[] listeners = listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener listener = listeners[i];
+ if( listener instanceof AvailabilityListener )
+ {
+ AvailabilityListener availabilityListener =
(AvailabilityListener) listener;
+ availabilityListener.availabilityChanged( e );
+ }
+ }
+ }
+ else if( event instanceof StateEvent )
+ {
+ StateEvent e = (StateEvent) event;
+ EventListener[] listeners = listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener listener = listeners[i];
+ if( listener instanceof StateListener )
+ {
+ StateListener stateListener = (StateListener) listener;
+ stateListener.stateChanged( e );
+ }
+ }
+ }
+ else
+ {
+ final String error =
+ "Event type not supported."
+ + "\nEvent Class: " + event.getClass().getName();
+ m_monitor.warn( error );
+ }
+ }
+
+ public abstract Manager getManager();
+
+ /**
+ * Return an initialized instance of the component.
+ * @return the resolved instance
+ */
+ public Object resolve() throws Exception
+ {
+ return getManager().resolve( this, true );
+ }
+
+ /**
+ * Return an initialized instance of the component using a supplied
isolation policy.
+ * If the isolation policy is TRUE an implementation shall make best
efforts to isolate
+ * implementation concerns under the object that is returned. Typically
isolation
+ * involves the creation of a proxy of a component implementation
instance that
+ * exposes a component's service interfaces to a client. If the
isolation policy if
+ * FALSE the implementation shall return the component implementation
instance.
+ *
+ * @param isolation the isolation policy
+ * @return the resolved instance
+ */
+ public Object resolve( boolean policy ) throws Exception
+ {
+ return getManager().resolve( this, policy );
+ }
+
+ /**
+ * Initialize the component.
+ */
+ //public void initialize() throws Exception
+ //{
+ // getManager().initialize( this );
+ //}
+
+ /**
+ * Applies a state transition identified by a supplied transition key.
+ *
+ * @param key the key identifying the transition to apply to the
component's controller
+ * @return the state resulting from the transition
+ * @exception if a transition error occurs
+ */
+ public State apply( String key ) throws Exception
+ {
+ return getManager().apply( this, key );
+ }
+
+ /**
+ * Executes an operation identified by a supplied operation key.
+ *
+ * @param key the key identifying the operation to execute
+ * @exception if a transition error occurs
+ */
+ public void execute( String key ) throws Exception
+ {
+ getManager().execute( this, key );
+ }
+
+ /**
+ * Release a reference to an object managed by the instance.
+ *
+ * @param instance the instance to release
+ */
+ public void release( Object object )
+ {
+ }
+
+ /**
+ * Termination of the component.
+ */
+ //public void terminate()
+ //{
+ // getManager().terminate( this );
+ //}
+
+ //protected void setInitialized( boolean flag )
+ //{
+ // m_initialized = flag;
+ // AvailabilityEvent event = new AvailabilityEvent( this, flag );
+ // super.enqueueEvent( event );
+ //}
+
+ protected Monitor getMonitor()
+ {
+ return m_monitor;
+ }
+}

Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/model/Appliance.java
(from r2460,
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceInvocationHandler.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/Appliance.java
Thu May 5 08:13:26 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 Stephen J. McConnell.
+ * Copyright 2004-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.
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.control;
+package net.dpml.composition.model;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
@@ -24,23 +24,22 @@
import java.lang.reflect.UndeclaredThrowableException;
import java.net.URI;

-import net.dpml.composition.event.AvailabilityEvent;
-import net.dpml.composition.event.AvailabilityListener;
import net.dpml.composition.model.ComponentEntry;

import net.dpml.parts.control.Disposable;
+import net.dpml.parts.model.AvailabilityEvent;
+import net.dpml.parts.model.AvailabilityListener;
import net.dpml.parts.state.ResourceUnavailableException;

/**
- * The ApplianceInvocationHandler class represents an instance of a
component.
- * It is responsible for the incarnation, runtime management, execution, and
- * etherialization of the instance it controls.
+ * An appliance is an invocation handler maintained by a component. It is
used
+ * during the construction of proxies to the component model holding the
appliance.
*
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: ApplianceInvocationHandler.java 2106 2005-03-21 18:46:10Z
mcconnell AT dpml.net $
*/
-final class ApplianceInvocationHandler
- implements InvocationHandler, Disposable, AvailabilityListener
+final class Appliance
+ implements InvocationHandler, AvailabilityListener, Disposable
{
//-------------------------------------------------------------------
// state
@@ -57,10 +56,9 @@
/**
* Create a proxy invocation handler.
*
- * @param holder the instance holder
+ * @param component the component model
*/
- ApplianceInvocationHandler( ComponentEntry component )
- throws Exception
+ Appliance( ComponentEntry component )
{
assertNotNull( component, "component" );
m_component = component;
@@ -93,12 +91,7 @@
public Object invoke( final Object proxy, final Method method, final
Object[] args )
throws Throwable
{
- if( m_disposed )
- {
- throw new IllegalStateException( "destroyed" );
- }
-
- // check if our availability flag has bene set to FALSE
+ // check if our availability flag is set to FALSE

if( false == m_available )
{
@@ -131,25 +124,28 @@
return m_component.getURI();
}

+ /**
+ * Request for the component manager or finalization method to release
+ * references.
+ */
public void dispose()
{
if( !m_disposed )
{
- m_disposed = true;
m_component.removeAvailabilityListener( this );
- m_component.release( this );
+ m_disposed = true;
}
}

- protected void finalize() throws Throwable
- {
- dispose();
- }
-
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------

+ public void finalize()
+ {
+ dispose();
+ }
+
private Throwable handleInvocationThrowable( Method method, Throwable e )
{
final String name = method.getName();
@@ -205,3 +201,4 @@
}
}
}
+

Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ApplianceException.java
(from r2453,
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceException.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceException.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ApplianceException.java
Thu May 5 08:13:26 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 Stephen J. McConnell.
+ * Copyright 2004-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.
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.control;
+package net.dpml.composition.model;

/**
* Exception to indicate that there was a appliance related error.
@@ -61,3 +61,4 @@
}
}

+

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentEntry.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentEntry.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentEntry.java
Thu May 5 08:13:26 2005
@@ -33,18 +33,14 @@
import java.util.Map.Entry;
import java.util.Vector;

-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
import net.dpml.activity.Executable;
import net.dpml.activity.Startable;

import net.dpml.composition.control.ComponentController;
import net.dpml.composition.control.CompositionController;
import net.dpml.composition.state.DefaultState;
-import net.dpml.composition.event.AvailabilityEvent;
-import net.dpml.composition.event.AvailabilityListener;
import net.dpml.composition.event.EventProducer;
+import net.dpml.composition.event.WeakEventProducer;

import net.dpml.parts.control.Identifiable;
import net.dpml.parts.control.LifecycleException;
@@ -55,6 +51,8 @@
import net.dpml.parts.state.State;
import net.dpml.parts.state.ResourceUnavailableException;
import net.dpml.parts.model.Component;
+import net.dpml.parts.model.AvailabilityEvent;
+import net.dpml.parts.model.AvailabilityListener;
import net.dpml.parts.control.Manager;

/**
@@ -66,7 +64,7 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: LifestyleManager.java 259 2004-10-30 07:24:40Z mcconnell $
*/
-public class ComponentEntry extends EventProducer implements Entry, Component
+public class ComponentEntry extends WeakEventProducer implements Entry,
Component
{
private final Map m_proxies = new WeakHashMap();

@@ -76,6 +74,7 @@
private final URI m_uri;
private final ContextMap m_context;
private final DefaultState m_graph;
+
private DefaultState m_state;
private boolean m_initialized = false;
private ComponentController m_manager;
@@ -124,6 +123,15 @@
m_state = m_graph;
}

+ /**
+ * Return the availability status of the model.
+ * @return the availability status
+ */
+ public boolean isOperational()
+ {
+ return true;
+ }
+
public void addAvailabilityListener( AvailabilityListener listener )
{
super.addListener( listener );
@@ -375,17 +383,17 @@
* Create, register and return a proxy to the instance managed by this
* holder. The implementation will register the proxy as a weak reference
* key in an internal table of proxies.
- *
- * @param handler the invocation handler from which a proxy will be
created
+ *
* @return the proxy reflecting the service interfaces declared by the
component type
*/
- public Object getProxy( InvocationHandler handler )
+ public Object getProxy()
{
CompositionModel model = getModel();
ClassLoader classloader = model.getClassLoader();
Class[] interfaces = model.getServiceClasses();
- Object proxy = Proxy.newProxyInstance( classloader, interfaces,
handler );
- m_proxies.put( proxy, this );
+ Appliance appliance = new Appliance( this );
+ Object proxy = Proxy.newProxyInstance( classloader, interfaces,
appliance );
+ //m_proxies.put( proxy, this );
return proxy;
}

@@ -443,29 +451,40 @@
return;
}

- synchronized( m_proxies )
+ try
{
- m_disposed = true;
- CompositionModel model = getModel();
- CompositionController controller =
model.getCompositionController();
- Object[] proxies = (Object[]) m_proxies.keySet().toArray( new
Object[0] );
- for( int i=0; i<proxies.length; i++ )
- {
- Object proxy = proxies[i];
- m_manager.release( proxy );
- }
- m_proxies.clear();
- controller.getInstanceTable().remove( this );
- try
- {
- Object instance = getLocalInstance();
- m_manager.release( instance );
- }
- catch( IllegalStateException e )
- {
- // pass
- }
+ //Object instance = getLocalInstance();
+ m_manager.terminate( this );
}
+ catch( IllegalStateException e )
+ {
+ // pass
+ }
+
+ getModel().getComponentTable().remove( this );
+
+ //synchronized( m_proxies )
+ //{
+ // m_disposed = true;
+ // CompositionModel model = getModel();
+ // Object[] proxies = (Object[]) m_proxies.keySet().toArray( new
Object[0] );
+ // for( int i=0; i<proxies.length; i++ )
+ // {
+ // Object proxy = proxies[i];
+ // m_manager.release( proxy );
+ // }
+ // m_proxies.clear();
+ // getModel().getComponentTable().remove( this );
+ // try
+ // {
+ // Object instance = getLocalInstance();
+ // m_manager.release( instance );
+ // }
+ // catch( IllegalStateException e )
+ // {
+ // // pass
+ // }
+ //}
}

/**
@@ -479,14 +498,15 @@
*/
public void release( Object proxy )
{
- synchronized( m_proxies )
- {
- m_proxies.remove( proxy );
- //if( m_proxies.isEmpty() )
- //{
- // dispose();
- //}
- }
+ //synchronized( m_proxies )
+ //{
+ // m_proxies.remove( proxy );
+ // if( m_proxies.isEmpty() )
+ // {
+ // //dispose();
+ // System.out.println( "NO PROXIES LEFT" );
+ // }
+ //}
}

public String toString()
@@ -500,6 +520,7 @@
*/
protected void finalize()
{
+ m_monitor.debug( "component model finalization in " + getURI() );
dispose();
}


Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentTable.java
(from r2453,
development/main/metro/composition/control/src/main/net/dpml/composition/control/InstanceTable.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/InstanceTable.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentTable.java
Thu May 5 08:13:26 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.control;
+package net.dpml.composition.model;

import java.io.Serializable;
import java.util.Map;
@@ -31,47 +31,46 @@
* @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 InstanceTable implements Serializable
+public class ComponentTable implements Serializable
{
- private final CompositionController m_controller;
+ private final CompositionModel m_model;

- private final Map m_holders = new WeakHashMap();
+ private final Map m_components = new WeakHashMap();

/**
* Creation of a new instance table.
*
* @param controller the controller
*/
- public InstanceTable( CompositionController controller )
+ public ComponentTable( CompositionModel model )
{
- m_controller = controller;
+ m_model = model;
}

- public void add( ComponentEntry holder )
+ public void add( ComponentEntry entry )
{
- if( null == holder )
+ if( null == entry )
{
- throw new NullPointerException( "holder" );
+ throw new NullPointerException( "entry" );
}
- m_holders.put( holder, holder.getModel() );
+ m_components.put( entry, m_model );
}

- public ComponentEntry get( CompositionModel model, Object key )
+ public ComponentEntry get( Object key )
{
if( null == key )
{
throw new NullPointerException( "key" );
}
- synchronized( m_holders )
+ synchronized( m_components )
{
- ComponentEntry[] holders = (ComponentEntry[])
m_holders.keySet().toArray( new ComponentEntry[0] );
- for( int i=0; i<holders.length; i++ )
+ ComponentEntry[] components = (ComponentEntry[])
m_components.keySet().toArray( new ComponentEntry[0] );
+ for( int i=0; i<components.length; i++ )
{
- ComponentEntry holder = holders[i];
- CompositionModel m = holder.getModel();
- if( key.equals( holder.getKey() ) && m.equals( model ) )
+ ComponentEntry component = components[i];
+ if( key.equals( component.getKey() ) )
{
- return holder;
+ return component;
}
}
return null;
@@ -80,22 +79,22 @@

private ComponentEntry[] list()
{
- return (ComponentEntry[]) m_holders.keySet().toArray( new
ComponentEntry[0] );
+ return (ComponentEntry[]) m_components.keySet().toArray( new
ComponentEntry[0] );
}

- public void remove( ComponentEntry holder )
+ public void remove( ComponentEntry component )
{
- m_holders.remove( holder );
+ m_components.remove( component );
}

- public void remove( CompositionModel model, Object key )
+ public void remove( Object key )
{
- synchronized( m_holders )
+ synchronized( m_components )
{
- ComponentEntry holder = get( model, key );
- if( null != holder )
+ ComponentEntry component = get( key );
+ if( null != component )
{
- remove( holder );
+ remove( component );
}
}
}
@@ -106,14 +105,14 @@
{
return false;
}
- else if( false == ( other instanceof InstanceTable ) )
+ else if( false == ( other instanceof ComponentTable ) )
{
return false;
}
else
{
- InstanceTable table = (InstanceTable) other;
- if( false == m_controller.equals( table.m_controller ) )
+ ComponentTable table = (ComponentTable) other;
+ if( false == m_model.equals( table.m_model ) )
{
return false;
}
@@ -125,8 +124,8 @@
}
for( int i=0; i<mine.length; i++ )
{
- ComponentEntry holder = mine[i];
- if( false == holder.equals( yours[i] ) )
+ ComponentEntry entry = mine[i];
+ if( false == entry.equals( yours[i] ) )
{
return false;
}
@@ -137,12 +136,12 @@

public int hashCode()
{
- int hash = m_controller.hashCode();
- ComponentEntry[] holders = list();
- for( int i=0; i<holders.length; i++ )
+ int hash = m_model.hashCode();
+ ComponentEntry[] entries = list();
+ for( int i=0; i<entries.length; i++ )
{
- ComponentEntry holder = holders[i];
- hash ^= holder.hashCode();
+ ComponentEntry entry = entries[i];
+ hash ^= entry.hashCode();
}
return hash;
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/CompositionModel.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/CompositionModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/CompositionModel.java
Thu May 5 08:13:26 2005
@@ -44,6 +44,7 @@
import net.dpml.parts.control.Controller;

import net.dpml.parts.model.Component;
+import net.dpml.parts.model.Provider;
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
@@ -60,6 +61,7 @@
*/
public class CompositionModel implements Model, Configurable,
Parameterizable, Serializable
{
+ private final ComponentTable m_table;
private final List m_errors = new LinkedList();

private final String m_key;
@@ -78,6 +80,7 @@
private Configuration m_configuration;
private Parameters m_parameters;

+
/**
* Creation of a new root component model.
*
@@ -134,6 +137,7 @@
m_uri = CompositionController.createURI( partition, name );
m_class = loadComponentClass( classloader, profile );

+ m_table = new ComponentTable( this );
m_parts = new PartsTable( this );
m_context = new ContextTable( this, parent );
m_type = controller.loadType( m_class );
@@ -255,15 +259,15 @@
}
}
}
-
- public Component getComponent() throws ModelException
+
+ public Provider getProvider()
{
- return getCompositionController().getComponent( this );
+ return getCompositionController().getProvider( this );
}

- public Component getComponent( Object key ) throws ModelException
+ public Provider getProvider( Object key )
{
- return getCompositionController().getComponent( this, key );
+ return getCompositionController().getProvider( this, key );
}

/**
@@ -330,24 +334,6 @@
}
}

- /*
- public Object getValue()
- {
- try
- {
- return getController().resolve( this );
- }
- catch( Exception e )
- {
- final String error =
- "Unable to establish value due in ["
- + this
- + "].";
- throw new ModelRuntimeException( error, e );
- }
- }
- */
-
public Throwable[] getIssues()
{
if( m_errors.isEmpty() )
@@ -395,6 +381,11 @@
return m_interfaces;
}

+ public ComponentTable getComponentTable()
+ {
+ return m_table;
+ }
+
public ContextTable getContextTable()
{
return m_context;

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ContextTable.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ContextTable.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ContextTable.java
Thu May 5 08:13:26 2005
@@ -27,6 +27,7 @@
import net.dpml.parts.control.DelegationException;
import net.dpml.parts.control.HandlerNotFoundException;
import net.dpml.parts.model.Component;
+import net.dpml.parts.model.Provider;
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
@@ -126,8 +127,8 @@
CompositionController controller =
model.getCompositionController();
try
{
- Component entry = controller.getComponent( model,
classloader, part, key );
- addEntry( key, entry );
+ Provider provider = controller.getComponent( null, model,
classloader, part, key );
+ addEntry( key, provider );
}
catch( ModelException e )
{
@@ -159,24 +160,24 @@
}
}

- public void addEntry( String key, Entry entry ) throws ModelException
+ public void addEntry( String key, Provider provider ) throws
ModelException
{
if( null == key )
{
throw new NullPointerException( "key" );
}
- if( null == entry )
+ if( null == provider )
{
- throw new NullPointerException( "entry" );
+ throw new NullPointerException( "provider" );
}
if( m_entries.containsKey( key ) )
{
throw new DuplicateKeyException( key );
}
- setEntry( key, entry );
+ setEntry( key, provider );
}

- public void setEntry( String key, Entry value )
+ public void setEntry( String key, Provider value )
{
if( null == key )
{
@@ -188,9 +189,9 @@
}
}

- public Entry getEntry( String key )
+ public Provider getEntry( String key )
{
- return (Entry) m_entries.get( key );
+ return (Provider) m_entries.get( key );
}

public boolean containsKey( String key )
@@ -204,39 +205,16 @@

public Object getValue( String key, Object[] args )
{
- Entry entry = getEntry( key );
- if( null == entry )
+ Provider provider = getEntry( key );
+ if( null == provider )
{
return getDefaultValueUsingArgs( args );
}
- else if( entry instanceof Component )
- {
- Component component = (Component) entry;
- try
- {
- return component.resolve();
- }
- catch( Exception e )
- {
- final String error =
- "Unexpected error while attempting to resolve the value of
context entry."
- + "\nModel: " + getModel().getURI()
- + "\nContext Key: " + key
- + "\nComponent URI: " + component.getURI();
- throw new ModelRuntimeException( error, e );
- }
- }
- else if( entry instanceof ReferenceEntry )
+ else
{
- // TODO: move this to the controller
- ReferenceEntry reference = (ReferenceEntry) entry;
- URI ref = reference.getReferenceURI();
- Model provider = reference.getProviderModel();
try
{
- Controller controller = provider.getController();
- Component component = controller.getComponent( provider,
ref.getFragment() );
- return component.getManager().resolve( component, true );
+ return provider.resolve();
}
catch( Exception e )
{
@@ -244,23 +222,10 @@
"Unexpected error while attempting to resolve the value of
context entry."
+ "\nModel: " + getModel().getURI()
+ "\nContext Key: " + key
- + "\nReference URI: " + ref
- + "\nProvider: " + provider.getURI();
+ + "\nComponent URI: " + provider.getURI();
throw new ModelRuntimeException( error, e );
}
}
- else
- {
- Object value = entry.getValue();
- if( null == value )
- {
- return getDefaultValueUsingArgs( args );
- }
- else
- {
- return value;
- }
- }
}

private Object getDefaultValueUsingArgs( Object[] args )

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceEntry.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceEntry.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceEntry.java
Thu May 5 08:13:26 2005
@@ -31,6 +31,10 @@
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
import net.dpml.parts.model.Component;
+import net.dpml.parts.model.Provider;
+import net.dpml.parts.model.AvailabilityListener;
+import net.dpml.parts.state.State;
+import net.dpml.parts.state.StateListener;

/**
* Default implementation of a the context entry constructor model.
@@ -38,7 +42,7 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: DefaultConstructorModel.java 1518 2005-01-17 17:13:05Z
niclas $
*/
-public class ReferenceEntry implements Entry
+public class ReferenceEntry implements Provider
{
//--------------------------------------------------------------
// state
@@ -106,33 +110,62 @@
}

//--------------------------------------------------------------
- // Entry
+ // Provider
//--------------------------------------------------------------

- public Object getKey()
+ public void release( Object proxy )
{
- return m_key;
+ getProviderModel().getProvider().release( proxy );
}

- /**
- * Return the context entry value.
- *
- * @return the context entry value
- */
- public Object getValue()
+ public void execute( String key ) throws Exception
{
- throw new UnsupportedOperationException( "getValue/0" );
+ getProviderModel().getProvider().execute( key );
}

- /**
- * Set the value.
- *
- * @param the new value
- */
- public Object setValue( Object value )
+ public State apply( String key ) throws Exception
+ {
+ return getProviderModel().getProvider().apply( key );
+ }
+
+ public Object resolve() throws Exception
+ {
+ return getProviderModel().getProvider().resolve();
+ }
+
+ public Object resolve( boolean flag ) throws Exception
+ {
+ return getProviderModel().getProvider().resolve( flag );
+ }
+
+ public void removeStateListener( StateListener listener )
+ {
+ getProviderModel().getProvider().removeStateListener( listener );
+ }
+
+ public void removeAvailabilityListener( AvailabilityListener listener )
+ {
+ getProviderModel().getProvider().removeAvailabilityListener(
listener );
+ }
+
+ public void addStateListener( StateListener listener )
+ {
+ getProviderModel().getProvider().addStateListener( listener );
+ }
+
+ public void addAvailabilityListener( AvailabilityListener listener )
+ {
+ getProviderModel().getProvider().addAvailabilityListener( listener );
+ }
+
+ public State getState()
+ {
+ return getProviderModel().getProvider().getState();
+ }
+
+ public boolean isOperational()
{
- throw new UnsupportedOperationException( "setValue/1" );
+ return getProviderModel().getProvider().isOperational();
}
-

}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueEntry.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueEntry.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueEntry.java
Thu May 5 08:13:26 2005
@@ -28,6 +28,7 @@
import net.dpml.parts.control.Controller;
import net.dpml.parts.control.Manager;

+import net.dpml.parts.control.Monitor;
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
@@ -40,7 +41,7 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: DefaultConstructorModel.java 1518 2005-01-17 17:13:05Z
niclas $
*/
-public class ValueEntry implements Component
+public class ValueEntry extends AbstractComponent
{
//--------------------------------------------------------------
// state
@@ -73,9 +74,11 @@
* context argument is null.
*/
public ValueEntry(
- ValueModel model, String name, Manager manager, ClassLoader
classloader, ValueDirective directive, Model parent )
+ Monitor monitor, ValueModel model, String name, Manager manager,
ClassLoader classloader,
+ ValueDirective directive, Model parent )
throws ModelException, NullPointerException
{
+ super( monitor );
if( directive == null )
{
throw new NullPointerException( "directive" );
@@ -103,23 +106,22 @@
}

/**
- * Return the key identifying this instance.
- *
- * @return the key
+ * Return the availability status of the model.
+ * @return the availability status
*/
- public Object getKey()
+ public boolean isOperational()
{
- return m_key;
+ return true;
}

/**
- * Return the current state.
+ * Return the key identifying this instance.
*
- * @return the state
+ * @return the key
*/
- public State getState()
+ public Object getKey()
{
- throw new UnsupportedOperationException( "getState/0" );
+ return m_key;
}

public URI getURI()
@@ -127,29 +129,6 @@
return m_uri;
}

- /**
- * Return an initialized instance of the component.
- * @return the resolved instance
- */
- public Object resolve()
- {
- return getValue();
- }
-
- /**
- * Return an initialized instance of the component.
- * @param proxy the proxy policy
- * @return the resolved instance
- */
- public Object resolve( boolean policy )
- {
- return getValue();
- }
-
- public void release( Object instance )
- {
- }
-
public Object getInstance()
{
return getValue();
@@ -164,29 +143,6 @@
}

/**
- * Applies a state transition identified by a supplied transition key.
- *
- * @param key the key identifying the transition to apply to the
component's controller
- * @return the state resulting from the transition
- * @exception if a transition error occurs
- */
- public State apply( String key ) throws Exception
- {
- return m_manager.apply( this, key );
- }
-
- /**
- * Executes an operation identified by a supplied operation key.
- *
- * @param key the key identifying the operation to execute
- * @exception if a transition error occurs
- */
- public void execute( String key ) throws Exception
- {
- m_manager.execute( this, key );
- }
-
- /**
* Termination of the component.
*/
public void terminate()

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueModel.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueModel.java
Thu May 5 08:13:26 2005
@@ -26,11 +26,13 @@
import net.dpml.composition.data.ValueDirective.Value;

import net.dpml.parts.control.Controller;
+import net.dpml.parts.control.Monitor;
import net.dpml.parts.control.Manager;
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
import net.dpml.parts.model.Component;
+import net.dpml.parts.model.Provider;

/**
* Default implementation of a the context entry constructor model.
@@ -67,6 +69,7 @@
* context argument is null.
*/
public ValueModel(
+ Monitor monitor,
String name, CompositionController controller, URI partition,
Manager manager, ClassLoader classloader,
ValueDirective directive, Model parent )
throws ModelException, NullPointerException
@@ -85,7 +88,7 @@
m_directive = directive;
m_uri = CompositionController.createURI( partition, name );
m_partition = partition;
- m_entry = new ValueEntry( this, name, manager, classloader,
directive, parent );
+ m_entry = new ValueEntry( monitor, this, name, manager, classloader,
directive, parent );
}

public URI getURI()
@@ -120,14 +123,18 @@
return m_key;
}

- public Component getComponent() throws ModelException
+ public Provider getProvider()
{
- return m_entry;
+ return getComponent();
}

- public Component getComponent( Object id ) throws ModelException
+ public Provider getProvider( Object key )
{
throw new UnsupportedOperationException( "getComponent/1" );
}

+ public Component getComponent()
+ {
+ return m_entry;
+ }
}

Modified:
development/main/metro/composition/part/src/main/net/dpml/composition/info/PartDescriptor.java
==============================================================================
---
development/main/metro/composition/part/src/main/net/dpml/composition/info/PartDescriptor.java
(original)
+++
development/main/metro/composition/part/src/main/net/dpml/composition/info/PartDescriptor.java
Thu May 5 08:13:26 2005
@@ -65,6 +65,7 @@
public static final String CONTEXT_MAP_KEY = "ContextMap";
public static final String CONTEXT_MANAGER_KEY = "ContextManager";
public static final String COMPONENT_KEY = "Component";
+ public static final String PROVIDER_KEY = "Provider";
public static final String MODEL_KEY = "Model";

public static String toString( int semantic )
@@ -98,6 +99,10 @@
{
return MODEL_KEY;
}
+ else if( name.endsWith( PROVIDER_KEY ) )
+ {
+ return PROVIDER_KEY;
+ }
else if( name.endsWith( COMPONENT_KEY ) )
{
return COMPONENT_KEY;
@@ -161,6 +166,13 @@
String substring = name.substring( 0, j );
return formatKey( substring, 3 );
}
+ else if( name.endsWith( PROVIDER_KEY ) )
+ {
+ int n = PROVIDER_KEY.length();
+ int j = name.length() - n;
+ String substring = name.substring( 0, j );
+ return formatKey( substring, 3 );
+ }
else if( name.endsWith( COMPONENT_KEY ) )
{
int n = COMPONENT_KEY.length();

Modified:
development/main/metro/composition/testing/test/src/main/net/dpml/test/config/ConfigurableContainer.java
==============================================================================
---
development/main/metro/composition/testing/test/src/main/net/dpml/test/config/ConfigurableContainer.java
(original)
+++
development/main/metro/composition/testing/test/src/main/net/dpml/test/config/ConfigurableContainer.java
Thu May 5 08:13:26 2005
@@ -90,7 +90,7 @@
((Configurable)model).configure( conf );
}
}
- model.getComponent().resolve();
+ model.getProvider().resolve();
}

private Logger getLogger()

Modified:
development/main/metro/composition/testing/test/src/main/net/dpml/test/state/ManagingContainer.java
==============================================================================
---
development/main/metro/composition/testing/test/src/main/net/dpml/test/state/ManagingContainer.java
(original)
+++
development/main/metro/composition/testing/test/src/main/net/dpml/test/state/ManagingContainer.java
Thu May 5 08:13:26 2005
@@ -77,6 +77,7 @@
Parts parts = getParts();
Component component = parts.getTestComponent();
component.initialize();
+ component.resolve();
component.apply( "start" );
component.execute( "audit" );
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/ExampleTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/ExampleTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/ExampleTestCase.java
Thu May 5 08:13:26 2005
@@ -48,7 +48,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-example-one.part" );
Model model = helper.getCompositionManager().getModel( uri,
"example" );
- Example example = (Example) model.getComponent().resolve();
+ Example example = (Example) model.getProvider().resolve();
example.doMyStuff();
}

@@ -62,7 +62,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-example-two.part" );
Model model = helper.getCompositionManager().getModel( uri,
"example" );
- Example example = (Example) model.getComponent().resolve();
+ Example example = (Example) model.getProvider().resolve();
example.doMyStuff();
}

@@ -75,7 +75,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-example-three.part" );
Model model = helper.getCompositionManager().getModel( uri,
"example" );
- Example example = (Example) model.getComponent().resolve();
+ Example example = (Example) model.getProvider().resolve();
example.doMyStuff();
}

@@ -89,7 +89,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-example-four.part" );
Model model = helper.getCompositionManager().getModel( uri,
"example" );
- Example example = (Example) model.getComponent().resolve();
+ Example example = (Example) model.getProvider().resolve();
example.doMyStuff();
}
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/SimpleTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/SimpleTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/SimpleTestCase.java
Thu May 5 08:13:26 2005
@@ -40,6 +40,11 @@
public class SimpleTestCase extends TestCase
{
private static final String PATH = "acme-simple.part";
+
+ public void tearDown()
+ {
+ System.gc();
+ }

/**
* Test the construction of the widget component and the invocation of
@@ -50,9 +55,9 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().getModel( uri, "widget"
);
- Widget widget = (Widget) model.getComponent().resolve();
+ Widget widget = (Widget) model.getProvider().resolve();
widget.doWidgetStuff( "green" );
- model.getComponent().release( widget );
+ model.getProvider().release( widget );
}

/**
@@ -64,9 +69,9 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-widget.part" );
Model model = helper.getCompositionManager().getModel( uri, "widget"
);
- Widget widget = (Widget) model.getComponent().resolve();
+ Widget widget = (Widget) model.getProvider().resolve();
widget.doWidgetStuff( "green" );
- model.getComponent().release( widget );
+ model.getProvider().release( widget );
}

/**
@@ -77,7 +82,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().getModel( uri, "widget"
);
- Widget widget = (Widget) model.getComponent().resolve();
+ Widget widget = (Widget) model.getProvider().resolve();
try
{
WidgetComponent w = (WidgetComponent) widget;
@@ -89,7 +94,7 @@
}
finally
{
- model.getComponent().release( widget );
+ model.getProvider().release( widget );
}
}

@@ -102,13 +107,13 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().getModel( uri, "widget"
);
- WidgetComponent widget = (WidgetComponent)
model.getComponent().resolve( false );
+ WidgetComponent widget = (WidgetComponent)
model.getProvider().resolve( false );
String name = widget.getName();
assertEquals( "name", "widget", name );
String newName = "freight";
widget.setName( newName );
assertEquals( "name", newName, widget.getName() );
- model.getComponent().release( widget );
+ model.getProvider().release( widget );
}

/**
@@ -121,8 +126,8 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().getModel( uri, "widget"
);
- WidgetComponent widget = (WidgetComponent) model.getComponent( id
).resolve( false );
- model.getComponent( id ).release( widget );
+ WidgetComponent widget = (WidgetComponent) model.getProvider( id
).resolve( false );
+ model.getProvider( id ).release( widget );
}

/**
@@ -138,20 +143,20 @@
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().getModel( uri, "widget"
);
Controller controller = model.getController();
- Widget w1 = (Widget) model.getComponent( "acme-widget-one"
).resolve( false );
- Widget w2 = (Widget) model.getComponent( "acme-widget-two"
).resolve( false );
+ Widget w1 = (Widget) model.getProvider( "acme-widget-one" ).resolve(
false );
+ Widget w2 = (Widget) model.getProvider( "acme-widget-two" ).resolve(
false );
if( w1.equals( w2 ) )
{
fail( "Widget w1 and w2 are not unique!" );
}
- Widget w3 = (Widget) model.getComponent( "acme-widget-one"
).resolve( false );
+ Widget w3 = (Widget) model.getProvider( "acme-widget-one" ).resolve(
false );
if( !w1.equals( w3 ) )
{
System.out.println( "" + System.identityHashCode( w1 ) );
System.out.println( "" + System.identityHashCode( w3 ) );
fail( "Widget w1 and w3 are not the same!" );
}
- model.getComponent( "acme-widget-one" ).terminate();
- model.getComponent( "acme-widget-two" ).terminate();
+ //model.getComponent( "acme-widget-one" ).terminate();
+ //model.getComponent( "acme-widget-two" ).terminate();
}
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/test/config/ConfigurationTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/test/config/ConfigurationTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/test/config/ConfigurationTestCase.java
Thu May 5 08:13:26 2005
@@ -48,8 +48,8 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "configurable-container.part" );
Model model = helper.getCompositionManager().getModel( uri );
- ConfigurableContainer container = (ConfigurableContainer)
model.getComponent().resolve( false );
- model.getComponent().release( container );
+ ConfigurableContainer container = (ConfigurableContainer)
model.getProvider().resolve( false );
+ model.getProvider().release( container );
helper.dispose();
}
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/test/state/ManagementTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/test/state/ManagementTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/test/state/ManagementTestCase.java
Thu May 5 08:13:26 2005
@@ -41,13 +41,19 @@
*/
public class ManagementTestCase extends TestCase
{
+ public void tearDown()
+ {
+ System.gc();
+ }
+
+
/**
* Test the construction of the example component and the invocation of
* the provided controller via </code>the
net.dpml.parts.state.StateManager</code> interface
*/
public void testManagedComponent() throws Exception
{
- Component component = getComponent();
+ Component component = getComponent( "managed-component.part" );
component.initialize();
List list = new LinkedList();
while ( false == list.contains( component.getState() ) )
@@ -67,10 +73,7 @@

public void testManagingContainer() throws Exception
{
- CompositionHelper helper = new CompositionHelper( false );
- URI uri = helper.toURI( "managing-container.part" );
- Model model = helper.getCompositionManager().getModel( uri );
- Component component = model.getComponent();
+ Component component = getComponent( "managing-container.part" );
try
{
component.initialize();
@@ -81,11 +84,11 @@
}
}

- Component getComponent() throws Exception
+ Component getComponent( String path ) throws Exception
{
CompositionHelper helper = new CompositionHelper( false );
- URI uri = helper.toURI( "managed-component.part" );
+ URI uri = helper.toURI( path );
Model model = helper.getCompositionManager().getModel( uri );
- return model.getComponent( this );
+ return model.getController().getComponent( null, model, this );
}
}

Added: development/main/metro/composition/testing/workshop/build.properties
==============================================================================
--- (empty file)
+++ development/main/metro/composition/testing/workshop/build.properties
Thu May 5 08:13:26 2005
@@ -0,0 +1,2 @@
+
+project.test.fork = true

Added: development/main/metro/composition/testing/workshop/build.xml
==============================================================================
--- (empty file)
+++ development/main/metro/composition/testing/workshop/build.xml Thu
May 5 08:13:26 2005
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<project name="dpml-composition-testing-workshop" default="install"
basedir="."
+ xmlns:transit="antlib:net.dpml.transit"
xmlns:x="plugin:dpml/magic/dpml-magic-core">
+
+ <transit:import uri="artifact:template:dpml/magic/standard"/>
+
+ <target name="build" depends="standard.build">
+
+ <types xmlns="plugin:dpml/composition/dpml-composition-builder">
+ <type class="net.dpml.test.WorkshopComponent"/>
+ </types>
+
+ <component dest="target/test/test.part"
+ xmlns="plugin:dpml/composition/dpml-composition-builder"
+ type="net.dpml.test.WorkshopComponent"
+ name="demo">
+ </component>
+
+ </target>
+
+</project>

Added:
development/main/metro/composition/testing/workshop/src/main/net/dpml/test/WorkshopComponent.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/testing/workshop/src/main/net/dpml/test/WorkshopComponent.java
Thu May 5 08:13:26 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.test;
+
+import java.util.logging.Logger;
+
+/**
+ * Experimental component dealing with state management.
+ *
+ * @author <a href="mailto:info AT dpml.net";>The Digital Product Meta
Library</a>
+ */
+public class WorkshopComponent
+{
+ // ------------------------------------------------------------------
+ // static
+ // ------------------------------------------------------------------
+
+ public static final boolean TYPE_THREADSAFE_CAPABLE = false;
+
+ // ------------------------------------------------------------------
+ // state
+ // ------------------------------------------------------------------
+
+ private final Logger m_logger;
+
+ // ------------------------------------------------------------------
+ // constructor
+ // ------------------------------------------------------------------
+
+ /**
+ * Creation of a component that describes an activity model.
+ *
+ * @param logger the logging channel assigned by the container
+ */
+ public WorkshopComponent( final Logger logger )
+ {
+ m_logger = logger;
+ m_logger.info( "instantiation" );
+ }
+
+ // ------------------------------------------------------------------
+ // implementation
+ // ------------------------------------------------------------------
+
+ private Logger getLogger()
+ {
+ return m_logger;
+ }
+
+ protected void finalize() throws Exception
+ {
+ m_logger.info( "finalization" );
+ }
+}

Added:
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/WorkshopTestCase.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/WorkshopTestCase.java
Thu May 5 08:13:26 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.test;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import net.dpml.composition.unit.CompositionHelper;
+
+import net.dpml.parts.control.Manager;
+import net.dpml.parts.model.Component;
+import net.dpml.parts.model.Model;
+
+/**
+ * Test a simple component case.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta
+ * Library</a>
+ */
+public class WorkshopTestCase extends TestCase
+{
+ /**
+ * Test the construction of the example component and the invocation of
+ * the provided controller via </code>the
net.dpml.parts.state.StateManager</code> interface
+ */
+ public void testComponent() throws Exception
+ {
+ CompositionHelper helper = new CompositionHelper( false );
+ URI uri = helper.toURI( "test.part" );
+ Model model = helper.getCompositionManager().getModel( uri );
+ Object instance = model.getProvider( "123" ).resolve();
+ for( int i=0; i<10; i++ )
+ {
+ model.getProvider( "123" ).resolve();
+ }
+
+ System.gc();
+ System.out.println( "# a: " + instance );
+ instance = null;
+ System.gc();
+ sleep( 100 );
+ System.out.println( "# b" );
+ model = null;
+ System.gc();
+ sleep( 100 );
+ System.out.println( "# c" );
+ }
+
+ private void sleep( int time )
+ {
+ try
+ {
+ Thread.currentThread().sleep( time );
+ }
+ catch( Throwable e )
+ {
+ }
+ }
+}

Modified:
development/main/metro/composition/unit/src/main/net/dpml/composition/unit/CompositionHelper.java
==============================================================================
---
development/main/metro/composition/unit/src/main/net/dpml/composition/unit/CompositionHelper.java
(original)
+++
development/main/metro/composition/unit/src/main/net/dpml/composition/unit/CompositionHelper.java
Thu May 5 08:13:26 2005
@@ -126,6 +126,7 @@
public void dispose()
{
getCompositionManager().dispose();
+ System.gc();
}

/**

Modified: development/main/metro/index.xml
==============================================================================
--- development/main/metro/index.xml (original)
+++ development/main/metro/index.xml Thu May 5 08:13:26 2005
@@ -494,6 +494,26 @@
</plugins>
</project>

+ <project basedir="composition/testing/workshop">
+ <info>
+ <group>dpml/test</group>
+ <name>dpml-composition-testing-workshop</name>
+ <types>
+ <type>jar</type>
+ <type>part</type>
+ </types>
+ </info>
+ <dependencies>
+ <include key="dpml-parts-api"/>
+ <include key="dpml-activity-api"/>
+ <include key="dpml-composition-unit" runtime="false"/>
+ </dependencies>
+ <plugins>
+ <include key="dpml-composition-builder"/>
+ </plugins>
+ </project>
+
+
<!-- Utilities -->

<project basedir="util/defaults">

Modified:
development/main/metro/parts/src/main/net/dpml/parts/control/Controller.java
==============================================================================
---
development/main/metro/parts/src/main/net/dpml/parts/control/Controller.java
(original)
+++
development/main/metro/parts/src/main/net/dpml/parts/control/Controller.java
Thu May 5 08:13:26 2005
@@ -21,6 +21,7 @@
import java.net.URI;

import net.dpml.parts.model.Model;
+import net.dpml.parts.model.Provider;
import net.dpml.parts.model.Component;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.part.Part;
@@ -70,23 +71,39 @@
throws ModelException, HandlerNotFoundException, DelegationException;

/**
- * Return a default instance model.
+ * Return a default service provider.
*
* @param model the reference model
- * @param identity the instance identity
- * @return the model
+ * @return the service provider
+ */
+ Provider getProvider( Model model );
+
+ /**
+ * Return an identified service provider.
+ *
+ * @param model the reference model
+ * @param identity the privider identity
+ * @return the service provider
+ */
+ Provider getProvider( Model model, Object identity );
+
+ /**
+ * Return a default service provider component.
+ *
+ * @param model the reference model
+ * @return the service provider
*/
- Component getComponent( Model model )
+ Component getComponent( Component owner, Model model )
throws ModelException;

/**
- * Return a model relative to a supplied model and identity.
+ * Return an identified service provider component.
*
* @param model the reference model
- * @param identity the instance identity
- * @return the model
+ * @param identity the privider identity
+ * @return the service provider
*/
- Component getComponent( Model model, Object identity )
+ Component getComponent( Component owner, Model model, Object identity )
throws ModelException;

/**
@@ -94,10 +111,10 @@
*
* @param parent the parent classloader
* @param part the part datastructure
- * @param name the name to assign to the model
- * @return the model
+ * @param name the name to assign to the provider model
+ * @return the default provider
*/
- Component getComponent( ClassLoader parent, Part part, String name )
+ Component getComponent( Component owner, ClassLoader parent, Part part,
String name )
throws ModelException, HandlerNotFoundException, DelegationException;

}

Added:
development/main/metro/parts/src/main/net/dpml/parts/model/AvailabilityEvent.java
==============================================================================
--- (empty file)
+++
development/main/metro/parts/src/main/net/dpml/parts/model/AvailabilityEvent.java
Thu May 5 08:13:26 2005
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2005 Stephen 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.parts.model;
+
+import java.util.EventObject;
+
+/**
+ * Exception thrown if a requested resource is unavailable.
+ *
+ */
+public class AvailabilityEvent extends EventObject
+{
+ private final boolean m_available;
+
+ /**
+ * Creation of a new availability event.
+ * @param model the component model
+ * @param available the component model availability status
+ */
+ public AvailabilityEvent( Component model, boolean available )
+ {
+ super( model );
+ m_available = available;
+ }
+
+ public boolean isAvailable()
+ {
+ return m_available;
+ }
+}

Added:
development/main/metro/parts/src/main/net/dpml/parts/model/AvailabilityListener.java
==============================================================================
--- (empty file)
+++
development/main/metro/parts/src/main/net/dpml/parts/model/AvailabilityListener.java
Thu May 5 08:13:26 2005
@@ -0,0 +1,33 @@
+/*
+ * 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.parts.model;
+
+import java.util.EventListener;
+
+/**
+ *
+ *
+ * @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 AvailabilityListener extends EventListener
+{
+ void availabilityChanged( AvailabilityEvent event );
+}
+

Modified:
development/main/metro/parts/src/main/net/dpml/parts/model/Component.java
==============================================================================
--- development/main/metro/parts/src/main/net/dpml/parts/model/Component.java
(original)
+++ development/main/metro/parts/src/main/net/dpml/parts/model/Component.java
Thu May 5 08:13:26 2005
@@ -26,6 +26,8 @@
import net.dpml.parts.control.Manager;

import net.dpml.parts.state.State;
+import net.dpml.parts.state.StateEvent;
+import net.dpml.parts.state.StateListener;

/**
*
@@ -33,7 +35,7 @@
* @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 Component extends Entry, Identifiable
+public interface Component extends Provider
{
/**
* Return a Manager for the component.
@@ -41,60 +43,11 @@
Manager getManager();

/**
- * Return an initialized instance of the component.
- * @return the resolved instance
- */
- Object resolve() throws Exception;
-
- /**
- * Return an initialized instance of the component using a supplied
isolation policy.
- * If the isolation policy is TRUE an implementation shall make best
efforts to isolate
- * implementation concerns under the object that is returned. Typically
isolation
- * involves the creation of a proxy of a component implementation
instance that
- * exposes a component's service interfaces to a client. If the
isolation policy if
- * FALSE the implementation shall return the component implementation
instance.
- *
- * @param isolation the isolation policy
- * @return the resolved instance
- */
- Object resolve( boolean isolation ) throws Exception;
-
- /**
* Initialize the component.
*/
void initialize() throws Exception;

/**
- * Return the current state of the component.
- * @return the current state
- */
- State getState();
-
- /**
- * Applies a state transition identified by a supplied transition key.
- *
- * @param key the key identifying the transition to apply to the
component's controller
- * @return the state resulting from the transition
- * @exception if a transition error occurs
- */
- State apply( String key ) throws Exception;
-
- /**
- * Executes an operation identified by a supplied operation key.
- *
- * @param key the key identifying the operation to execute
- * @exception if a transition error occurs
- */
- void execute( String key ) throws Exception;
-
- /**
- * Release a reference to an object managed by the instance.
- *
- * @param instance the instance to release
- */
- void release( Object object );
-
- /**
* Termination of the component.
*/
void terminate();

Modified:
development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
==============================================================================
--- development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
(original)
+++ development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
Thu May 5 08:13:26 2005
@@ -23,7 +23,6 @@

import net.dpml.parts.control.Controller;
import net.dpml.parts.control.Identifiable;
-import net.dpml.parts.control.Manager;

/**
* The Model interface defines a common view of a component part. Operations
@@ -53,22 +52,18 @@
Object getKey();

/**
- * Return a component representing the default component for this model.
+ * Return the default service provider.
*
- * @return the default component
- * @exception ModelException if a model related error occurs
+ * @return the default service provider
*/
- Component getComponent() throws ModelException;
+ Provider getProvider();

/**
- * Model capable of handling identifiable components may return a
component via
- * this operation. Model implementations that do not support identity
may throw
- * an UnsupportedOperationException.
+ * Optional operation that returns an identifiable service provider.
*
- * @param id the component identifier
- * @return the identfied component
- * @exception ModelException if a model related error occurs
+ * @param id the service provider identifier
+ * @return the identfied provider
*/
- Component getComponent( Object id ) throws ModelException;
+ Provider getProvider( Object id );

}

Added:
development/main/metro/parts/src/main/net/dpml/parts/model/Provider.java
==============================================================================
--- (empty file)
+++ development/main/metro/parts/src/main/net/dpml/parts/model/Provider.java
Thu May 5 08:13:26 2005
@@ -0,0 +1,102 @@
+/*
+ * 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.parts.model;
+
+import java.net.URI;
+import java.util.Map.Entry;
+
+import net.dpml.parts.control.Controller;
+import net.dpml.parts.control.Identifiable;
+import net.dpml.parts.control.Manager;
+
+import net.dpml.parts.state.State;
+import net.dpml.parts.state.StateEvent;
+import net.dpml.parts.state.StateListener;
+
+/**
+ *
+ *
+ * @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 Provider extends Identifiable
+{
+ /**
+ * Return the operational status of the model.
+ * @return the operational status
+ */
+ boolean isOperational();
+
+ void addAvailabilityListener( AvailabilityListener listener );
+
+ void removeAvailabilityListener( AvailabilityListener listener );
+
+ /**
+ * Return the current state of the component.
+ * @return the current state
+ */
+ State getState();
+
+ void addStateListener( StateListener listener );
+
+ void removeStateListener( StateListener listener );
+
+ /**
+ * Return an initialized instance of the component.
+ * @return the resolved instance
+ */
+ Object resolve() throws Exception;
+
+ /**
+ * Return an initialized instance of the component using a supplied
isolation policy.
+ * If the isolation policy is TRUE an implementation shall make best
efforts to isolate
+ * implementation concerns under the object that is returned. Typically
isolation
+ * involves the creation of a proxy of a component implementation
instance that
+ * exposes a component's service interfaces to a client. If the
isolation policy if
+ * FALSE the implementation shall return the component implementation
instance.
+ *
+ * @param isolation the isolation policy
+ * @return the resolved instance
+ */
+ Object resolve( boolean isolation ) throws Exception;
+
+ /**
+ * Applies a state transition identified by a supplied transition key.
+ *
+ * @param key the key identifying the transition to apply to the
component's controller
+ * @return the state resulting from the transition
+ * @exception if a transition error occurs
+ */
+ State apply( String key ) throws Exception;
+
+ /**
+ * Executes an operation identified by a supplied operation key.
+ *
+ * @param key the key identifying the operation to execute
+ * @exception if a transition error occurs
+ */
+ void execute( String key ) throws Exception;
+
+ /**
+ * Release a reference to an object managed by the instance.
+ *
+ * @param instance the instance to release
+ */
+ void release( Object object );
+}



  • svn commit: r2462 - in development/main/metro: . composition/builder/src/main/net/dpml/composition/builder composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/event composition/control/src/main/net/dpml/composition/model composition/part/src/main/net/dpml/composition/info composition/testing/test/src/main/net/dpml/test/config composition/testing/test/src/main/net/dpml/test/state composition/testing/test/src/test/net/dpml/composition/testing composition/testing/test/src/test/net/dpml/test/config composition/testing/test/src/test/net/dpml/test/state composition/testing/workshop composition/testing/workshop/src composition/testing/workshop/src/main composition/testing/workshop/src/main/net composition/testing/workshop/src/main/net/dpml composition/testing/workshop/src/main/net/dpml/test composition/testing/workshop/src/test composition/testing/workshop/src/test/net composition/testing/workshop/src/test/net/dpml composition/testing/workshop/src/test/net/dpml/test composition/unit/src/main/net/dpml/composition/unit parts/src/main/net/dpml/parts/control parts/src/main/net/dpml/parts/model, mcconnell, 05/04/2005

Archive powered by MHonArc 2.6.24.

Top of Page