Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2073 - in development/laboratory/plus/standard: builder builder/src/main/net/dpml/metro/builder/impl control control/src/main/net/dpml/metro/control/impl model part part/src part/src/main/net/dpml/metro/meta part/src/main/net/dpml/metro/model part/src/main/net/dpml/metro/type

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: r2073 - in development/laboratory/plus/standard: builder builder/src/main/net/dpml/metro/builder/impl control control/src/main/net/dpml/metro/control/impl model part part/src part/src/main/net/dpml/metro/meta part/src/main/net/dpml/metro/model part/src/main/net/dpml/metro/type
  • Date: Mon, 14 Mar 2005 20:18:01 -0500

Author: mcconnell AT dpml.net
Date: Mon Mar 14 20:18:00 2005
New Revision: 2073

Added:

development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/AbstractController.java

development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartController.java

development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartHandler.java

development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartListingControl.java
- copied, changed from r2071,
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/DebugController.java

development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ConsoleMonitor.java

development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/TransitHome.java
development/laboratory/plus/standard/part/
- copied from r2071, development/laboratory/plus/standard/model/
development/laboratory/plus/standard/part/build.xml
- copied, changed from r2072,
development/laboratory/plus/standard/model/build.xml
development/laboratory/plus/standard/part/src/
- copied from r2072, development/laboratory/plus/standard/model/src/

development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/ComponentTypeHandler.java
Removed:

development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/DebugController.java
development/laboratory/plus/standard/model/

development/laboratory/plus/standard/part/src/main/net/dpml/metro/meta/ComponentTypeHandler.java

development/laboratory/plus/standard/part/src/main/net/dpml/metro/model/ComponentPartHandler.java
Modified:
development/laboratory/plus/standard/builder/build.xml

development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentModelBuilderTask.java

development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentTypeBuilderTask.java

development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/TypeBuilder.java
development/laboratory/plus/standard/control/build.xml

development/laboratory/plus/standard/part/src/main/net/dpml/metro/model/ComponentModel.java

development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/Registry.java

development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/TypeEntry.java

development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/TypeHandler.java
Log:
sorting out where things should be

Modified: development/laboratory/plus/standard/builder/build.xml
==============================================================================
--- development/laboratory/plus/standard/builder/build.xml (original)
+++ development/laboratory/plus/standard/builder/build.xml Mon Mar 14
20:18:00 2005
@@ -7,13 +7,16 @@
<transit:import uri="artifact:template:dpml/magic/standard"/>

<target name="init" depends="standard.init">
- <x:property key="dpml-metro-model-api" feature="uri" type="plugin"
name="model.plugin"/>
- <filter token="TYPE-HANDLER-URI" value="${model.plugin}"/>
- <filter token="TYPE-BUILDER-URI" value="${model.plugin}"/>
- <filter token="PART-HANDLER-URI" value="${model.plugin}"/>
- <filter token="PART-BUILDER-URI" value="${model.plugin}"/>
- <filter token="CONTROL-HANDLER-URI" value="${model.plugin}"/>
- <filter token="CONTROL-BUILDER-URI" value="${model.plugin}"/>
+ <x:property key="dpml-metro-control-impl" feature="uri" type="plugin"
name="control.plugin"/>
+ <x:property key="dpml-metro-part-impl" feature="uri" type="plugin"
name="builder.plugin"/>
+
+ <filter token="TYPE-BUILDER-URI" value="${builder.plugin}"/>
+ <filter token="PART-BUILDER-URI" value="${builder.plugin}"/>
+
+ <filter token="TYPE-HANDLER-URI" value="${control.plugin}"/>
+ <filter token="PART-HANDLER-URI" value="${control.plugin}"/>
+ <filter token="CONTROL-HANDLER-URI" value="${control.plugin}"/>
+ <filter token="CONTROL-BUILDER-URI" value="${control.plugin}"/>
</target>

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

