Skip to Content.
Sympa Menu

notify-dpml - r1165 - in trunk: lab lab/component/src/main/dpmlx/component lab/lang/src/main/dpmlx/lang lab/lang/src/main/dpmlx/schema lab/test lab/test/etc/test lab/test/src/test/dpmlx/schema/test main/metro/runtime/src/main/net/dpml/metro/runtime main/transit/core/src/main/net/dpml main/transit/core/src/main/net/dpml/part main/transit/core/src/main/net/dpml/transit

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1165 - in trunk: lab lab/component/src/main/dpmlx/component lab/lang/src/main/dpmlx/lang lab/lang/src/main/dpmlx/schema lab/test lab/test/etc/test lab/test/src/test/dpmlx/schema/test main/metro/runtime/src/main/net/dpml/metro/runtime main/transit/core/src/main/net/dpml main/transit/core/src/main/net/dpml/part main/transit/core/src/main/net/dpml/transit
  • Date: Fri, 3 Mar 2006 21:33:26 +0100

Author: mcconnell
Date: 2006-03-03 21:33:07 +0100 (Fri, 03 Mar 2006)
New Revision: 1165

Added:
trunk/lab/lang/src/main/dpmlx/schema/PartHandlerFactory.java
trunk/main/transit/core/src/main/net/dpml/part/
trunk/main/transit/core/src/main/net/dpml/part/PartHandler.java
trunk/main/transit/core/src/main/net/dpml/part/StandardPartHandler.java
Removed:
trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java
trunk/lab/lang/src/main/dpmlx/schema/PluginPartHandler.java
Modified:
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
trunk/lab/lang/src/main/dpmlx/lang/PartDirective.java
trunk/lab/lang/src/main/dpmlx/schema/DOMDocumentBuilder.java
trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
trunk/lab/lang/src/main/dpmlx/schema/Plugin.java
trunk/lab/library.xml
trunk/lab/test/build.xml
trunk/lab/test/etc/test/component.xml
trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
trunk/main/transit/core/src/main/net/dpml/transit/StandardClassLoader.java
Log:
first steps in moving combined plugin/part model into trunk

Modified:
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
===================================================================
---
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
2006-03-03 17:34:30 UTC (rev 1164)
+++
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -22,7 +22,8 @@

import net.dpml.metro.data.ComponentDirective;

-import net.dpml.transit.info.ValueDirective;
+import net.dpml.transit.Value;
+import net.dpml.transit.Construct;
import net.dpml.transit.util.ElementHelper;

import dpmlx.lang.Strategy;
@@ -105,35 +106,35 @@
String spec = ElementHelper.getAttribute( element, "uri" );
URI uri = new URI( spec );
Element[] elements = ElementHelper.getChildren( element, "param"
);
- ValueDirective[] values = createValueDirectives( elements );
+ Value[] values = createValues( elements );
return new PartDirective( uri, values );
}
}

- private ValueDirective[] createValueDirectives( Element[] elements )
+ private Value[] createValues( Element[] elements )
{
- ValueDirective[] values = new ValueDirective[ elements.length ];
+ Value[] values = new Value[ elements.length ];
for( int i=0; i<elements.length; i++ )
{
- values[i] = createValueDirective( elements[i] );
+ values[i] = createValue( elements[i] );
}
return values;
}

- private ValueDirective createValueDirective( Element element )
+ private Value createValue( Element element )
{
String classname = ElementHelper.getAttribute( element, "class" );
String method = ElementHelper.getAttribute( element, "method" );
Element[] elements = ElementHelper.getChildren( element, "param" );
if( elements.length > 0 )
{
- ValueDirective[] values = createValueDirectives( elements );
- return new ValueDirective( classname, method, values );
+ Value[] values = createValues( elements );
+ return new Construct( classname, method, values );
}
else
{
String value = ElementHelper.getAttribute( element, "value" );
- return new ValueDirective( classname, method, value );
+ return new Construct( classname, method, value );
}
}
}

Modified: trunk/lab/lang/src/main/dpmlx/lang/PartDirective.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/PartDirective.java 2006-03-03
17:34:30 UTC (rev 1164)
+++ trunk/lab/lang/src/main/dpmlx/lang/PartDirective.java 2006-03-03
20:33:07 UTC (rev 1165)
@@ -21,7 +21,7 @@
import java.io.Serializable;
import java.net.URI;

