Skip to Content.
Sympa Menu

notify-dpml - r1532 - in trunk/main: lang/component/etc lang/part/etc metro/model/src/main/net/dpml/metro/data metro/runtime/etc/data/parts metro/runtime/src/main/net/dpml/metro/builder metro/runtime/src/test/net/dpml/metro/builder

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: r1532 - in trunk/main: lang/component/etc lang/part/etc metro/model/src/main/net/dpml/metro/data metro/runtime/etc/data/parts metro/runtime/src/main/net/dpml/metro/builder metro/runtime/src/test/net/dpml/metro/builder
  • Date: Mon, 3 Jul 2006 05:42:17 +0200

Author: mcconnell
Date: 2006-07-03 05:42:12 +0200 (Mon, 03 Jul 2006)
New Revision: 1532

Added:
trunk/main/metro/model/src/main/net/dpml/metro/data/ImportDirective.java
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/ArrayTestCase.java

trunk/main/metro/runtime/src/test/net/dpml/metro/builder/ImportTestCase.java
Removed:
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/PartsTestCase.java
Modified:
trunk/main/lang/component/etc/component.xsd
trunk/main/lang/part/etc/part.xsd
trunk/main/metro/runtime/etc/data/parts/test.xml

trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentDecoder.java
Log:
addition of support for part import at the data-structure level

Modified: trunk/main/lang/component/etc/component.xsd
===================================================================
--- trunk/main/lang/component/etc/component.xsd 2006-06-30 06:12:38 UTC (rev
1531)
+++ trunk/main/lang/component/etc/component.xsd 2006-07-03 03:42:12 UTC (rev
1532)
@@ -51,23 +51,23 @@
<complexType name="ContextType">
<choice minOccurs="0" maxOccurs="unbounded">
<element ref="this:entry"/>
- <element name="component" type="this:TaggedComponent" minOccurs="0"
maxOccurs="unbounded"/>
+ <element name="component" type="this:TaggedComponent" minOccurs="0"
maxOccurs="unbounded"/> <!-- remove ? -->
</choice>
</complexType>

<complexType name="EntryType">
<complexContent>
- <extension base="part:ValueType">
- <attribute name="key" type="string" use="required"/>
- <attribute name="lookup" type="string"/> <!-- yukk -->
+ <extension base="part:TaggedValueType">
+ <attribute name="lookup" type="string"/>
</extension>
</complexContent>
</complexType>

<complexType name="PartsType">
- <sequence>
+ <choice minOccurs="0" maxOccurs="unbounded">
<element name="component" type="this:TaggedComponent" minOccurs="0"
maxOccurs="unbounded"/>
- </sequence>
+ <element name="import" type="this:TaggedComponentImport"
minOccurs="0" maxOccurs="unbounded"/>
+ </choice>
</complexType>

<complexType name="TaggedComponent">
@@ -78,6 +78,11 @@
</complexContent>
</complexType>

+ <complexType name="TaggedComponentImport">
+ <attribute name="key" type="string" use="required"/>
+ <attribute name="uri" type="anyURI" use="required"/>
+ </complexType>
+
<simpleType name="lifestyle">
<restriction base="string">
<enumeration value="singleton"/>

Modified: trunk/main/lang/part/etc/part.xsd
===================================================================
--- trunk/main/lang/part/etc/part.xsd 2006-06-30 06:12:38 UTC (rev 1531)
+++ trunk/main/lang/part/etc/part.xsd 2006-07-03 03:42:12 UTC (rev 1532)
@@ -93,6 +93,14 @@
<attribute name="method" type="string"/>
</complexType>

+ <complexType name="TaggedValueType">
+ <complexContent>
+ <extension base="this:ValueType">
+ <attribute name="key" type="string" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
<complexType name="codebase">
<complexContent>
<extension base="this:CodeBaseType">

