Skip to Content.
Sympa Menu

notify-dpml - r1994 - in trunk: . main/metro/part/src/main/net/dpml/runtime main/metro/testing/plus main/metro/testing/plus/etc

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: r1994 - in trunk: . main/metro/part/src/main/net/dpml/runtime main/metro/testing/plus main/metro/testing/plus/etc
  • Date: Fri, 27 Apr 2007 18:52:04 +0200

Author: mcconnell
Date: 2007-04-27 18:51:38 +0200 (Fri, 27 Apr 2007)
New Revision: 1994

Added:
trunk/main/metro/testing/plus/etc/test.xml
Modified:
trunk/index.xml
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategy.java

trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategyHandler.java
trunk/main/metro/part/src/main/net/dpml/runtime/PartsDirective.java
trunk/main/metro/testing/plus/project.xml
Log:
Resolve bug in the encoding of <part> statements and improve robustness of
general component encoding code.

Modified: trunk/index.xml
===================================================================
--- trunk/index.xml 2007-04-27 16:49:11 UTC (rev 1993)
+++ trunk/index.xml 2007-04-27 16:51:38 UTC (rev 1994)
@@ -20,7 +20,7 @@
<property name="project.svn.host"
value="svn://svn.berlios.de/dpml/trunk/main"/>
<property name="project.major.version" value="2"/>
<property name="project.minor.version" value="0"/>
- <property name="project.micro.version" value="2"/>
+ <property name="project.micro.version" value="3"/>
<property name="project.javadoc.linksource" value="false"/>
</properties>


Modified:
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategy.java
===================================================================
--- trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategy.java
2007-04-27 16:49:11 UTC (rev 1993)
+++ trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategy.java
2007-04-27 16:51:38 UTC (rev 1994)
@@ -22,6 +22,7 @@
import dpml.lang.Disposable;
import dpml.state.StateDecoder;
import dpml.util.DefaultLogger;
+import dpml.util.ElementHelper;

import java.io.IOException;
import java.io.File;
@@ -44,6 +45,7 @@
import net.dpml.appliance.Appliance;

import net.dpml.lang.Buffer;
+import net.dpml.lang.DecodingException;
import net.dpml.lang.ServiceRegistry;
import net.dpml.lang.StandardServiceRegistry;
import net.dpml.lang.Strategy;
@@ -54,6 +56,8 @@

import net.dpml.util.Logger;

+import org.w3c.dom.Element;
+
import static dpml.state.DefaultState.NULL_STATE;

