Skip to Content.
Sympa Menu

notify-dpml - r1164 - in trunk/lab: . component component/etc/deliverables/xsds component/src/main/dpmlx/component lang/src/main/dpmlx/lang 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: r1164 - in trunk/lab: . component component/etc/deliverables/xsds component/src/main/dpmlx/component lang/src/main/dpmlx/lang lang/src/main/dpmlx/schema part/etc/deliverables/xsds test/etc/test test/src/test/dpmlx/schema/test
  • Date: Fri, 3 Mar 2006 18:34:33 +0100

Author: mcconnell
Date: 2006-03-03 18:34:30 +0100 (Fri, 03 Mar 2006)
New Revision: 1164

Added:
trunk/lab/lang/src/main/dpmlx/lang/BuilderException.java
trunk/lab/lang/src/main/dpmlx/lang/PartDirective.java
Removed:
trunk/lab/component/src/main/dpmlx/component/ComponentStrategy.java
Modified:
trunk/lab/component/build.xml
trunk/lab/component/etc/deliverables/xsds/component.xsd
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
trunk/lab/lang/src/main/dpmlx/lang/Strategy.java
trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
trunk/lab/library.xml
trunk/lab/part/etc/deliverables/xsds/part.xsd
trunk/lab/test/etc/test/component.xml
trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
Log:
improvements

Modified: trunk/lab/component/build.xml
===================================================================
--- trunk/lab/component/build.xml 2006-03-02 16:03:47 UTC (rev 1163)
+++ trunk/lab/component/build.xml 2006-03-03 17:34:30 UTC (rev 1164)
@@ -9,6 +9,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"/>
+ <x:filter feature="uri" type="plugin" token="CONTROLLER_URI"
ref="dpml/metro/dpml-metro-runtime"/>
</target>

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

Modified: trunk/lab/component/etc/deliverables/xsds/component.xsd
===================================================================
--- trunk/lab/component/etc/deliverables/xsds/component.xsd 2006-03-02
16:03:47 UTC (rev 1163)
+++ trunk/lab/component/etc/deliverables/xsds/component.xsd 2006-03-03
17:34:30 UTC (rev 1164)
@@ -13,8 +13,6 @@
<import namespace="@PART-XSD-URI@"
schemaLocation="@PART-XSD-URI@"/>

- <element name="component" type="metro:part"/>
-
<!--
Definition of a plugin component deployment strategy.
-->
@@ -33,7 +31,7 @@
<sequence>
<element name="param" type="metro:ValueType" minOccurs="0"
maxOccurs="unbounded"/>
</sequence>
- <attribute name="uri" type="string"/>
+ <attribute name="uri" type="string" use="required"/>
</complexType>

<complexType name="ComponentType">
@@ -41,20 +39,11 @@
<element name="context" type="metro:ContextType" minOccurs="0"
maxOccurs="1"/>
<element name="parts" type="metro:PartsType" minOccurs="0"
maxOccurs="1"/>
</sequence>
- <attribute name="class" type="string"/>
+ <attribute name="class" type="string" use="required"/>
<attribute name="lifestyle" type="metro:lifestyle"/>
<attribute name="collection" type="metro:collection"/>
</complexType>

- <complexType name="part">
- <complexContent>
- <extension base="metro:ComponentType">
- <attribute name="alias" type="boolean"/>
- <attribute name="type" type="string" default="part"/>
- </extension>
- </complexContent>
- </complexType>
-
<complexType name="ContextType">
<sequence>
<element name="entry" type="metro:EntryType" minOccurs="0"
maxOccurs="unbounded"/>