-import net.dpml.transit.info.ValueDirective;
+import net.dpml.transit.Value;

/**
* Immutable part creation directive.
@@ -32,9 +32,9 @@
public final class PartDirective implements Serializable
{
private final URI m_uri;
- private final ValueDirective[] m_params;
+ private final Value[] m_params;

- public PartDirective( URI uri, ValueDirective[] params )
+ public PartDirective( URI uri, Value[] params )
{
if( null == uri )
{
@@ -43,7 +43,7 @@
m_uri = uri;
if( null == params )
{
- m_params = new ValueDirective[0];
+ m_params = new Value[0];
}
else
{
@@ -64,7 +64,7 @@
* Get the values to be used during part instantiation.
* @return the directives
*/
- public ValueDirective[] getValueDirectives()
+ public Value[] getValues()
{
return m_params;
}

Deleted: trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java 2006-03-03 17:34:30
UTC (rev 1164)
+++ trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java 2006-03-03 20:33:07
UTC (rev 1165)
@@ -1,44 +0,0 @@
-/*
- * Copyright 2006 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 dpmlx.lang;
-
-import net.dpml.lang.Classpath;
-
-/**
- * Interface implemented by part runtime handlers. Handler are identified
- * by the uri returned from the <tt>Part.getStrategy().getController()</tt>.
- */
-public interface PartHandler
-{
- /**
- * Build a classloader stack.
- * @param anchor the anchor classloader to server as the classloader
chain root
- * @param classpath the part classpath definition
- */
- ClassLoader getClassLoader( ClassLoader anchor, Classpath classpath );
-
- /**
- * Instantiate a value.
- * @param classloader the implementation classloader established for the
part
- * @param data the part deployment data
- * @param args supplimentary arguments
- * @exception Exception if a deployment error occurs
- */
- Object getInstance( ClassLoader classloader, Object data, Object[] args
) throws Exception;
-}

Modified: trunk/lab/lang/src/main/dpmlx/schema/DOMDocumentBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/DOMDocumentBuilder.java
2006-03-03 17:34:30 UTC (rev 1164)
+++ trunk/lab/lang/src/main/dpmlx/schema/DOMDocumentBuilder.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -38,7 +38,6 @@
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
-//import org.xml.sax.helpers.DefaultHandler;

import org.w3c.dom.Document;


Added: trunk/lab/lang/src/main/dpmlx/schema/PartHandlerFactory.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PartHandlerFactory.java
2006-03-03 17:34:30 UTC (rev 1164)
+++ trunk/lab/lang/src/main/dpmlx/schema/PartHandlerFactory.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2006 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 dpmlx.schema;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Hashtable;
+
+import dpmlx.lang.PartDirective;
+
+import net.dpml.lang.Classpath;
+import net.dpml.part.PartHandler;
+import net.dpml.part.StandardPartHandler;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.Repository;
+import net.dpml.transit.Value;
+import net.dpml.transit.Construct;
+
+
+/**
+ * Factory used to locate part handlers.
+ */
+public class PartHandlerFactory
+{
+ private static final StandardPartHandler HANDLER = new
StandardPartHandler();
+
+ private Hashtable m_map = new Hashtable();
+
+ private static final PartHandlerFactory FACTORY = new
PartHandlerFactory();
+
+ public static PartHandlerFactory getInstance()
+ {
+ return FACTORY;
+ }
+
+ private PartHandlerFactory()
+ {
+ }
+
+ /**
+ * Locate or resolve a part handler.
+ * @param uri the part uri
+ * @param args part instantiation arguments
+ * @exception Exception if an error occurs during handler resolution
+ */
+ public PartHandler getPartHandler( PartDirective directive ) throws
Exception
+ {
+ URI uri = directive.getURI();
+ Value[] params = directive.getValues();
+ Object[] args = Construct.getArgs( null, params, new Object[0] );
+ return getPartHandler( uri, args );
+ }
+
+ /**
+ * Locate or resolve a part handler.
+ * @param uri the part uri
+ * @param args part instantiation arguments
+ * @exception Exception if an error occurs during handler resolution
+ */
+ public PartHandler getPartHandler( URI uri, Object[] args ) throws
Exception
+ {
+ if( StandardPartHandler.PART_HANDLER_URI.equals( uri ) )
+ {
+ return HANDLER;
+ }
+ else
+ {
+ synchronized( m_map )
+ {
+ if( m_map.containsKey( uri ) )
+ {
+ return (PartHandler) m_map.get( uri );
+ }
+ else
+ {
+ PartHandler handler = loadPartHandler( uri, args );
+ m_map.put( uri, handler );
+ return handler;
+ }
+ }
+ }
+ }
+
+ private PartHandler loadPartHandler( URI uri, Object[] args ) throws
Exception
+ {
+ ClassLoader classloader = PartHandler.class.getClassLoader();
+ Repository repository = Transit.getInstance().getRepository();
+ Object instance = repository.getPlugin( classloader, uri, args );
+ if( instance instanceof PartHandler )
+ {
+ return (PartHandler) instance;
+ }
+ else
+ {
+ final String error =
+ "Plugin uri does not resolve to an instance of "
+ + PartHandler.class.getName()
+ + "."
+ + "\nURI: " + uri
+ + "\nCLass: " + instance.getClass().getName();
+ throw new IllegalArgumentException( error );
+ }
+ }
+}

