Skip to Content.
Sympa Menu

notify-dpml - r1158 - in trunk/lab: . component component/etc/deliverables/xsds lang/src/main/dpmlx/schema part/etc/deliverables/xsds test/etc/test test/src/test/dpmlx/schema/test

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: r1158 - in trunk/lab: . component component/etc/deliverables/xsds lang/src/main/dpmlx/schema part/etc/deliverables/xsds test/etc/test test/src/test/dpmlx/schema/test
  • Date: Wed, 1 Mar 2006 09:57:03 +0100

Author: mcconnell
Date: 2006-03-01 09:56:59 +0100 (Wed, 01 Mar 2006)
New Revision: 1158

Modified:
trunk/lab/component/build.xml
trunk/lab/component/etc/deliverables/xsds/project.xsd
trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java
trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
trunk/lab/library.xml
trunk/lab/part/etc/deliverables/xsds/project.xsd
trunk/lab/test/etc/test/component.xml
trunk/lab/test/etc/test/plugin.xml
trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
Log:
update such that custom elements extend <strategy>

Modified: trunk/lab/component/build.xml
===================================================================
--- trunk/lab/component/build.xml 2006-03-01 05:15:17 UTC (rev 1157)
+++ trunk/lab/component/build.xml 2006-03-01 08:56:59 UTC (rev 1158)
@@ -8,6 +8,7 @@

<target name="init" depends="standard.init">
<x:filter feature="uri" type="xsd" token="PROJECT-XSD-URI"/>
+ <x:filter feature="uri" type="xsd" token="PART-XSD-URI"
key="dpmlx-part"/>
</target>

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

Modified: trunk/lab/component/etc/deliverables/xsds/project.xsd
===================================================================
--- trunk/lab/component/etc/deliverables/xsds/project.xsd 2006-03-01
05:15:17 UTC (rev 1157)
+++ trunk/lab/component/etc/deliverables/xsds/project.xsd 2006-03-01
08:56:59 UTC (rev 1158)
@@ -1,19 +1,35 @@
<?xml version="1.0"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+ xmlns:part="@PART-XSD-URI@"
targetNamespace="@PROJECT-XSD-URI@"
xmlns="@PROJECT-XSD-URI@"
elementFormDefault="qualified">

+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace";
+ schemaLocation="artifact:xsd:org/w3/xml#2001"/>
+
+ <xsd:import namespace="@PART-XSD-URI@"
+ schemaLocation="@PART-XSD-URI@"/>
+
<xsd:element name="component" type="ComponentType"/>

<xsd:complexType name="ComponentType">
- <xsd:sequence>
- <xsd:element name="context" type="ContextType" minOccurs="0"
maxOccurs="1"/>
- </xsd:sequence>
- <xsd:attribute name="type" type="xsd:string"/>
- <xsd:attribute name="lifestyle" type="xsd:string"/>
- <xsd:attribute name="collection" type="xsd:string"/>
+ <xsd:annotation>
+ <xsd:documentation xml:lang="en">
+ Definition of a component deployment model for the DPML Metro
Platform.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:complexContent>
+ <xsd:extension base="part:StrategyType">
+ <xsd:sequence>
+ <xsd:element name="context" type="ContextType" minOccurs="0"
maxOccurs="1"/>
+ </xsd:sequence>
+ <xsd:attribute name="type" type="xsd:string"/>
+ <xsd:attribute name="lifestyle" type="xsd:string"/>
+ <xsd:attribute name="collection" type="xsd:string"/>
+ </xsd:extension>
+ </xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="ContextType">

Modified: trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java 2006-03-01
05:15:17 UTC (rev 1157)
+++ trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java 2006-03-01
08:56:59 UTC (rev 1158)
@@ -38,12 +38,19 @@

import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.Attr;
+import org.w3c.dom.TypeInfo;

/**
* Construct a part.
*/
public class PartBuilder
{
+ private static final String SCHEMA_INSTANCE_NS =
+ "http://www.w3.org/2001/XMLSchema-instance";;
+
private static StandardBuilder BUILDER = new StandardBuilder();

public Part loadPart( URI uri ) throws Exception
@@ -75,38 +82,29 @@
return new Part( info, strategy, classpath );
}