Deleted: trunk/lab/component/src/main/dpmlx/component/ComponentStrategy.java
===================================================================
--- trunk/lab/component/src/main/dpmlx/component/ComponentStrategy.java
2006-03-02 16:03:47 UTC (rev 1163)
+++ trunk/lab/component/src/main/dpmlx/component/ComponentStrategy.java
2006-03-03 17:34:30 UTC (rev 1164)
@@ -1,38 +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.component;
-
-import java.io.Serializable;
-import java.net.URI;
-
-import dpmlx.lang.Strategy;
-
-/**
- * Part deployment strategy description.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class ComponentStrategy extends Strategy
-{
- public ComponentStrategy( Serializable data ) throws Exception
- {
- super( new URI( "link:plugin:dpml/metro/dpml-metro-runtime" ), data
);
- }
-}

Modified:
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
===================================================================
---
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
2006-03-02 16:03:47 UTC (rev 1163)
+++
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
2006-03-03 17:34:30 UTC (rev 1164)
@@ -20,8 +20,15 @@

import java.net.URI;

+import net.dpml.metro.data.ComponentDirective;
+
+import net.dpml.transit.info.ValueDirective;
+import net.dpml.transit.util.ElementHelper;
+
import dpmlx.lang.Strategy;
import dpmlx.lang.StrategyBuilder;
+import dpmlx.lang.PartDirective;
+import dpmlx.lang.BuilderException;

import org.w3c.dom.Element;

@@ -33,6 +40,8 @@
*/
public class ComponentStrategyBuilder implements StrategyBuilder
{
+ private final String CONTROLLER = "@CONTROLLER_URI@";
+
/**
* Constructs a component deployment strategy.
*
@@ -41,6 +50,90 @@
*/
public Strategy buildStrategy( Element element ) throws Exception
{
- return new ComponentStrategy( "Hello World" );
+ Element controller = ElementHelper.getChild( element, "controller" );
+ PartDirective control = createControllerDirective( controller );
+ Element directive = ElementHelper.getChild( element, "component" );
+ ComponentDirective component = createComponentDirective( directive );
+ return new Strategy( control, component );
}
+
+ private ComponentDirective createComponentDirective( Element element )
throws BuilderException
+ {
+ String classname = getComponentClassname( element );
+ String name = getComponentName( element );
+ return new ComponentDirective( name, classname );
+ }
+
+ private String getComponentClassname( Element element ) throws
BuilderException
+ {
+ String classname = ElementHelper.getAttribute( element, "class" );
+ if( null == classname )
+ {
+ final String error =
+ "Missing component 'class' attribute.";
+ throw new BuilderException( element, error );
+ }
+ else
+ {
+ return classname;
+ }
+ }
+
+ private String getComponentName( Element element )
+ {
+ return ElementHelper.getAttribute( element, "name" );
+ }
+
+ private PartDirective createControllerDirective( Element element )
throws Exception
+ {
+ if( null == element )
+ {
+ try
+ {
+ URI uri = new URI( CONTROLLER );
+ return new PartDirective( uri, null );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error during part directive creation.";
+ throw new RuntimeException( error, e );
+ }
+ }
+ else
+ {
+ String spec = ElementHelper.getAttribute( element, "uri" );
+ URI uri = new URI( spec );
+ Element[] elements = ElementHelper.getChildren( element, "param"
);
+ ValueDirective[] values = createValueDirectives( elements );
+ return new PartDirective( uri, values );
+ }
+ }
+
+ 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, "param" );
+ 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 );
+ }
+ }
}