Modified: trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
2006-03-03 17:34:30 UTC (rev 1164)
+++ trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -25,8 +25,10 @@
import dpmlx.lang.StrategyBuilder;
import dpmlx.lang.PartDirective;

-import net.dpml.transit.info.ValueDirective;
+import net.dpml.transit.Value;
+import net.dpml.transit.Construct;
import net.dpml.transit.util.ElementHelper;
+import net.dpml.part.StandardPartHandler;

import org.w3c.dom.TypeInfo;
import org.w3c.dom.Element;
@@ -39,7 +41,8 @@
*/
public class PartStrategyBuilder implements StrategyBuilder
{
- private static final PartDirective TRANSIT_DIRECTIVE =
createTransitDirective();
+ private static final PartDirective TRANSIT_DIRECTIVE =
+ new PartDirective( StandardPartHandler.PART_HANDLER_URI, null );

public Strategy buildStrategy( Element element ) throws Exception
{
@@ -56,7 +59,7 @@
{
String classname = ElementHelper.getAttribute( element, "class"
);
Element[] elements = ElementHelper.getChildren( element, "param"
);
- ValueDirective[] values = createValueDirectives( elements );
+ Value[] values = createValues( elements );
Plugin plugin = new Plugin( classname, values );
return new Strategy( TRANSIT_DIRECTIVE, plugin );
}
@@ -79,44 +82,30 @@
}
}

- private ValueDirective[] createValueDirectives( Element[] elements )
+ private Value[] createValues( Element[] elements )
{
- ValueDirective[] values = new ValueDirective[ elements.length ];
+ Value[] values = new Value[ elements.length ];
for( int i=0; i<elements.length; i++ )
{
- values[i] = createValueDirective( elements[i] );
+ values[i] = createValue( elements[i] );
}
return values;
}

- private ValueDirective createValueDirective( Element element )
+ private Value createValue( Element element )
{
String classname = ElementHelper.getAttribute( element, "class" );
String method = ElementHelper.getAttribute( element, "method" );
Element[] elements = ElementHelper.getChildren( element, "param" );
if( elements.length > 0 )
{
- ValueDirective[] values = createValueDirectives( elements );
- return new ValueDirective( classname, method, values );
+ Value[] values = createValues( elements );
+ return new Construct( classname, method, values );
}
else
{
String value = ElementHelper.getAttribute( element, "value" );
- return new ValueDirective( classname, method, value );
+ return new Construct( classname, method, value );
}
}
-
- private static PartDirective createTransitDirective()
- {
- try
- {
- URI uri = new URI( "internal:transit" );
- return new PartDirective( uri, null );
- }
- catch( Throwable e )
- {
- e.printStackTrace();
- return null;
- }
- }
}

Modified: trunk/lab/lang/src/main/dpmlx/schema/Plugin.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/Plugin.java 2006-03-03 17:34:30
UTC (rev 1164)
+++ trunk/lab/lang/src/main/dpmlx/schema/Plugin.java 2006-03-03 20:33:07
UTC (rev 1165)
@@ -21,14 +21,14 @@
import java.io.Serializable;
import java.util.Arrays;