+ private URI getStrategyBuilderURI( Element element ) throws Exception
+ {
+ TypeInfo info = element.getSchemaTypeInfo();
+ String namespace = info.getTypeNamespace();
+ return getBuilderURI( namespace );
+ }
+
private Strategy getStrategy( ClassLoader loader, Element root ) throws
Exception
{
- Element plugin = ElementHelper.getChild( root, "plugin" );
- if( null != plugin )
+ Element strategy = ElementHelper.getChild( root, "strategy" );
+ TypeInfo info = strategy.getSchemaTypeInfo();
+ String namespace = info.getTypeNamespace();
+ Artifact artifact = Artifact.createArtifact( namespace );
+ if( "dpmlx".equals( artifact.getGroup() ) && "dpmlx-part".equals(
artifact.getName() ) )
{
- // This is a standard transit plugin containing either
- // a <class> element or a <resource> element as such is
- // a concern private to the transit implementation to
- // resolve the plugin strategy.
-
- Element element = getSingleNestedElement( plugin );
PluginStrategyBuilder builder = new PluginStrategyBuilder();
- return builder.buildStrategy( element );
+ return builder.buildStrategy( strategy );
}
else
{
- // This is a custom deployment strategy defined under
- // a <strategy> element and all we know is its namespace
- // and that the nested element is the argument to a
- // custom instantiation handler. On the grounds that the
- // namespace is declared in the form of an artifact with
- // the type 'xsd', we construct a new plugin artifact using
- // the same group, name and version. If such a plugin
- // exists using the link protocol we use otherwise we
- // attempt to locate a plugin using the artifact protocol.
-
- Element strategy = ElementHelper.getChild( root, "strategy" );
- Element element = getSingleNestedElement( strategy );
- String namespace = element.getNamespaceURI();
URI uri = getBuilderURI( namespace );
StrategyBuilder builder = loadStrategyBuilder( uri );
- return builder.buildStrategy( element );
+ return builder.buildStrategy( strategy );
}
}