Added: trunk/lab/lang/src/main/dpmlx/lang/BuilderException.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/BuilderException.java 2006-03-02
16:03:47 UTC (rev 1163)
+++ trunk/lab/lang/src/main/dpmlx/lang/BuilderException.java 2006-03-03
17:34:30 UTC (rev 1164)
@@ -0,0 +1,63 @@
+/*
+ * 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 org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class BuilderException extends Exception
+{
+ private final Element m_element;
+
+ public BuilderException( Element element, String message )
+ {
+ super( message );
+ m_element = element;
+ }
+
+ public Element getElement()
+ {
+ return m_element;
+ }
+
+ public String getMessage()
+ {
+ try
+ {
+ String message = super.getMessage();
+ StringBuffer buffer = new StringBuffer( message );
+ Element element = getElement();
+ String tag = element.getTagName();
+ buffer.append( "\nElement: <" );
+ buffer.append( tag );
+ buffer.append( " ...>" );
+ Document document = element.getOwnerDocument();
+ String uri = document.getDocumentURI();
+ if( null != uri )
+ {
+ buffer.append( "\nDocument: " + uri );
+ }
+ return buffer.toString();
+ }
+ catch( Throwable e )
+ {
+ return super.getMessage();
+ }
+ }
+}

Added: trunk/lab/lang/src/main/dpmlx/lang/PartDirective.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/PartDirective.java 2006-03-02
16:03:47 UTC (rev 1163)
+++ trunk/lab/lang/src/main/dpmlx/lang/PartDirective.java 2006-03-03
17:34:30 UTC (rev 1164)
@@ -0,0 +1,105 @@
+/*
+ * 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 java.io.Serializable;
+import java.net.URI;
+
+import net.dpml.transit.info.ValueDirective;
+
+/**
+ * Immutable part creation directive.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class PartDirective implements Serializable
+{
+ private final URI m_uri;
+ private final ValueDirective[] m_params;
+
+ public PartDirective( URI uri, ValueDirective[] params )
+ {
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+ m_uri = uri;
+ if( null == params )
+ {
+ m_params = new ValueDirective[0];
+ }
+ else
+ {
+ m_params = params;
+ }
+ }
+
+ /**
+ * Get the part uri.
+ * @return the uri
+ */
+ public URI getURI()
+ {
+ return m_uri;
+ }
+
+ /**
+ * Get the values to be used during part instantiation.
+ * @return the directives
+ */
+ public ValueDirective[] getValueDirectives()
+ {
+ return m_params;
+ }
+
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else if( other instanceof PartDirective )
+ {
+ PartDirective part = (PartDirective) other;
+ if( !m_uri.equals( part.m_uri ) )
+ {
+ return false;
+ }
+ else
+ {
+ return m_params.equals( part.m_params );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ int hash = m_uri.hashCode();
+ for( int i=0; i<m_params.length; i++ )
+ {
+ hash ^= m_params[i].hashCode();
+ }
+ return hash;
+ }
+}