Added:
trunk/main/metro/model/src/main/net/dpml/metro/data/ImportDirective.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/data/ImportDirective.java
2006-06-30 06:12:38 UTC (rev 1531)
+++ trunk/main/metro/model/src/main/net/dpml/metro/data/ImportDirective.java
2006-07-03 03:42:12 UTC (rev 1532)
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2004 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.data;
+
+import java.net.URI;
+
+import net.dpml.component.Directive;
+
+/**
+ * A reference directive is a reference to a part within the enclosing part's
+ * context or parts.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class ImportDirective extends AbstractDirective implements
Directive
+{
+ /**
+ * Serial version identifier.
+ */
+ static final long serialVersionUID = 1L;
+
+ /**
+ * The part import uri.
+ */
+ private final URI m_uri;
+
+ /**
+ * Creation of a new import directive.
+ * @param uri the part uri to import
+ * @exception NullPointerException if the key or uri arguments are null.
+ */
+ public ImportDirective( final URI uri )
+ throws NullPointerException
+ {
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+ m_uri = uri;
+ }
+
+ /**
+ * Return the uri of the component part to import.
+ *
+ * @return the uri
+ */
+ public URI getURI()
+ {
+ return m_uri;
+ }
+
+ /**
+ * Test if the supplied object is equal to this object.
+ * @param other the object to compare with this instance
+ * @return TRUE if the supplied object is equal to this object
+ */
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else
+ {
+ if( other instanceof ImportDirective )
+ {
+ ImportDirective directive = (ImportDirective) other;
+ return m_uri.equals( directive.m_uri );
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Return the hashcode for the instance.
+ * @return the instance hashcode
+ */
+ public int hashCode()
+ {
+ return m_uri.hashCode();
+ }
+}

Modified: trunk/main/metro/runtime/etc/data/parts/test.xml
===================================================================
--- trunk/main/metro/runtime/etc/data/parts/test.xml 2006-06-30 06:12:38
UTC (rev 1531)
+++ trunk/main/metro/runtime/etc/data/parts/test.xml 2006-07-03 03:42:12
UTC (rev 1532)
@@ -1,17 +1,8 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8" ?>

-<part xmlns="@PART-XSD-URI@">
- <info title="Component Part"/>
-
- <component xmlns="@COMPONENT-XSD-URI@"
- type="net.dpml.test.array.ArrayTestComponent"
- name="test">
- <context>
- <entry key="test" lookup="acme.Widget"/>
- </context>
- </component>
-
- <classpath/>
-
-</part>
+<component xmlns="@COMPONENT-XSD-URI@" name="widget" type="acme.Widget">
+ <parts>
+ <import key="test" uri="artifact:part:org/acme/acme-Widget#1.2.3"/>
+ </parts>
+</component>


Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentDecoder.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentDecoder.java
2006-06-30 06:12:38 UTC (rev 1531)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/builder/ComponentDecoder.java
2006-07-03 03:42:12 UTC (rev 1532)
@@ -29,6 +29,8 @@
import net.dpml.metro.data.ComponentDirective;
import net.dpml.metro.data.ValueDirective;
import net.dpml.metro.data.LookupDirective;
+import net.dpml.metro.data.ImportDirective;
+
import net.dpml.metro.info.LifestylePolicy;
import net.dpml.metro.info.CollectionPolicy;
import net.dpml.metro.info.PartReference;
@@ -100,8 +102,19 @@
{
throw new NullPointerException( "root" );
}
-
- return createComponentDirective( root );
+ String tag = root.getTagName();
+ if( "component".equals( tag ) )
+ {
+ return createComponentDirective( root );
+ }
+ else
+ {
+ final String error =
+ "Component directive element name ["
+ + tag
+ + "] is not recognized.";
+ throw new DecodingException( root, error );
+ }
}