/**
@@ -85,6 +89,7 @@
private final ExecutorService m_queue =
Executors.newSingleThreadExecutor();

private ServiceRegistry m_registry;
+ private Element m_element;

/**
* Creation of a new component strategy.
@@ -144,6 +149,11 @@
m_handler = getLifestyleHandler( m_lifestyle );
}

+ void setElement( Element element )
+ {
+ m_element = element;
+ }
+
/**
* Get the component name.
* @return the name
@@ -521,48 +531,122 @@
* @param key the component key
* @exception IOException if an error occurs
*/
- public void encode( Buffer buffer, String key ) throws IOException
+ public void encode( Buffer buffer, String key ) throws IOException
{
- String name = getComponentName();
- String classname = getComponentClass().getName();
- ContextDirective context = getContextModel().getDirective();
- PartsDirective parts = getPartsDirective();
-
boolean flag = buffer.isNamespace( NAMESPACE );
- if( flag )
+ if( null != m_element )
{
- buffer.nl( "<component" );
+ String k = ElementHelper.getAttribute( m_element, "key" );
+ if( m_element.getLocalName().equals( "part" ) )
+ {
+ buffer.nl( "<part" );
+ if( !flag )
+ {
+ buffer.write( " xmlns=\"" + NAMESPACE + "\"" );
+ }
+ String uri = ElementHelper.getAttribute( m_element, "uri" );
+ buffer.write( " key=\"" + k + "\"" );
+ buffer.write( " uri=\"" + uri + "\"" );
+ Element[] elements = ElementHelper.getChildren( m_element );
+ if( elements.length == 0 )
+ {
+ buffer.write( "/>" );
+ }
+ else
+ {
+ buffer.write( ">" );
+ for( Element elem : elements )
+ {
+ String local = elem.getLocalName();
+ if( "param".equals( local ) )
+ {
+ Buffer b = buffer.indent();
+ b.nl( "<param key=\"" );
+ String name = ElementHelper.getAttribute( elem,
"key" );
+ b.write( name );
+ b.write( "\" value=\"" );
+ String value = ElementHelper.getAttribute( elem,
"value" );
+ b.write( value );
+ b.write( "\"/>" );
+ }
+ else
+ {
+ String spec = DecodingException.list( elem );
+ String warning =
+ "Ignoring unrecognized element: "
+ + local
+ + "\n"
+ + spec;
+ getLogger().warn( warning );
+ }
+ }
+ buffer.nl( "</part>" );
+ }
+ return;
+ }
+ else
+ {
+ String classname = getComponentClass().getName();
+ String name = ElementHelper.getAttribute( m_element, "name"
);
+ String priority = ElementHelper.getAttribute( m_element,
"priority" );
+ String lifestyle = ElementHelper.getAttribute( m_element,
"lifestyle" );
+ String lifecycle = ElementHelper.getAttribute( m_element,
"lifecycle" );
+ String collection = ElementHelper.getAttribute( m_element,
"collection" );
+ String activation = ElementHelper.getAttribute( m_element,
"activation" );
+ ContextDirective context = getContextModel().getDirective();
+ PartsDirective parts = getPartsDirective();
+ buffer.nl( "<component" );
+ if( !flag )
+ {
+ buffer.write( " xmlns=\"" + NAMESPACE + "\"" );
+ }
+ buffer.write( " class=\"" + classname + "\"" );
+ if( null != key )
+ {
+ buffer.write( " key=\"" + k + "\"" );
+ }
+ if( null != name )
+ {
+ buffer.write( " name=\"" + name + "\"" );
+ }
+ if( ( null != priority ) && ( !"0".equals( priority ) ) )
+ {
+ buffer.write( " priority=\"" + priority + "\"" );
+ }
+ if( null != lifestyle )
+ {
+ buffer.write( " lifestyle=\"" + lifestyle + "\"" );
+ }
+ if( null != lifecycle )
+ {
+ buffer.write( " lifecycle=\"" + lifestyle + "\"" );
+ }
+ if( null != collection )
+ {
+ buffer.write( " collection=\"" + collection + "\"" );
+ }
+ if( null != activation )
+ {
+ buffer.write( " activation=\"" + activation + "\"" );
+ }
+ if( ( context.size() == 0 ) && ( parts.size() == 0 ) )
+ {
+ buffer.write( "/>" );
+ }
+ else
+ {
+ buffer.write( ">" );
+ Buffer b = buffer.namespace( NAMESPACE );
+ context.encode( b.indent(), null );
+ parts.encode( b.indent() );
+ buffer.nl( "</component>" );
+ }
+ }
}
else
{
- buffer.nl( "<component xmlns=\"" + NAMESPACE + "\"" );
- buffer.nl( " " );
+ throw new IllegalStateException( "Undefined element" );
}
- if( null != key )
- {
- buffer.write( " key=\"" + key + "\"" );
- }
- if( null != name )
- {
- buffer.write( " name=\"" + name + "\"" );
- }
- if( m_priority != 0 )
- {
- buffer.write( " priority=\"" + m_priority + "\"" );
- }
- buffer.write( " class=\"" + classname + "\"" );
- if( ( context.size() == 0 ) && ( parts.size() == 0 ) )
- {
- buffer.write( "/>" );
- }
- else
- {
- buffer.write( ">" );
- Buffer b = buffer.namespace( NAMESPACE );
- context.encode( b.indent(), null );
- parts.encode( b.indent() );
- buffer.nl( "</component>" );
- }
}

private PartsDirective getPartsDirective( PartsDirective directive )