-import net.dpml.transit.info.ValueDirective;
+import net.dpml.transit.Value;

class Plugin implements Serializable
{
private final String m_classname;
- private final ValueDirective[] m_params;
+ private final Value[] m_params;

- public Plugin( String classname, ValueDirective[] params )
+ public Plugin( String classname, Value[] params )
{
m_classname = classname;
m_params = params;
@@ -39,7 +39,7 @@
return m_classname;
}

- public ValueDirective[] getValueDirectives()
+ public Value[] getValues()
{
return m_params;
}

Deleted: trunk/lab/lang/src/main/dpmlx/schema/PluginPartHandler.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PluginPartHandler.java 2006-03-03
17:34:30 UTC (rev 1164)
+++ trunk/lab/lang/src/main/dpmlx/schema/PluginPartHandler.java 2006-03-03
20:33:07 UTC (rev 1165)
@@ -1,53 +0,0 @@
-/*
- * Copyright 2006 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 dpmlx.schema;
-
-import java.io.Serializable;
-
-import net.dpml.lang.Classpath;
-
-import dpmlx.lang.PartHandler;
-
-/**
- * Construct a part.
- */
-public class PluginPartHandler implements PartHandler
-{
- /**
- * Build a classloader stack.
- * @param anchor the anchor classloader to server as the classloader
chain root
- * @param classpath the part classpath definition
- */
- public ClassLoader getClassLoader( ClassLoader anchor, Classpath
classpath )
- {
- throw new UnsupportedOperationException( "getClassLoader" );
- }
-
- /**
- * Instantiate a value.
- * @param classloader the implementation classloader established for the
part
- * @param data the part deployment data
- * @param args supplimentary arguments
- * @exception Exception if a deployment error occurs
- */
- public Object getInstance( ClassLoader classloader, Object data,
Object[] args ) throws Exception
- {
- throw new UnsupportedOperationException( "getInstance" );
- }
-}

Modified: trunk/lab/library.xml
===================================================================
--- trunk/lab/library.xml 2006-03-03 17:34:30 UTC (rev 1164)
+++ trunk/lab/library.xml 2006-03-03 20:33:07 UTC (rev 1165)
@@ -60,6 +60,7 @@
<dependencies scope="test">
<include key="dpmlx-lang"/>
<include ref="ant/ant-junit"/>
+ <include ref="dpml/metro/dpml-part-api"/>
</dependencies>
</project>


Modified: trunk/lab/test/build.xml
===================================================================
--- trunk/lab/test/build.xml 2006-03-03 17:34:30 UTC (rev 1164)
+++ trunk/lab/test/build.xml 2006-03-03 20:33:07 UTC (rev 1165)
@@ -9,6 +9,7 @@
<target name="init" depends="standard.init">
<x:filter feature="uri" type="xsd" token="COMPONENT-XSD-URI"
ref="dpmlx/dpmlx-component"/>
<x:filter feature="uri" type="xsd" token="PART-XSD-URI"
ref="dpmlx/dpmlx-part"/>
+ <x:filter feature="uri" type="plugin" token="METRO-CONTROLLER-URI"
ref="dpml/metro/dpml-metro-runtime"/>
</target>

</project>

Modified: trunk/lab/test/etc/test/component.xml
===================================================================
--- trunk/lab/test/etc/test/component.xml 2006-03-03 17:34:30 UTC (rev
1164)
+++ trunk/lab/test/etc/test/component.xml 2006-03-03 20:33:07 UTC (rev
1165)
@@ -15,6 +15,9 @@
</info>

<strategy xsi:type="component:definition">
+ <controller xmlns="@COMPONENT-XSD-URI@" uri="@METRO-CONTROLLER-URI@" >
+ <param class="net.dpml.part.InitialContext"/>
+ </controller>
<component xmlns="@COMPONENT-XSD-URI@" class="org.acme.Widget" >
<context>
<entry key="foo" value="abc"/>

Modified: trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
===================================================================
--- trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-03-03 17:34:30 UTC (rev 1164)
+++ trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -10,7 +10,10 @@
import dpmlx.lang.PartDirective;
import dpmlx.schema.PartBuilder;
import dpmlx.schema.UnresolvableHandlerException;
+import dpmlx.schema.PartHandlerFactory;

+import net.dpml.part.PartHandler;
+
import junit.framework.TestCase;

import org.w3c.dom.Document;
@@ -64,5 +67,15 @@

System.out.println( " Controller: " + uri );
System.out.println( " Data: " + data.getClass().getName() );
+
+ try
+ {
+ PartHandler handler =
PartHandlerFactory.getInstance().getPartHandler( directive );
+ System.out.println( " Handler: " + handler );
+ }
+ catch( Throwable e )
+ {
+ System.out.println( " " + e.toString() );
+ }
}
}

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
2006-03-03 17:34:30 UTC (rev 1164)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -45,6 +45,9 @@
import net.dpml.part.Model;
import net.dpml.part.Component;