Modified: trunk/lab/lang/src/main/dpmlx/lang/Strategy.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/Strategy.java 2006-03-02 16:03:47
UTC (rev 1163)
+++ trunk/lab/lang/src/main/dpmlx/lang/Strategy.java 2006-03-03 17:34:30
UTC (rev 1164)
@@ -29,10 +29,10 @@
*/
public class Strategy implements Serializable
{
- private final URI m_controller;
+ private final PartDirective m_controller;
private final Serializable m_data;

- public Strategy( URI controller, Serializable data )
+ public Strategy( PartDirective controller, Serializable data )
{
if( null == controller )
{
@@ -47,11 +47,11 @@
}

/**
- * Get the uri identifying the deployment controller.
+ * Get the controller deployment directive.
*
* @return the deployment controller uri
*/
- public URI getControllerURI()
+ public PartDirective getPartDirective()
{
return m_controller;
}

Modified: trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
2006-03-02 16:03:47 UTC (rev 1163)
+++ trunk/lab/lang/src/main/dpmlx/schema/PartStrategyBuilder.java
2006-03-03 17:34:30 UTC (rev 1164)
@@ -23,6 +23,7 @@

import dpmlx.lang.Strategy;
import dpmlx.lang.StrategyBuilder;
+import dpmlx.lang.PartDirective;

import net.dpml.transit.info.ValueDirective;
import net.dpml.transit.util.ElementHelper;
@@ -38,6 +39,8 @@
*/
public class PartStrategyBuilder implements StrategyBuilder
{
+ private static final PartDirective TRANSIT_DIRECTIVE =
createTransitDirective();
+
public Strategy buildStrategy( Element element ) throws Exception
{
if( !"strategy".equals( element.getTagName() ) )
@@ -52,10 +55,10 @@
if( "plugin".equals( type ) )
{
String classname = ElementHelper.getAttribute( element, "class"
);
- Element[] elements = ElementHelper.getChildren( element,
"params" );
+ Element[] elements = ElementHelper.getChildren( element, "param"
);
ValueDirective[] values = createValueDirectives( elements );
Plugin plugin = new Plugin( classname, values );
- return new PluginStrategy( plugin );
+ return new Strategy( TRANSIT_DIRECTIVE, plugin );
}
else if( "resource".equals( type ) )
{
@@ -64,7 +67,7 @@
String urn = ElementHelper.getValue( urnElement );
String path = ElementHelper.getValue( pathElement );
Resource resource = new Resource( urn, path );
- return new ResourceStrategy( resource );
+ return new Strategy( TRANSIT_DIRECTIVE, resource );
}
else
{
@@ -90,7 +93,7 @@
{
String classname = ElementHelper.getAttribute( element, "class" );
String method = ElementHelper.getAttribute( element, "method" );
- Element[] elements = ElementHelper.getChildren( element, "params" );
+ Element[] elements = ElementHelper.getChildren( element, "param" );
if( elements.length > 0 )
{
ValueDirective[] values = createValueDirectives( elements );
@@ -103,38 +106,17 @@
}
}

- private abstract static class PartStrategy extends Strategy
+ private static PartDirective createTransitDirective()
{
- PartStrategy( URI uri, Serializable data ) throws Exception
+ try
{
- super( uri, data );
+ URI uri = new URI( "internal:transit" );
+ return new PartDirective( uri, null );
}
- }
-
- private static class PluginStrategy extends PartStrategy
- {
- PluginStrategy( Plugin plugin ) throws Exception
+ catch( Throwable e )
{
- super( new URI( "part:plugin" ), plugin );
+ e.printStackTrace();
+ return null;
}
-
- 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();
- }
- }
-
}

Modified: trunk/lab/library.xml
===================================================================
--- trunk/lab/library.xml 2006-03-02 16:03:47 UTC (rev 1163)
+++ trunk/lab/library.xml 2006-03-03 17:34:30 UTC (rev 1164)
@@ -45,6 +45,7 @@
</dependencies>
<dependencies scope="runtime">
<include key="dpmlx-lang"/>
+ <include ref="dpml/metro/dpml-metro-model"/>
</dependencies>
</project>


Modified: trunk/lab/part/etc/deliverables/xsds/part.xsd
===================================================================
--- trunk/lab/part/etc/deliverables/xsds/part.xsd 2006-03-02 16:03:47
UTC (rev 1163)
+++ trunk/lab/part/etc/deliverables/xsds/part.xsd 2006-03-03 17:34:30
UTC (rev 1164)
@@ -17,7 +17,6 @@

<complexType name="StrategyType" abstract="true"/>

- <element name="plugin" type="part:plugin"/>
<complexType name="plugin">
<complexContent>
<extension base="part:StrategyType">
@@ -29,7 +28,6 @@
</complexContent>
</complexType>

- <element name="resource" type="part:resource"/>
<complexType name="resource">
<complexContent>
<extension base="part:StrategyType">

Modified: trunk/lab/test/etc/test/component.xml
===================================================================
--- trunk/lab/test/etc/test/component.xml 2006-03-02 16:03:47 UTC (rev
1163)
+++ trunk/lab/test/etc/test/component.xml 2006-03-03 17:34:30 UTC (rev
1164)
@@ -15,7 +15,7 @@
</info>

<strategy xsi:type="component:definition">
- <component xmlns="@COMPONENT-XSD-URI@" class="org.acme.Widget">
+ <component xmlns="@COMPONENT-XSD-URI@" class="org.acme.Widget" >
<context>
<entry key="foo" value="abc"/>
<entry key="bar">

Modified: trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
===================================================================
--- trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-03-02 16:03:47 UTC (rev 1163)
+++ trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-03-03 17:34:30 UTC (rev 1164)
@@ -7,6 +7,7 @@

import dpmlx.lang.Part;
import dpmlx.lang.Strategy;
+import dpmlx.lang.PartDirective;
import dpmlx.schema.PartBuilder;
import dpmlx.schema.UnresolvableHandlerException;

@@ -57,7 +58,11 @@
System.out.println( "source: " + file );
Part part = m_builder.loadPart( file.toURI() );
Strategy strategy = part.getStrategy();
- System.out.println( " Controller: " + strategy.getControllerURI() );
- System.out.println( " Data: " +
strategy.getDeploymentData().getClass().getName() );
+ PartDirective directive = strategy.getPartDirective();
+ URI uri = directive.getURI();
+ Object data = strategy.getDeploymentData();
+
+ System.out.println( " Controller: " + uri );
+ System.out.println( " Data: " + data.getClass().getName() );
}
}




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

Archive powered by MHonArc 2.6.24.

Top of Page