Modified:
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategyHandler.java
===================================================================
---
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategyHandler.java
2007-04-27 16:49:11 UTC (rev 1993)
+++
trunk/main/metro/part/src/main/net/dpml/runtime/ComponentStrategyHandler.java
2007-04-27 16:51:38 UTC (rev 1994)
@@ -136,7 +136,6 @@
partsElement,
resolver,
path );
-
ComponentStrategy strategy =
new ComponentStrategy(
partition,
@@ -148,7 +147,7 @@
collection,
context,
parts );
-
+ strategy.setElement( element );
return strategy;
}
catch( IOException ioe )
@@ -253,7 +252,7 @@
return CollectionPolicy.HARD;
}

- private int getPriority( Element element, Resolver resolver )
+ static int getPriority( Element element, Resolver resolver )
{
String value = ElementHelper.getAttribute( element, "priority",
null, resolver );
if( null == value )
@@ -266,7 +265,7 @@
}
}

- private Class loadComponentClass( ClassLoader classloader, Element
element, Resolver resolver ) throws DecodingException
+ static Class loadComponentClass( ClassLoader classloader, Element
element, Resolver resolver ) throws DecodingException
{
String classname = buildComponentClassname( element, resolver );
try
@@ -284,7 +283,7 @@
}
}

- private String buildComponentClassname( Element element, Resolver
resolver )
+ private static String buildComponentClassname( Element element, Resolver
resolver )
{
String classname = ElementHelper.getAttribute( element, "class",
null, resolver );
if( null != classname )
@@ -297,7 +296,7 @@
}
}

- private static String getComponentName( Class c, Element element,
Resolver resolver )
+ static String getComponentName( Class c, Element element, Resolver
resolver )
{
String name = getComponentName( element, resolver );
return getComponentName( c, name );
@@ -352,7 +351,7 @@
}
}

- private static String getComponentPath( String partition, String name )
+ static String getComponentPath( String partition, String name )
{
if( null == partition )
{

Modified: trunk/main/metro/part/src/main/net/dpml/runtime/PartsDirective.java
===================================================================
--- trunk/main/metro/part/src/main/net/dpml/runtime/PartsDirective.java
2007-04-27 16:49:11 UTC (rev 1993)
+++ trunk/main/metro/part/src/main/net/dpml/runtime/PartsDirective.java
2007-04-27 16:51:38 UTC (rev 1994)
@@ -118,8 +118,10 @@
URI codebase = getCodebase( element, resolver );
try
{
- return Strategy.load( classloader, null, codebase, partition
);
-
+ ComponentStrategy strategy =
+ (ComponentStrategy) Strategy.load( classloader, null,
codebase, partition );
+ strategy.setElement( element );
+ return strategy;
}
catch( Exception e )
{

Added: trunk/main/metro/testing/plus/etc/test.xml
===================================================================
--- trunk/main/metro/testing/plus/etc/test.xml 2007-04-27 16:49:11 UTC (rev
1993)
+++ trunk/main/metro/testing/plus/etc/test.xml 2007-04-27 16:51:38 UTC (rev
1994)
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+
+ <component xmlns="dpml:metro"
class="org.acme.reference.AggregatingComponent" name="reference">
+ <parts>
+ <part key="hello" uri="link:part:dpml/metro/dpml-metro-blade">
+ <param key="message" value="OK"/>
+ </part>
+ </parts>
+ </component>

Modified: trunk/main/metro/testing/plus/project.xml
===================================================================
--- trunk/main/metro/testing/plus/project.xml 2007-04-27 16:49:11 UTC (rev
1993)
+++ trunk/main/metro/testing/plus/project.xml 2007-04-27 16:51:38 UTC (rev
1994)
@@ -6,6 +6,7 @@

<types>
<type id="jar" test="true"/>
+ <type id="part" test="true" source="etc/test.xml"/>
</types>

<dependencies>




  • r1994 - in trunk: . main/metro/part/src/main/net/dpml/runtime main/metro/testing/plus main/metro/testing/plus/etc, mcconnell at BerliOS, 04/27/2007

Archive powered by MHonArc 2.6.24.

Top of Page