Modified:
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentModelBuilderTask.java
==============================================================================
---
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentModelBuilderTask.java
(original)
+++
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentModelBuilderTask.java
Mon Mar 14 20:18:00 2005
@@ -39,16 +39,19 @@
import net.dpml.metro.builder.IntrospectionException;
import net.dpml.metro.builder.BuilderRuntimeException;
import net.dpml.metro.meta.PartDescriptor;
-import net.dpml.metro.meta.ComponentTypeHandler;
+
import net.dpml.metro.part.Part;
import net.dpml.metro.part.PartHolder;
-import net.dpml.metro.part.BadStrategyException;
+
import net.dpml.metro.type.Registry;
import net.dpml.metro.type.Type;
import net.dpml.metro.type.TypeReference;
import net.dpml.metro.type.TypeHandler;
import net.dpml.metro.type.TypeNotFoundException;
import net.dpml.metro.type.RegistryNotFoundException;
+import net.dpml.metro.type.ComponentTypeHandler;
+
+import net.dpml.metro.control.BadStrategyException;

import net.dpml.magic.tasks.ProjectTask;
import net.dpml.magic.model.Resource;
@@ -180,7 +183,7 @@
//checkTypeMeetsCriteria( reference, descriptor );
}

- return new ComponentModel( reference );
+ return new ComponentModel( PART_HANDLER_URI, reference );
}

private Type resolveType( ClassLoader classloader )

Modified:
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentTypeBuilderTask.java
==============================================================================
---
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentTypeBuilderTask.java
(original)
+++
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentTypeBuilderTask.java
Mon Mar 14 20:18:00 2005
@@ -34,15 +34,19 @@
import net.dpml.metro.meta.DependencyDescriptor;
import net.dpml.metro.meta.PartDescriptor;
import net.dpml.metro.meta.InfoDescriptor;
+
import net.dpml.metro.part.Part;
import net.dpml.metro.part.Descriptor;
-import net.dpml.metro.part.BadStrategyException;
+
import net.dpml.metro.builder.PartBuilder;
import net.dpml.metro.builder.IntrospectionException;
+
import net.dpml.metro.type.Type;
import net.dpml.metro.type.RegistryNotFoundException;
import net.dpml.metro.type.TypeNotFoundException;

+import net.dpml.metro.control.BadStrategyException;
+
import net.dpml.magic.model.Definition;
import net.dpml.magic.project.Context;
import net.dpml.magic.tasks.ProjectTask;

Modified:
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/TypeBuilder.java
==============================================================================
---
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/TypeBuilder.java
(original)
+++
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/TypeBuilder.java
Mon Mar 14 20:18:00 2005
@@ -23,7 +23,9 @@

import net.dpml.metro.builder.Builder;
import net.dpml.metro.builder.IntrospectionException;
-import net.dpml.metro.part.BadStrategyException;
+
+import net.dpml.metro.control.BadStrategyException;
+
import net.dpml.metro.type.TypeNotFoundException;
import net.dpml.metro.type.RegistryNotFoundException;
import net.dpml.metro.type.Type;

Modified: development/laboratory/plus/standard/control/build.xml
==============================================================================
--- development/laboratory/plus/standard/control/build.xml (original)
+++ development/laboratory/plus/standard/control/build.xml Mon Mar 14
20:18:00 2005
@@ -7,11 +7,11 @@
<transit:import uri="artifact:template:dpml/magic/standard"/>

<target name="init" depends="standard.init">
- <x:filter feature="plugin" token="CONTROLLER-URI"/>
+ <x:filter feature="plugin" token="PART-HANDLER-URI"/>
</target>

<target name="package" depends="standard.package">
- <x:export class="net.dpml.metro.control.impl.DefaultController"/>
+ <x:export class="net.dpml.metro.control.impl.ComponentPartController"/>
</target>

</project>

