notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r1163 - in trunk/lab: component/etc/deliverables/xsds lang/src/main/dpmlx/lang lang/src/main/dpmlx/schema part/etc/deliverables/xsds test/etc/test
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r1163 - in trunk/lab: component/etc/deliverables/xsds lang/src/main/dpmlx/lang lang/src/main/dpmlx/schema part/etc/deliverables/xsds test/etc/test
- Date: Thu, 2 Mar 2006 17:03:50 +0100
Author: mcconnell
Date: 2006-03-02 17:03:47 +0100 (Thu, 02 Mar 2006)
New Revision: 1163
Added:
trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
trunk/lab/lang/src/main/dpmlx/schema/Plugin.java
trunk/lab/lang/src/main/dpmlx/schema/PluginPartHandler.java
trunk/lab/lang/src/main/dpmlx/schema/Resource.java
Removed:
trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
Modified:
trunk/lab/component/etc/deliverables/xsds/component.xsd
trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java
trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java
trunk/lab/part/etc/deliverables/xsds/part.xsd
trunk/lab/test/etc/test/component.xml
Log:
tweaking model construction
Modified: trunk/lab/component/etc/deliverables/xsds/component.xsd
===================================================================
--- trunk/lab/component/etc/deliverables/xsds/component.xsd 2006-03-02
14:21:13 UTC (rev 1162)
+++ trunk/lab/component/etc/deliverables/xsds/component.xsd 2006-03-02
16:03:47 UTC (rev 1163)
@@ -62,19 +62,20 @@
</complexType>
<complexType name="EntryType">
- <sequence>
- <element name="value" type="metro:ValueType" minOccurs="0"
maxOccurs="unbounded"/>
- </sequence>
- <attribute name="key" type="string"/>
- <attribute name="value" type="string"/>
+ <complexContent>
+ <extension base="metro:ValueType">
+ <attribute name="key" type="string"/>
+ </extension>
+ </complexContent>
</complexType>
-
+
<complexType name="ValueType">
<sequence>
- <element name="value" type="metro:ValueType" minOccurs="0"
maxOccurs="unbounded"/>
+ <element name="param" type="metro:ValueType" minOccurs="0"
maxOccurs="unbounded"/>
</sequence>
<attribute name="class" type="string"/>
<attribute name="value" type="string"/>
+ <attribute name="method" type="string"/>
</complexType>
<complexType name="PartsType">
Modified: trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java 2006-03-02 14:21:13
UTC (rev 1162)
+++ trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java 2006-03-02 16:03:47
UTC (rev 1163)
@@ -18,29 +18,27 @@
package dpmlx.lang;
-import java.net.URI;
+import net.dpml.lang.Classpath;
/**
- * Interface implemented by part handlers.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
+ * Interface implemented by part runtime handlers. Handler are identified
+ * by the uri returned from the <tt>Part.getStrategy().getController()</tt>.
*/
public interface PartHandler
{
/**
- * Return a deployment defintion.
- *
- * @param classloader the classloader
- * @exception Exception if an error occurs
+ * Build a classloader stack.
+ * @param anchor the anchor classloader to server as the classloader
chain root
+ * @param classpath the part classpath definition
*/
- Strategy getStrategy() throws Exception;
-
+ ClassLoader getClassLoader( ClassLoader anchor, Classpath classpath );
+
/**
- * Handle the deployment of a part.
- *
- * @param args supplimentary deployment arguments
- * @exception Exception if an error occurs
+ * 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( Object[] args ) throws Exception;
+ Object getInstance( ClassLoader classloader, Object data, Object[] args
) throws Exception;
}
Modified: trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java 2006-03-02
14:21:13 UTC (rev 1162)
+++ trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java 2006-03-02
16:03:47 UTC (rev 1163)
@@ -102,7 +102,7 @@
Artifact artifact = Artifact.createArtifact( namespace );
if( "dpmlx".equals( artifact.getGroup() ) && "dpmlx-part".equals(
artifact.getName() ) )
{
- PluginStrategyBuilder builder = new PluginStrategyBuilder();
+ PartStrategyBuilder builder = new PartStrategyBuilder();
return builder.buildStrategy( strategy );
}
else
Copied: trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java (from
rev 1161, trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java)
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
2006-03-02 14:04:51 UTC (rev 1161)
+++ trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
2006-03-02 16:03:47 UTC (rev 1163)
@@ -0,0 +1,140 @@
+/*
+ * 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 java.net.URI;
+
+import dpmlx.lang.Strategy;
+import dpmlx.lang.StrategyBuilder;
+
+import net.dpml.transit.info.ValueDirective;
+import net.dpml.transit.util.ElementHelper;
+
+import org.w3c.dom.TypeInfo;
+import org.w3c.dom.Element;
+
+/**
+ * Utility used to build a plugin strategy from a DOM element.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class PartStrategyBuilder implements StrategyBuilder
+{
+ public Strategy buildStrategy( Element element ) throws Exception
+ {
+ if( !"strategy".equals( element.getTagName() ) )
+ {
+ final String error =
+ "Invalid element name.";
+ throw new IllegalArgumentException( error );
+ }
+
+ TypeInfo info = element.getSchemaTypeInfo();
+ String type = info.getTypeName();
+ if( "plugin".equals( type ) )
+ {
+ String classname = ElementHelper.getAttribute( element, "class"
);
+ Element[] elements = ElementHelper.getChildren( element,
"params" );
+ ValueDirective[] values = createValueDirectives( elements );
+ Plugin plugin = new Plugin( classname, values );
+ return new PluginStrategy( plugin );
+ }
+ else if( "resource".equals( type ) )
+ {
+ Element urnElement = ElementHelper.getChild( element, "urn" );
+ Element pathElement = ElementHelper.getChild( element, "path" );
+ String urn = ElementHelper.getValue( urnElement );
+ String path = ElementHelper.getValue( pathElement );
+ Resource resource = new Resource( urn, path );
+ return new ResourceStrategy( resource );
+ }
+ else
+ {
+ final String error =
+ "Strategy element ["
+ + type
+ + "] is not recognized.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private ValueDirective[] createValueDirectives( Element[] elements )
+ {
+ ValueDirective[] values = new ValueDirective[ elements.length ];
+ for( int i=0; i<elements.length; i++ )
+ {
+ values[i] = createValueDirective( elements[i] );
+ }
+ return values;
+ }
+
+ private ValueDirective createValueDirective( Element element )
+ {
+ String classname = ElementHelper.getAttribute( element, "class" );
+ String method = ElementHelper.getAttribute( element, "method" );
+ Element[] elements = ElementHelper.getChildren( element, "params" );
+ if( elements.length > 0 )
+ {
+ ValueDirective[] values = createValueDirectives( elements );
+ return new ValueDirective( classname, method, values );
+ }
+ else
+ {
+ String value = ElementHelper.getAttribute( element, "value" );
+ return new ValueDirective( classname, method, value );
+ }
+ }
+
+ private abstract static class PartStrategy extends Strategy
+ {
+ PartStrategy( URI uri, Serializable data ) throws Exception
+ {
+ super( uri, data );
+ }
+ }
+
+ private static class PluginStrategy extends PartStrategy
+ {
+ PluginStrategy( Plugin plugin ) throws Exception
+ {
+ super( new URI( "part:plugin" ), plugin );
+ }
+
+ public Plugin getPlugin()
+ {
+ return (Plugin) super.getDeploymentData();
+ }
+ }
+
+ private static class ResourceStrategy extends PartStrategy
+ {
+ ResourceStrategy( Resource resource ) throws Exception
+ {
+ super( new URI( "part:resource" ), resource );
+ }
+
+ public Resource getResource()
+ {
+ return (Resource) super.getDeploymentData();
+ }
+ }
+
+}
Added: trunk/lab/lang/src/main/dpmlx/schema/Plugin.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/Plugin.java 2006-03-02 14:21:13
UTC (rev 1162)
+++ trunk/lab/lang/src/main/dpmlx/schema/Plugin.java 2006-03-02 16:03:47
UTC (rev 1163)
@@ -0,0 +1,81 @@
+/*
+ * 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 java.util.Arrays;
+
+import net.dpml.transit.info.ValueDirective;
+
+class Plugin implements Serializable
+{
+ private final String m_classname;
+ private final ValueDirective[] m_params;
+
+ public Plugin( String classname, ValueDirective[] params )
+ {
+ m_classname = classname;
+ m_params = params;
+ }
+
+ public String getClassname()
+ {
+ return m_classname;
+ }
+
+ public ValueDirective[] getValueDirectives()
+ {
+ return m_params;
+ }
+
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else if( other instanceof Plugin )
+ {
+ Plugin plugin = (Plugin) other;
+ if( !m_classname.equals( plugin.m_classname ) )
+ {
+ return false;
+ }
+ else
+ {
+
+ return Arrays.equals( m_params, plugin.m_params );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ int hash = m_classname.hashCode();
+ for( int i=0; i<m_params.length; i++ )
+ {
+ hash ^= m_params[i].hashCode();
+ }
+ return hash;
+ }
+}
Added: trunk/lab/lang/src/main/dpmlx/schema/PluginPartHandler.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PluginPartHandler.java 2006-03-02
14:21:13 UTC (rev 1162)
+++ trunk/lab/lang/src/main/dpmlx/schema/PluginPartHandler.java 2006-03-02
16:03:47 UTC (rev 1163)
@@ -0,0 +1,53 @@
+/*
+ * 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" );
+ }
+}
Deleted: trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
2006-03-02 14:21:13 UTC (rev 1162)
+++ trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
2006-03-02 16:03:47 UTC (rev 1163)
@@ -1,183 +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 java.net.URI;
-
-import dpmlx.lang.Strategy;
-import dpmlx.lang.StrategyBuilder;
-
-import net.dpml.transit.util.ElementHelper;
-
-import org.w3c.dom.TypeInfo;
-import org.w3c.dom.Element;
-
-/**
- * Utility used to build a plugin strategy from a DOM element.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class PluginStrategyBuilder implements StrategyBuilder
-{
- public Strategy buildStrategy( Element element ) throws Exception
- {
- if( !"strategy".equals( element.getTagName() ) )
- {
- final String error =
- "Invalid element name.";
- throw new IllegalArgumentException( error );
- }
-
- TypeInfo info = element.getSchemaTypeInfo();
- String type = info.getTypeName();
- if( "plugin".equals( type ) )
- {
- String classname = ElementHelper.getAttribute( element, "class"
);
- return new ClassStrategy( classname );
- }
- else if( "resource".equals( type ) )
- {
- Element urnElement = ElementHelper.getChild( element, "urn" );
- Element pathElement = ElementHelper.getChild( element, "path" );
- String urn = ElementHelper.getValue( urnElement );
- String path = ElementHelper.getValue( pathElement );
- Resource resource = new Resource( urn, path );
- return new ResourceStrategy( resource );
- }
- else
- {
- final String error =
- "Strategy element ["
- + type
- + "] is not recognized.";
- throw new IllegalArgumentException( error );
- }
- }
-
- /**
- * Handle the deployment of a part.
- *
- * @param classloader the classloader
- * @param args supplimentary deployment arguments
- * @exception Exception if an error occurs
- */
- /*
- public Object getInstance( Object[] args ) throws Exception
- {
- if( m_strategy instanceof ClassStrategy )
- {
- ClassStrategy strategy = (ClassStrategy) m_strategy;
- Class c = strategy.getPluginClass( m_classloader );
- Repository repository = Transit.getInstance().getRepository();
- repository.instantiate( c, args );
- }
- else
- {
- final String error =
- "Resource instantiation not supported.";
- throw new UnsupportedOperationException( error );
- }
- }
- */
-
- private abstract static class PluginStrategy extends Strategy
- {
- PluginStrategy( URI uri, Serializable data ) throws Exception
- {
- super( uri, data );
- }
- }
-
- private static class ClassStrategy extends PluginStrategy
- {
- ClassStrategy( String classname ) throws Exception
- {
- super( new URI( "plugin:class" ), classname );
- }
-
- public String getClassname()
- {
- return (String) super.getDeploymentData();
- }
-
- public Class getPluginClass( ClassLoader classloader ) throws
ClassNotFoundException
- {
- String classname = getClassname();
- return classloader.loadClass( classname );
- }
- }
-
- private static class ResourceStrategy extends PluginStrategy
- {
- ResourceStrategy( Resource resource ) throws Exception
- {
- super( new URI( "plugin:resource" ), resource );
- }
-
- public Resource getResource()
- {
- return (Resource) super.getDeploymentData();
- }
- }
-
- private static class Resource implements Serializable
- {
- private final String m_urn;
- private final String m_path;
-
- public Resource( String urn, String path )
- {
- m_urn = urn;
- m_path = path;
- }
-
- public boolean equals( Object other )
- {
- if( null == other )
- {
- return false;
- }
- else if( other instanceof Resource )
- {
- Resource resource = (Resource) other;
- if( !m_urn.equals( resource.m_urn ) )
- {
- return false;
- }
- else
- {
- return m_path.equals( resource.m_path );
- }
- }
- else
- {
- return false;
- }
- }
-
- public int hashCode()
- {
- int hash = m_urn.hashCode();
- hash ^= m_path.hashCode();
- return hash;
- }
- }
-}
Added: trunk/lab/lang/src/main/dpmlx/schema/Resource.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/Resource.java 2006-03-02 14:21:13
UTC (rev 1162)
+++ trunk/lab/lang/src/main/dpmlx/schema/Resource.java 2006-03-02 16:03:47
UTC (rev 1163)
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+class Resource implements Serializable
+{
+ private final String m_urn;
+ private final String m_path;
+
+ public Resource( String urn, String path )
+ {
+ m_urn = urn;
+ m_path = path;
+ }
+
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else if( other instanceof Resource )
+ {
+ Resource resource = (Resource) other;
+ if( !m_urn.equals( resource.m_urn ) )
+ {
+ return false;
+ }
+ else
+ {
+ return m_path.equals( resource.m_path );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ int hash = m_urn.hashCode();
+ hash ^= m_path.hashCode();
+ return hash;
+ }
+}
Modified: trunk/lab/part/etc/deliverables/xsds/part.xsd
===================================================================
--- trunk/lab/part/etc/deliverables/xsds/part.xsd 2006-03-02 14:21:13
UTC (rev 1162)
+++ trunk/lab/part/etc/deliverables/xsds/part.xsd 2006-03-02 16:03:47
UTC (rev 1163)
@@ -21,6 +21,9 @@
<complexType name="plugin">
<complexContent>
<extension base="part:StrategyType">
+ <sequence>
+ <element name="param" type="part:ValueType" minOccurs="0"
maxOccurs="unbounded"/>
+ </sequence>
<attribute name="class" type="string"/>
</extension>
</complexContent>
@@ -72,6 +75,14 @@
</simpleContent>
</complexType>
+ <complexType name="ValueType">
+ <sequence>
+ <element name="param" type="part:ValueType" minOccurs="0"
maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="class" type="string"/>
+ <attribute name="value" type="string"/>
+ <attribute name="method" type="string"/>
+ </complexType>
</schema>
Modified: trunk/lab/test/etc/test/component.xml
===================================================================
--- trunk/lab/test/etc/test/component.xml 2006-03-02 14:21:13 UTC (rev
1162)
+++ trunk/lab/test/etc/test/component.xml 2006-03-02 16:03:47 UTC (rev
1163)
@@ -19,10 +19,10 @@
<context>
<entry key="foo" value="abc"/>
<entry key="bar">
- <value class="Gizmo">
- <value value="foo"/>
- <value value="bar"/>
- </value>
+ <param class="Gizmo">
+ <param value="foo"/>
+ <param value="bar"/>
+ </param>
</entry>
</context>
<parts>
- r1163 - in trunk/lab: component/etc/deliverables/xsds lang/src/main/dpmlx/lang lang/src/main/dpmlx/schema part/etc/deliverables/xsds test/etc/test, mcconnell at BerliOS, 03/02/2006
Archive powered by MHonArc 2.6.24.