Modified: trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
2006-03-01 05:15:17 UTC (rev 1157)
+++ trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
2006-03-01 08:56:59 UTC (rev 1158)
@@ -38,27 +38,35 @@
{
public Strategy buildStrategy( Element element ) throws Exception
{
- String name = element.getTagName();
- if( "class".equals( name ) )
+ if( !"strategy".equals( element.getTagName() ) )
{
- String classname = ElementHelper.getValue( element );
+ final String error =
+ "Invalid element name.";
+ throw new IllegalArgumentException( error );
+ }
+ Element classElement = ElementHelper.getChild( element, "class" );
+ if( null != classElement )
+ {
+ String classname = ElementHelper.getValue( classElement );
return new ClassStrategy( classname );
}
- else if( "resource".equals( name ) )
+ else
{
- Element urnElement = ElementHelper.getChild( element, "urn" );
- Element pathElement = ElementHelper.getChild( element, "path" );
+ Element resourceElement = ElementHelper.getChild( element,
"resource" );
+ if( null == resourceElement )
+ {
+ final String error =
+ "Invalid strategy element.";
+ throw new IllegalArgumentException( error );
+ }
+
+ Element urnElement = ElementHelper.getChild( resourceElement,
"urn" );
+ Element pathElement = ElementHelper.getChild( resourceElement,
"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 =
- "Element [" + name + "] is not recognized.";
- throw new IllegalArgumentException( error );
- }
}

/**

Modified: trunk/lab/library.xml
===================================================================
--- trunk/lab/library.xml 2006-03-01 05:15:17 UTC (rev 1157)
+++ trunk/lab/library.xml 2006-03-01 08:56:59 UTC (rev 1158)
@@ -40,6 +40,9 @@
value="dpmlx.component.ComponentStrategyBuilder"/>
</type>
</types>
+ <dependencies scope="build">
+ <include key="dpmlx-part"/>
+ </dependencies>
<dependencies scope="runtime">
<include key="dpmlx-lang"/>
</dependencies>

Modified: trunk/lab/part/etc/deliverables/xsds/project.xsd
===================================================================
--- trunk/lab/part/etc/deliverables/xsds/project.xsd 2006-03-01 05:15:17
UTC (rev 1157)
+++ trunk/lab/part/etc/deliverables/xsds/project.xsd 2006-03-01 08:56:59
UTC (rev 1158)
@@ -9,18 +9,23 @@
<xsd:complexType name="PartType">
<xsd:sequence>
<xsd:element name="info" type="InfoType"/>
+ <xsd:element name="strategy" type="StrategyType"/>
+ <!--
<xsd:choice>
<xsd:element name="strategy" type="StrategyType"/>
<xsd:element name="plugin" type="PluginType"/>
</xsd:choice>
+ -->
<xsd:element name="classpath" type="ClassPathType"/>
</xsd:sequence>
</xsd:complexType>

- <xsd:complexType name="StrategyType">
+ <xsd:complexType name="StrategyType" abstract="true">
+ <!--
<xsd:sequence>
<xsd:any minOccurs="0"/>
</xsd:sequence>
+ -->
<xsd:attribute name="uri" type="xsd:anyURI"/>
</xsd:complexType>

@@ -53,10 +58,14 @@
</xsd:complexType>

<xsd:complexType name="PluginType">
- <xsd:choice>
- <xsd:element name="class" type="ClassType"/>
- <xsd:element name="resource" type="ResourceType"/>
- </xsd:choice>
+ <xsd:complexContent>
+ <xsd:extension base="StrategyType">
+ <xsd:choice>
+ <xsd:element name="class" type="ClassType"/>
+ <xsd:element name="resource" type="ResourceType"/>
+ </xsd:choice>
+ </xsd:extension>
+ </xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="ClassType">

Modified: trunk/lab/test/etc/test/component.xml
===================================================================
--- trunk/lab/test/etc/test/component.xml 2006-03-01 05:15:17 UTC (rev
1157)
+++ trunk/lab/test/etc/test/component.xml 2006-03-01 08:56:59 UTC (rev
1158)
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<part xmlns="@PART-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
- xmlns:metro="@COMPONENT-XSD-URI@"
+ xmlns:m="@COMPONENT-XSD-URI@"
xsi:schemaLocation="
@PART-XSD-URI@ @PART-XSD-URI@
@COMPONENT-XSD-URI@ @COMPONENT-XSD-URI@
@@ -13,15 +13,14 @@
</description>
</info>

- <strategy uri="link:plugin:dpml/metro/dpml-metro-builder">
- <metro:component type="org.acme.Widget">
- <metro:context>
- <metro:entry key="foo" value="abc"/>
- <metro:entry key="bar">
- <metro:value class="int" value="2"/>
- </metro:entry>
- </metro:context>
- </metro:component>
+ <strategy xsi:type="m:ComponentType"
+ uri="link:plugin:dpml/metro/dpml-metro-builder" type="org.acme.Widget">
+ <m:context>
+ <m:entry key="foo" value="abc"/>
+ <m:entry key="bar">
+ <m:value class="int" value="2"/>
+ </m:entry>
+ </m:context>
</strategy>

<classpath>

Modified: trunk/lab/test/etc/test/plugin.xml
===================================================================
--- trunk/lab/test/etc/test/plugin.xml 2006-03-01 05:15:17 UTC (rev 1157)
+++ trunk/lab/test/etc/test/plugin.xml 2006-03-01 08:56:59 UTC (rev 1158)
@@ -11,7 +11,7 @@
</description>
</info>

- <plugin>
+ <strategy xsi:type="PluginType">
<class>Widget</class>
<!--
<resource>
@@ -19,7 +19,7 @@
<path>net/dpml/metro/tools/antlib.xml</path>
</resource>
-->
- </plugin>
+ </strategy>

<classpath>
<public>

Modified: trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
===================================================================
--- trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-03-01 05:15:17 UTC (rev 1157)
+++ trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-03-01 08:56:59 UTC (rev 1158)
@@ -56,149 +56,6 @@
System.out.println( "source: " + file );
Part part = m_builder.loadPart( file.toURI() );
System.out.println( "# PART: " + part );
-
- /*
- Document doc = m_builder.parse( path );
- final Element root = doc.getDocumentElement();
- final String namespace = root.getNamespaceURI();
-
- // construct the classloader using the <classpath> element
-
- // check if we are a classic plugin or if a custom strategy
- // has been declared
-
- Element plugin = ElementHelper.getChild( root, "plugin" );
- if( null != plugin )
- {
- // This is a standard transit plugin containing either
- // a <class> element or a <resource> element as such is
- // a concern private to the transit implementation to
- // resolve the plugin strategy.
-
- System.out.println( "plugin (namespace): " + namespace );
- }
- else
- {
- // This is a custom deployment strategy defined under
- // a <strategy> element and all we know is its namespace
- // and that the nested element is the argument to a
- // custom instantiation handler. On the grounds that the
- // namespace is declared in the form of an artifact with
- // the type 'xsd', we construct a new plugin artifact using
- // the same group, name and version. If such a plugin
- // exists using the link protocol we use otherwise we
- // attempt to locate a plugin using the artifact protocol.
-
- Element strategy = ElementHelper.getChild( root, "strategy" );
- Element implementation = getSingleNestedElement( strategy );
- String urn = implementation.getNamespaceURI();
- System.out.println( "strategy (namespace): " + urn );
- URI uri = getImplementationHandler( urn );
- System.out.println( "resolved: " + uri );
-
- PartHandler handler = loadPartHandler( uri, implementation );
- //Object instance = handler.getInstance( classloader, new
Object[0] );
- System.out.println( "handler: " + handler.getClass().getName() );
- }
- */
+ System.out.println( "# STRATEGY: " + part.getStrategy() );
}
-
- /*
- private Element getSingleNestedElement( Element parent ) throws Exception
- {
- if( null == parent )
- {
- throw new NullPointerException( "parent" );
- }
- else
- {
- Element[] children = ElementHelper.getChildren( parent );
- if( children.length == 1 )
- {
- return children[0];
- }
- else
- {
- final String error =
- "Parent element does not contain a single child.";
- throw new IllegalArgumentException( error );
- }
- }
-
- }
-
- private URI getImplementationHandler( String urn ) throws Exception
- {
- URI raw = new URI( urn );
- if( Artifact.isRecognized( raw ) )
- {
- Artifact artifact = Artifact.createArtifact( raw );
- String scheme = artifact.getScheme();
- String group = artifact.getGroup();
- String name = artifact.getName();
- String type = artifact.getType();
- String version = artifact.getVersion();
-
- try
- {
- String path = "link:plugin:" + group + "/" + name;
- Artifact link = Artifact.createArtifact( path );
- System.out.println( " checking: " + link );
- URL linkUrl = link.toURL();
- linkUrl.getContent( new Class[]{File.class} ); // test for
existance
- return link.toURI();
- }
- catch( ArtifactNotFoundException e )
- {
- Artifact result = Artifact.createArtifact( group, name,
version, "plugin" );
- try
- {
- System.out.println( " checking: " + result );
- URL url = result.toURL();
- url.getContent( new Class[]{File.class} );
- return result.toURI();
- }
- catch( ArtifactNotFoundException anfe )
- {
- System.out.println( " unresolved" );
- final String error =
- "Unable to resolve a strategy handler for the urn ["
- + urn
- + "].";
- throw new UnresolvableHandlerException( error,
result.toURI() );
- }
- }
- }
- else
- {
- final String error =
- "Namespace urn ["
- + urn
- + "] is not a recognized artifact protocol.";
- throw new IllegalArgumentException( error );
- }
- }
-
- private PartHandler loadPartHandler( URI uri, Element implementation )
throws Exception
- {
- ClassLoader classloader = PartHandler.class.getClassLoader();
- Repository repository = Transit.getInstance().getRepository();
- Object[] args = new Object[]{ implementation };
- Object handler = repository.getPlugin( classloader, uri, args );
- if( handler instanceof PartHandler )
- {
- return (PartHandler) handler;
- }
- else
- {
- final String error =
- "Part handler plugin ["
- + uri
- + "] does not implement the "
- + PartHandler.class.getName()
- + " interface.";
- throw new IllegalArgumentException( error );
- }
- }
- */
}




  • r1158 - in trunk/lab: . component component/etc/deliverables/xsds lang/src/main/dpmlx/schema part/etc/deliverables/xsds test/etc/test test/src/test/dpmlx/schema/test, mcconnell at BerliOS, 03/01/2006

Archive powered by MHonArc 2.6.24.

Top of Page