Added:
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/AbstractController.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/AbstractController.java
Mon Mar 14 20:18:00 2005
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.control.impl;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Hashtable;
+
+import net.dpml.metro.part.Part;
+import net.dpml.metro.model.ComponentModel;
+
+import net.dpml.metro.control.Home;
+import net.dpml.metro.control.Control;
+import net.dpml.metro.control.PartHandler;
+import net.dpml.metro.control.Manager;
+import net.dpml.metro.control.Monitor;
+import net.dpml.metro.control.DuplicateNameException;
+import net.dpml.metro.control.UnsupportedPartTypeException;
+
+/**
+ * A initial test controller.
+ *
+ * @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 abstract class AbstractController implements Control
+{
+ //--------------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------------
+
+ private String m_name;
+ private Thread m_thread;
+ private URI m_uri;
+
+ //--------------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------------
+
+ public AbstractController( String name, Thread thread )
+ {
+ this( name, thread, PART_HANDLER_URI );
+ }
+
+ public AbstractController( String name, Thread thread, URI uri )
+ {
+ m_thread = thread;
+ m_name = name;
+ m_uri = uri;
+ }
+
+ //--------------------------------------------------------------------
+ // Control
+ //--------------------------------------------------------------------
+
+ public URI getURI()
+ {
+ return m_uri;
+ }
+
+ public String getName()
+ {
+ return m_name;
+ }
+
+ /**
+ * Start the controller.
+ * @param monitor a control monitor supplied by a controlling system
+ * @exception if a startup failure occurs
+ */
+ public void start() throws Exception
+ {
+ if( null != m_thread )
+ {
+ m_thread.start();
+ }
+ }
+
+ /**
+ * Stop the controller.
+ */
+ public void stop()
+ {
+ if( null != m_thread )
+ {
+ m_thread.interrupt();
+ }
+ }
+
+ //--------------------------------------------------------------------
+ // static utilities
+ //--------------------------------------------------------------------
+
+ private static final URI PART_HANDLER_URI = createStaticURI(
"@PART-HANDLER-URI@" );
+
+ private static URI createStaticURI( String path )
+ {
+ try
+ {
+ return new URI( path );
+ }
+ catch( Throwable e )
+ {
+ return null;
+ }
+ }
+}

Added:
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartController.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartController.java
Mon Mar 14 20:18:00 2005
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.control.impl;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Hashtable;
+
+import net.dpml.metro.part.Part;
+import net.dpml.metro.model.ComponentModel;
+
+import net.dpml.metro.control.Home;
+import net.dpml.metro.control.PartHandler;
+import net.dpml.metro.control.Manager;
+import net.dpml.metro.control.Monitor;
+import net.dpml.metro.control.DuplicateNameException;
+import net.dpml.metro.control.UnsupportedPartTypeException;
+
+/**
+ * A initial test controller.
+ *
+ * @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 ComponentPartController extends ComponentPartHandler implements
Manager
+{
+ //--------------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------------
+
+ private Thread m_thread;
+ private Map m_map = new Hashtable();
+ private Monitor m_monitor;
+
+ //--------------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------------
+
+ public ComponentPartController( Home home, Monitor monitor )
+ {
+ super();
+ m_thread = new Worker( home, this );
+ m_monitor = monitor;
+ }
+
+ //--------------------------------------------------------------------
+ // Controller
+ //--------------------------------------------------------------------
+
+ public String getName()
+ {
+ return "master";
+ }
+
+ /**
+ * Add a part to the collection of parts managed by this controller.
+ *
+ * @param name the name identifying the part within the collection
+ * @param part the part to add
+ */
+ public void addPart( String name, Part part )
+ throws DuplicateNameException, UnsupportedPartTypeException
+ {
+ if( null != m_map.get( name ) )
+ {
+ throw new DuplicateNameException( name );
+ }
+ else if( part instanceof ComponentModel )
+ {
+ m_map.put( name, part );
+ }
+ else
+ {
+ throw new UnsupportedPartTypeException( part );
+ }
+ }
+
+ /**
+ * Return an array of managed parts.
+ * @return the parts array
+ */
+ public Part[] getParts()
+ {
+ return getComponentParts();
+ }
+
+ /**
+ * Return an array of managed parts.
+ * @return the parts array
+ */
+ public ComponentModel[] getComponentParts()
+ {
+ return (ComponentModel[]) m_map.values().toArray( new
ComponentModel[0] );
+ }
+
+ /**
+ * Startup of the controller.
+ */
+ public void start()
+ {
+ m_thread.start();
+ }
+
+ /**
+ * Stop the controller.
+ */
+ public void stop()
+ {
+ m_thread.interrupt();
+ }
+
+ public void listPart()
+ {
+ getMonitor().info( "listing part in the master controller" );
+ ComponentModel[] parts = (ComponentModel[]) getComponentParts();
+ for( int i=0; i<parts.length; i++ )
+ {
+ Part part = parts[i];
+ getMonitor().info( "part: " + part );
+ }
+ }
+
+ //--------------------------------------------------------------------
+ // internal
+ //--------------------------------------------------------------------
+
+ private Monitor getMonitor()
+ {
+ return m_monitor;
+ }
+
+ //--------------------------------------------------------------------
+ // static utilities
+ //--------------------------------------------------------------------
+
+ private static final URI CONTROLLER_URI = setupURI( "@CONTROLLER-URI@" );
+
+ protected static URI setupURI( String spec )
+ {
+ try
+ {
+ return new URI( spec );
+ }
+ catch( URISyntaxException ioe )
+ {
+ return null;
+ }
+ }
+
+ /**
+ * A little worker thread to do the background stuff.
+ */
+ private static class Worker extends Thread
+ {
+ private final Home m_home;
+ private final ComponentPartController m_parent;
+
+ public Worker( Home home, ComponentPartController parent )
+ {
+ m_home = home;
+ m_parent = parent;
+ }
+
+ private boolean m_continue = true;
+
+ public void run()
+ {
+ while( m_continue )
+ {
+ try
+ {
+ getMonitor().info( "working" );
+ sleep( 1000 );
+ getMonitor().info( "done" );
+ getMonitor().notifyCompletion( true );
+ m_continue = false;
+ }
+ catch( InterruptedException ie )
+ {
+ getMonitor().notifyCompletion( false );
+ m_continue = false;
+ }
+ }
+ }
+
+ private Monitor getMonitor()
+ {
+ return m_parent.getMonitor();
+ }
+ }
+}