private ComponentDirective createComponentDirective( Element element )
throws DecodingException
@@ -295,11 +308,11 @@
ValueDirective directive = buildValueDirective( element );
return new PartReference( key, directive );
}
- else if( "component".equals( name ) )
- {
- ComponentDirective directive = createComponentDirective(
element );
- return new PartReference( key, directive );
- }
+ //else if( "component".equals( name ) )
+ //{
+ // ComponentDirective directive = buildComponent( element );
+ // return new PartReference( key, directive );
+ //}
else
{
final String error =
@@ -358,9 +371,39 @@

private PartReference createPartReference( Element element ) throws
DecodingException
{
+ String tag = element.getTagName();
String key = ElementHelper.getAttribute( element, "key" );
- ComponentDirective directive = createComponentDirective( element );
- return new PartReference( key, directive );
+ if( "component".equals( tag ) )
+ {
+ ComponentDirective directive = buildComponent( element );
+ return new PartReference( key, directive );
+ }
+ else if( "import".equals( tag ) )
+ {
+ String spec = ElementHelper.getAttribute( element, "uri" );
+ try
+ {
+ URI uri = new URI( spec );
+ ImportDirective directive = new ImportDirective( uri );
+ return new PartReference( key, directive );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Internal error while attempting to construct import
directive."
+ + "\nImport URI: " + spec
+ + "\nPart key: " + key;
+ throw new DecodingException( element, error );
+ }
+ }
+ else
+ {
+ final String error =
+ "Component part element name ["
+ + tag
+ + "] is not recognized.";
+ throw new DecodingException( element, error );
+ }
}

/**

Copied:
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/ArrayTestCase.java
(from rev 1524,
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/PartsTestCase.java)
===================================================================
---
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/PartsTestCase.java
2006-06-20 07:55:19 UTC (rev 1524)
+++
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/ArrayTestCase.java
2006-07-03 03:42:12 UTC (rev 1532)
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2005-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.metro.builder;
+
+import java.io.File;
+import java.net.URI;
+
+import net.dpml.component.Directive;
+import net.dpml.lang.Value;
+
+import net.dpml.metro.info.PartReference;
+import net.dpml.metro.data.ContextDirective;
+import net.dpml.metro.data.ComponentDirective;
+import net.dpml.metro.data.ValueDirective;
+
+import junit.framework.TestCase;
+
+/**
+ * Default array argument in context.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ */
+public class ArrayTestCase extends TestCase
+{
+ private ComponentDecoder m_builder;
+
+ /**
+ * Testcase setup.
+ * @exception Exception if a setup error occurs
+ */
+ public void setUp() throws Exception
+ {
+ m_builder = new ComponentDecoder();
+ }
+
+ /**
+ * List the state graph.
+ * @exception Exception if an error occurs
+ */
+ public void testExampleOne() throws Exception
+ {
+ String testPath = System.getProperty( "project.test.dir" );
+ File test = new File( testPath );
+ File example = new File( test, "components/array.xml" );
+ URI uri = example.toURI();
+ ComponentDirective component = m_builder.loadComponentDirective( uri
);
+ ContextDirective context = component.getContextDirective();
+ PartReference[] entries = context.getDirectives();
+ if( entries.length != 1 )
+ {
+ fail( "Invalid entries length - expected 1, found " +
entries.length );
+ }
+ else
+ {
+ PartReference entry = entries[0];
+ String key = entry.getKey();
+ Directive directive = entry.getDirective();
+ if( directive instanceof ValueDirective )
+ {
+ ValueDirective value = (ValueDirective) directive;
+ String base = value.getBaseValue();
+ String method = value.getMethodName();
+ String target = value.getTargetExpression();
+ Value[] values = value.getValues();
+ //System.out.println( "# TARGET: " + target );
+ //System.out.println( "# METHOD: " + method );
+ //System.out.println( "# BASE: " + base );
+ //System.out.println( "# VALUES: " + values.length );
+ }
+ else
+ {
+ fail( "Expected ValueDirective, found " +
directive.getClass().getName() );
+ }
+ }
+ }
+}
+
+
+

Added:
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/ImportTestCase.java
===================================================================
---
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/ImportTestCase.java
2006-06-30 06:12:38 UTC (rev 1531)
+++
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/ImportTestCase.java
2006-07-03 03:42:12 UTC (rev 1532)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 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.builder;
+
+import java.io.File;
+import java.net.URI;
+
+import net.dpml.metro.data.ComponentDirective;
+
+import junit.framework.TestCase;
+
+/**
+ * Test component import.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ */
+public class ImportTestCase extends TestCase
+{
+ private ComponentDecoder m_builder;
+
+ /**
+ * Testcase setup.
+ * @exception Exception if a setup error occurs
+ */
+ public void setUp() throws Exception
+ {
+ m_builder = new ComponentDecoder();
+ }
+
+ /**
+ * List the state graph.
+ * @exception Exception if an error occurs
+ */
+ public void testComponentLoading() throws Exception
+ {
+ String testPath = System.getProperty( "project.test.dir" );
+ File test = new File( testPath );
+ File example = new File( test, "parts/test.xml" );
+ URI uri = example.toURI();
+ ComponentDirective directive = m_builder.loadComponentDirective( uri
);
+ }
+}
+
+
+

Deleted:
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/PartsTestCase.java
===================================================================
---
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/PartsTestCase.java
2006-06-30 06:12:38 UTC (rev 1531)
+++
trunk/main/metro/runtime/src/test/net/dpml/metro/builder/PartsTestCase.java
2006-07-03 03:42:12 UTC (rev 1532)
@@ -1,95 +0,0 @@
-/*
- * Copyright 2005-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.metro.builder;
-
-import java.io.File;
-import java.net.URI;
-
-import net.dpml.component.Directive;
-import net.dpml.lang.Value;
-
-import net.dpml.metro.info.PartReference;
-import net.dpml.metro.data.ContextDirective;
-import net.dpml.metro.data.ComponentDirective;
-import net.dpml.metro.data.ValueDirective;
-
-import junit.framework.TestCase;
-
-/**
- * Default state machine test-case.
- *
- * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
- */
-public class PartsTestCase extends TestCase
-{
- private ComponentDecoder m_builder;
-
- /**
- * Testcase setup.
- * @exception Exception if a setup error occurs
- */
- public void setUp() throws Exception
- {
- m_builder = new ComponentDecoder();
- }
-
- /**
- * List the state graph.
- * @exception Exception if an error occurs
- */
- public void testExampleOne() throws Exception
- {
- String testPath = System.getProperty( "project.test.dir" );
- File test = new File( testPath );
- File example = new File( test, "components/array.xml" );
- URI uri = example.toURI();
- ComponentDirective component = m_builder.loadComponentDirective( uri
);
- ContextDirective context = component.getContextDirective();
- PartReference[] entries = context.getDirectives();
- if( entries.length != 1 )
- {
- fail( "Invalid entries length - expected 1, found " +
entries.length );
- }
- else
- {
- PartReference entry = entries[0];
- String key = entry.getKey();
- Directive directive = entry.getDirective();
- if( directive instanceof ValueDirective )
- {
- ValueDirective value = (ValueDirective) directive;
- String base = value.getBaseValue();
- String method = value.getMethodName();
- String target = value.getTargetExpression();
- Value[] values = value.getValues();
- //System.out.println( "# TARGET: " + target );
- //System.out.println( "# METHOD: " + method );
- //System.out.println( "# BASE: " + base );
- //System.out.println( "# VALUES: " + values.length );
- }
- else
- {
- fail( "Expected ValueDirective, found " +
directive.getClass().getName() );
- }
- }
- }
-}
-
-
-




  • r1532 - in trunk/main: lang/component/etc lang/part/etc metro/model/src/main/net/dpml/metro/data metro/runtime/etc/data/parts metro/runtime/src/main/net/dpml/metro/builder metro/runtime/src/test/net/dpml/metro/builder, mcconnell at BerliOS, 07/02/2006

Archive powered by MHonArc 2.6.24.

Top of Page