+import net.dpml.part.PartHandler;
+import net.dpml.part.StandardPartHandler;
+
import net.dpml.transit.Repository;
import net.dpml.transit.Transit;

@@ -55,7 +58,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public class CompositionController implements Controller
+public class CompositionController extends StandardPartHandler implements
Controller
{
//--------------------------------------------------------------------
// immutable state
@@ -100,6 +103,10 @@
}

//--------------------------------------------------------------------
+ // PartHandler
+ //--------------------------------------------------------------------
+
+ //--------------------------------------------------------------------
// Controller
//--------------------------------------------------------------------


Added: trunk/main/transit/core/src/main/net/dpml/part/PartHandler.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartHandler.java
2006-03-03 17:34:30 UTC (rev 1164)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartHandler.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2006 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.part;
+
+import java.io.IOException;
+
+import net.dpml.lang.Classpath;
+
+/**
+ * Interface implemented by part runtime handlers. Handler are identified
+ * by the uri returned from the <tt>Part.getStrategy().getController()</tt>.
+ */
+public interface PartHandler
+{
+ /**
+ * Build a classloader stack.
+ * @param anchor the anchor classloader to server as the classloader
chain root
+ * @param classpath the part classpath definition
+ * @exception IOException if an IO error occurs during classpath
evaluation
+ */
+ ClassLoader getClassLoader( ClassLoader anchor, Classpath classpath )
throws IOException;
+
+ /**
+ * Instantiate a value.
+ * @param classloader the implementation classloader established for the
part
+ * @param data the part deployment data
+ * @param args supplimentary arguments
+ * @exception Exception if a deployment error occurs
+ */
+ Object getInstance( ClassLoader classloader, Object data, Object[] args
) throws Exception;
+}