Added:
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartHandler.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartHandler.java
Mon Mar 14 20:18:00 2005
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.control.impl;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.rmi.MarshalledObject;
+import java.net.URI;
+import java.net.URL;
+
+import net.dpml.metro.part.Part;
+import net.dpml.metro.part.PartHolder;
+
+import net.dpml.metro.control.PartNotFoundException;
+import net.dpml.metro.control.PartHandler;
+import net.dpml.metro.control.BadStrategyException;
+import net.dpml.metro.control.PartHandlerRuntimeException;
+
+import net.dpml.transit.artifact.Handler;
+
+/**
+ * Definition of a type handler.
+ *
+ * @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 ComponentPartHandler implements PartHandler
+{
+ public URI getURI()
+ {
+ return PART_HANDLER_URI;
+ }
+
+ public Part loadPart( URI uri )
+ throws BadStrategyException, PartNotFoundException, IOException
+ {
+ System.out.println( "## loading part uri: " + uri );
+
+ URL url = resolveURL( uri );
+
+ System.out.println( "## loading part: " + url );
+
+ InputStream input = url.openStream();
+ if( null == input )
+ {
+ throw new PartNotFoundException( uri );
+ }
+ ObjectInputStream stream = new ObjectInputStream( input );
+ try
+ {
+ PartHolder holder = (PartHolder) stream.readObject();
+ URI handler = holder.getPartHandlerURI();
+ return loadPart( handler, holder.getByteArray() );
+ }
+ catch( BadStrategyException e )
+ {
+ throw e;
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Error loading part handler ["
+ + uri
+ + "].";
+ throw new PartHandlerRuntimeException( error, e );
+ }
+ }
+
+ public Part loadPart( URI handler, byte[] bytes ) throws
BadStrategyException, IOException
+ {
+ if( false == getURI().equals( handler ) )
+ {
+ throw new BadStrategyException( getURI(), handler );
+ }
+ try
+ {
+ ByteArrayInputStream input = new ByteArrayInputStream( bytes );
+ ObjectInputStream stream = new ObjectInputStream( input );
+ return (Part) stream.readObject();
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to load a part from a byte
array.";
+ throw new PartHandlerRuntimeException( error, e );
+ }
+ }
+
+ private URL resolveURL( URI uri ) throws IOException
+ {
+ if( "artifact".equals( uri.getScheme() ) )
+ {
+ return new URL( null, uri.toString(), new Handler() );
+ }
+ else
+ {
+ return uri.toURL();
+ }
+ }
+
+ private static final URI PART_HANDLER_URI = createStaticURI(
"@PART-HANDLER-URI@" );
+
+ private static URI createStaticURI( String path )
+ {
+ try
+ {
+ return new URI( path );
+ }
+ catch( Throwable e )
+ {
+ return null;
+ }
+ }
+}

Copied:
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartListingControl.java
(from r2071,
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/DebugController.java)
==============================================================================
---
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/DebugController.java
(original)
+++
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ComponentPartListingControl.java
Mon Mar 14 20:18:00 2005
@@ -22,10 +22,12 @@
import java.net.URISyntaxException;

import net.dpml.metro.part.Part;
-import net.dpml.metro.part.PartHandler;
-import net.dpml.metro.kernel.Kernel;
import net.dpml.metro.model.ComponentModel;
-import net.dpml.metro.control.Controller;
+
+import net.dpml.metro.control.Home;
+import net.dpml.metro.control.PartHandler;
+import net.dpml.metro.control.Control;
+import net.dpml.metro.control.Manager;
import net.dpml.metro.control.Monitor;

/**
@@ -34,55 +36,19 @@
* @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 DebugController implements Controller
+public class ComponentPartListingControl extends AbstractController
implements Control
{
//--------------------------------------------------------------------
- // state
- //--------------------------------------------------------------------
-
- private Thread m_thread;
-
- //--------------------------------------------------------------------
// constructor
//--------------------------------------------------------------------

- public DebugController( PartHandler handler, Monitor monitor, Part part )
- {
- m_thread = new Worker( handler, monitor, part );
- }
-
- //--------------------------------------------------------------------
- // Controller
- //--------------------------------------------------------------------
-
- public URI getControllerURI()
- {
- return CONTROLLER_URI;
- }
-
- public String getName()
- {
- return "debugger";
- }
-
- /**
- * Startup of the controller.
- */
- public void start()
- {
- m_thread.start();
- }
-
- /**
- * Stop the controller.
- */
- public void stop()
+ public ComponentPartListingControl( Manager manager, Monitor monitor,
Part part )
{
- m_thread.interrupt();
+ super( "listing", new Worker( manager, monitor, part ) );
}

//--------------------------------------------------------------------
- // imlementation
+ // static utilities
//--------------------------------------------------------------------

/**
@@ -90,13 +56,13 @@
*/
private static class Worker extends Thread
{
+ private final Manager m_manager;
private final Monitor m_monitor;
- private final PartHandler m_handler;
private final Part m_part;

- public Worker( PartHandler handler, Monitor monitor, Part part )
+ public Worker( Manager manager, Monitor monitor, Part part )
{
- m_handler = handler;
+ m_manager = manager;
m_monitor = monitor;
m_part = part;
}
@@ -127,29 +93,9 @@
return m_monitor;
}

- private PartHandler getPartHandler()
- {
- return m_handler;
- }
-
private void listPart()
{
- getMonitor().info( "listing part: " + m_part );
+ getMonitor().info( "CPLC: " + m_part );
}
}
-
- private static URI CONTROLLER_URI = setupURI( "@CONTROLLER-URI@" );
-
- protected static URI setupURI( String spec )
- {
- try
- {
- return new URI( spec );
- }
- catch( URISyntaxException ioe )
- {
- return null;
- }
- }
-
}

Added:
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ConsoleMonitor.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/ConsoleMonitor.java
Mon Mar 14 20:18:00 2005
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.control.impl;
+
+import net.dpml.metro.control.Monitor;
+
+
+/**
+ * Monitor supplied to a startable controller.
+ *
+ * @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 ConsoleMonitor implements Monitor
+{
+ private String m_category;
+ private boolean m_debug;
+
+ public ConsoleMonitor( String category, boolean debug )
+ {
+ m_category = category;
+ m_debug = debug;
+ }
+
+ /**
+ * Log the supplied debug level message.
+ * @param mesage the message to log
+ */
+ public void debug( String message )
+ {
+ if( m_debug )
+ {
+ write( "DEBUG", message );
+ }
+ }
+
+ /**
+ * Log the supplied info level message.
+ * @param mesage the message to log
+ */
+ public void info( String message )
+ {
+ write( "INFO ", message );
+ }
+
+ /**
+ * Log the supplied info level message.
+ * @param mesage the message to log
+ */
+ public void warn( String message )
+ {
+ write( "WARN ", message );
+ }
+
+ /**
+ * Log the supplied error level message.
+ * @param mesage the message to log
+ * @param throwable the exception
+ */
+ public void error( String message, Throwable throwable )
+ {
+ write( "ERROR", message );
+ throwable.printStackTrace();
+ }
+
+ /**
+ * Log the monitor of a normal termination.
+ * @param status TRUE if the monitor completed all scheduled activities
+ * without interruption
+ */
+ public void notifyCompletion( boolean status )
+ {
+ debug( "completion notification (" + status + ")" );
+ }
+
+ /**
+ * Log the monitor of a runtime failure.
+ * @param throwable the failure cause
+ */
+ public void notifyFailure( Throwable throwable )
+ {
+ warn( "failure notification" );
+ throwable.printStackTrace();
+ }
+
+ /**
+ * Log the supplied debug level message.
+ * @param mesage the message to log
+ */
+ private void write( String level, String message )
+ {
+ System.out.println( "[" + level + "] (" + m_category + ") " +
message );
+ }
+}