Added: trunk/main/transit/core/src/main/net/dpml/part/StandardPartHandler.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/StandardPartHandler.java
2006-03-03 17:34:30 UTC (rev 1164)
+++ trunk/main/transit/core/src/main/net/dpml/part/StandardPartHandler.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2006 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.part;
+
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.io.IOException;
+
+import net.dpml.lang.Category;
+import net.dpml.lang.Classpath;
+
+import net.dpml.transit.Artifact;
+import net.dpml.transit.StandardClassLoader;
+
+/**
+ * Construct a part.
+ */
+public class StandardPartHandler implements PartHandler
+{
+ public static final URI PART_HANDLER_URI = createHandlerURI();
+
+ /**
+ * Build a classloader stack.
+ * @param anchor the anchor classloader to server as the classloader
chain root
+ * @param classpath the part classpath definition
+ */
+ public ClassLoader getClassLoader( ClassLoader anchor, Classpath
classpath ) throws IOException
+ {
+ if( null == anchor )
+ {
+ throw new NullPointerException( "anchor" );
+ }
+ if( null == classpath )
+ {
+ throw new NullPointerException( "classpath" );
+ }
+
+ URL[] sysUrls = getURLs( classpath, Category.SYSTEM );
+ URL[] apis = getURLs( classpath, Category.PUBLIC );
+ URL[] spis = getURLs( classpath, Category.PROTECTED );
+ URL[] imps = getURLs( classpath, Category.PRIVATE );
+ //if( sysUrls.length > 0 )
+ //{
+ // updateSystemClassLoader( plugin, sysUrls );
+ //}
+
+ ClassLoader parent = buildClassLoader( Category.PUBLIC, anchor, apis
);
+ parent = buildClassLoader( Category.PROTECTED, parent, spis );
+ parent = buildClassLoader( Category.PRIVATE, parent, imps );
+ return parent;
+ }
+
+ /**
+ * Instantiate a value.
+ * @param classloader the implementation classloader established for the
part
+ * @param data the part deployment data
+ * @param args supplimentary arguments
+ * @exception Exception if a deployment error occurs
+ */
+ public Object getInstance( ClassLoader classloader, Object data,
Object[] args ) throws Exception
+ {
+ throw new UnsupportedOperationException( "getInstance" );
+ }
+
+ private URL[] getURLs( Classpath classpath, Category category ) throws
IOException
+ {
+ URI[] uris = classpath.getDependencies( category );
+ return getURLs( uris );
+ }
+
+ /**
+ * Convert a sequncence of URIs to URLs.
+ * @param uris the uris to convert
+ * @return the corresponding urls
+ * @exception IOException of a transformation error occurs
+ */
+ private URL[] getURLs( URI[] uris ) throws IOException
+ {
+ URL[] urls = new URL[ uris.length ];
+ for( int i=0; i < urls.length; i++ )
+ {
+ URI uri = uris[i];
+ urls[i] = Artifact.toURL( uri );
+ }
+ return urls;
+ }
+
+ /**
+ * Internal utility class to build a classloader. If the supplied url
+ * sequence is zero length the parent classloader is returned directly.
+ *
+ * @param category the type of classloader (api, spi, impl)
+ * @param parent the parent classloader
+ * @param urls the urls to assign as classloader content
+ * @return the classloader
+ */
+ private ClassLoader buildClassLoader( Category category, ClassLoader
parent, URL[] urls )
+ {
+ if( 0 == urls.length )
+ {
+ return parent;
+ }
+ ArrayList list = new ArrayList();
+ for( int i=0; i < urls.length; i++ )
+ {
+ if( isaCandidate( parent, urls[i] ) )
+ {
+ list.add( urls[i] );
+ }
+ }
+ URL[] qualified = (URL[]) list.toArray( new URL[0] );
+ if( qualified.length == 0 )
+ {
+ return parent;
+ }
+ else
+ {
+ return new StandardClassLoader( null, category, qualified,
parent );
+ }
+ }
+
+ /**
+ * Test if the supplied url is already present within the supplied
classloader.
+ * @param classloader the classloader to validate against
+ * @param url to url to check for
+ * @return true if the url is not included in the classloader
+ */
+ private boolean isaCandidate( ClassLoader classloader, URL url )
+ {
+ if( classloader instanceof URLClassLoader )
+ {
+ URL[] urls = ( (URLClassLoader) classloader ).getURLs();
+ for( int i=0; i < urls.length; i++ )
+ {
+ if( urls[i].equals( url ) )
+ {
+ return false;
+ }
+ }
+ ClassLoader parent = classloader.getParent();
+ if( parent == null )
+ {
+ return true;
+ }
+ else
+ {
+ return isaCandidate( parent, url );
+ }
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ private static URI createHandlerURI()
+ {
+ try
+ {
+ return new URI( "internal:transit" );
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+}

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/StandardClassLoader.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/StandardClassLoader.java
2006-03-03 17:34:30 UTC (rev 1164)
+++
trunk/main/transit/core/src/main/net/dpml/transit/StandardClassLoader.java
2006-03-03 20:33:07 UTC (rev 1165)
@@ -193,7 +193,14 @@
listClasspath( buffer, parent );
}

- label = label.concat( "\nGroup: " + m_plugin + " " +
cl.getCategory() );
+ if( null != m_plugin )
+ {
+ label = label.concat( "\nGroup: " + m_plugin + " " +
cl.getCategory() );
+ }
+ else
+ {
+ label = label.concat( "\nCategory: " + cl.getCategory() );
+ }
buffer.append( label );
buffer.append( "\n" );
appendEntries( buffer, cl );




  • r1165 - in trunk: lab lab/component/src/main/dpmlx/component lab/lang/src/main/dpmlx/lang lab/lang/src/main/dpmlx/schema lab/test lab/test/etc/test lab/test/src/test/dpmlx/schema/test main/metro/runtime/src/main/net/dpml/metro/runtime main/transit/core/src/main/net/dpml main/transit/core/src/main/net/dpml/part main/transit/core/src/main/net/dpml/transit, mcconnell at BerliOS, 03/03/2006

Archive powered by MHonArc 2.6.24.

Top of Page