Added:
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/TransitHome.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/control/src/main/net/dpml/metro/control/impl/TransitHome.java
Mon Mar 14 20:18:00 2005
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.control.impl;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.io.ObjectInputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.WeakHashMap;
+
+import net.dpml.metro.control.Home;
+import net.dpml.metro.control.PartNotFoundException;
+import net.dpml.metro.control.HandlerNotFoundException;
+import net.dpml.metro.control.HomeRuntimeException;
+import net.dpml.metro.control.PartHandler;
+import net.dpml.metro.control.Handler;
+import net.dpml.metro.control.Control;
+import net.dpml.metro.control.Manager;
+
+import net.dpml.metro.part.Part;
+import net.dpml.metro.part.PartHolder;
+
+import net.dpml.transit.repository.StandardLoader;
+import net.dpml.transit.TransitException;
+
+/**
+ * The TransitHome class implements handler resolution using Transit as the
+ * underlying resource managmeent framework.
+ *
+ * @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 TransitHome implements Home
+{
+ private final WeakHashMap m_handlers = new WeakHashMap();
+ private final WeakHashMap m_controllers = new WeakHashMap();
+
+ private final StandardLoader m_loader;
+
+ public TransitHome()
+ {
+ try
+ {
+ m_loader = new StandardLoader();
+ }
+ catch( TransitException e )
+ {
+ final String error =
+ "Internal error suring home initialization.";
+ throw new HomeRuntimeException( error, e );
+ }
+ }
+
+ /**
+ * Load a part and return the master controller to the client.
+ * @param uri the part uri
+ * @return the master controller
+ */
+ public PartHandler getPartHandler( Part part ) throws IOException,
HandlerNotFoundException
+ {
+ URI uri = part.getPartHandlerURI();
+ return resolvePartHandler( uri );
+ }
+
+ public PartHolder loadPartHolder( URI uri ) throws IOException,
PartNotFoundException
+ {
+ URL url = uriToUrl( uri );
+ InputStream input = url.openStream();
+ if( null == input )
+ {
+ throw new PartNotFoundException( uri );
+ }
+ ObjectInputStream stream = new ObjectInputStream( input );
+ try
+ {
+ return (PartHolder) stream.readObject();
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Internal error while attempting to load a part form the url ["
+ + url
+ + "].";
+ throw new HomeRuntimeException( error, e );
+ }
+ }
+
+ public PartHandler loadPartHandler( URI spec )
+ throws PartNotFoundException, HandlerNotFoundException, IOException
+ {
+ PartHolder holder = loadPartHolder( spec );
+ URI uri = holder.getPartHandlerURI();
+ return resolvePartHandler( uri );
+ }
+
+ public Part loadPart( URI spec )
+ throws PartNotFoundException, HandlerNotFoundException, IOException
+ {
+ PartHolder holder = loadPartHolder( spec );
+ URI uri = holder.getPartHandlerURI();
+ try
+ {
+ PartHandler handler = resolvePartHandler( uri );
+ return handler.loadPart( uri, holder.getByteArray() );
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( HandlerNotFoundException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Internal error while attempting to load a part form the url ["
+ + spec
+ + "].";
+ throw new HomeRuntimeException( error, e );
+ }
+ }
+
+ public PartHandler resolvePartHandler( URI uri ) throws
HandlerNotFoundException, IOException
+ {
+ Handler handler = resolveHandler( uri );
+ return (PartHandler) handler;
+ }
+
+ private Handler resolveHandler( URI uri ) throws
HandlerNotFoundException, IOException
+ {
+ String key = uri.toString();
+ synchronized( m_handlers )
+ {
+ Handler handler = (Handler) m_handlers.get( key );
+ if( null == handler )
+ {
+ handler = loadHandler( uri );
+ m_handlers.put( key, handler );
+ }
+ return handler;
+ }
+ }
+
+ private Handler loadHandler( URI uri ) throws HandlerNotFoundException
+ {
+ ClassLoader classloader = Handler.class.getClassLoader();
+ ConsoleMonitor monitor = new ConsoleMonitor( "manager", true );
+ try
+ {
+ return (Handler) m_loader.getPlugin( classloader, uri, new
Object[]{ this, monitor } );
+ }
+ catch( IOException e )
+ {
+ throw new HandlerNotFoundException( uri, e );
+ }
+ }
+
+ private URL uriToUrl( URI uri )
+ {
+ try
+ {
+ return new URL( null, uri.toString(), new
net.dpml.transit.artifact.Handler() );
+ }
+ catch( Exception e )
+ {
+ throw new HomeRuntimeException( "uri convertion error", e );
+ }
+ }
+}

Copied: development/laboratory/plus/standard/part/build.xml (from r2072,
development/laboratory/plus/standard/model/build.xml)
==============================================================================
--- development/laboratory/plus/standard/model/build.xml (original)
+++ development/laboratory/plus/standard/part/build.xml Mon Mar 14 20:18:00
2005
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>

-<project name="dpml-metro-model-api" default="install" basedir="."
+<project name="dpml-metro-part-impl" 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="init" depends="standard.init">
- <x:filter feature="plugin" token="TYPE-HANDLER-URI"/>
- <x:filter feature="plugin" token="PART-HANDLER-URI"/>
- <x:filter key="dpml-metro-control-impl" feature="plugin"
token="STRATEGY-URI"/>
+ <x:property key="dpml-metro-control-impl" feature="plugin"
name="controller.uri"/>
+ <filter value="${controller.uri}" token="TYPE-HANDLER-URI"/>
+ <filter value="${controller.uri}" token="PART-HANDLER-URI"/>
</target>

<target name="package" depends="standard.package">
<x:export>
<antlib resource="net/dpml/metro/model/antlib.xml"
- urn="plugin:dpml/metro/dpml-metro-model-api"/>
+ urn="plugin:dpml/metro/dpml-metro-part-impl"/>
</x:export>
</target>


Modified:
development/laboratory/plus/standard/part/src/main/net/dpml/metro/model/ComponentModel.java
==============================================================================
---
development/laboratory/plus/standard/model/src/main/net/dpml/metro/model/ComponentModel.java
(original)
+++
development/laboratory/plus/standard/part/src/main/net/dpml/metro/model/ComponentModel.java
Mon Mar 14 20:18:00 2005
@@ -36,24 +36,39 @@
{
private TypeReference m_type;
private ControlDescriptor[] m_controls;
+ private URI m_controller;

- public ComponentModel( TypeReference type )
+ public ComponentModel( URI controller, TypeReference type )
{
- this( type, EMPTY_CONTROLS );
+ this( controller, type, EMPTY_CONTROLS );
}

- public ComponentModel( TypeReference type, ControlDescriptor[] controls )
+ public ComponentModel( URI controller, TypeReference type,
ControlDescriptor[] controls )
{
if( null == type )
{
throw new NullPointerException( "type" );
}
+ if( null == controller )
+ {
+ throw new NullPointerException( "controller" );
+ }
if( null == controls )
{
throw new NullPointerException( "controls" );
}
m_type = type;
m_controls = controls;
+ m_controller = controller;
+ }
+
+ /**
+ * Return the part handler uri.
+ * @return the uri of the part handler
+ */
+ public URI getPartHandlerURI()
+ {
+ return m_controller;
}

/**

Added:
development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/ComponentTypeHandler.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/ComponentTypeHandler.java
Mon Mar 14 20:18:00 2005
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.type;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.rmi.MarshalledObject;
+import java.net.URI;
+import java.net.URL;
+
+import net.dpml.metro.type.Type;
+import net.dpml.metro.type.TypeHandler;
+import net.dpml.metro.type.TypeHandlerRuntimeException;
+import net.dpml.metro.type.TypeReference;
+import net.dpml.metro.type.Registry;
+import net.dpml.metro.type.RegistryNotFoundException;
+import net.dpml.metro.type.TypeNotFoundException;
+
+import net.dpml.metro.meta.ComponentDescriptor;
+
+import net.dpml.metro.control.BadStrategyException;
+
+import net.dpml.transit.artifact.Handler;
+
+/**
+ * Definition of a type handler.
+ *
+ * @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 ComponentTypeHandler implements TypeHandler
+{
+ public URI getURI()
+ {
+ return TYPE_HANDLER_URI;
+ }
+
+ public Type loadType( TypeReference reference )
+ throws RegistryNotFoundException, BadStrategyException,
TypeNotFoundException, IOException
+ {
+ URI uri = reference.getRegistryURI();
+ URL url = resolveURL( uri );
+ Registry registry = Registry.loadRegistry( url );
+ String classname = reference.getClassname();
+ return registry.getType( this, classname );
+ }
+
+ public Type loadType( URI strategy, byte[] bytes ) throws
BadStrategyException, IOException
+ {
+ if( getURI().equals( strategy ) == false )
+ {
+ throw new BadStrategyException( getURI(), strategy );
+ }
+ try
+ {
+ ByteArrayInputStream input = new ByteArrayInputStream( bytes );
+ ObjectInputStream stream = new ObjectInputStream( input );
+ return (ComponentDescriptor) stream.readObject();
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to load a type (strategy: "
+ + strategy
+ + ") from a byte array.";
+ throw new TypeHandlerRuntimeException( error, e );
+ }
+ }
+
+ private static final URI TYPE_HANDLER_URI = createStaticURI(
"@TYPE-HANDLER-URI@" );
+
+ private static URI createStaticURI( String path )
+ {
+ try
+ {
+ return new URI( path );
+ }
+ catch( Throwable e )
+ {
+ return null;
+ }
+ }
+
+ private URL resolveURL( URI uri ) throws IOException
+ {
+ if( "artifact".equals( uri.getScheme() ) )
+ {
+ return new URL( null, uri.toString(), new Handler() );
+ }
+ else
+ {
+ return uri.toURL();
+ }
+ }
+}

Modified:
development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/Registry.java
==============================================================================
---
development/laboratory/plus/standard/model/src/main/net/dpml/metro/type/Registry.java
(original)
+++
development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/Registry.java
Mon Mar 14 20:18:00 2005
@@ -29,7 +29,8 @@
import java.io.Serializable;

import net.dpml.metro.part.Descriptor;
-import net.dpml.metro.part.BadStrategyException;
+
+import net.dpml.metro.control.BadStrategyException;

/**
* A registry is a container of serialized component type holders keyed by
classname.

Modified:
development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/TypeEntry.java
==============================================================================
---
development/laboratory/plus/standard/model/src/main/net/dpml/metro/type/TypeEntry.java
(original)
+++
development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/TypeEntry.java
Mon Mar 14 20:18:00 2005
@@ -24,7 +24,8 @@
import java.net.URI;

import net.dpml.metro.part.Holder;
-import net.dpml.metro.part.BadStrategyException;
+
+import net.dpml.metro.control.BadStrategyException;

/**
* A type entry is an immutable datatype associating a classname with a

Modified:
development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/TypeHandler.java
==============================================================================
---
development/laboratory/plus/standard/model/src/main/net/dpml/metro/type/TypeHandler.java
(original)
+++
development/laboratory/plus/standard/part/src/main/net/dpml/metro/type/TypeHandler.java
Mon Mar 14 20:18:00 2005
@@ -22,8 +22,8 @@
import java.io.IOException;
import java.net.URI;

-import net.dpml.metro.part.Handler;
-import net.dpml.metro.part.BadStrategyException;
+import net.dpml.metro.control.Handler;
+import net.dpml.metro.control.BadStrategyException;

/**
* Definition of a type handler.



  • svn commit: r2073 - in development/laboratory/plus/standard: builder builder/src/main/net/dpml/metro/builder/impl control control/src/main/net/dpml/metro/control/impl model part part/src part/src/main/net/dpml/metro/meta part/src/main/net/dpml/metro/model part/src/main/net/dpml/metro/type, mcconnell, 03/14/2005

Archive powered by MHonArc 2.6.24.

Top of Page