Skip to Content.
Sympa Menu

notify-dpml - r1230 - in trunk/main: depot/library/src/main/net/dpml/library/impl depot/tools/builder/src/main/net/dpml/tools/tasks metro metro/builder/src/main/net/dpml/metro/builder metro/builder/src/test/net/dpml/metro/builder metro/runtime/src/main/net/dpml/metro/runtime metro/state/impl/src/main/net/dpml/state/impl metro/state/impl/src/test/net/dpml/state metro/state/impl/src/test/net/dpml/state/test metro/tools/src/main/net/dpml/metro/tools planet/http/server station/api/src/main/net/dpml/station/info station/api/src/test/net/dpml/station/info station/builder/src/main/net/dpml/station/builder station/console/src/main/net/dpml/station/console station/server/src/test/net/dpml/station/server transit/core/src/main/net/dpml/lang transit/core/src/main/net/dpml/part transit/core/src/main/net/dpml/transit transit/core/src/main/net/dpml/transit/info transit/core/src/main/net/dpml/transit/link transit/core/src/test/net/dpml/part transit/core/src/test/net/dpml/transit/info

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: r1230 - in trunk/main: depot/library/src/main/net/dpml/library/impl depot/tools/builder/src/main/net/dpml/tools/tasks metro metro/builder/src/main/net/dpml/metro/builder metro/builder/src/test/net/dpml/metro/builder metro/runtime/src/main/net/dpml/metro/runtime metro/state/impl/src/main/net/dpml/state/impl metro/state/impl/src/test/net/dpml/state metro/state/impl/src/test/net/dpml/state/test metro/tools/src/main/net/dpml/metro/tools planet/http/server station/api/src/main/net/dpml/station/info station/api/src/test/net/dpml/station/info station/builder/src/main/net/dpml/station/builder station/console/src/main/net/dpml/station/console station/server/src/test/net/dpml/station/server transit/core/src/main/net/dpml/lang transit/core/src/main/net/dpml/part transit/core/src/main/net/dpml/transit transit/core/src/main/net/dpml/transit/info transit/core/src/main/net/dpml/transit/link transit/core/src/test/net/dpml/part transit/core/src/test/net/dpml/transit/info
  • Date: Mon, 20 Mar 2006 10:50:51 +0100

Author: mcconnell
Date: 2006-03-20 10:50:38 +0100 (Mon, 20 Mar 2006)
New Revision: 1230

Added:

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentConstants.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentDecoder.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentEncoder.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyDecoder.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyEncoder.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentTypeDecoder.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentTypeEncoder.java
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateDecoder.java
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateEncoder.java
trunk/main/transit/core/src/main/net/dpml/lang/Decoder.java
trunk/main/transit/core/src/main/net/dpml/lang/DecodingException.java
trunk/main/transit/core/src/main/net/dpml/lang/Encoder.java
trunk/main/transit/core/src/main/net/dpml/part/DecoderFactory.java
trunk/main/transit/core/src/main/net/dpml/part/PartDecoder.java
trunk/main/transit/core/src/main/net/dpml/part/PartEncoder.java
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyDecoder.java
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyEncoder.java
trunk/main/transit/core/src/main/net/dpml/part/ValueDecoder.java
trunk/main/transit/core/src/main/net/dpml/part/ValueEncoder.java
Removed:

trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultTypeBuilder.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyBuilder.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyWriter.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentWriter.java
trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeBuilder.java
trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeWriter.java
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateBuilder.java
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateWriter.java
trunk/main/planet/http/server/etc/
trunk/main/transit/core/src/main/net/dpml/lang/Builder.java
trunk/main/transit/core/src/main/net/dpml/lang/BuilderException.java
trunk/main/transit/core/src/main/net/dpml/part/AbstractBuilder.java
trunk/main/transit/core/src/main/net/dpml/part/PartBuilder.java
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyBuilder.java
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyWriter.java
trunk/main/transit/core/src/main/net/dpml/part/PartWriter.java
trunk/main/transit/core/src/main/net/dpml/part/StrategyBuilder.java
trunk/main/transit/core/src/main/net/dpml/part/ValueBuilder.java
trunk/main/transit/core/src/main/net/dpml/part/ValueWriter.java
Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultType.java
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PartTask.java

trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentBuilder.java

trunk/main/metro/builder/src/test/net/dpml/metro/builder/LookupTestCase.java

trunk/main/metro/builder/src/test/net/dpml/metro/builder/MinimalTestCase.java
trunk/main/metro/builder/src/test/net/dpml/metro/builder/PartsTestCase.java
trunk/main/metro/builder/src/test/net/dpml/metro/builder/TypesTestCase.java
trunk/main/metro/module.xml

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
trunk/main/metro/state/impl/src/test/net/dpml/state/EmptyTestCase.java
trunk/main/metro/state/impl/src/test/net/dpml/state/TransitionTestCase.java

trunk/main/metro/state/impl/src/test/net/dpml/state/test/DefaultStateMachineTestCase.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/CatalogTask.java

trunk/main/metro/tools/src/main/net/dpml/metro/tools/ComponentBuilderTask.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/StateDataType.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/StateTask.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypesTask.java

trunk/main/station/api/src/main/net/dpml/station/info/ApplicationDescriptor.java

trunk/main/station/api/src/test/net/dpml/station/info/ApplicationDescriptorTestCase.java

trunk/main/station/api/src/test/net/dpml/station/info/RegistryDescriptorTestCase.java

trunk/main/station/builder/src/main/net/dpml/station/builder/RegistryBuilder.java

trunk/main/station/console/src/main/net/dpml/station/console/StationPlugin.java

trunk/main/station/server/src/test/net/dpml/station/server/RemoteApplicationRegistryTestCase.java
trunk/main/transit/core/src/main/net/dpml/part/PartHandlerFactory.java
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java

trunk/main/transit/core/src/main/net/dpml/transit/info/CodeBaseDirective.java

trunk/main/transit/core/src/main/net/dpml/transit/info/ContentDirective.java
trunk/main/transit/core/src/main/net/dpml/transit/info/LayoutDirective.java
trunk/main/transit/core/src/main/net/dpml/transit/link/Handler.java
trunk/main/transit/core/src/test/net/dpml/part/PartTestCase.java

trunk/main/transit/core/src/test/net/dpml/transit/info/CodeBaseDirectiveTestCase.java

trunk/main/transit/core/src/test/net/dpml/transit/info/ContentDirectiveTestCase.java

trunk/main/transit/core/src/test/net/dpml/transit/info/LayoutDirectiveTestCase.java
Log:
resolve excessive use of inheritance in element builders by refactoring to a
cleaner (and simpler) Encode/Decoder approach

Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultType.java
===================================================================
--- trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultType.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultType.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -23,13 +23,13 @@
import java.util.Hashtable;

import net.dpml.library.info.TypeDirective;
-
import net.dpml.library.Type;

-import net.dpml.lang.Builder;
-import net.dpml.lang.BuilderException;
-import net.dpml.part.AbstractBuilder;
+import net.dpml.lang.Decoder;
+import net.dpml.lang.DecodingException;

+import net.dpml.part.DecoderFactory;
+
import org.w3c.dom.Element;
import org.w3c.dom.TypeInfo;

@@ -105,15 +105,15 @@
throw new IllegalStateException( error );
}
}
- AbstractBuilder factory = new AbstractBuilder( map );
- Builder builder = factory.getBuilder( element );
- return builder.build( getClass().getClassLoader(), element );
+ DecoderFactory factory = new DecoderFactory( map );
+ Decoder decoder = factory.loadDecoder( element );
+ return decoder.decode( getClass().getClassLoader(), element );
}
catch( Throwable e )
{
final String error =
- "Unexpected error while attempting to load foreign builder.";
- throw new BuilderException( element, error, e );
+ "Unexpected error while attempting to data.";
+ throw new RuntimeException( error, e );
}
}


Deleted:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultTypeBuilder.java
===================================================================
---
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultTypeBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultTypeBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,151 +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 net.dpml.library.impl;
-
-import java.util.Properties;
-import java.util.Map;
-
-import net.dpml.library.Type;
-import net.dpml.library.TypeBuilder;
-import net.dpml.library.info.TypeDirective;
-
-import net.dpml.transit.util.ElementHelper;
-
-import net.dpml.lang.BuilderException;
-
-import net.dpml.part.AbstractBuilder;
-
-import org.w3c.dom.Element;
-
-/**
- * Utility used to build a type defintion from a DOM element.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class DefaultTypeBuilder extends AbstractBuilder implements
TypeBuilder
-{
- private static final String PART_XSD_URI = "@PART-XSD-URI@";
- private static final String MODULE_XSD_URI = "@MODULE-XSD-URI@";
- private static final String COMMON_XSD_URI = "@COMMON-XSD-URI@";
-
- DefaultTypeBuilder( Map map )
- {
- super( map );
- }
-
- /**
- * Return the id of the type produced by the builder. The method
- * always throws an UnsupportedOperationException as the default
- * builder handles generic type production where the type id is
- * declared within supplied type derectives.
- *
- * @return the type id
- */
- public String getID()
- {
- throw new UnsupportedOperationException( "getID" );
- }
-
- /**
- * Construct a type instance using a supplied classloader and type
- * production directive.
- * @param classloader the base classloader
- * @param type the type production directive
- * @return the type instance
- * @exception Exception if a type instance creation error occurs
- */
- public Type buildType( ClassLoader classloader, TypeDirective type )
throws Exception
- {
- throw new UnsupportedOperationException( "buildType" );
- }
-
- /**
- * Return the id of the type to be produced given a DOM element. The
- * implementation assumes that the supplied element will expose an id
- * attribute contining the type identifier. If no such attribute exists
- * a runtime exception will be thrown.
- *
- * @param element the DOM element
- * @return the type id
- */
- protected String getID( Element element )
- {
- final String id = ElementHelper.getAttribute( element, "id" );
- if( null == id )
- {
- final String error =
- "Missing type 'id'.";
- throw new BuilderException( element, error );
- }
- else
- {
- return id;
- }
- }
-
- /**
- * Return the alias production flag.
- * The implementation assumes that the supplied element may expose an
alias
- * attribute contining the flag boolean status. If no such attribute
exists
- * 'false' is returned otherwise the attribute value as a boolean will be
- * returned.
- *
- * @param element the DOM element
- * @return the type id
- */
- protected boolean getAliasFlag( Element element )
- {
- return ElementHelper.getBooleanAttribute( element, "alias", false );
- }
-
- /**
- * Return a properties instance populated with any property assertions
contained
- * as nested <property> elements within the supplied element.
- * @param element the DOM element representing the type production
assertion
- * @return the properties
- */
- protected Properties getProperties( Element element )
- {
- Properties properties = new Properties();
- Element[] children = ElementHelper.getChildren( element );
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- String tag = child.getTagName();
- if( "property".equals( tag ) )
- {
- String key = ElementHelper.getAttribute( child, "name", null
);
- if( null == key )
- {
- final String error =
- "Property declaration does not contain a 'name'
attribute.";
- throw new IllegalArgumentException( error );
- }
- else
- {
- String value = ElementHelper.getAttribute( child,
"value", null );
- properties.setProperty( key, value );
- }
- }
- }
- return properties;
- }
-
-}

Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
===================================================================
---
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -32,6 +32,7 @@

import javax.xml.XMLConstants;

+import net.dpml.library.TypeBuilder;
import net.dpml.library.info.LibraryDirective;
import net.dpml.library.info.ImportDirective;
import net.dpml.library.info.IncludeDirective;
@@ -43,18 +44,15 @@
import net.dpml.library.info.TypeDirective;
import net.dpml.library.info.Scope;

-import net.dpml.library.TypeBuilder;
-
-import net.dpml.part.AbstractBuilder;
-
import net.dpml.transit.Repository;
import net.dpml.transit.Transit;
import net.dpml.transit.util.ElementHelper;

import net.dpml.lang.Category;
-import net.dpml.lang.BuilderException;
+import net.dpml.lang.DecodingException;

import net.dpml.part.DOM3DocumentBuilder;
+import net.dpml.part.DecoderFactory;

import org.w3c.dom.Element;
import org.w3c.dom.Document;
@@ -66,7 +64,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public final class LibraryBuilder extends AbstractBuilder
+public final class LibraryBuilder
{
private static final String PART_XSD_URI = "@PART-XSD-URI@";
private static final String MODULE_XSD_URI = "@MODULE-XSD-URI@";
@@ -86,8 +84,10 @@
private static final String TYPE_ELEMENT_NAME = "type";
private static final String PROJECT_ELEMENT_NAME = "project";
private static final String PROPERTIES_ELEMENT_NAME = "properties";
+
+ private static final DOM3DocumentBuilder DOCUMENT_BUILDER = new
DOM3DocumentBuilder();

- private DOM3DocumentBuilder m_builder = new DOM3DocumentBuilder();
+ private final DecoderFactory m_decoderFactory;

/**
* Creation of a new library builder.
@@ -103,7 +103,7 @@
*/
public LibraryBuilder( Map map )
{
- super( map );
+ m_decoderFactory = new DecoderFactory( map );
}

/**
@@ -161,7 +161,7 @@
{
try
{
- final Document document = m_builder.parse( uri );
+ final Document document = DOCUMENT_BUILDER.parse( uri );
Element root = document.getDocumentElement();
return buildResourceDirectiveFromElement( null, root, null );
}
@@ -259,7 +259,7 @@
private Element getRootElement( File source ) throws IOException
{
File file = source.getCanonicalFile();
- final Document document = m_builder.parse( file.toURI() );
+ final Document document = DOCUMENT_BUILDER.parse( file.toURI() );
return document.getDocumentElement();
}

@@ -782,7 +782,7 @@
+ namespace
+ "\nType Name: "
+ info.getTypeName();
- throw new BuilderException( element, error );
+ throw new DecodingException( element, error );
}
}
else if( info.isDerivedFrom( PART_XSD_URI, "StrategyType",
TypeInfo.DERIVATION_EXTENSION ) )
@@ -798,7 +798,7 @@
+ namespace
+ "\nElement Name (from Schema Info): "
+ info.getTypeName();
- throw new BuilderException( element, error );
+ throw new DecodingException( element, error );
}
}
else
@@ -808,7 +808,7 @@
"Element is not derivived from AbstractType defined under the
common namespace."
+ "\nNamespace: " + namespace
+ "\nElement Name (from Schema Info): " + info.getTypeName();
- throw new BuilderException( element, error );
+ throw new DecodingException( element, error );
}
}

@@ -1117,14 +1117,14 @@
* @param element the DOM element
* @return the id value
*/
- protected String getID( Element element )
+ protected String getID( Element element ) throws DecodingException
{
final String id = ElementHelper.getAttribute( element, "id" );
if( null == id )
{
final String error =
"Missing type 'id'.";
- throw new BuilderException( element, error );
+ throw new DecodingException( element, error );
}
else
{

Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PartTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PartTask.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PartTask.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -31,7 +31,7 @@

import net.dpml.part.Info;
import net.dpml.part.Part;
-import net.dpml.part.PartBuilder;
+import net.dpml.part.PartEncoder;
import net.dpml.part.Strategy;

import net.dpml.library.Type;
@@ -159,8 +159,8 @@
try
{
Thread.currentThread().setContextClassLoader( classloader );
- PartBuilder builder = new PartBuilder();
- builder.writePart( part, output, "" );
+ PartEncoder encoder = new PartEncoder();
+ encoder.encodePart( part, output, "" );
checksum( file );
asc( file );
}

Modified:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentBuilder.java
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -19,308 +19,55 @@
package net.dpml.metro.builder;

import java.io.IOException;
-import java.net.URI;
+import java.io.Writer;

-import net.dpml.lang.Value;
-import net.dpml.lang.BuilderException;
+import net.dpml.lang.Decoder;
+import net.dpml.lang.DecodingException;
+import net.dpml.lang.Encoder;

-import net.dpml.component.ActivationPolicy;
+import net.dpml.part.DecoderFactory;

-import net.dpml.metro.data.ContextDirective;
-import net.dpml.metro.data.CategoryDirective;
-import net.dpml.metro.data.CategoriesDirective;
-import net.dpml.metro.data.ComponentDirective;
-import net.dpml.metro.data.ValueDirective;
-import net.dpml.metro.data.LookupDirective;
-import net.dpml.metro.info.LifestylePolicy;
-import net.dpml.metro.info.CollectionPolicy;
-import net.dpml.metro.info.PartReference;
-import net.dpml.metro.info.Priority;
-
-import net.dpml.part.DOM3DocumentBuilder;
-
-import net.dpml.transit.util.ElementHelper;
-
-import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
- * Construct a state graph.
+ * Component strategy builder.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
*/
-public class ComponentBuilder extends ComponentWriter
+public class ComponentBuilder extends ComponentConstants implements Decoder,
Encoder
{
- private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
+ private final ComponentStrategyDecoder m_strategyDecoder;
+ private final ComponentStrategyEncoder m_strategyEncoder;

- private static final String SCHEMA_URN = "@COMPONENT-XSD-URI@";
-
- private static final DOM3DocumentBuilder BUILDER = new
DOM3DocumentBuilder();
-
- private static final TypeBuilder TYPE_BUILDER = new TypeBuilder();
-
- /**
- * Construct a component directive using the supplied uri.
- * @param uri the part uri
- * @return the component directive
- * @exception IOException if an error occurs during directive creation
- */
- public ComponentDirective loadComponentDirective( URI uri ) throws
IOException
+ public ComponentBuilder( DecoderFactory factory )
{
- if( null == uri )
- {
- throw new NullPointerException( "uri" );
- }
- try
- {
- final Document document = BUILDER.parse( uri );
- final Element root = document.getDocumentElement();
- return buildComponent( root );
- }
- catch( Throwable e )
- {
- final String error =
- "An error while attempting to load a component directive."
- + "\nURI: " + uri;
- IOException exception = new IOException( error );
- exception.initCause( e );
- throw exception;
- }
+ m_strategyDecoder = new ComponentStrategyDecoder( factory );
+ m_strategyEncoder = new ComponentStrategyEncoder();
}

/**
- * Construct a component directive using the supplied DOM element.
- * @param root the element representing the component directive definition
- * @return the component directive
- * @exception Exception if an error occurs during directive creation
+ * Constructs a component deployment strategy.
+ * @param classloader the base classloader
+ * @param element the DOM element
+ * @return the deployment strategy
+ * @exception Exception if an error occurs
*/
- public ComponentDirective buildComponent( Element root ) throws Exception
+ public Object decode( ClassLoader classloader, Element element ) throws
DecodingException
{
- if( null == root )
- {
- throw new NullPointerException( "root" );
- }
-
- return createComponentDirective( root );
+ return m_strategyDecoder.decode( classloader, element );
}

- private ComponentDirective createComponentDirective( Element element )
throws BuilderException
- {
- String classname = buildComponentClassname( element );
- String name = buildComponentName( element );
- ActivationPolicy activation = buildActivationPolicy( element );
- CollectionPolicy collection = buildCollectionPolicy( element );
- LifestylePolicy lifestyle = buildLifestylePolicy( element );
- CategoriesDirective categories = getNestedCategoriesDirective(
element );
- ContextDirective context = getNestedContextDirective( element );
- PartReference[] parts = getNestedParts( element );
-
- return new ComponentDirective(
- name, activation, collection, lifestyle, classname,
- categories, context, null, null, parts );
- }

- private String buildComponentClassname( 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 ActivationPolicy buildActivationPolicy( Element element ) throws
BuilderException
- {
- String defaultValue = ActivationPolicy.SYSTEM.getName();
- String policy = ElementHelper.getAttribute( element, "activation",
defaultValue );
- return ActivationPolicy.parse( policy );
- }
-
- private LifestylePolicy buildLifestylePolicy( Element element ) throws
BuilderException
- {
- String defaultValue = LifestylePolicy.TRANSIENT.getName();
- String policy = ElementHelper.getAttribute( element, "lifestyle",
defaultValue );
- return LifestylePolicy.parse( policy );
- }
-
- private CollectionPolicy buildCollectionPolicy( Element element ) throws
BuilderException
- {
- String defaultValue = CollectionPolicy.SYSTEM.getName();
- String policy = ElementHelper.getAttribute( element, "collection",
defaultValue );
- return CollectionPolicy.parse( policy );
- }
-
- private String buildComponentName( Element element )
- {
- return ElementHelper.getAttribute( element, "name" );
- }
-
- private CategoriesDirective getNestedCategoriesDirective( Element root )
- {
- Element element = ElementHelper.getChild( root, "categories" );
- if( null == element )
- {
- return null;
- }
- else
- {
- return createCategoriesDirective( element );
- }
- }
-
- private CategoriesDirective createCategoriesDirective( Element element )
- {
- if( null == element )
- {
- return null;
- }
- else
- {
- String name = ElementHelper.getAttribute( element, "name" );
- Priority priority = createPriority( element );
- String target = ElementHelper.getAttribute( element, "target" );
- CategoryDirective[] categories = createCategoryDirectiveArray(
element );
- return new CategoriesDirective( name, priority, target,
categories );
- }
- }
-
- private CategoryDirective createCategoryDirective( Element element )
- {
- String name = ElementHelper.getAttribute( element, "name" );
- Priority priority = createPriority( element );
- String target = ElementHelper.getAttribute( element, "target" );
- return new CategoryDirective( name, priority, target );
- }
-
- private CategoryDirective[] createCategoryDirectiveArray( Element
element )
- {
- Element[] children = ElementHelper.getChildren( element );
- CategoryDirective[] categories = new CategoryDirective[
children.length ];
- for( int i=0; i<categories.length; i++ )
- {
- Element elem = children[i];
- if( "category".equals( elem.getTagName() ) )
- {
- categories[i] = createCategoryDirective( elem );
- }
- else
- {
- categories[i] = createCategoriesDirective( elem );
- }
- }
- return categories;
- }
-
- private Priority createPriority( Element element )
- {
- String priority = ElementHelper.getAttribute( element, "priority" );
- if( null == priority )
- {
- return null;
- }
- else
- {
- return Priority.parse( priority );
- }
- }
-
- private ContextDirective getNestedContextDirective( Element root )
- {
- Element context = ElementHelper.getChild( root, "context" );
- if( null == context )
- {
- return null;
- }
- else
- {
- return createContextDirective( context );
- }
- }
-
- private ContextDirective createContextDirective( Element element )
- {
- String classname = ElementHelper.getAttribute( element, "class" );
- Element[] children = ElementHelper.getChildren( element );
- PartReference[] entries = new PartReference[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element elem = children[i];
- entries[i] = createContextEntryPartReference( elem );
- }
- return new ContextDirective( classname, entries );
- }
-
- private PartReference createContextEntryPartReference( Element element )
- {
- String key = ElementHelper.getAttribute( element, "key" );
- String spec = ElementHelper.getAttribute( element, "lookup" );
- if( null != spec )
- {
- LookupDirective directive = new LookupDirective( spec );
- return new PartReference( key, directive );
- }
- else
- {
- ValueDirective directive = buildValueDirective( element );
- return new PartReference( key, directive );
- }
- }
-
- /**
- * Build a value directive using a supplied DOM element.
- * @param element the DOM element
- * @return the value directive
+ /**
+ * Export a component directive to an output stream as XML.
+ * @param writer the print writer
+ * @param object the object to encode
+ * @param pad character offset
+ * @exception IOException if an IO error occurs
*/
- protected ValueDirective buildValueDirective( Element element )
+ public void encode( Writer writer, Object object, String pad ) throws
IOException
{
- String classname = ElementHelper.getAttribute( element, "class" );
- String method = ElementHelper.getAttribute( element, "method" );
- Element[] elements = ElementHelper.getChildren( element, "param" );
- if( elements.length > 0 )
- {
- Value[] values = buildValues( elements );
- return new ValueDirective( classname, method, values );
- }
- else
- {
- String value = ElementHelper.getAttribute( element, "value" );
- return new ValueDirective( classname, method, value );
- }
+ m_strategyEncoder.encode( writer, object, pad );
}
-
- private PartReference[] getNestedParts( Element root )
- {
- Element parts = ElementHelper.getChild( root, "parts" );
- if( null == parts )
- {
- return null;
- }
- else
- {
- return createParts( parts );
- }
- }
-
- private PartReference[] createParts( Element element )
- {
- Element[] children = ElementHelper.getChildren( element );
- PartReference[] parts = new PartReference[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element elem = children[i];
- parts[i] = createPartReference( elem );
- }
- return parts;
- }
-
- private PartReference createPartReference( Element element )
- {
- String key = ElementHelper.getAttribute( element, "key" );
- ComponentDirective directive = createComponentDirective( element );
- return new PartReference( key, directive );
- }
}

Added:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentConstants.java
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentConstants.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentConstants.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,46 @@
+/*
+ * 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 net.dpml.metro.builder;
+
+import java.net.URI;
+
+/**
+ * Component constants.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+class ComponentConstants
+{
+ static final URI CONTROLLER_URI = createURI( "@CONTROLLER-URI@" );
+ static final URI BUILDER_URI = createURI( "@BUILDER-URI@" );
+
+ private static URI createURI( String spec )
+ {
+ try
+ {
+ return new URI( spec );
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+}

Copied:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentDecoder.java
(from rev 1227,
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentBuilder.java)
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentBuilder.java
2006-03-19 17:53:09 UTC (rev 1227)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentDecoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,329 @@
+/*
+ * 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 net.dpml.metro.builder;
+
+import java.io.IOException;
+import java.net.URI;
+
+import net.dpml.lang.Value;
+import net.dpml.lang.DecodingException;
+
+import net.dpml.component.ActivationPolicy;
+
+import net.dpml.metro.data.ContextDirective;
+import net.dpml.metro.data.CategoryDirective;
+import net.dpml.metro.data.CategoriesDirective;
+import net.dpml.metro.data.ComponentDirective;
+import net.dpml.metro.data.ValueDirective;
+import net.dpml.metro.data.LookupDirective;
+import net.dpml.metro.info.LifestylePolicy;
+import net.dpml.metro.info.CollectionPolicy;
+import net.dpml.metro.info.PartReference;
+import net.dpml.metro.info.Priority;
+
+import net.dpml.part.DOM3DocumentBuilder;
+import net.dpml.part.ValueDecoder;
+
+import net.dpml.transit.util.ElementHelper;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Construct a state graph.
+ */
+public class ComponentDecoder
+{
+ private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
+
+ private static final String SCHEMA_URN = "@COMPONENT-XSD-URI@";
+
+ private static final DOM3DocumentBuilder DOCUMENT_BUILDER = new
DOM3DocumentBuilder();
+
+ private static final ComponentTypeDecoder TYPE_DECODER = new
ComponentTypeDecoder();
+
+ private static final ValueDecoder VALUE_DECODER = new ValueDecoder();
+
+ /**
+ * Construct a component directive using the supplied uri.
+ * @param uri the part uri
+ * @return the component directive
+ * @exception IOException if an error occurs during directive creation
+ */
+ public ComponentDirective loadComponentDirective( URI uri ) throws
IOException
+ {
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+ try
+ {
+ final Document document = DOCUMENT_BUILDER.parse( uri );
+ final Element root = document.getDocumentElement();
+ return buildComponent( root );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "An error while attempting to load a component directive."
+ + "\nURI: " + uri;
+ IOException exception = new IOException( error );
+ exception.initCause( e );
+ throw exception;
+ }
+ }
+
+ /**
+ * Construct a component directive using the supplied DOM element.
+ * @param root the element representing the component directive definition
+ * @return the component directive
+ * @exception Exception if an error occurs during directive creation
+ */
+ public ComponentDirective buildComponent( Element root ) throws
DecodingException
+ {
+ if( null == root )
+ {
+ throw new NullPointerException( "root" );
+ }
+
+ return createComponentDirective( root );
+ }
+
+ private ComponentDirective createComponentDirective( Element element )
throws DecodingException
+ {
+ String classname = buildComponentClassname( element );
+ String name = buildComponentName( element );
+ ActivationPolicy activation = buildActivationPolicy( element );
+ CollectionPolicy collection = buildCollectionPolicy( element );
+ LifestylePolicy lifestyle = buildLifestylePolicy( element );
+ CategoriesDirective categories = getNestedCategoriesDirective(
element );
+ ContextDirective context = getNestedContextDirective( element );
+ PartReference[] parts = getNestedParts( element );
+
+ return new ComponentDirective(
+ name, activation, collection, lifestyle, classname,
+ categories, context, null, null, parts );
+ }
+
+ private String buildComponentClassname( Element element ) throws
DecodingException
+ {
+ String classname = ElementHelper.getAttribute( element, "class" );
+ if( null == classname )
+ {
+ final String error =
+ "Missing component 'class' attribute.";
+ throw new DecodingException( element, error );
+ }
+ else
+ {
+ return classname;
+ }
+ }
+
+ private ActivationPolicy buildActivationPolicy( Element element ) throws
DecodingException
+ {
+ String defaultValue = ActivationPolicy.SYSTEM.getName();
+ String policy = ElementHelper.getAttribute( element, "activation",
defaultValue );
+ return ActivationPolicy.parse( policy );
+ }
+
+ private LifestylePolicy buildLifestylePolicy( Element element ) throws
DecodingException
+ {
+ String defaultValue = LifestylePolicy.TRANSIENT.getName();
+ String policy = ElementHelper.getAttribute( element, "lifestyle",
defaultValue );
+ return LifestylePolicy.parse( policy );
+ }
+
+ private CollectionPolicy buildCollectionPolicy( Element element ) throws
DecodingException
+ {
+ String defaultValue = CollectionPolicy.SYSTEM.getName();
+ String policy = ElementHelper.getAttribute( element, "collection",
defaultValue );
+ return CollectionPolicy.parse( policy );
+ }
+
+ private String buildComponentName( Element element )
+ {
+ return ElementHelper.getAttribute( element, "name" );
+ }
+
+ private CategoriesDirective getNestedCategoriesDirective( Element root )
+ {
+ Element element = ElementHelper.getChild( root, "categories" );
+ if( null == element )
+ {
+ return null;
+ }
+ else
+ {
+ return createCategoriesDirective( element );
+ }
+ }
+
+ private CategoriesDirective createCategoriesDirective( Element element )
+ {
+ if( null == element )
+ {
+ return null;
+ }
+ else
+ {
+ String name = ElementHelper.getAttribute( element, "name" );
+ Priority priority = createPriority( element );
+ String target = ElementHelper.getAttribute( element, "target" );
+ CategoryDirective[] categories = createCategoryDirectiveArray(
element );
+ return new CategoriesDirective( name, priority, target,
categories );
+ }
+ }
+
+ private CategoryDirective createCategoryDirective( Element element )
+ {
+ String name = ElementHelper.getAttribute( element, "name" );
+ Priority priority = createPriority( element );
+ String target = ElementHelper.getAttribute( element, "target" );
+ return new CategoryDirective( name, priority, target );
+ }
+
+ private CategoryDirective[] createCategoryDirectiveArray( Element
element )
+ {
+ Element[] children = ElementHelper.getChildren( element );
+ CategoryDirective[] categories = new CategoryDirective[
children.length ];
+ for( int i=0; i<categories.length; i++ )
+ {
+ Element elem = children[i];
+ if( "category".equals( elem.getTagName() ) )
+ {
+ categories[i] = createCategoryDirective( elem );
+ }
+ else
+ {
+ categories[i] = createCategoriesDirective( elem );
+ }
+ }
+ return categories;
+ }
+
+ private Priority createPriority( Element element )
+ {
+ String priority = ElementHelper.getAttribute( element, "priority" );
+ if( null == priority )
+ {
+ return null;
+ }
+ else
+ {
+ return Priority.parse( priority );
+ }
+ }
+
+ private ContextDirective getNestedContextDirective( Element root )
+ {
+ Element context = ElementHelper.getChild( root, "context" );
+ if( null == context )
+ {
+ return null;
+ }
+ else
+ {
+ return createContextDirective( context );
+ }
+ }
+
+ private ContextDirective createContextDirective( Element element )
+ {
+ String classname = ElementHelper.getAttribute( element, "class" );
+ Element[] children = ElementHelper.getChildren( element );
+ PartReference[] entries = new PartReference[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element elem = children[i];
+ entries[i] = createContextEntryPartReference( elem );
+ }
+ return new ContextDirective( classname, entries );
+ }
+
+ private PartReference createContextEntryPartReference( Element element )
+ {
+ String key = ElementHelper.getAttribute( element, "key" );
+ String spec = ElementHelper.getAttribute( element, "lookup" );
+ if( null != spec )
+ {
+ LookupDirective directive = new LookupDirective( spec );
+ return new PartReference( key, directive );
+ }
+ else
+ {
+ ValueDirective directive = buildValueDirective( element );
+ return new PartReference( key, directive );
+ }
+ }
+
+ /**
+ * Build a value directive using a supplied DOM element.
+ * @param element the DOM element
+ * @return the value directive
+ */
+ protected ValueDirective buildValueDirective( Element element )
+ {
+ String classname = ElementHelper.getAttribute( element, "class" );
+ String method = ElementHelper.getAttribute( element, "method" );
+ Element[] elements = ElementHelper.getChildren( element, "param" );
+ if( elements.length > 0 )
+ {
+ Value[] values = VALUE_DECODER.decodeValues( elements );
+ return new ValueDirective( classname, method, values );
+ }
+ else
+ {
+ String value = ElementHelper.getAttribute( element, "value" );
+ return new ValueDirective( classname, method, value );
+ }
+ }
+
+ private PartReference[] getNestedParts( Element root ) throws
DecodingException
+ {
+ Element parts = ElementHelper.getChild( root, "parts" );
+ if( null == parts )
+ {
+ return null;
+ }
+ else
+ {
+ return createParts( parts );
+ }
+ }
+
+ private PartReference[] createParts( Element element ) throws
DecodingException
+ {
+ Element[] children = ElementHelper.getChildren( element );
+ PartReference[] parts = new PartReference[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element elem = children[i];
+ parts[i] = createPartReference( elem );
+ }
+ return parts;
+ }
+
+ private PartReference createPartReference( Element element ) throws
DecodingException
+ {
+ String key = ElementHelper.getAttribute( element, "key" );
+ ComponentDirective directive = createComponentDirective( element );
+ return new PartReference( key, directive );
+ }
+}

Copied:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentEncoder.java
(from rev 1216,
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentWriter.java)
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentWriter.java
2006-03-18 20:35:20 UTC (rev 1216)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentEncoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,477 @@
+/*
+ * 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 net.dpml.metro.builder;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import javax.xml.XMLConstants;
+
+import net.dpml.component.ActivationPolicy;
+import net.dpml.component.Directive;
+
+import net.dpml.lang.Value;
+import net.dpml.lang.Encoder;
+
+import net.dpml.part.ValueEncoder;
+
+import net.dpml.metro.data.ContextDirective;
+import net.dpml.metro.data.CategoryDirective;
+import net.dpml.metro.data.CategoriesDirective;
+import net.dpml.metro.data.ComponentDirective;
+import net.dpml.metro.data.LookupDirective;
+import net.dpml.metro.data.ValueDirective;
+import net.dpml.metro.info.LifestylePolicy;
+import net.dpml.metro.info.CollectionPolicy;
+import net.dpml.metro.info.PartReference;
+import net.dpml.metro.info.Priority;
+
+/**
+ * Component part handler.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ComponentEncoder extends ComponentConstants implements Encoder
+{
+ private static final String CONTROLLER_URI = "@CONTROLLER-URI@";
+ private static final String BUILDER_URI = "@BUILDER-URI@";
+ private static final String XML_HEADER = "<?xml version=\"1.0\"?>";
+ private static final String TYPE_SCHEMA_URN = "@TYPE-XSD-URI@";
+ private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
+ private static final String PART_SCHEMA_URN = "@PART-XSD-URI@";
+ private static final String COMPONENT_SCHEMA_URN = "@COMPONENT-XSD-URI@";
+ private static final String PARTIAL_COMPONENT_HEADER =
+ "<component xmlns=\""
+ + COMPONENT_SCHEMA_URN
+ + "\""
+ + "\n xmlns:xsi=\""
+ + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
+ + "\"\n xmlns:part=\""
+ + PART_SCHEMA_URN
+ + "\"\n xmlns:type=\""
+ + TYPE_SCHEMA_URN
+ + "\"\n xmlns:component=\""
+ + COMPONENT_SCHEMA_URN
+ + "\"";
+
+ private static final ValueEncoder VALUE_ENCODER = new ValueEncoder();
+
+ /**
+ * Export a component directive to an output stream as XML.
+ * @param directive the component directive
+ * @param output the output stream
+ * @exception IOException if an IO error occurs
+ */
+ public void export( ComponentDirective directive, OutputStream output )
throws IOException
+ {
+ final Writer writer = new OutputStreamWriter( output );
+
+ writer.write( XML_HEADER );
+ writer.write( "\n\n" );
+ writer.write( PARTIAL_COMPONENT_HEADER );
+ writeAttributes( writer, directive, "" );
+ writeBody( writer, directive, " " );
+ writer.write( "\n" );
+ writer.write( "</component>" );
+ writer.write( "\n" );
+ writer.flush();
+ output.close();
+ }
+
+ /**
+ * Export a component directive to an output stream as XML.
+ * @param writer the print writer
+ * @param object the object to encode
+ * @param pad character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void encode( Writer writer, Object object, String pad ) throws
IOException
+ {
+ if( object instanceof ComponentDirective )
+ {
+ writeTaggedComponent( writer, (ComponentDirective) object, null,
pad );
+ }
+ else
+ {
+ final String error =
+ "Encoding subject is not recognized."
+ + "\nClass: " + object.getClass().getName();
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Export a component directive to an output stream as XML.
+ * @param writer the print writer
+ * @param directive the component directive
+ * @param pad character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void writeComponent(
+ Writer writer, ComponentDirective directive, String pad ) throws
IOException
+ {
+ writeTaggedComponent( writer, directive, null, pad );
+ }
+
+ /**
+ * Export a tagged component directive to an output stream as XML.
+ * @param writer the print writer
+ * @param directive the component directive
+ * @param key the key identifying the component
+ * @param pad character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void writeTaggedComponent(
+ Writer writer, ComponentDirective directive, String key, String pad )
throws IOException
+ {
+ writer.write( "\n" + pad + "<component xmlns=\"" +
COMPONENT_SCHEMA_URN + "\"" );
+ if( null != key )
+ {
+ writer.write( " key=\"" + key + "\"" );
+ }
+ writer.write( "\n" + pad + " " );
+ writeAttributes( writer, directive, pad + " " );
+ writeBody( writer, directive, pad + " " );
+ writer.write( "\n" + pad + "</component>" );
+ }
+
+ void writeAttributes(
+ Writer writer, ComponentDirective directive, String pad ) throws
IOException
+ {
+ String classname = directive.getClassname();
+ writer.write( " class=\"" + classname + "\"" );
+ String name = directive.getName();
+ if( null != name )
+ {
+ writer.write( "\n" + pad + " name=\"" + name + "\"" );
+ }
+ LifestylePolicy lifestyle = directive.getLifestylePolicy();
+ if( null != lifestyle )
+ {
+ writer.write( "\n" + pad + " lifestyle=\"" + lifestyle.getName()
+ "\"" );
+ }
+ CollectionPolicy collection = directive.getCollectionPolicy();
+ if( null != collection )
+ {
+ writer.write( "\n" + pad + " collection=\"" +
collection.getName() + "\"" );
+ }
+ ActivationPolicy activation = directive.getActivationPolicy();
+ if( null != activation )
+ {
+ writer.write( "\n" + pad + " activation=\"" +
activation.getName() + "\"" );
+ }
+ writer.write( ">" );
+ }
+
+ void writeBody(
+ Writer writer, ComponentDirective directive, String pad ) throws
IOException
+ {
+ CategoriesDirective categories = directive.getCategoriesDirective();
+ ContextDirective context = directive.getContextDirective();
+ PartReference[] parts = directive.getPartReferences();
+ writeCategoriesDirective( writer, categories, pad );
+ writeContextDirective( writer, context, pad );
+ writeParts( writer, parts, pad );
+ }
+
+ private void writeCategoriesDirective(
+ Writer writer, CategoriesDirective categories, String pad ) throws
IOException
+ {
+ String name = categories.getName();
+ Priority priority = categories.getPriority();
+ String target = categories.getTarget();
+ CategoryDirective[] subCategories = categories.getCategories();
+
+ if( isaNullValue( name ) && isaNullPriority( priority ) &&
isaNullValue( target )
+ && ( subCategories.length == 0 ) )
+ {
+ return;
+ }
+
+ writer.write( "\n" + pad + "<categories" );
+ if( !isaNullValue( name ) )
+ {
+ writer.write( " name=\"" + name + "\"" );
+ }
+ if( !isaNullPriority( priority ) )
+ {
+ writer.write( " priority=\"" + priority.getName() + "\"" );
+ }
+ if( !isaNullValue( target ) )
+ {
+ writer.write( " target=\"" + target + "\"" );
+ }
+ if( subCategories.length == 0 )
+ {
+ writer.write( "/>" );
+ }
+ else
+ {
+ writer.write( ">" );
+ for( int i=0; i<subCategories.length; i++ )
+ {
+ CategoryDirective directive = subCategories[i];
+ if( directive instanceof CategoriesDirective )
+ {
+ CategoriesDirective c = (CategoriesDirective) directive;
+ writeCategoriesDirective( writer, c, pad + " " );
+ }
+ else
+ {
+ writeCategoryDirective( writer, directive, pad + " " );
+ }
+ }
+ writer.write( "\n" + pad + "</categories>" );
+ }
+ }
+
+ private boolean isaNullPriority( Priority priority )
+ {
+ if( null == priority )
+ {
+ return true;
+ }
+ else
+ {
+ return Priority.DEBUG.equals( priority );
+ }
+ }
+
+ private boolean isaNullValue( String value )
+ {
+ if( null == value )
+ {
+ return true;
+ }
+ else
+ {
+ return "".equals( value );
+ }
+ }
+
+ private void writeCategoryDirective(
+ Writer writer, CategoryDirective category, String pad ) throws
IOException
+ {
+ String name = category.getName();
+ Priority priority = category.getPriority();
+ String target = category.getTarget();
+
+ writer.write( "\n" + pad + "<category" );
+ if( null != name )
+ {
+ writer.write( " name=\"" + name + "\"" );
+ }
+ if( null != priority )
+ {
+ writer.write( " priority=\"" + priority.getName() + "\"" );
+ }
+ if( null != target )
+ {
+ writer.write( " target=\"" + target + "\"" );
+ }
+ writer.write( "/>" );
+ }
+
+ private void writeContextDirective(
+ Writer writer, ContextDirective context, String pad ) throws
IOException
+ {
+ String classname = context.getClassname();
+ PartReference[] parts = context.getDirectives();
+
+ if( ( null == classname ) && ( parts.length == 0 ) )
+ {
+ return;
+ }
+
+ writer.write( "\n" + pad + "<context" );
+ if( null != classname )
+ {
+ writer.write( " class=\"" + classname + "\"" );
+ }
+ if( parts.length == 0 )
+ {
+ writer.write( "/>" );
+ }
+ else
+ {
+ writer.write( ">" );
+ writeContextEntries( writer, parts, pad + " " );
+ writer.write( "\n" + pad + "</context>" );
+ }
+ }
+
+ /**
+ * Write a collection of part references.
+ * @param writer the writer
+ * @param parts the part refernece array
+ * @param pad the offset
+ * @exception IOException if an IO error occurs
+ */
+ protected void writeParts(
+ Writer writer, PartReference[] parts, String pad ) throws IOException
+ {
+ if( parts.length == 0 )
+ {
+ return;
+ }
+ else
+ {
+ writer.write( "\n" + pad + "<parts>" );
+ writePartReferences( writer, parts, pad + " " );
+ writer.write( "\n" + pad + "</parts>" );
+ }
+ }
+
+ private void writePartReferences(
+ Writer writer, PartReference[] parts, String pad ) throws IOException
+ {
+ for( int i=0; i<parts.length; i++ )
+ {
+ PartReference ref = parts[i];
+ writePartReference( writer, ref, pad );
+ }
+ }
+
+ private void writeContextEntries(
+ Writer writer, PartReference[] parts, String pad ) throws IOException
+ {
+ for( int i=0; i<parts.length; i++ )
+ {
+ PartReference ref = parts[i];
+ writeContextEntry( writer, ref, pad );
+ }
+ }
+
+ private void writeContextEntry(
+ Writer writer, PartReference part, String pad ) throws IOException
+ {
+ String key = part.getKey();
+ if( null == key )
+ {
+ throw new IllegalStateException( "key" );
+ }
+ Directive directive = part.getDirective();
+ if( null == directive )
+ {
+ throw new IllegalStateException( "directive" );
+ }
+ if( directive instanceof ValueDirective )
+ {
+ ValueDirective value = (ValueDirective) directive;
+ writeEntry( writer, key, value, pad );
+ }
+ else if( directive instanceof LookupDirective )
+ {
+ LookupDirective value = (LookupDirective) directive;
+ writeLookupEntry( writer, key, value, pad );
+ }
+ else
+ {
+ String classname = directive.getClass().getName();
+ final String message = "WARNING: UNRECOGNIZED ENTRY: "+
classname;
+ System.out.println( "# " + message );
+ System.out.println( "# key: " + key );
+ System.out.println( "# class: " + classname );
+ writer.write( "\n" + pad + "<!-- " + message + " -->" );
+ writer.write( "\n" + pad + "<!-- " );
+ writer.write( "\n" + pad + "key: " + key );
+ writer.write( "\n" + pad + "class: " +
directive.getClass().getName() );
+ writer.write( "\n" + pad + "-->" );
+ }
+ }
+
+ private void writeLookupEntry(
+ Writer writer, String key, LookupDirective directive, String pad )
throws IOException
+ {
+ String classname = directive.getServiceClassname();
+ writer.write( "\n" + pad + "<entry key=\"" + key + "\" lookup=\"" +
classname + "\"/>" );
+ }
+
+ private void writePartReference(
+ Writer writer, PartReference part, String pad ) throws IOException
+ {
+ String key = part.getKey();
+ if( null == key )
+ {
+ throw new IllegalStateException( "key" );
+ }
+
+ Directive directive = part.getDirective();
+ if( null == directive )
+ {
+ throw new IllegalStateException( "directive" );
+ }
+ if( directive instanceof ComponentDirective )
+ {
+ ComponentDirective component = (ComponentDirective) directive;
+ writeTaggedComponent( writer, component, key, pad );
+ }
+ else
+ {
+ String classname = directive.getClass().getName();
+ final String error =
+ "Part reference class not recognized."
+ + "\nClass: " + classname;
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Write a context entry.
+ * @param writer the writer
+ * @param key the entry key
+ * @param value the value directive
+ * @param pad the offset
+ * @exception IOException if an IO error occurs
+ */
+ protected void writeEntry( Writer writer, String key, ValueDirective
value, String pad ) throws IOException
+ {
+ String target = value.getTargetExpression();
+ String method = value.getMethodName();
+
+ writer.write( "\n" + pad + "<entry key=\"" + key + "\"" );
+ if( null != target )
+ {
+ writer.write( " class=\"" + target + "\"" );
+ }
+ if( null != method )
+ {
+ writer.write( " method=\"" + method + "\"" );
+ }
+ Value[] values = value.getValues();
+ if( values.length > 0 )
+ {
+ writer.write( ">" );
+ VALUE_ENCODER.encodeValues( writer, values, pad + " " );
+ writer.write( "\n" + pad + "</entry>" );
+ }
+ else
+ {
+ String v = value.getBaseValue();
+ if( null != v )
+ {
+ writer.write( " value=\"" + v + "\"" );
+ }
+ writer.write( "/>" );
+ }
+ }
+}

Deleted:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyBuilder.java
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,162 +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 net.dpml.metro.builder;
-
-import java.net.URI;
-import java.util.Map;
-
-import net.dpml.lang.Builder;
-import net.dpml.lang.BuilderException;
-import net.dpml.lang.Value;
-
-import net.dpml.metro.data.ComponentDirective;
-
-import net.dpml.part.Strategy;
-import net.dpml.part.StrategyBuilder;
-import net.dpml.part.PartDirective;
-
-import net.dpml.library.Type;
-
-import net.dpml.transit.util.ElementHelper;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.TypeInfo;
-
-/**
- * Component part handler.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class ComponentStrategyBuilder extends ComponentStrategyWriter
implements StrategyBuilder, Builder
-{
- /**
- * Creation of a new component strategy builder.
- */
- public ComponentStrategyBuilder()
- {
- super( null );
- }
-
- /**
- * Creation of a new component strategy builder.
- * @param map namespace to builder uri map
- */
- public ComponentStrategyBuilder( Map map )
- {
- super( map );
- }
-
- /**
- * Constructs a component deployment strategy.
- * @param classloader the base classloader
- * @param element the DOM element
- * @return the deployment strategy
- * @exception Exception if an error occurs
- */
- public Object build( ClassLoader classloader, Element element ) throws
Exception
- {
- return buildStrategy( classloader, element );
- }
-
- /**
- * Constructs a type definition.
- * @param classloader the base classloader
- * @param element the DOM element
- * @return the component part strategy
- * @exception Exception if an error occurs
- */
- public Type buildType( ClassLoader classloader, Element element ) throws
Exception
- {
- boolean alias = ElementHelper.getBooleanAttribute( element, "alias",
false );
- Strategy strategy = buildStrategy( classloader, element );
- return new DefaultType( "part", alias, strategy );
- }
-
- /**
- * Constructs a component deployment strategy.
- * @param classloader the base classloader
- * @param element the DOM element
- * @return the deployment strategy
- * @exception Exception if an error occurs
- */
- public Strategy buildStrategy( ClassLoader classloader, Element element
) throws Exception
- {
- TypeInfo info = element.getSchemaTypeInfo();
- String namespace = info.getTypeNamespace();
- String name = info.getTypeName();
-
- URI uri = new URI( BUILDER_URI );
- boolean alias = ElementHelper.getBooleanAttribute( element, "alias",
false );
-
- if( "component".equals( name ) )
- {
- PartDirective control = createControllerDirective( null );
- ComponentDirective component = createComponentDirective( element
);
- return new Strategy( uri, control, component, alias );
- }
- else if( "strategy".equals( name ) )
- {
- Element controller = ElementHelper.getChild( element,
"controller" );
- PartDirective control = createControllerDirective( controller );
- Element directive = ElementHelper.getChild( element, "component"
);
- ComponentDirective component = createComponentDirective(
directive );
- return new Strategy( uri, control, component, alias );
- }
- else
- {
- final String error =
- "Strategy element name ["
- + name
- + "] is not recognized (expecting either 'component' or
'strategy').";
- throw new BuilderException( element, error );
- }
- }
-
- private ComponentDirective createComponentDirective( Element element )
throws Exception
- {
- return BUILDER.buildComponent( element );
- }
-
- private PartDirective createControllerDirective( Element element )
throws Exception
- {
- if( null == element )
- {
- try
- {
- URI uri = new URI( CONTROLLER_URI );
- 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"
);
- Value[] values = buildValues( elements );
- return new PartDirective( uri, values );
- }
- }
-}

Copied:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyDecoder.java
(from rev 1228,
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyBuilder.java)
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyBuilder.java
2006-03-19 17:57:39 UTC (rev 1228)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyDecoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,181 @@
+/*
+ * 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 net.dpml.metro.builder;
+
+import java.net.URI;
+import java.util.Map;
+
+import net.dpml.lang.Decoder;
+import net.dpml.lang.DecodingException;
+import net.dpml.lang.Value;
+
+import net.dpml.metro.data.ComponentDirective;
+
+import net.dpml.part.Strategy;
+import net.dpml.part.PartDirective;
+import net.dpml.part.DecoderFactory;
+import net.dpml.part.ValueDecoder;
+
+import net.dpml.library.Type;
+
+import net.dpml.transit.util.ElementHelper;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.TypeInfo;
+
+/**
+ * Component part handler.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ComponentStrategyDecoder extends ComponentConstants implements
Decoder
+{
+ private DecoderFactory m_factory;
+
+ private static final ComponentDecoder COMPONENT_DECODER = new
ComponentDecoder();
+
+ private static final ValueDecoder VALUE_DECODER = new ValueDecoder();
+
+ /**
+ * Creation of a new component strategy builder.
+ * @param factory the decoder factory
+ */
+ public ComponentStrategyDecoder( DecoderFactory factory )
+ {
+ m_factory = factory;
+ }
+
+ /**
+ * Constructs a component deployment strategy.
+ * @param classloader the base classloader
+ * @param element the DOM element
+ * @return the deployment strategy
+ * @exception Exception if an error occurs
+ */
+ public Object decode( ClassLoader classloader, Element element ) throws
DecodingException
+ {
+ return buildStrategy( classloader, element );
+ }
+
+ /**
+ * Constructs a type definition.
+ * @param classloader the base classloader
+ * @param element the DOM element
+ * @return the component part strategy
+ * @exception Exception if an error occurs
+ */
+ public Type buildType( ClassLoader classloader, Element element ) throws
Exception
+ {
+ boolean alias = ElementHelper.getBooleanAttribute( element, "alias",
false );
+ Strategy strategy = buildStrategy( classloader, element );
+ return new DefaultType( "part", alias, strategy );
+ }
+
+ /**
+ * Constructs a component deployment strategy.
+ * @param classloader the base classloader
+ * @param element the DOM element
+ * @return the deployment strategy
+ * @exception Exception if an error occurs
+ */
+ public Strategy buildStrategy( ClassLoader classloader, Element element
) throws DecodingException
+ {
+ TypeInfo info = element.getSchemaTypeInfo();
+ String namespace = info.getTypeNamespace();
+ String name = info.getTypeName();
+
+ boolean alias = ElementHelper.getBooleanAttribute( element, "alias",
false );
+
+ if( "component".equals( name ) )
+ {
+ PartDirective control = createControllerDirective( null );
+ ComponentDirective component = createComponentDirective( element
);
+ return new Strategy( BUILDER_URI, control, component, alias );
+ }
+ else if( "strategy".equals( name ) )
+ {
+ Element controller = ElementHelper.getChild( element,
"controller" );
+ PartDirective control = createControllerDirective( controller );
+ Element directive = ElementHelper.getChild( element, "component"
);
+ ComponentDirective component = createComponentDirective(
directive );
+ return new Strategy( BUILDER_URI, control, component, alias );
+ }
+ else
+ {
+ final String error =
+ "Strategy element name ["
+ + name
+ + "] is not recognized (expecting either 'component' or
'strategy').";
+ throw new DecodingException( element, error );
+ }
+ }
+
+ private ComponentDirective createComponentDirective( Element element )
throws DecodingException
+ {
+ return COMPONENT_DECODER.buildComponent( element );
+ }
+
+ private PartDirective createControllerDirective( Element element )
throws DecodingException
+ {
+ if( null == element )
+ {
+ try
+ {
+ return new PartDirective( CONTROLLER_URI, null );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error during part directive creation.";
+ throw new RuntimeException( error, e );
+ }
+ }
+ else
+ {
+ URI uri = decodeURI( element );
+ Element[] elements = ElementHelper.getChildren( element, "param"
);
+ Value[] values = VALUE_DECODER.decodeValues( elements );
+ return new PartDirective( uri, values );
+ }
+ }
+
+ private URI decodeURI( Element element ) throws DecodingException
+ {
+ String spec = ElementHelper.getAttribute( element, "uri" );
+ if( null == spec )
+ {
+ final String error =
+ "Missing uri attribute.";
+ throw new DecodingException( element, error );
+ }
+ try
+ {
+ return new URI( spec );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to construct uri from element uri attribute value ["
+ + spec
+ + "].";
+ throw new DecodingException( element, error, e );
+ }
+ }
+}

Copied:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyEncoder.java
(from rev 1216,
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyWriter.java)
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyWriter.java
2006-03-18 20:35:20 UTC (rev 1216)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyEncoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,122 @@
+/*
+ * 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 net.dpml.metro.builder;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+
+import net.dpml.metro.data.ComponentDirective;
+
+import net.dpml.part.Strategy;
+import net.dpml.part.ValueEncoder;
+
+import net.dpml.lang.Encoder;
+
+/**
+ * Component part handler.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ComponentStrategyEncoder extends ComponentConstants implements
Encoder
+{
+ static final String CONTROLLER_URI = "@CONTROLLER-URI@";
+ static final String BUILDER_URI = "@COMPONENT_DECODER-URI@";
+
+ private static final String COMPONENT_XSD_URI = "@COMPONENT-XSD-URI@";
+ private static final String XML_HEADER =
+ "<?xml version=\"1.0\"?>";
+ private static final String TYPE_SCHEMA_URN = "@TYPE-XSD-URI@";
+ private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
+ private static final String PART_SCHEMA_URN = "@PART-XSD-URI@";
+ private static final String COMPONENT_SCHEMA_URN = "@COMPONENT-XSD-URI@";
+
+ private static final String PARTIAL_COMPONENT_HEADER =
+ "<component xmlns=\""
+ + COMPONENT_SCHEMA_URN
+ + "\""
+ + "\n xmlns:xsi=\""
+ + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
+ + "\"\n xmlns:part=\""
+ + PART_SCHEMA_URN
+ + "\"\n xmlns:type=\""
+ + TYPE_SCHEMA_URN
+ + "\"\n xmlns:component=\""
+ + COMPONENT_SCHEMA_URN
+ + "\"";
+
+ static final ComponentEncoder COMPONENT_ENCODER = new ComponentEncoder();
+
+ /**
+ * Write a component strategy to an output stream writer.
+ * @param writer the output stream writer
+ * @param object the object to encode
+ * @param pad the character offset to apply
+ * @exception IOException if an IO error occurs
+ */
+ public void encode( Writer writer, Object object, String pad ) throws
IOException
+ {
+ if( object instanceof Strategy )
+ {
+ writeStrategy( writer, (Strategy) object, pad );
+ }
+ else
+ {
+ final String error =
+ "Encoding subject is not recognized."
+ + "\nObject: " + object.getClass().getName();
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Write a component strategy to an output stream writer.
+ * @param writer the output stream writer
+ * @param strategy the strategy instance
+ * @param pad the character offset to apply
+ * @exception IOException if an IO error occurs
+ */
+ public void writeStrategy(
+ Writer writer, Strategy strategy, String pad ) throws IOException
+ {
+ Object data = strategy.getDeploymentData();
+ if( data instanceof ComponentDirective )
+ {
+ ComponentDirective directive = (ComponentDirective) data;
+ writer.write( "\n" + pad + "<component xmlns=\"" +
COMPONENT_SCHEMA_URN + "\"" );
+ writer.write( "\n" + pad + " " );
+ COMPONENT_ENCODER.writeAttributes( writer, directive, pad + "
" );
+ COMPONENT_ENCODER.writeBody( writer, directive, pad + " " );
+ writer.write( "\n" + pad + "</component>" );
+ }
+ else
+ {
+ final String error =
+ "Strategy argument ["
+ + data.getClass().getName()
+ + "] is not an instance of "
+ + ComponentDirective.class.getName()
+ + ".";
+ throw new IllegalArgumentException( error );
+ }
+ }
+}

Deleted:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyWriter.java
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyWriter.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentStrategyWriter.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,106 +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 net.dpml.metro.builder;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Map;
-
-import javax.xml.XMLConstants;
-
-import net.dpml.metro.data.ComponentDirective;
-
-import net.dpml.part.Strategy;
-import net.dpml.part.ValueBuilder;
-
-/**
- * Component part handler.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class ComponentStrategyWriter extends ValueBuilder
-{
- static final String CONTROLLER_URI = "@CONTROLLER-URI@";
- static final String BUILDER_URI = "@BUILDER-URI@";
-
- private static final String COMPONENT_XSD_URI = "@COMPONENT-XSD-URI@";
- private static final String XML_HEADER =
- "<?xml version=\"1.0\"?>";
- private static final String TYPE_SCHEMA_URN = "@TYPE-XSD-URI@";
- private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
- private static final String PART_SCHEMA_URN = "@PART-XSD-URI@";
- private static final String COMPONENT_SCHEMA_URN = "@COMPONENT-XSD-URI@";
- private static final String PARTIAL_COMPONENT_HEADER =
- "<component xmlns=\""
- + COMPONENT_SCHEMA_URN
- + "\""
- + "\n xmlns:xsi=\""
- + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
- + "\"\n xmlns:part=\""
- + PART_SCHEMA_URN
- + "\"\n xmlns:type=\""
- + TYPE_SCHEMA_URN
- + "\"\n xmlns:component=\""
- + COMPONENT_SCHEMA_URN
- + "\"";
-
- static final ComponentBuilder BUILDER = new ComponentBuilder();
-
- /**
- * Creation of a new component strategy writer.
- * @param map the namespace to builder uri map
- */
- public ComponentStrategyWriter( Map map )
- {
- super( map );
- }
-
- /**
- * Write a component strategy to an output stream writer.
- * @param writer the output stream writer
- * @param strategy the strategy instance
- * @param pad the character offset to apply
- * @exception IOException if an IO error occurs
- */
- public void writeStrategy(
- Writer writer, Strategy strategy, String pad ) throws IOException
- {
- Object data = strategy.getDeploymentData();
- if( data instanceof ComponentDirective )
- {
- ComponentDirective directive = (ComponentDirective) data;
- writer.write( "\n" + pad + "<component xmlns=\"" +
COMPONENT_SCHEMA_URN + "\"" );
- writer.write( "\n" + pad + " " );
- BUILDER.writeAttributes( writer, directive, pad + " " );
- BUILDER.writeBody( writer, directive, pad + " " );
- writer.write( "\n" + pad + "</component>" );
- }
- else
- {
- final String error =
- "Strategy argument ["
- + data.getClass().getName()
- + "] is not an instance of "
- + ComponentDirective.class.getName()
- + ".";
- throw new IllegalArgumentException( error );
- }
- }
-}

Copied:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentTypeDecoder.java
(from rev 1228,
trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeBuilder.java)
===================================================================
--- trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeBuilder.java
2006-03-19 17:57:39 UTC (rev 1228)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentTypeDecoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,310 @@
+/*
+ * 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.builder;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Properties;
+
+import net.dpml.lang.Version;
+import net.dpml.lang.DecodingException;
+
+import net.dpml.metro.data.ComponentDirective;
+import net.dpml.metro.info.Type;
+import net.dpml.metro.info.InfoDescriptor;
+import net.dpml.metro.info.ContextDescriptor;
+import net.dpml.metro.info.CategoryDescriptor;
+import net.dpml.metro.info.ServiceDescriptor;
+import net.dpml.metro.info.EntryDescriptor;
+import net.dpml.metro.info.PartReference;
+import net.dpml.metro.info.CollectionPolicy;
+import net.dpml.metro.info.LifestylePolicy;
+import net.dpml.metro.info.ThreadSafePolicy;
+import net.dpml.metro.info.Priority;
+
+import net.dpml.part.DOM3DocumentBuilder;
+
+import net.dpml.state.State;
+import net.dpml.state.impl.StateDecoder;
+import net.dpml.state.impl.DefaultState;
+
+import net.dpml.transit.util.ElementHelper;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+
+/**
+ * Component type decoder.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class ComponentTypeDecoder
+{
+ private static final StateDecoder STATE_DECODER = new StateDecoder();
+
+ private static final DOM3DocumentBuilder DOCUMENT_BUILDER = new
DOM3DocumentBuilder();
+
+ private static final ComponentDecoder COMPONENT_DECODER = new
ComponentDecoder();
+
+ /**
+ * Load a type.
+ * @param subject the component implementation class
+ * @return the component type descriptor
+ * @exception IOException if an error occurs reading the type definition
+ */
+ public Type loadType( Class subject ) throws IOException
+ {
+ String classname = subject.getName();
+ String path = classname.replace( '.', '/' );
+ String target = path + ".type";
+ ClassLoader classloader = subject.getClassLoader();
+ URL url = classloader.getResource( target );
+ if( null == url )
+ {
+ return Type.createType( subject );
+ }
+ else
+ {
+ try
+ {
+ URI uri = new URI( url.toString() );
+ return loadType( uri );
+ }
+ catch( URISyntaxException e )
+ {
+ final String error =
+ "Bad uri value."
+ + "\nURI: " + url;
+ IOException exception = new IOException( error );
+ exception.initCause( e );
+ throw exception;
+ }
+ }
+ }
+
+ /**
+ * Load a type.
+ * @param uri the component type source uri
+ * @return the component type descriptor
+ * @exception IOException if an error occurs reading the type definition
+ */
+ public Type loadType( URI uri ) throws IOException
+ {
+ try
+ {
+ final Document document = DOCUMENT_BUILDER.parse( uri );
+ final Element root = document.getDocumentElement();
+ return buildType( root );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "An error while attempting to load a type."
+ + "\nType URI: " + uri;
+ IOException exception = new IOException( error );
+ exception.initCause( e );
+ throw exception;
+ }
+ }
+
+ private Type buildType( Element root ) throws Exception
+ {
+ InfoDescriptor info = buildNestedInfoDescriptor( root );
+ ServiceDescriptor[] services = buildNestedServices( root );
+ ContextDescriptor context = buildNestedContext( root );
+ CategoryDescriptor[] categories = buildNestedCategories( root );
+ State state = buildNestedState( root );
+ PartReference[] parts = buildNestedParts( root );
+ return new Type( info, categories, context, services, parts, state );
+ }
+
+ private InfoDescriptor buildNestedInfoDescriptor( Element root ) throws
DecodingException
+ {
+ Element info = ElementHelper.getChild( root, "info" );
+ if( null == info )
+ {
+ final String error =
+ "Definition of <type> is missing the required <info> element.";
+ throw new DecodingException( root, error );
+ }
+
+ String name = ElementHelper.getAttribute( info, "name" );
+ String classname = ElementHelper.getAttribute( info, "class" );
+ String version = ElementHelper.getAttribute( info, "version" );
+ String collection = ElementHelper.getAttribute( info, "collection",
"system" );
+ String lifestyle = ElementHelper.getAttribute( info, "lifestyle",
"system" );
+ String threadsafe = ElementHelper.getAttribute( info, "threadsafe",
"unknown" );
+ Properties properties = buildNestedProperties( info );
+
+ return new InfoDescriptor(
+ name,
+ classname,
+ Version.getVersion( version ),
+ LifestylePolicy.parse( lifestyle ),
+ CollectionPolicy.parse( collection ),
+ ThreadSafePolicy.parse( threadsafe ),
+ properties );
+ }
+
+ private ServiceDescriptor[] buildNestedServices( Element root )
+ {
+ Element element = ElementHelper.getChild( root, "services" );
+ if( null == element )
+ {
+ return new ServiceDescriptor[0];
+ }
+ else
+ {
+ Element[] children = ElementHelper.getChildren( element,
"service" );
+ ServiceDescriptor[] services = new ServiceDescriptor[
children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ String classname = ElementHelper.getAttribute( child,
"class" );
+ String version = ElementHelper.getAttribute( child,
"version", "1.0.0" );
+ services[i] = new ServiceDescriptor( classname,
Version.getVersion( version ) );
+ }
+ return services;
+ }
+ }
+
+ private ContextDescriptor buildNestedContext( Element root )
+ {
+ Element context = ElementHelper.getChild( root, "context" );
+ if( null == context )
+ {
+ return new ContextDescriptor( new EntryDescriptor[0] );
+ }
+ else
+ {
+ Element[] children = ElementHelper.getChildren( context, "entry"
);
+ EntryDescriptor[] entries = new EntryDescriptor[ children.length
];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ String key = ElementHelper.getAttribute( child, "key" );
+ String classname = ElementHelper.getAttribute( child,
"class" );
+ boolean optional = ElementHelper.getBooleanAttribute( child,
"optional", false );
+ boolean isVolatile = ElementHelper.getBooleanAttribute(
child, "volatile", false );
+ entries[i] = new EntryDescriptor( key, classname, optional,
isVolatile );
+ }
+ return new ContextDescriptor( entries );
+ }
+ }
+
+ private CategoryDescriptor[] buildNestedCategories( Element root )
+ {
+ Element element = ElementHelper.getChild( root, "categories" );
+ if( null == element )
+ {
+ return new CategoryDescriptor[0];
+ }
+ else
+ {
+ Element[] children = ElementHelper.getChildren( element,
"category" );
+ CategoryDescriptor[] categories = new CategoryDescriptor[
children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element elem = children[i];
+ String name = ElementHelper.getAttribute( elem, "name" );
+ String priority = ElementHelper.getAttribute( elem,
"priority" );
+ Properties properties = buildNestedProperties( elem );
+ categories[i] = new CategoryDescriptor( name,
Priority.parse( priority ), properties );
+ }
+ return categories;
+ }
+ }
+
+ private State buildNestedState( Element root )
+ {
+ // ISSUE: selection does not support namespace resolution
+ // and will fail with something like <acme:state>
+
+ Element element = ElementHelper.getChild( root, "state" );
+ if( null == element )
+ {
+ return new DefaultState();
+ }
+ else
+ {
+ return STATE_DECODER.buildStateGraph( element );
+ }
+ }
+
+ private PartReference[] buildNestedParts( Element root ) throws Exception
+ {
+ Element element = ElementHelper.getChild( root, "parts" );
+ if( null == element )
+ {
+ return new PartReference[0];
+ }
+ else
+ {
+ Element[] children = ElementHelper.getChildren( element );
+ if( children.length == 0 )
+ {
+ return new PartReference[0];
+ }
+ else
+ {
+ PartReference[] refs = new PartReference[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ refs[i] = buildPartReference( child );
+ }
+ return refs;
+ }
+ }
+ }
+
+ private PartReference buildPartReference( Element element ) throws
Exception
+ {
+ String key = ElementHelper.getAttribute( element, "key" );
+ ComponentDirective definition = COMPONENT_DECODER.buildComponent(
element );
+ return new PartReference( key, definition );
+ }
+
+ private Properties buildNestedProperties( Element element )
+ {
+ Element[] entries = ElementHelper.getChildren( element, "property" );
+ if( entries.length == 0 )
+ {
+ return null;
+ }
+ else
+ {
+ Properties properties = new Properties();
+ for( int i=0; i<entries.length; i++ )
+ {
+ Element elem = entries[i];
+ String name = ElementHelper.getAttribute( elem, "name" );
+ String value = ElementHelper.getAttribute( elem, "value" );
+ properties.setProperty( name, value );
+ }
+ return properties;
+ }
+ }
+
+}
+

Copied:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentTypeEncoder.java
(from rev 1216,
trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeWriter.java)
===================================================================
--- trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeWriter.java
2006-03-18 20:35:20 UTC (rev 1216)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentTypeEncoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,243 @@
+/*
+ * 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.builder;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import javax.xml.XMLConstants;
+
+import net.dpml.metro.info.Type;
+import net.dpml.metro.info.InfoDescriptor;
+import net.dpml.metro.info.ContextDescriptor;
+import net.dpml.metro.info.CategoryDescriptor;
+import net.dpml.metro.info.ServiceDescriptor;
+import net.dpml.metro.info.EntryDescriptor;
+import net.dpml.metro.info.PartReference;
+import net.dpml.metro.info.Descriptor;
+
+import net.dpml.state.State;
+import net.dpml.state.impl.StateEncoder;
+
+/**
+ * Type builder.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ComponentTypeEncoder
+{
+ private static final String XML_HEADER =
+ "<?xml version=\"1.0\"?>";
+
+ private static final String PART_SCHEMA_URN = "@PART-XSD-URI@";
+ private static final String COMPONENT_SCHEMA_URN = "@COMPONENT-XSD-URI@";
+ private static final String TYPE_SCHEMA_URN = "@TYPE-XSD-URI@";
+
+ private static final StateEncoder STATE_GRAPH_ENCODER = new
StateEncoder();
+
+ static final ComponentEncoder COMPONENT_ENCODER = new ComponentEncoder();
+
+ private static final String HEADER =
+ "<type xmlns=\""
+ + TYPE_SCHEMA_URN
+ + "\""
+ + "\n xmlns:xsi=\""
+ + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
+ + "\"\n xmlns:part=\""
+ + PART_SCHEMA_URN
+ + "\"\n xmlns:type=\""
+ + TYPE_SCHEMA_URN
+ + "\"\n xmlns:component=\""
+ + COMPONENT_SCHEMA_URN
+ + "\">";
+
+ private static final String FOOTER = "</type>";
+
+ /**
+ * Write the supplied type to an output stream.
+ * @param type the type descriptor
+ * @param output the output stream
+ * @exception IOException if an IO error occurs
+ */
+ public void export( Type type, OutputStream output ) throws IOException
+ {
+ final Writer writer = new OutputStreamWriter( output );
+ writer.write( XML_HEADER );
+ writer.write( "\n\n" );
+ writer.write( HEADER );
+ writer.write( "\n" );
+ writeBody( writer, type, " " );
+ writer.write( "\n" );
+ writer.write( FOOTER );
+ writer.write( "\n" );
+ writer.flush();
+ output.close();
+ }
+
+ private void writeBody( Writer writer, Type type, String pad ) throws
IOException
+ {
+ writeTypeInfo( writer, type.getInfo(), pad );
+ writeTypeServices( writer, type.getServiceDescriptors(), pad );
+ writeTypeContext( writer, type.getContextDescriptor(), pad );
+ writeTypeCategories( writer, type.getCategoryDescriptors(), pad );
+ writeTypeState( writer, type.getStateGraph(), pad );
+ writeTypeParts( writer, type.getPartReferences(), pad );
+ }
+
+ private void writeTypeInfo( Writer writer, InfoDescriptor info, String
pad ) throws IOException
+ {
+ writer.write( "\n" + pad + "<info" );
+ writer.write( " name=\"" + info.getName() );
+ writer.write( "\"\n" + pad + " class=\"" + info.getClassname() );
+ writer.write( "\"\n" + pad + " version=\"" + info.getVersion() );
+ writer.write( "\"\n" + pad + " lifestyle=\"" +
info.getLifestyle().getName().toLowerCase() );
+ writer.write( "\"\n" + pad + " collection=\"" +
info.getCollectionPolicy().getName().toLowerCase() );
+ writer.write( "\"\n" + pad + " threadsafe=\"" +
info.getThreadSafePolicy().getName().toLowerCase() );
+ writer.write( "\"" );
+ if( info.getAttributeNames().length > 0 )
+ {
+ writer.write( ">" );
+ writeAttributes( writer, info, pad + " " );
+ writer.write( "\n" + pad + "</info>" );
+ }
+ else
+ {
+ writer.write( "/>" );
+ }
+ }
+
+ private void writeTypeServices( Writer writer, ServiceDescriptor[]
services, String pad ) throws IOException
+ {
+ if( services.length == 0 )
+ {
+ return;
+ }
+ else
+ {
+ writer.write( "\n" + pad + "<services>" );
+ for( int i=0; i<services.length; i++ )
+ {
+ ServiceDescriptor service = services[i];
+ writer.write( "\n" + pad + " <service" );
+ writer.write( " class=\"" + service.getClassname() );
+ writer.write( "\" version=\"" + service.getVersion() );
+ writer.write( "\"/>" );
+ }
+ writer.write( "\n" + pad + "</services>" );
+ }
+ }
+
+ private void writeTypeContext( Writer writer, ContextDescriptor context,
String pad ) throws IOException
+ {
+ EntryDescriptor[] entries = context.getEntryDescriptors();
+ if( entries.length > 0 )
+ {
+ writer.write( "\n" + pad + "<context>" );
+ for( int i=0; i<entries.length; i++ )
+ {
+ EntryDescriptor entry = entries[i];
+ writer.write( "\n" + pad + " <entry" );
+ writer.write( " key=\"" + entry.getKey() );
+ writer.write( "\" class=\"" + entry.getClassname() );
+ if( entry.isOptional() )
+ {
+ writer.write( "\" optional=\"true\"" );
+ }
+ else
+ {
+ writer.write( "\" optional=\"false\"" );
+ }
+ if( entry.isVolatile() )
+ {
+ writer.write( "\" volatile=\"true\"" );
+ }
+ writer.write( "/>" );
+ }
+ writer.write( "\n" + pad + "</context>" );
+ }
+ else
+ {
+ return;
+ }
+ }
+
+ private void writeTypeCategories(
+ Writer writer, CategoryDescriptor[] categories, String pad ) throws
IOException
+ {
+ if( categories.length > 0 )
+ {
+ writer.write( "\n" + pad + "<categories>" );
+ for( int i=0; i<categories.length; i++ )
+ {
+ CategoryDescriptor category = categories[i];
+ writer.write( "\n" + pad + " <category" );
+ writer.write( " name=\"" + category.getName() );
+ writer.write(
+ "\" priority=\""
+ + category.getDefaultPriority().getName().toLowerCase() );
+ writer.write( "\"" );
+
+ if( category.getAttributeNames().length > 0 )
+ {
+ writer.write( ">" );
+ writeAttributes( writer, category, pad + " " );
+ writer.write( "\n" + pad + " </category>" );
+ }
+ else
+ {
+ writer.write( "/>" );
+ }
+ }
+ writer.write( "\n" + pad + "</categories>" );
+ }
+ else
+ {
+ return;
+ }
+ }
+
+ private void writeTypeState( Writer writer, State state, String pad )
throws IOException
+ {
+ STATE_GRAPH_ENCODER.writeState( writer, state, pad );
+ writer.write( "\n" );
+ }
+
+ private void writeTypeParts( Writer writer, PartReference[] parts,
String pad ) throws IOException
+ {
+ COMPONENT_ENCODER.writeParts( writer, parts, pad );
+ }
+
+ private void writeAttributes( Writer writer, Descriptor descriptor,
String pad ) throws IOException
+ {
+ String[] names = descriptor.getAttributeNames();
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ String value = descriptor.getAttribute( name, "" );
+ writer.write( "\n" + pad + "<property" );
+ writer.write( " name=\"" + name );
+ writer.write( "\" value=\"" + value );
+ writer.write( "\"/>" );
+ }
+ }
+}
+

Deleted:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentWriter.java
===================================================================
---
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentWriter.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/main/net/dpml/metro/builder/ComponentWriter.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,452 +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 net.dpml.metro.builder;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-
-import javax.xml.XMLConstants;
-
-import net.dpml.component.ActivationPolicy;
-import net.dpml.component.Directive;
-
-import net.dpml.lang.Value;
-
-import net.dpml.metro.data.ContextDirective;
-import net.dpml.metro.data.CategoryDirective;
-import net.dpml.metro.data.CategoriesDirective;
-import net.dpml.metro.data.ComponentDirective;
-import net.dpml.metro.data.LookupDirective;
-import net.dpml.metro.data.ValueDirective;
-import net.dpml.metro.info.LifestylePolicy;
-import net.dpml.metro.info.CollectionPolicy;
-import net.dpml.metro.info.PartReference;
-import net.dpml.metro.info.Priority;
-
-import net.dpml.part.PartBuilder;
-
-/**
- * Component part handler.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class ComponentWriter extends PartBuilder
-{
- private static final String CONTROLLER_URI = "@CONTROLLER-URI@";
- private static final String BUILDER_URI = "@BUILDER-URI@";
- private static final String XML_HEADER = "<?xml version=\"1.0\"?>";
- private static final String TYPE_SCHEMA_URN = "@TYPE-XSD-URI@";
- private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
- private static final String PART_SCHEMA_URN = "@PART-XSD-URI@";
- private static final String COMPONENT_SCHEMA_URN = "@COMPONENT-XSD-URI@";
- private static final String PARTIAL_COMPONENT_HEADER =
- "<component xmlns=\""
- + COMPONENT_SCHEMA_URN
- + "\""
- + "\n xmlns:xsi=\""
- + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
- + "\"\n xmlns:part=\""
- + PART_SCHEMA_URN
- + "\"\n xmlns:type=\""
- + TYPE_SCHEMA_URN
- + "\"\n xmlns:component=\""
- + COMPONENT_SCHEMA_URN
- + "\"";
-
- /**
- * Export a component directive to an output stream as XML.
- * @param directive the component directive
- * @param output the output stream
- * @exception IOException if an IO error occurs
- */
- public void export( ComponentDirective directive, OutputStream output )
throws IOException
- {
- final Writer writer = new OutputStreamWriter( output );
-
- writer.write( XML_HEADER );
- writer.write( "\n\n" );
- writer.write( PARTIAL_COMPONENT_HEADER );
- writeAttributes( writer, directive, "" );
- writeBody( writer, directive, " " );
- writer.write( "\n" );
- writer.write( "</component>" );
- writer.write( "\n" );
- writer.flush();
- output.close();
- }
-
- /**
- * Export a component directive to an output stream as XML.
- * @param writer the print writer
- * @param directive the component directive
- * @param pad character offset
- * @exception IOException if an IO error occurs
- */
- public void writeComponent(
- Writer writer, ComponentDirective directive, String pad ) throws
IOException
- {
- writeTaggedComponent( writer, directive, null, pad );
- }
-
- /**
- * Export a tagged component directive to an output stream as XML.
- * @param writer the print writer
- * @param directive the component directive
- * @param key the key identifying the component
- * @param pad character offset
- * @exception IOException if an IO error occurs
- */
- public void writeTaggedComponent(
- Writer writer, ComponentDirective directive, String key, String pad )
throws IOException
- {
- writer.write( "\n" + pad + "<component xmlns=\"" +
COMPONENT_SCHEMA_URN + "\"" );
- if( null != key )
- {
- writer.write( " key=\"" + key + "\"" );
- }
- writer.write( "\n" + pad + " " );
- writeAttributes( writer, directive, pad + " " );
- writeBody( writer, directive, pad + " " );
- writer.write( "\n" + pad + "</component>" );
- }
-
- void writeAttributes(
- Writer writer, ComponentDirective directive, String pad ) throws
IOException
- {
- String classname = directive.getClassname();
- writer.write( " class=\"" + classname + "\"" );
- String name = directive.getName();
- if( null != name )
- {
- writer.write( "\n" + pad + " name=\"" + name + "\"" );
- }
- LifestylePolicy lifestyle = directive.getLifestylePolicy();
- if( null != lifestyle )
- {
- writer.write( "\n" + pad + " lifestyle=\"" + lifestyle.getName()
+ "\"" );
- }
- CollectionPolicy collection = directive.getCollectionPolicy();
- if( null != collection )
- {
- writer.write( "\n" + pad + " collection=\"" +
collection.getName() + "\"" );
- }
- ActivationPolicy activation = directive.getActivationPolicy();
- if( null != activation )
- {
- writer.write( "\n" + pad + " activation=\"" +
activation.getName() + "\"" );
- }
- writer.write( ">" );
- }
-
- void writeBody(
- Writer writer, ComponentDirective directive, String pad ) throws
IOException
- {
- CategoriesDirective categories = directive.getCategoriesDirective();
- ContextDirective context = directive.getContextDirective();
- PartReference[] parts = directive.getPartReferences();
- writeCategoriesDirective( writer, categories, pad );
- writeContextDirective( writer, context, pad );
- writeParts( writer, parts, pad );
- }
-
- private void writeCategoriesDirective(
- Writer writer, CategoriesDirective categories, String pad ) throws
IOException
- {
- String name = categories.getName();
- Priority priority = categories.getPriority();
- String target = categories.getTarget();
- CategoryDirective[] subCategories = categories.getCategories();
-
- if( isaNullValue( name ) && isaNullPriority( priority ) &&
isaNullValue( target )
- && ( subCategories.length == 0 ) )
- {
- return;
- }
-
- writer.write( "\n" + pad + "<categories" );
- if( !isaNullValue( name ) )
- {
- writer.write( " name=\"" + name + "\"" );
- }
- if( !isaNullPriority( priority ) )
- {
- writer.write( " priority=\"" + priority.getName() + "\"" );
- }
- if( !isaNullValue( target ) )
- {
- writer.write( " target=\"" + target + "\"" );
- }
- if( subCategories.length == 0 )
- {
- writer.write( "/>" );
- }
- else
- {
- writer.write( ">" );
- for( int i=0; i<subCategories.length; i++ )
- {
- CategoryDirective directive = subCategories[i];
- if( directive instanceof CategoriesDirective )
- {
- CategoriesDirective c = (CategoriesDirective) directive;
- writeCategoriesDirective( writer, c, pad + " " );
- }
- else
- {
- writeCategoryDirective( writer, directive, pad + " " );
- }
- }
- writer.write( "\n" + pad + "</categories>" );
- }
- }
-
- private boolean isaNullPriority( Priority priority )
- {
- if( null == priority )
- {
- return true;
- }
- else
- {
- return Priority.DEBUG.equals( priority );
- }
- }
-
- private boolean isaNullValue( String value )
- {
- if( null == value )
- {
- return true;
- }
- else
- {
- return "".equals( value );
- }
- }
-
- private void writeCategoryDirective(
- Writer writer, CategoryDirective category, String pad ) throws
IOException
- {
- String name = category.getName();
- Priority priority = category.getPriority();
- String target = category.getTarget();
-
- writer.write( "\n" + pad + "<category" );
- if( null != name )
- {
- writer.write( " name=\"" + name + "\"" );
- }
- if( null != priority )
- {
- writer.write( " priority=\"" + priority.getName() + "\"" );
- }
- if( null != target )
- {
- writer.write( " target=\"" + target + "\"" );
- }
- writer.write( "/>" );
- }
-
- private void writeContextDirective(
- Writer writer, ContextDirective context, String pad ) throws
IOException
- {
- String classname = context.getClassname();
- PartReference[] parts = context.getDirectives();
-
- if( ( null == classname ) && ( parts.length == 0 ) )
- {
- return;
- }
-
- writer.write( "\n" + pad + "<context" );
- if( null != classname )
- {
- writer.write( " class=\"" + classname + "\"" );
- }
- if( parts.length == 0 )
- {
- writer.write( "/>" );
- }
- else
- {
- writer.write( ">" );
- writeContextEntries( writer, parts, pad + " " );
- writer.write( "\n" + pad + "</context>" );
- }
- }
-
- /**
- * Write a collection of part references.
- * @param writer the writer
- * @param parts the part refernece array
- * @param pad the offset
- * @exception IOException if an IO error occurs
- */
- protected void writeParts(
- Writer writer, PartReference[] parts, String pad ) throws IOException
- {
- if( parts.length == 0 )
- {
- return;
- }
- else
- {
- writer.write( "\n" + pad + "<parts>" );
- writePartReferences( writer, parts, pad + " " );
- writer.write( "\n" + pad + "</parts>" );
- }
- }
-
- private void writePartReferences(
- Writer writer, PartReference[] parts, String pad ) throws IOException
- {
- for( int i=0; i<parts.length; i++ )
- {
- PartReference ref = parts[i];
- writePartReference( writer, ref, pad );
- }
- }
-
- private void writeContextEntries(
- Writer writer, PartReference[] parts, String pad ) throws IOException
- {
- for( int i=0; i<parts.length; i++ )
- {
- PartReference ref = parts[i];
- writeContextEntry( writer, ref, pad );
- }
- }
-
- private void writeContextEntry(
- Writer writer, PartReference part, String pad ) throws IOException
- {
- String key = part.getKey();
- if( null == key )
- {
- throw new IllegalStateException( "key" );
- }
- Directive directive = part.getDirective();
- if( null == directive )
- {
- throw new IllegalStateException( "directive" );
- }
- if( directive instanceof ValueDirective )
- {
- ValueDirective value = (ValueDirective) directive;
- writeEntry( writer, key, value, pad );
- }
- else if( directive instanceof LookupDirective )
- {
- LookupDirective value = (LookupDirective) directive;
- writeLookupEntry( writer, key, value, pad );
- }
- else
- {
- String classname = directive.getClass().getName();
- final String message = "WARNING: UNRECOGNIZED ENTRY: "+
classname;
- System.out.println( "# " + message );
- System.out.println( "# key: " + key );
- System.out.println( "# class: " + classname );
- writer.write( "\n" + pad + "<!-- " + message + " -->" );
- writer.write( "\n" + pad + "<!-- " );
- writer.write( "\n" + pad + "key: " + key );
- writer.write( "\n" + pad + "class: " +
directive.getClass().getName() );
- writer.write( "\n" + pad + "-->" );
- }
- }
-
- private void writeLookupEntry(
- Writer writer, String key, LookupDirective directive, String pad )
throws IOException
- {
- String classname = directive.getServiceClassname();
- writer.write( "\n" + pad + "<entry key=\"" + key + "\" lookup=\"" +
classname + "\"/>" );
- }
-
- private void writePartReference(
- Writer writer, PartReference part, String pad ) throws IOException
- {
- String key = part.getKey();
- if( null == key )
- {
- throw new IllegalStateException( "key" );
- }
-
- Directive directive = part.getDirective();
- if( null == directive )
- {
- throw new IllegalStateException( "directive" );
- }
- if( directive instanceof ComponentDirective )
- {
- ComponentDirective component = (ComponentDirective) directive;
- writeTaggedComponent( writer, component, key, pad );
- }
- else
- {
- String classname = directive.getClass().getName();
- final String error =
- "Part reference class not recognized."
- + "\nClass: " + classname;
- throw new IllegalArgumentException( error );
- }
- }
-
- /**
- * Write a context entry.
- * @param writer the writer
- * @param key the entry key
- * @param value the value directive
- * @param pad the offset
- * @exception IOException if an IO error occurs
- */
- protected void writeEntry( Writer writer, String key, ValueDirective
value, String pad ) throws IOException
- {
- String target = value.getTargetExpression();
- String method = value.getMethodName();
-
- writer.write( "\n" + pad + "<entry key=\"" + key + "\"" );
- if( null != target )
- {
- writer.write( " class=\"" + target + "\"" );
- }
- if( null != method )
- {
- writer.write( " method=\"" + method + "\"" );
- }
- Value[] values = value.getValues();
- if( values.length > 0 )
- {
- writer.write( ">" );
- writeValues( writer, values, pad + " " );
- writer.write( "\n" + pad + "</entry>" );
- }
- else
- {
- String v = value.getBaseValue();
- if( null != v )
- {
- writer.write( " value=\"" + v + "\"" );
- }
- writer.write( "/>" );
- }
- }
-}

Deleted:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeBuilder.java
===================================================================
--- trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,308 +0,0 @@
-/*
- * 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.builder;
-
-import java.io.IOException;
-import java.net.URL;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Properties;
-
-import net.dpml.lang.Version;
-import net.dpml.lang.BuilderException;
-
-import net.dpml.metro.data.ComponentDirective;
-import net.dpml.metro.info.Type;
-import net.dpml.metro.info.InfoDescriptor;
-import net.dpml.metro.info.ContextDescriptor;
-import net.dpml.metro.info.CategoryDescriptor;
-import net.dpml.metro.info.ServiceDescriptor;
-import net.dpml.metro.info.EntryDescriptor;
-import net.dpml.metro.info.PartReference;
-import net.dpml.metro.info.CollectionPolicy;
-import net.dpml.metro.info.LifestylePolicy;
-import net.dpml.metro.info.ThreadSafePolicy;
-import net.dpml.metro.info.Priority;
-
-import net.dpml.part.DOM3DocumentBuilder;
-
-import net.dpml.state.State;
-import net.dpml.state.impl.StateBuilder;
-import net.dpml.state.impl.DefaultState;
-
-import net.dpml.transit.util.ElementHelper;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Document;
-
-
-/**
- * Type builder.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public final class TypeBuilder extends TypeWriter
-{
- private static final StateBuilder STATE_BUILDER = new StateBuilder();
-
- private static final DOM3DocumentBuilder BUILDER = new
DOM3DocumentBuilder();
-
- /**
- * Load a type.
- * @param subject the component implementation class
- * @return the component type descriptor
- * @exception IOException if an error occurs reading the type definition
- */
- public Type loadType( Class subject ) throws IOException
- {
- String classname = subject.getName();
- String path = classname.replace( '.', '/' );
- String target = path + ".type";
- ClassLoader classloader = subject.getClassLoader();
- URL url = classloader.getResource( target );
- if( null == url )
- {
- return Type.createType( subject );
- }
- else
- {
- try
- {
- URI uri = new URI( url.toString() );
- return loadType( uri );
- }
- catch( URISyntaxException e )
- {
- final String error =
- "Bad uri value."
- + "\nURI: " + url;
- IOException exception = new IOException( error );
- exception.initCause( e );
- throw exception;
- }
- }
- }
-
- /**
- * Load a type.
- * @param uri the component type source uri
- * @return the component type descriptor
- * @exception IOException if an error occurs reading the type definition
- */
- public Type loadType( URI uri ) throws IOException
- {
- try
- {
- final Document document = BUILDER.parse( uri );
- final Element root = document.getDocumentElement();
- return buildType( root );
- }
- catch( Throwable e )
- {
- final String error =
- "An error while attempting to load a type."
- + "\nType URI: " + uri;
- IOException exception = new IOException( error );
- exception.initCause( e );
- throw exception;
- }
- }
-
- private Type buildType( Element root ) throws Exception
- {
- InfoDescriptor info = buildNestedInfoDescriptor( root );
- ServiceDescriptor[] services = buildNestedServices( root );
- ContextDescriptor context = buildNestedContext( root );
- CategoryDescriptor[] categories = buildNestedCategories( root );
- State state = buildNestedState( root );
- PartReference[] parts = buildNestedParts( root );
- return new Type( info, categories, context, services, parts, state );
- }
-
- private InfoDescriptor buildNestedInfoDescriptor( Element root )
- {
- Element info = ElementHelper.getChild( root, "info" );
- if( null == info )
- {
- final String error =
- "Definition of <type> is missing the required <info> element.";
- throw new BuilderException( root, error );
- }
-
- String name = ElementHelper.getAttribute( info, "name" );
- String classname = ElementHelper.getAttribute( info, "class" );
- String version = ElementHelper.getAttribute( info, "version" );
- String collection = ElementHelper.getAttribute( info, "collection",
"system" );
- String lifestyle = ElementHelper.getAttribute( info, "lifestyle",
"system" );
- String threadsafe = ElementHelper.getAttribute( info, "threadsafe",
"unknown" );
- Properties properties = buildNestedProperties( info );
-
- return new InfoDescriptor(
- name,
- classname,
- Version.getVersion( version ),
- LifestylePolicy.parse( lifestyle ),
- CollectionPolicy.parse( collection ),
- ThreadSafePolicy.parse( threadsafe ),
- properties );
- }
-
- private ServiceDescriptor[] buildNestedServices( Element root )
- {
- Element element = ElementHelper.getChild( root, "services" );
- if( null == element )
- {
- return new ServiceDescriptor[0];
- }
- else
- {
- Element[] children = ElementHelper.getChildren( element,
"service" );
- ServiceDescriptor[] services = new ServiceDescriptor[
children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- String classname = ElementHelper.getAttribute( child,
"class" );
- String version = ElementHelper.getAttribute( child,
"version", "1.0.0" );
- services[i] = new ServiceDescriptor( classname,
Version.getVersion( version ) );
- }
- return services;
- }
- }
-
- private ContextDescriptor buildNestedContext( Element root )
- {
- Element context = ElementHelper.getChild( root, "context" );
- if( null == context )
- {
- return new ContextDescriptor( new EntryDescriptor[0] );
- }
- else
- {
- Element[] children = ElementHelper.getChildren( context, "entry"
);
- EntryDescriptor[] entries = new EntryDescriptor[ children.length
];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- String key = ElementHelper.getAttribute( child, "key" );
- String classname = ElementHelper.getAttribute( child,
"class" );
- boolean optional = ElementHelper.getBooleanAttribute( child,
"optional", false );
- boolean isVolatile = ElementHelper.getBooleanAttribute(
child, "volatile", false );
- entries[i] = new EntryDescriptor( key, classname, optional,
isVolatile );
- }
- return new ContextDescriptor( entries );
- }
- }
-
- private CategoryDescriptor[] buildNestedCategories( Element root )
- {
- Element element = ElementHelper.getChild( root, "categories" );
- if( null == element )
- {
- return new CategoryDescriptor[0];
- }
- else
- {
- Element[] children = ElementHelper.getChildren( element,
"category" );
- CategoryDescriptor[] categories = new CategoryDescriptor[
children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element elem = children[i];
- String name = ElementHelper.getAttribute( elem, "name" );
- String priority = ElementHelper.getAttribute( elem,
"priority" );
- Properties properties = buildNestedProperties( elem );
- categories[i] = new CategoryDescriptor( name,
Priority.parse( priority ), properties );
- }
- return categories;
- }
- }
-
- private State buildNestedState( Element root )
- {
- // ISSUE: selection does not support namespace resolution
- // and will fail with something like <acme:state>
-
- Element element = ElementHelper.getChild( root, "state" );
- if( null == element )
- {
- return new DefaultState();
- }
- else
- {
- return STATE_BUILDER.buildStateGraph( element );
- }
- }
-
- private PartReference[] buildNestedParts( Element root ) throws Exception
- {
- Element element = ElementHelper.getChild( root, "parts" );
- if( null == element )
- {
- return new PartReference[0];
- }
- else
- {
- Element[] children = ElementHelper.getChildren( element );
- if( children.length == 0 )
- {
- return new PartReference[0];
- }
- else
- {
- PartReference[] refs = new PartReference[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- refs[i] = buildPartReference( child );
- }
- return refs;
- }
- }
- }
-
- private PartReference buildPartReference( Element element ) throws
Exception
- {
- String key = ElementHelper.getAttribute( element, "key" );
- ComponentDirective definition = COMPONENT_BUILDER.buildComponent(
element );
- return new PartReference( key, definition );
- }
-
- private Properties buildNestedProperties( Element element )
- {
- Element[] entries = ElementHelper.getChildren( element, "property" );
- if( entries.length == 0 )
- {
- return null;
- }
- else
- {
- Properties properties = new Properties();
- for( int i=0; i<entries.length; i++ )
- {
- Element elem = entries[i];
- String name = ElementHelper.getAttribute( elem, "name" );
- String value = ElementHelper.getAttribute( elem, "value" );
- properties.setProperty( name, value );
- }
- return properties;
- }
- }
-
-}
-

Deleted:
trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeWriter.java
===================================================================
--- trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeWriter.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/builder/src/main/net/dpml/metro/builder/TypeWriter.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,245 +0,0 @@
-/*
- * 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.builder;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-
-import javax.xml.XMLConstants;
-
-import net.dpml.metro.info.Type;
-import net.dpml.metro.info.InfoDescriptor;
-import net.dpml.metro.info.ContextDescriptor;
-import net.dpml.metro.info.CategoryDescriptor;
-import net.dpml.metro.info.ServiceDescriptor;
-import net.dpml.metro.info.EntryDescriptor;
-import net.dpml.metro.info.PartReference;
-import net.dpml.metro.info.Descriptor;
-
-import net.dpml.state.State;
-import net.dpml.state.impl.StateBuilder;
-
-import net.dpml.part.ValueWriter;
-
-/**
- * Type builder.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-//public class TypeWriter extends ComponentBuilder
-public class TypeWriter extends ValueWriter
-{
- private static final String XML_HEADER =
- "<?xml version=\"1.0\"?>";
-
- private static final String PART_SCHEMA_URN = "@PART-XSD-URI@";
- private static final String COMPONENT_SCHEMA_URN = "@COMPONENT-XSD-URI@";
- private static final String TYPE_SCHEMA_URN = "@TYPE-XSD-URI@";
-
- private static final StateBuilder STATE_BUILDER = new StateBuilder();
-
- static final ComponentBuilder COMPONENT_BUILDER = new ComponentBuilder();
-
- private static final String HEADER =
- "<type xmlns=\""
- + TYPE_SCHEMA_URN
- + "\""
- + "\n xmlns:xsi=\""
- + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
- + "\"\n xmlns:part=\""
- + PART_SCHEMA_URN
- + "\"\n xmlns:type=\""
- + TYPE_SCHEMA_URN
- + "\"\n xmlns:component=\""
- + COMPONENT_SCHEMA_URN
- + "\">";
-
- private static final String FOOTER = "</type>";
-
- /**
- * Write the supplied type to an output stream.
- * @param type the type descriptor
- * @param output the output stream
- * @exception IOException if an IO error occurs
- */
- public void export( Type type, OutputStream output ) throws IOException
- {
- final Writer writer = new OutputStreamWriter( output );
- writer.write( XML_HEADER );
- writer.write( "\n\n" );
- writer.write( HEADER );
- writer.write( "\n" );
- writeBody( writer, type, " " );
- writer.write( "\n" );
- writer.write( FOOTER );
- writer.write( "\n" );
- writer.flush();
- output.close();
- }
-
- private void writeBody( Writer writer, Type type, String pad ) throws
IOException
- {
- writeTypeInfo( writer, type.getInfo(), pad );
- writeTypeServices( writer, type.getServiceDescriptors(), pad );
- writeTypeContext( writer, type.getContextDescriptor(), pad );
- writeTypeCategories( writer, type.getCategoryDescriptors(), pad );
- writeTypeState( writer, type.getStateGraph(), pad );
- writeTypeParts( writer, type.getPartReferences(), pad );
- }
-
- private void writeTypeInfo( Writer writer, InfoDescriptor info, String
pad ) throws IOException
- {
- writer.write( "\n" + pad + "<info" );
- writer.write( " name=\"" + info.getName() );
- writer.write( "\"\n" + pad + " class=\"" + info.getClassname() );
- writer.write( "\"\n" + pad + " version=\"" + info.getVersion() );
- writer.write( "\"\n" + pad + " lifestyle=\"" +
info.getLifestyle().getName().toLowerCase() );
- writer.write( "\"\n" + pad + " collection=\"" +
info.getCollectionPolicy().getName().toLowerCase() );
- writer.write( "\"\n" + pad + " threadsafe=\"" +
info.getThreadSafePolicy().getName().toLowerCase() );
- writer.write( "\"" );
- if( info.getAttributeNames().length > 0 )
- {
- writer.write( ">" );
- writeAttributes( writer, info, pad + " " );
- writer.write( "\n" + pad + "</info>" );
- }
- else
- {
- writer.write( "/>" );
- }
- }
-
- private void writeTypeServices( Writer writer, ServiceDescriptor[]
services, String pad ) throws IOException
- {
- if( services.length == 0 )
- {
- return;
- }
- else
- {
- writer.write( "\n" + pad + "<services>" );
- for( int i=0; i<services.length; i++ )
- {
- ServiceDescriptor service = services[i];
- writer.write( "\n" + pad + " <service" );
- writer.write( " class=\"" + service.getClassname() );
- writer.write( "\" version=\"" + service.getVersion() );
- writer.write( "\"/>" );
- }
- writer.write( "\n" + pad + "</services>" );
- }
- }
-
- private void writeTypeContext( Writer writer, ContextDescriptor context,
String pad ) throws IOException
- {
- EntryDescriptor[] entries = context.getEntryDescriptors();
- if( entries.length > 0 )
- {
- writer.write( "\n" + pad + "<context>" );
- for( int i=0; i<entries.length; i++ )
- {
- EntryDescriptor entry = entries[i];
- writer.write( "\n" + pad + " <entry" );
- writer.write( " key=\"" + entry.getKey() );
- writer.write( "\" class=\"" + entry.getClassname() );
- if( entry.isOptional() )
- {
- writer.write( "\" optional=\"true\"" );
- }
- else
- {
- writer.write( "\" optional=\"false\"" );
- }
- if( entry.isVolatile() )
- {
- writer.write( "\" volatile=\"true\"" );
- }
- writer.write( "/>" );
- }
- writer.write( "\n" + pad + "</context>" );
- }
- else
- {
- return;
- }
- }
-
- private void writeTypeCategories( Writer writer, CategoryDescriptor[]
categories, String pad ) throws IOException
- {
- if( categories.length > 0 )
- {
- writer.write( "\n" + pad + "<categories>" );
- for( int i=0; i<categories.length; i++ )
- {
- CategoryDescriptor category = categories[i];
- writer.write( "\n" + pad + " <category" );
- writer.write( " name=\"" + category.getName() );
- writer.write(
- "\" priority=\""
- + category.getDefaultPriority().getName().toLowerCase() );
- writer.write( "\"" );
-
- if( category.getAttributeNames().length > 0 )
- {
- writer.write( ">" );
- writeAttributes( writer, category, pad + " " );
- writer.write( "\n" + pad + " </category>" );
- }
- else
- {
- writer.write( "/>" );
- }
- }
- writer.write( "\n" + pad + "</categories>" );
- }
- else
- {
- return;
- }
- }
-
- private void writeTypeState( Writer writer, State state, String pad )
throws IOException
- {
- STATE_BUILDER.writeState( writer, state, pad );
- writer.write( "\n" );
- }
-
- private void writeTypeParts( Writer writer, PartReference[] parts,
String pad ) throws IOException
- {
- COMPONENT_BUILDER.writeParts( writer, parts, pad );
- }
-
- private void writeAttributes( Writer writer, Descriptor descriptor,
String pad ) throws IOException
- {
- String[] names = descriptor.getAttributeNames();
- for( int i=0; i<names.length; i++ )
- {
- String name = names[i];
- String value = descriptor.getAttribute( name, "" );
- writer.write( "\n" + pad + "<property" );
- writer.write( " name=\"" + name );
- writer.write( "\" value=\"" + value );
- writer.write( "\"/>" );
- }
- }
-}
-

Modified:
trunk/main/metro/builder/src/test/net/dpml/metro/builder/LookupTestCase.java
===================================================================
---
trunk/main/metro/builder/src/test/net/dpml/metro/builder/LookupTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/test/net/dpml/metro/builder/LookupTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -37,7 +37,7 @@
*/
public class LookupTestCase extends TestCase
{
- private ComponentBuilder m_builder;
+ private ComponentDecoder m_builder;

/**
* Testcase setup.
@@ -45,7 +45,7 @@
*/
public void setUp() throws Exception
{
- m_builder = new ComponentBuilder();
+ m_builder = new ComponentDecoder();
}

/**

Modified:
trunk/main/metro/builder/src/test/net/dpml/metro/builder/MinimalTestCase.java
===================================================================
---
trunk/main/metro/builder/src/test/net/dpml/metro/builder/MinimalTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/test/net/dpml/metro/builder/MinimalTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -32,7 +32,7 @@
*/
public class MinimalTestCase extends TestCase
{
- private ComponentBuilder m_builder;
+ private ComponentDecoder m_builder;

/**
* Testcase setup.
@@ -40,7 +40,7 @@
*/
public void setUp() throws Exception
{
- m_builder = new ComponentBuilder();
+ m_builder = new ComponentDecoder();
}

/**

Modified:
trunk/main/metro/builder/src/test/net/dpml/metro/builder/PartsTestCase.java
===================================================================
---
trunk/main/metro/builder/src/test/net/dpml/metro/builder/PartsTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/test/net/dpml/metro/builder/PartsTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -38,7 +38,7 @@
*/
public class PartsTestCase extends TestCase
{
- private ComponentBuilder m_builder;
+ private ComponentDecoder m_builder;

/**
* Testcase setup.
@@ -46,7 +46,7 @@
*/
public void setUp() throws Exception
{
- m_builder = new ComponentBuilder();
+ m_builder = new ComponentDecoder();
}

/**

Modified:
trunk/main/metro/builder/src/test/net/dpml/metro/builder/TypesTestCase.java
===================================================================
---
trunk/main/metro/builder/src/test/net/dpml/metro/builder/TypesTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/builder/src/test/net/dpml/metro/builder/TypesTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -34,7 +34,7 @@
*/
public class TypesTestCase extends TestCase
{
- private TypeBuilder m_builder;
+ private ComponentTypeDecoder m_builder;

/**
* Testcase setup.
@@ -42,7 +42,7 @@
*/
public void setUp() throws Exception
{
- m_builder = new TypeBuilder();
+ m_builder = new ComponentTypeDecoder();
}

/**

Modified: trunk/main/metro/module.xml
===================================================================
--- trunk/main/metro/module.xml 2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/module.xml 2006-03-20 09:50:38 UTC (rev 1230)
@@ -74,7 +74,7 @@
<project name="dpml-metro-builder" basedir="builder">
<types>
<type id="jar"/>
- <part:plugin alias="true"
class="net.dpml.metro.builder.ComponentStrategyBuilder"/>
+ <part:plugin alias="true"
class="net.dpml.metro.builder.ComponentBuilder"/>
</types>
<dependencies>
<include key="dpml-metro-model"/>

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -50,7 +50,7 @@
import net.dpml.metro.ComponentModel;
import net.dpml.metro.ContextModel;
import net.dpml.metro.PartsManager;
-import net.dpml.metro.builder.TypeBuilder;
+import net.dpml.metro.builder.ComponentTypeDecoder;

import net.dpml.parameters.Parameters;

@@ -66,7 +66,7 @@
// static

//--------------------------------------------------------------------------

- private static final TypeBuilder BUILDER = new TypeBuilder();
+ private static final ComponentTypeDecoder BUILDER = new
ComponentTypeDecoder();


//--------------------------------------------------------------------------
// state

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -43,7 +43,8 @@
import net.dpml.component.Component;

import net.dpml.part.Part;
-import net.dpml.part.PartBuilder;
+import net.dpml.part.PartDecoder;
+import net.dpml.part.DecoderFactory;
import net.dpml.part.StandardPartHandler;
import net.dpml.part.Strategy;

@@ -68,21 +69,14 @@
private static final String COMPONENT_NAMESPACE_URI =
"@COMPONENT-NAMESPACE-URI@";
private static final String COMPONENT_BUILDER_URI =
"@COMPONENT-BUILDER-URI@";

- static final PartBuilder BUILDER = createPartBuilder();
+ static final PartDecoder BUILDER = createPartDecoder();

- private static PartBuilder createPartBuilder()
+ private static PartDecoder createPartDecoder()
{
Map map = new Hashtable();
- try
- {
- map.put( COMPONENT_NAMESPACE_URI, new URI( COMPONENT_BUILDER_URI
) );
- return new PartBuilder( map );
- }
- catch( Exception e )
- {
- e.printStackTrace();
- return new PartBuilder();
- }
+ map.put( COMPONENT_NAMESPACE_URI, createStaticURI(
COMPONENT_BUILDER_URI ) );
+ DecoderFactory factory = new DecoderFactory( map );
+ return new PartDecoder( factory );
}

//--------------------------------------------------------------------

Deleted:
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateBuilder.java
===================================================================
---
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,272 +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 net.dpml.state.impl;
-
-import java.io.IOException;
-import java.net.URI;
-
-import javax.xml.XMLConstants;
-
-import net.dpml.state.State;
-import net.dpml.state.Action;
-import net.dpml.state.Trigger.TriggerEvent;
-import net.dpml.state.StateBuilderRuntimeException;
-
-import net.dpml.part.DOM3DocumentBuilder;
-
-import net.dpml.transit.util.ElementHelper;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- * Construct a state graph.
- */
-public class StateBuilder extends StateWriter
-{
- private static final String XML_HEADER =
- "<?xml version=\"1.0\"?>";
-
- private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
-
- private static final String STATE_HEADER =
- "<state xmlns=\""
- + STATE_SCHEMA_URN
- + "\""
- + "\n xmlns:xsi=\""
- + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
- + "\">";
-
- private static final String STATE_FOOTER = "</state>";
-
- private static final DOM3DocumentBuilder BUILDER = new
DOM3DocumentBuilder();
-
- /**
- * Load a state graph.
- * @param uri the graph uri
- * @return the constructed state graph
- * @exception IOException if an IO error occurs while reading the
- * graph data
- */
- public State loadState( URI uri ) throws IOException
- {
- if( null == uri )
- {
- throw new NullPointerException( "uri" );
- }
- try
- {
- final Document document = BUILDER.parse( uri );
- final Element root = document.getDocumentElement();
- return buildStateGraph( root );
- }
- catch( Throwable e )
- {
- final String error =
- "An error while attempting to load a state graph."
- + "\nURI: " + uri;
- IOException exception = new IOException( error );
- exception.initCause( e );
- throw exception;
- }
- }
-
- /**
- * Build a state graph.
- * @param element a DOM element representing the root of the state graph
- * @return the constructed state
- */
- public State buildStateGraph( Element element )
- {
- if( null == element )
- {
- throw new NullPointerException( "element" );
- }
-
- boolean terminal = ElementHelper.getBooleanAttribute( element,
"terminal" );
- DefaultTransition[] transitions = buildNestedTransitions( element );
- DefaultOperation[] operations = buildNestedOperations( element );
- DefaultInterface[] interfaces = buildNestedInterfaces( element );
- DefaultState[] states = buildNestedStates( 1, element );
- DefaultTrigger[] triggers = buildNestedTriggers( element );
- return new DefaultState(
- "root", triggers, transitions, interfaces, operations, states,
terminal );
- }
-
- private DefaultTransition[] buildNestedTransitions( Element element )
- {
- Element[] children = ElementHelper.getChildren( element,
"transition" );
- DefaultTransition[] transitions = new DefaultTransition[
children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- transitions[i] = buildTransition( child );
- }
- return transitions;
- }
-
- private DefaultOperation[] buildNestedOperations( Element element )
- {
- Element[] children = ElementHelper.getChildren( element, "operation"
);
- DefaultOperation[] operations = new DefaultOperation[
children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- operations[i] = buildOperation( child );
- }
- return operations;
- }
-
- private DefaultInterface[] buildNestedInterfaces( Element element )
- {
- Element[] children = ElementHelper.getChildren( element, "interface"
);
- DefaultInterface[] interfaces = new DefaultInterface[
children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- interfaces[i] = buildInterface( child );
- }
- return interfaces;
- }
-
- private DefaultState[] buildNestedStates( int n, Element element )
- {
- Element[] children = ElementHelper.getChildren( element, "state" );
- DefaultState[] states = new DefaultState[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- states[i] = buildState( n, child );
- }
- return states;
- }
-
- private DefaultTrigger[] buildNestedTriggers( Element element )
- {
- Element[] children = ElementHelper.getChildren( element, "trigger" );
- DefaultTrigger[] triggers = new DefaultTrigger[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- triggers[i] = buildTrigger( child );
- }
- return triggers;
- }
-
- private DefaultTransition buildTransition( Element element )
- {
- String name = ElementHelper.getAttribute( element, "name" );
- String target = ElementHelper.getAttribute( element, "target" );
- Element child = ElementHelper.getChild( element, "operation" );
- DefaultOperation operation = buildOperation( child );
- return new DefaultTransition( name, target, operation );
- }
-
- private DefaultOperation buildOperation( Element element )
- {
- if( null == element )
- {
- return null;
- }
- String name = ElementHelper.getAttribute( element, "name" );
- String method = ElementHelper.getAttribute( element, "method" );
- return new DefaultOperation( name, method );
- }
-
- private DefaultInterface buildInterface( Element element )
- {
- String classname = ElementHelper.getAttribute( element, "class" );
- return new DefaultInterface( classname );
- }
-
- private DefaultState buildState( int n, Element element )
- {
- String name = ElementHelper.getAttribute( element, "name" );
- boolean terminal = ElementHelper.getBooleanAttribute( element,
"terminal" );
- DefaultTransition[] transitions = buildNestedTransitions( element );
- DefaultOperation[] operations = buildNestedOperations( element );
- DefaultInterface[] interfaces = buildNestedInterfaces( element );
- DefaultState[] states = buildNestedStates( n+1, element );
- DefaultTrigger[] triggers = buildNestedTriggers( element );
- return new DefaultState(
- name, triggers, transitions, interfaces, operations, states,
terminal );
- }
-
- private DefaultTrigger buildTrigger( Element element )
- {
- String type = ElementHelper.getAttribute( element, "event" );
- TriggerEvent event = TriggerEvent.parse( type );
- Element child = getSingleNestedElement( element );
- Action action = buildAction( child );
- return new DefaultTrigger( event, action );
- }
-
- private Action buildAction( Element element )
- {
- String name = element.getTagName();
- if( name.equals( "transition" ) )
- {
- return buildTransition( element );
- }
- else if( name.equals( "operation" ) )
- {
- return buildOperation( element );
- }
- else if( name.equals( "apply" ) )
- {
- String id = ElementHelper.getAttribute( element, "id" );
- return new ApplyAction( id );
- }
- else if( name.equals( "exec" ) )
- {
- String id = ElementHelper.getAttribute( element, "id" );
- return new ExecAction( id );
- }
- else
- {
- final String error =
- "Illegal element name ["
- + name
- + "] supplied to action builder.";
- throw new StateBuilderRuntimeException( error );
- }
- }
-
- private Element getSingleNestedElement( Element parent )
- {
- 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 );
- }
- }
- }
-}

Copied:
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateDecoder.java
(from rev 1216,
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateBuilder.java)
===================================================================
---
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateBuilder.java
2006-03-18 20:35:20 UTC (rev 1216)
+++
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateDecoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,272 @@
+/*
+ * 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 net.dpml.state.impl;
+
+import java.io.IOException;
+import java.net.URI;
+
+import javax.xml.XMLConstants;
+
+import net.dpml.state.State;
+import net.dpml.state.Action;
+import net.dpml.state.Trigger.TriggerEvent;
+import net.dpml.state.StateBuilderRuntimeException;
+
+import net.dpml.part.DOM3DocumentBuilder;
+
+import net.dpml.transit.util.ElementHelper;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Construct a state graph.
+ */
+public class StateDecoder
+{
+ private static final String XML_HEADER =
+ "<?xml version=\"1.0\"?>";
+
+ private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
+
+ private static final String STATE_HEADER =
+ "<state xmlns=\""
+ + STATE_SCHEMA_URN
+ + "\""
+ + "\n xmlns:xsi=\""
+ + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
+ + "\">";
+
+ private static final String STATE_FOOTER = "</state>";
+
+ private static final DOM3DocumentBuilder BUILDER = new
DOM3DocumentBuilder();
+
+ /**
+ * Load a state graph.
+ * @param uri the graph uri
+ * @return the constructed state graph
+ * @exception IOException if an IO error occurs while reading the
+ * graph data
+ */
+ public State loadState( URI uri ) throws IOException
+ {
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+ try
+ {
+ final Document document = BUILDER.parse( uri );
+ final Element root = document.getDocumentElement();
+ return buildStateGraph( root );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "An error while attempting to load a state graph."
+ + "\nURI: " + uri;
+ IOException exception = new IOException( error );
+ exception.initCause( e );
+ throw exception;
+ }
+ }
+
+ /**
+ * Build a state graph.
+ * @param element a DOM element representing the root of the state graph
+ * @return the constructed state
+ */
+ public State buildStateGraph( Element element )
+ {
+ if( null == element )
+ {
+ throw new NullPointerException( "element" );
+ }
+
+ boolean terminal = ElementHelper.getBooleanAttribute( element,
"terminal" );
+ DefaultTransition[] transitions = buildNestedTransitions( element );
+ DefaultOperation[] operations = buildNestedOperations( element );
+ DefaultInterface[] interfaces = buildNestedInterfaces( element );
+ DefaultState[] states = buildNestedStates( 1, element );
+ DefaultTrigger[] triggers = buildNestedTriggers( element );
+ return new DefaultState(
+ "root", triggers, transitions, interfaces, operations, states,
terminal );
+ }
+
+ private DefaultTransition[] buildNestedTransitions( Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element,
"transition" );
+ DefaultTransition[] transitions = new DefaultTransition[
children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ transitions[i] = buildTransition( child );
+ }
+ return transitions;
+ }
+
+ private DefaultOperation[] buildNestedOperations( Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element, "operation"
);
+ DefaultOperation[] operations = new DefaultOperation[
children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ operations[i] = buildOperation( child );
+ }
+ return operations;
+ }
+
+ private DefaultInterface[] buildNestedInterfaces( Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element, "interface"
);
+ DefaultInterface[] interfaces = new DefaultInterface[
children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ interfaces[i] = buildInterface( child );
+ }
+ return interfaces;
+ }
+
+ private DefaultState[] buildNestedStates( int n, Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element, "state" );
+ DefaultState[] states = new DefaultState[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ states[i] = buildState( n, child );
+ }
+ return states;
+ }
+
+ private DefaultTrigger[] buildNestedTriggers( Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element, "trigger" );
+ DefaultTrigger[] triggers = new DefaultTrigger[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ triggers[i] = buildTrigger( child );
+ }
+ return triggers;
+ }
+
+ private DefaultTransition buildTransition( Element element )
+ {
+ String name = ElementHelper.getAttribute( element, "name" );
+ String target = ElementHelper.getAttribute( element, "target" );
+ Element child = ElementHelper.getChild( element, "operation" );
+ DefaultOperation operation = buildOperation( child );
+ return new DefaultTransition( name, target, operation );
+ }
+
+ private DefaultOperation buildOperation( Element element )
+ {
+ if( null == element )
+ {
+ return null;
+ }
+ String name = ElementHelper.getAttribute( element, "name" );
+ String method = ElementHelper.getAttribute( element, "method" );
+ return new DefaultOperation( name, method );
+ }
+
+ private DefaultInterface buildInterface( Element element )
+ {
+ String classname = ElementHelper.getAttribute( element, "class" );
+ return new DefaultInterface( classname );
+ }
+
+ private DefaultState buildState( int n, Element element )
+ {
+ String name = ElementHelper.getAttribute( element, "name" );
+ boolean terminal = ElementHelper.getBooleanAttribute( element,
"terminal" );
+ DefaultTransition[] transitions = buildNestedTransitions( element );
+ DefaultOperation[] operations = buildNestedOperations( element );
+ DefaultInterface[] interfaces = buildNestedInterfaces( element );
+ DefaultState[] states = buildNestedStates( n+1, element );
+ DefaultTrigger[] triggers = buildNestedTriggers( element );
+ return new DefaultState(
+ name, triggers, transitions, interfaces, operations, states,
terminal );
+ }
+
+ private DefaultTrigger buildTrigger( Element element )
+ {
+ String type = ElementHelper.getAttribute( element, "event" );
+ TriggerEvent event = TriggerEvent.parse( type );
+ Element child = getSingleNestedElement( element );
+ Action action = buildAction( child );
+ return new DefaultTrigger( event, action );
+ }
+
+ private Action buildAction( Element element )
+ {
+ String name = element.getTagName();
+ if( name.equals( "transition" ) )
+ {
+ return buildTransition( element );
+ }
+ else if( name.equals( "operation" ) )
+ {
+ return buildOperation( element );
+ }
+ else if( name.equals( "apply" ) )
+ {
+ String id = ElementHelper.getAttribute( element, "id" );
+ return new ApplyAction( id );
+ }
+ else if( name.equals( "exec" ) )
+ {
+ String id = ElementHelper.getAttribute( element, "id" );
+ return new ExecAction( id );
+ }
+ else
+ {
+ final String error =
+ "Illegal element name ["
+ + name
+ + "] supplied to action builder.";
+ throw new StateBuilderRuntimeException( error );
+ }
+ }
+
+ private Element getSingleNestedElement( Element parent )
+ {
+ 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 );
+ }
+ }
+ }
+}

Copied:
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateEncoder.java
(from rev 1216,
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateWriter.java)
===================================================================
--- trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateWriter.java
2006-03-18 20:35:20 UTC (rev 1216)
+++
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateEncoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,337 @@
+/*
+ * 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 net.dpml.state.impl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+
+import javax.xml.XMLConstants;
+
+import net.dpml.state.State;
+import net.dpml.state.Action;
+import net.dpml.state.Trigger.TriggerEvent;
+import net.dpml.state.Trigger;
+import net.dpml.state.Transition;
+import net.dpml.state.Operation;
+import net.dpml.state.Interface;
+
+/**
+ * Construct a state graph.
+ */
+public class StateEncoder
+{
+ private static final String XML_HEADER =
+ "<?xml version=\"1.0\"?>";
+
+ private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
+
+ /**
+ * Externalize the part to XML.
+ * @param state the state graph to externalize
+ * @param output the output stream
+ * @exception IOException if an IO error occurs
+ */
+ public void export( State state, OutputStream output ) throws IOException
+ {
+ final Writer writer = new OutputStreamWriter( output );
+
+ writer.write( XML_HEADER );
+ writer.write( "\n\n" );
+ writer.write( "<state xmlns=\""
+ + STATE_SCHEMA_URN
+ + "\""
+ + "\n xmlns:xsi=\""
+ + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
+ + "\"" );
+ if( state.isTerminal() )
+ {
+ writer.write( " terminal=\"true\">" );
+ }
+ else
+ {
+ writer.write( ">" );
+ }
+ writer.write( "\n" );
+ writeBody( writer, state, "" );
+ writer.write( "\n" );
+ writer.write( "\n</state>" );
+ writer.write( "\n" );
+ writer.flush();
+ output.close();
+ }
+
+ /**
+ * Write the state.
+ * @param writer the stream writer
+ * @param state the state to externalize
+ * @param pad the pad offset
+ * @exception IOException if an IO error occurs
+ */
+ public void writeState( Writer writer, State state, String pad ) throws
IOException
+ {
+ if( isEmpty( state ) )
+ {
+ return;
+ }
+ else
+ {
+ writer.write( "\n" + pad + "<state xmlns=\"" + STATE_SCHEMA_URN
+ "\"" );
+ if( state.isTerminal() )
+ {
+ writer.write( " terminal=\"true\"" );
+ }
+ writer.write( ">" );
+ writeBody( writer, state, pad + " " );
+ writer.write( "\n" + pad + "</state>" );
+ }
+ }
+
+ private void writeBody( Writer writer, State state, String pad ) throws
IOException
+ {
+ Trigger[] triggers = state.getTriggers();
+ Transition[] transitions = state.getTransitions();
+ Operation[] operations = state.getOperations();
+ Interface[] interfaces = state.getInterfaces();
+ State[] states = state.getStates();
+
+ writeTriggers( writer, triggers, pad );
+ writeTransitions( writer, transitions, pad );
+ writeOperations( writer, operations, pad );
+ writeInterfaces( writer, interfaces, pad );
+ writeStates( writer, states, pad );
+ }
+
+ private void writeTriggers( Writer writer, Trigger[] triggers, String
pad ) throws IOException
+ {
+ if( triggers.length == 0 )
+ {
+ return;
+ }
+ else
+ {
+ for( int i=0; i<triggers.length; i++ )
+ {
+ Trigger trigger = triggers[i];
+ writeTrigger( writer, trigger, pad );
+ }
+ }
+ }
+
+ private void writeTrigger( Writer writer, Trigger trigger, String pad )
throws IOException
+ {
+ TriggerEvent event = trigger.getEvent();
+ writer.write( "\n" + pad + "<trigger event=\"" );
+ writer.write( event.getName() );
+ writer.write( "\">" );
+ Action action = trigger.getAction();
+ writeAction( writer, action, pad + " " );
+ writer.write( "\n" + pad + "</trigger>" );
+ }
+
+ private void writeTransitions( Writer writer, Transition[] transitions,
String pad ) throws IOException
+ {
+ if( transitions.length == 0 )
+ {
+ return;
+ }
+ else
+ {
+ for( int i=0; i<transitions.length; i++ )
+ {
+ Transition transition = transitions[i];
+ writeTransition( writer, transition, pad );
+ }
+ }
+ }
+
+ private void writeOperations( Writer writer, Operation[] operations,
String pad ) throws IOException
+ {
+ if( operations.length == 0 )
+ {
+ return;
+ }
+ else
+ {
+ for( int i=0; i<operations.length; i++ )
+ {
+ Operation operation = operations[i];
+ writeOperation( writer, operation, pad );
+ }
+ }
+ }
+
+ private void writeInterfaces( Writer writer, Interface[] interfaces,
String pad ) throws IOException
+ {
+ if( interfaces.length == 0 )
+ {
+ return;
+ }
+ else
+ {
+ for( int i=0; i<interfaces.length; i++ )
+ {
+ Interface spec = interfaces[i];
+ writeInterface( writer, spec, pad );
+ }
+ }
+ }
+
+ private void writeStates( Writer writer, State[] states, String pad )
throws IOException
+ {
+ if( states.length == 0 )
+ {
+ return;
+ }
+ else
+ {
+ for( int i=0; i<states.length; i++ )
+ {
+ State state = states[i];
+ writeNestedState( writer, state, pad );
+ }
+ }
+ }
+
+ private void writeTransition( Writer writer, Transition transition,
String pad ) throws IOException
+ {
+ String name = transition.getName();
+ String target = transition.getTargetName();
+ writer.write( "\n" + pad + "<transition name=\"" + name + "\"
target=\"" + target + "\"" );
+ Operation operation = transition.getOperation();
+ if( null == operation )
+ {
+ writer.write( "/>" );
+ }
+ else
+ {
+ writer.write( ">" );
+ writeOperation( writer, operation, pad + " " );
+ writer.write( "\n" + pad + "</transition>" );
+ }
+ }
+
+ private void writeOperation( Writer writer, Operation operation, String
pad ) throws IOException
+ {
+ String name = operation.getName();
+ String method = operation.getMethodName();
+ writer.write( "\n" + pad + "<operation name=\"" + name + "\"" );
+ if( null != method )
+ {
+ writer.write( " method=\"" + method + "\"" );
+ }
+ writer.write( "/>" );
+ }
+
+ private void writeInterface( Writer writer, Interface spec, String pad )
throws IOException
+ {
+ String classname = spec.getClassname();
+ writer.write( "\n" + pad + "<interface class=\"" + classname +
"\"/>" );
+ }
+
+ private void writeAction( Writer writer, Action action, String pad )
throws IOException
+ {
+ if( action instanceof Transition )
+ {
+ Transition transition = (Transition) action;
+ writeTransition( writer, transition, pad );
+ }
+ else if( action instanceof Operation )
+ {
+ Operation operation = (Operation) action;
+ writeOperation( writer, operation, pad );
+ }
+ else if( action instanceof Interface )
+ {
+ Interface spec = (Interface) action;
+ writeInterface( writer, spec, pad );
+ }
+ else if( action instanceof ExecAction )
+ {
+ ExecAction exec = (ExecAction) action;
+ writeExecAction( writer, exec, pad );
+ }
+ else if( action instanceof ApplyAction )
+ {
+ ApplyAction apply = (ApplyAction) action;
+ writeApplyAction( writer, apply, pad );
+ }
+ else
+ {
+ final String error =
+ "Unrecognized action class ["
+ + action.getClass().getName()
+ + "].";
+ throw new IOException( error );
+ }
+ }
+ private void writeExecAction( Writer writer, ExecAction action, String
pad ) throws IOException
+ {
+ String id = action.getID();
+ writer.write( "\n" + pad + "<exec id=\"" + id + "\"/>" );
+ }
+
+ private void writeApplyAction( Writer writer, ApplyAction action, String
pad ) throws IOException
+ {
+ String id = action.getID();
+ writer.write( "\n" + pad + "<apply id=\"" + id + "\"/>" );
+ }
+
+ private void writeNestedState( Writer writer, State state, String pad )
throws IOException
+ {
+ String name = state.getName();
+ writer.write( "\n" + pad + "<state name=\"" + name + "\"" );
+ if( state.isTerminal() )
+ {
+ writer.write( " terminal=\"true\">" );
+ }
+ else
+ {
+ writer.write( ">" );
+ }
+ writeBody( writer, state, pad + " " );
+ writer.write( "\n" + pad + "</state>" );
+ }
+
+ private boolean isEmpty( State state )
+ {
+ if( state.getTriggers().length > 0 )
+ {
+ return false;
+ }
+ if( state.getTransitions().length > 0 )
+ {
+ return false;
+ }
+ if( state.getOperations().length > 0 )
+ {
+ return false;
+ }
+ if( state.getInterfaces().length > 0 )
+ {
+ return false;
+ }
+ if( state.getStates().length > 0 )
+ {
+ return false;
+ }
+ return true;
+ }
+}

Deleted:
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateWriter.java
===================================================================
--- trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateWriter.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/state/impl/src/main/net/dpml/state/impl/StateWriter.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,337 +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 net.dpml.state.impl;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.io.OutputStreamWriter;
-
-import javax.xml.XMLConstants;
-
-import net.dpml.state.State;
-import net.dpml.state.Action;
-import net.dpml.state.Trigger.TriggerEvent;
-import net.dpml.state.Trigger;
-import net.dpml.state.Transition;
-import net.dpml.state.Operation;
-import net.dpml.state.Interface;
-
-/**
- * Construct a state graph.
- */
-public class StateWriter
-{
- private static final String XML_HEADER =
- "<?xml version=\"1.0\"?>";
-
- private static final String STATE_SCHEMA_URN = "@STATE-XSD-URI@";
-
- /**
- * Externalize the part to XML.
- * @param state the state graph to externalize
- * @param output the output stream
- * @exception IOException if an IO error occurs
- */
- public void export( State state, OutputStream output ) throws IOException
- {
- final Writer writer = new OutputStreamWriter( output );
-
- writer.write( XML_HEADER );
- writer.write( "\n\n" );
- writer.write( "<state xmlns=\""
- + STATE_SCHEMA_URN
- + "\""
- + "\n xmlns:xsi=\""
- + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
- + "\"" );
- if( state.isTerminal() )
- {
- writer.write( " terminal=\"true\">" );
- }
- else
- {
- writer.write( ">" );
- }
- writer.write( "\n" );
- writeBody( writer, state, "" );
- writer.write( "\n" );
- writer.write( "\n</state>" );
- writer.write( "\n" );
- writer.flush();
- output.close();
- }
-
- /**
- * Write the state.
- * @param writer the stream writer
- * @param state the state to externalize
- * @param pad the pad offset
- * @exception IOException if an IO error occurs
- */
- public void writeState( Writer writer, State state, String pad ) throws
IOException
- {
- if( isEmpty( state ) )
- {
- return;
- }
- else
- {
- writer.write( "\n" + pad + "<state xmlns=\"" + STATE_SCHEMA_URN
+ "\"" );
- if( state.isTerminal() )
- {
- writer.write( " terminal=\"true\"" );
- }
- writer.write( ">" );
- writeBody( writer, state, pad + " " );
- writer.write( "\n" + pad + "</state>" );
- }
- }
-
- private void writeBody( Writer writer, State state, String pad ) throws
IOException
- {
- Trigger[] triggers = state.getTriggers();
- Transition[] transitions = state.getTransitions();
- Operation[] operations = state.getOperations();
- Interface[] interfaces = state.getInterfaces();
- State[] states = state.getStates();
-
- writeTriggers( writer, triggers, pad );
- writeTransitions( writer, transitions, pad );
- writeOperations( writer, operations, pad );
- writeInterfaces( writer, interfaces, pad );
- writeStates( writer, states, pad );
- }
-
- private void writeTriggers( Writer writer, Trigger[] triggers, String
pad ) throws IOException
- {
- if( triggers.length == 0 )
- {
- return;
- }
- else
- {
- for( int i=0; i<triggers.length; i++ )
- {
- Trigger trigger = triggers[i];
- writeTrigger( writer, trigger, pad );
- }
- }
- }
-
- private void writeTrigger( Writer writer, Trigger trigger, String pad )
throws IOException
- {
- TriggerEvent event = trigger.getEvent();
- writer.write( "\n" + pad + "<trigger event=\"" );
- writer.write( event.getName() );
- writer.write( "\">" );
- Action action = trigger.getAction();
- writeAction( writer, action, pad + " " );
- writer.write( "\n" + pad + "</trigger>" );
- }
-
- private void writeTransitions( Writer writer, Transition[] transitions,
String pad ) throws IOException
- {
- if( transitions.length == 0 )
- {
- return;
- }
- else
- {
- for( int i=0; i<transitions.length; i++ )
- {
- Transition transition = transitions[i];
- writeTransition( writer, transition, pad );
- }
- }
- }
-
- private void writeOperations( Writer writer, Operation[] operations,
String pad ) throws IOException
- {
- if( operations.length == 0 )
- {
- return;
- }
- else
- {
- for( int i=0; i<operations.length; i++ )
- {
- Operation operation = operations[i];
- writeOperation( writer, operation, pad );
- }
- }
- }
-
- private void writeInterfaces( Writer writer, Interface[] interfaces,
String pad ) throws IOException
- {
- if( interfaces.length == 0 )
- {
- return;
- }
- else
- {
- for( int i=0; i<interfaces.length; i++ )
- {
- Interface spec = interfaces[i];
- writeInterface( writer, spec, pad );
- }
- }
- }
-
- private void writeStates( Writer writer, State[] states, String pad )
throws IOException
- {
- if( states.length == 0 )
- {
- return;
- }
- else
- {
- for( int i=0; i<states.length; i++ )
- {
- State state = states[i];
- writeNestedState( writer, state, pad );
- }
- }
- }
-
- private void writeTransition( Writer writer, Transition transition,
String pad ) throws IOException
- {
- String name = transition.getName();
- String target = transition.getTargetName();
- writer.write( "\n" + pad + "<transition name=\"" + name + "\"
target=\"" + target + "\"" );
- Operation operation = transition.getOperation();
- if( null == operation )
- {
- writer.write( "/>" );
- }
- else
- {
- writer.write( ">" );
- writeOperation( writer, operation, pad + " " );
- writer.write( "\n" + pad + "</transition>" );
- }
- }
-
- private void writeOperation( Writer writer, Operation operation, String
pad ) throws IOException
- {
- String name = operation.getName();
- String method = operation.getMethodName();
- writer.write( "\n" + pad + "<operation name=\"" + name + "\"" );
- if( null != method )
- {
- writer.write( " method=\"" + method + "\"" );
- }
- writer.write( "/>" );
- }
-
- private void writeInterface( Writer writer, Interface spec, String pad )
throws IOException
- {
- String classname = spec.getClassname();
- writer.write( "\n" + pad + "<interface class=\"" + classname +
"\"/>" );
- }
-
- private void writeAction( Writer writer, Action action, String pad )
throws IOException
- {
- if( action instanceof Transition )
- {
- Transition transition = (Transition) action;
- writeTransition( writer, transition, pad );
- }
- else if( action instanceof Operation )
- {
- Operation operation = (Operation) action;
- writeOperation( writer, operation, pad );
- }
- else if( action instanceof Interface )
- {
- Interface spec = (Interface) action;
- writeInterface( writer, spec, pad );
- }
- else if( action instanceof ExecAction )
- {
- ExecAction exec = (ExecAction) action;
- writeExecAction( writer, exec, pad );
- }
- else if( action instanceof ApplyAction )
- {
- ApplyAction apply = (ApplyAction) action;
- writeApplyAction( writer, apply, pad );
- }
- else
- {
- final String error =
- "Unrecognized action class ["
- + action.getClass().getName()
- + "].";
- throw new IOException( error );
- }
- }
- private void writeExecAction( Writer writer, ExecAction action, String
pad ) throws IOException
- {
- String id = action.getID();
- writer.write( "\n" + pad + "<exec id=\"" + id + "\"/>" );
- }
-
- private void writeApplyAction( Writer writer, ApplyAction action, String
pad ) throws IOException
- {
- String id = action.getID();
- writer.write( "\n" + pad + "<apply id=\"" + id + "\"/>" );
- }
-
- private void writeNestedState( Writer writer, State state, String pad )
throws IOException
- {
- String name = state.getName();
- writer.write( "\n" + pad + "<state name=\"" + name + "\"" );
- if( state.isTerminal() )
- {
- writer.write( " terminal=\"true\">" );
- }
- else
- {
- writer.write( ">" );
- }
- writeBody( writer, state, pad + " " );
- writer.write( "\n" + pad + "</state>" );
- }
-
- private boolean isEmpty( State state )
- {
- if( state.getTriggers().length > 0 )
- {
- return false;
- }
- if( state.getTransitions().length > 0 )
- {
- return false;
- }
- if( state.getOperations().length > 0 )
- {
- return false;
- }
- if( state.getInterfaces().length > 0 )
- {
- return false;
- }
- if( state.getStates().length > 0 )
- {
- return false;
- }
- return true;
- }
-}

Modified:
trunk/main/metro/state/impl/src/test/net/dpml/state/EmptyTestCase.java
===================================================================
--- trunk/main/metro/state/impl/src/test/net/dpml/state/EmptyTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/state/impl/src/test/net/dpml/state/EmptyTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -21,7 +21,7 @@
import java.io.File;
import java.net.URI;

-import net.dpml.state.impl.StateBuilder;
+import net.dpml.state.impl.StateDecoder;

import junit.framework.TestCase;

@@ -32,7 +32,7 @@
*/
public class EmptyTestCase extends TestCase
{
- private StateBuilder m_builder;
+ private StateDecoder m_decoder;

/**
* Testcase setup.
@@ -40,7 +40,7 @@
*/
public void setUp() throws Exception
{
- m_builder = new StateBuilder();
+ m_decoder = new StateDecoder();
}

/**
@@ -53,7 +53,7 @@
File test = new File( testPath );
File example = new File( test, "empty.xml" );
URI uri = example.toURI();
- State state = m_builder.loadState( uri );
+ State state = m_decoder.loadState( uri );
assertEquals( "substates", 0, state.getStates().length );
assertEquals( "transitions", 0, state.getTransitions().length );
assertEquals( "triggers", 0, state.getTriggers().length );

Modified:
trunk/main/metro/state/impl/src/test/net/dpml/state/TransitionTestCase.java
===================================================================
---
trunk/main/metro/state/impl/src/test/net/dpml/state/TransitionTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/state/impl/src/test/net/dpml/state/TransitionTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -21,7 +21,7 @@
import java.io.File;
import java.net.URI;

-import net.dpml.state.impl.StateBuilder;
+import net.dpml.state.impl.StateDecoder;

import junit.framework.TestCase;

@@ -32,7 +32,7 @@
*/
public class TransitionTestCase extends TestCase
{
- private StateBuilder m_builder;
+ private StateDecoder m_decoder;

/**
* Testcase setup.
@@ -40,7 +40,7 @@
*/
public void setUp() throws Exception
{
- m_builder = new StateBuilder();
+ m_decoder = new StateDecoder();
}

/**
@@ -53,7 +53,7 @@
File test = new File( testPath );
File example = new File( test, "transition.xml" );
URI uri = example.toURI();
- State state = m_builder.loadState( uri );
+ State state = m_decoder.loadState( uri );
assertEquals( "substates", 0, state.getStates().length );
assertEquals( "transitions", 3, state.getTransitions().length );
assertEquals( "triggers", 0, state.getTriggers().length );

Modified:
trunk/main/metro/state/impl/src/test/net/dpml/state/test/DefaultStateMachineTestCase.java
===================================================================
---
trunk/main/metro/state/impl/src/test/net/dpml/state/test/DefaultStateMachineTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/state/impl/src/test/net/dpml/state/test/DefaultStateMachineTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -29,7 +29,7 @@
import net.dpml.state.Trigger;
import net.dpml.state.Action;
import net.dpml.state.impl.DefaultStateMachine;
-import net.dpml.state.impl.StateBuilder;
+import net.dpml.state.impl.StateDecoder;

/**
* Default state machine test-case.
@@ -52,7 +52,7 @@
File example = new File( test, "example.xgraph" );
try
{
- StateBuilder builder = new StateBuilder();
+ StateDecoder builder = new StateDecoder();
m_state = builder.loadState( example.toURI() );
m_machine = new DefaultStateMachine( m_state );
}

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/CatalogTask.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/CatalogTask.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/CatalogTask.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -30,13 +30,15 @@
import java.util.Arrays;
import java.util.Map;

+import net.dpml.component.Directive;
+
import net.dpml.metro.info.PartReference;
import net.dpml.metro.info.EntryDescriptor;
import net.dpml.metro.info.Type;
import net.dpml.metro.info.ContextDescriptor;
import net.dpml.metro.info.ServiceDescriptor;
-import net.dpml.component.Directive;
import net.dpml.metro.data.ComponentDirective;
+import net.dpml.metro.builder.ComponentTypeDecoder;

import net.dpml.transit.Transit;

@@ -55,8 +57,8 @@
*/
public class CatalogTask extends Task
{
- private static final net.dpml.metro.builder.TypeBuilder TYPE_BUILDER =
- new net.dpml.metro.builder.TypeBuilder();
+ private static final ComponentTypeDecoder COMPONENT_TYPE_DECODER =
+ new ComponentTypeDecoder();

private File m_work;
private File m_destination;
@@ -738,7 +740,7 @@
try
{
URI uri = source.toURI();
- Type type = TYPE_BUILDER.loadType( uri );
+ Type type = COMPONENT_TYPE_DECODER.loadType( uri );
createTypePage( htmls, type );
}
catch( Exception e )

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ComponentBuilderTask.java
===================================================================
---
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ComponentBuilderTask.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ComponentBuilderTask.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -28,6 +28,12 @@
import java.net.URISyntaxException;

import net.dpml.component.Directive;
+import net.dpml.component.ActivationPolicy;
+
+import net.dpml.configuration.Configuration;
+
+import net.dpml.library.info.Scope;
+
import net.dpml.metro.data.ComponentDirective;
import net.dpml.metro.data.ContextDirective;
import net.dpml.metro.data.CategoriesDirective;
@@ -36,14 +42,10 @@
import net.dpml.metro.info.PartReference;
import net.dpml.metro.info.Type;
import net.dpml.metro.info.EntryDescriptor;
+import net.dpml.metro.builder.ComponentTypeDecoder;

-import net.dpml.library.info.Scope;
-
-import net.dpml.configuration.Configuration;
-
import net.dpml.parameters.Parameters;

-import net.dpml.component.ActivationPolicy;
import net.dpml.part.Strategy;
import net.dpml.part.PartDirective;

@@ -64,8 +66,8 @@
{
private static final String NAMESPACE = "@COMPONENT-XSD-URI@";

- private static final net.dpml.metro.builder.TypeBuilder TYPE_BUILDER =
- new net.dpml.metro.builder.TypeBuilder();
+ private static final ComponentTypeDecoder COMPONENT_TYPE_DECODER =
+ new ComponentTypeDecoder();

private URI m_uri;
private String m_key;
@@ -536,7 +538,7 @@
try
{
Class c = classloader.loadClass( classname );
- return TYPE_BUILDER.loadType( c );
+ return COMPONENT_TYPE_DECODER.loadType( c );
}
catch( Throwable e )
{

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/StateDataType.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/StateDataType.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/StateDataType.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -33,7 +33,7 @@
import net.dpml.state.Operation;
import net.dpml.state.Interface;
import net.dpml.state.Transition;
-import net.dpml.state.impl.StateBuilder;
+import net.dpml.state.impl.StateDecoder;
import net.dpml.state.impl.DefaultState;

import org.apache.tools.ant.Project;
@@ -49,7 +49,7 @@
*/
public class StateDataType
{
- private static final StateBuilder BUILDER = new StateBuilder();
+ private static final StateDecoder STATE_DECODER = new StateDecoder();

private final boolean m_root;
private final GenericTask m_task;
@@ -272,7 +272,7 @@
m_task.log( "importing state graph: " + m_uri );
try
{
- return BUILDER.loadState( m_uri );
+ return STATE_DECODER.loadState( m_uri );
}
catch( Exception e )
{
@@ -411,7 +411,7 @@
else
{
URI uri = new URI( url.toString() );
- return BUILDER.loadState( uri );
+ return STATE_DECODER.loadState( uri );
}
}
catch( Throwable e )

Modified: trunk/main/metro/tools/src/main/net/dpml/metro/tools/StateTask.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/StateTask.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/StateTask.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -25,7 +25,7 @@
import net.dpml.tools.tasks.GenericTask;

import net.dpml.state.State;
-import net.dpml.state.impl.StateBuilder;
+import net.dpml.state.impl.StateEncoder;

import org.apache.tools.ant.BuildException;

@@ -37,7 +37,7 @@
*/
public class StateTask extends GenericTask
{
- private static final StateBuilder BUILDER = new StateBuilder();
+ private static final StateEncoder STATE_ENCODER = new StateEncoder();

private File m_output;
private StateDataType m_data;
@@ -150,7 +150,7 @@
try
{
State graph = getData().getState();
- BUILDER.export( graph, output );
+ STATE_ENCODER.export( graph, output );
}
catch( Exception e )
{

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -33,6 +33,7 @@
import java.util.Map;
import java.util.Properties;

+import net.dpml.metro.builder.ComponentTypeEncoder;
import net.dpml.metro.info.CategoryDescriptor;
import net.dpml.metro.info.ContextDescriptor;
import net.dpml.metro.info.InfoDescriptor;
@@ -46,9 +47,10 @@

import net.dpml.state.State;
import net.dpml.state.impl.DefaultState;
-import net.dpml.state.impl.StateBuilder;
+import net.dpml.state.impl.StateDecoder;

import net.dpml.library.info.Scope;
+
import net.dpml.tools.tasks.GenericTask;

import org.apache.tools.ant.BuildException;
@@ -65,10 +67,10 @@
*/
public class TypeBuilderTask extends GenericTask implements TypeBuilder
{
- private static final StateBuilder STATE_BUILDER = new StateBuilder();
- private static final net.dpml.metro.builder.TypeBuilder TYPE_BUILDER =
- new net.dpml.metro.builder.TypeBuilder();
-
+ private static final StateDecoder STATE_DECODER = new StateDecoder();
+ private static final ComponentTypeEncoder COMPONENT_TYPE_ENCODER =
+ new ComponentTypeEncoder();
+
//---------------------------------------------------------------
// state
//---------------------------------------------------------------
@@ -238,7 +240,7 @@
*/
public URI getBuilderURI()
{
- return TYPE_BUILDER_URI;
+ return COMPONENT_TYPE_DECODER_URI;
}

//---------------------------------------------------------------
@@ -310,7 +312,7 @@
OutputStream output = getOutputStream( type );
try
{
- TYPE_BUILDER.export( type, output );
+ COMPONENT_TYPE_ENCODER.export( type, output );
}
finally
{
@@ -691,7 +693,7 @@
else
{
URI uri = new URI( url.toString() );
- return STATE_BUILDER.loadState( uri );
+ return STATE_DECODER.loadState( uri );
}
}
catch( Throwable e )
@@ -991,7 +993,7 @@
}

private static final URI TYPE_HANDLER_URI = setupURI(
"@PART-HANDLER-URI@" );
- private static final URI TYPE_BUILDER_URI = setupURI(
"@PART-BUILDER-URI@" );
+ private static final URI COMPONENT_TYPE_DECODER_URI = setupURI(
"@PART-BUILDER-URI@" );

/**
* Internal utility to create a static uri.

Modified: trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypesTask.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypesTask.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypesTask.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -27,9 +27,11 @@
import java.beans.IntrospectionException;

import net.dpml.tools.tasks.GenericTask;
+
import net.dpml.library.info.Scope;

import net.dpml.metro.info.Type;
+import net.dpml.metro.builder.ComponentTypeEncoder;

import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
@@ -45,9 +47,10 @@
*/
public class TypesTask extends GenericTask implements DynamicElementNS
{
- private static final net.dpml.metro.builder.TypeBuilder BUILDER =
- new net.dpml.metro.builder.TypeBuilder();
-
+ private static final ComponentTypeEncoder COMPONENT_TYPE_ENCODER =
+ new ComponentTypeEncoder();
+
+
private List m_builders = new LinkedList();

/**
@@ -107,7 +110,7 @@
OutputStream output = getOutputStream( type );
try
{
- BUILDER.export( type, output );
+ COMPONENT_TYPE_ENCODER.export( type, output );
}
finally
{

Modified:
trunk/main/station/api/src/main/net/dpml/station/info/ApplicationDescriptor.java
===================================================================
---
trunk/main/station/api/src/main/net/dpml/station/info/ApplicationDescriptor.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/station/api/src/main/net/dpml/station/info/ApplicationDescriptor.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -66,9 +66,9 @@
* @exception URISyntaxException if the codebase URI is invalid
*/
public ApplicationDescriptor(
- String codebase, String title, ValueDirective[] parameters, String
base,
+ URI codebase, String title, ValueDirective[] parameters, String base,
StartupPolicy policy, int startupTimeout, int shutdownTimeout,
- Properties properties, String config ) throws URISyntaxException
+ Properties properties, URI config )
{
super( codebase, parameters );

@@ -95,14 +95,7 @@
m_shutdown = shutdownTimeout;
m_properties = properties;
m_title = title;
- if( null != config )
- {
- m_config = new URI( config );
- }
- else
- {
- m_config = null;
- }
+ m_config = config;
}

/**

Modified:
trunk/main/station/api/src/test/net/dpml/station/info/ApplicationDescriptorTestCase.java
===================================================================
---
trunk/main/station/api/src/test/net/dpml/station/info/ApplicationDescriptorTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/station/api/src/test/net/dpml/station/info/ApplicationDescriptorTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -62,8 +62,8 @@

m_descriptor =
new ApplicationDescriptor(
- m_codebase.toASCIIString(), m_title, m_values, m_base, m_policy,
- m_startup, m_shutdown, m_properties, m_config.toASCIIString() );
+ m_codebase, m_title, m_values, m_base, m_policy,
+ m_startup, m_shutdown, m_properties, m_config );
}

/**
@@ -77,7 +77,7 @@
{
new ApplicationDescriptor(
null, m_title, m_values, m_base, m_policy,
- m_startup, m_shutdown, m_properties, m_config.toASCIIString()
);
+ m_startup, m_shutdown, m_properties, m_config );

fail( "No NPE" );
}

Modified:
trunk/main/station/api/src/test/net/dpml/station/info/RegistryDescriptorTestCase.java
===================================================================
---
trunk/main/station/api/src/test/net/dpml/station/info/RegistryDescriptorTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/station/api/src/test/net/dpml/station/info/RegistryDescriptorTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -18,6 +18,7 @@

package net.dpml.station.info;

+import java.net.URI;
import java.util.Arrays;
import java.util.Properties;

@@ -45,19 +46,19 @@
new Entry(
"aaa",
new ApplicationDescriptor(
- "link:part:acme/demo", "test", new ValueDirective[0], null,
StartupPolicy.AUTOMATIC,
+ new URI( "link:part:acme/demo" ), "test", new
ValueDirective[0], null, StartupPolicy.AUTOMATIC,
0, 0, new Properties(), null ) );
m_entries[1] =
new Entry(
"bbb",
new ApplicationDescriptor(
- "link:part:acme/demo", "test", new ValueDirective[0], null,
StartupPolicy.AUTOMATIC,
+ new URI( "link:part:acme/demo" ), "test", new
ValueDirective[0], null, StartupPolicy.AUTOMATIC,
0, 0, new Properties(), null ) );
m_entries[2] =
new Entry(
"ccc",
new ApplicationDescriptor(
- "link:part:acme/demo", "test", new ValueDirective[0], null,
StartupPolicy.AUTOMATIC,
+ new URI( "link:part:acme/demo" ), "test", new
ValueDirective[0], null, StartupPolicy.AUTOMATIC,
0, 0, new Properties(), null ) );

m_descriptor = new RegistryDescriptor( m_entries );

Modified:
trunk/main/station/builder/src/main/net/dpml/station/builder/RegistryBuilder.java
===================================================================
---
trunk/main/station/builder/src/main/net/dpml/station/builder/RegistryBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/station/builder/src/main/net/dpml/station/builder/RegistryBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -18,6 +18,7 @@

package net.dpml.station.builder;

+import java.io.IOException;
import java.net.URI;
import java.util.Properties;

@@ -28,8 +29,8 @@

import net.dpml.part.DOM3DocumentBuilder;

-import net.dpml.lang.BuilderException;
-import net.dpml.lang.Builder;
+import net.dpml.lang.DecodingException;
+import net.dpml.lang.Decoder;

import net.dpml.lang.ValueDirective;
import net.dpml.transit.util.ElementHelper;
@@ -43,7 +44,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public final class RegistryBuilder implements Builder
+public final class RegistryBuilder implements Decoder
{
private static final DOM3DocumentBuilder DOCUMENT_BUILDER =
new DOM3DocumentBuilder();
@@ -54,21 +55,21 @@
* @return the registry descriptor
* @exception Exception if an error occurs
*/
- public Object build( URI uri ) throws Exception
+ public Object build( URI uri ) throws DecodingException, IOException
{
Document document = DOCUMENT_BUILDER.parse( uri );
Element root = document.getDocumentElement();
- return build( null, root );
+ return decode( null, root );
}

/**
- * Build a registry descriptior from a DOM element.
+ * Decode a registry descriptior from a DOM element.
* @param classloader the base classloader
* @param element the element representing the root registry
* @return the registry descriptor
* @exception Exception if an error occurs
*/
- public Object build( ClassLoader classloader, Element element ) throws
Exception
+ public Object decode( ClassLoader classloader, Element element ) throws
DecodingException
{
String tag = element.getTagName();
if( "application".equals( tag ) )
@@ -83,11 +84,11 @@
{
final String error =
"Document element name [" + tag + "] not recognized.";
- throw new BuilderException( element, error );
+ throw new DecodingException( element, error );
}
}

- private RegistryDescriptor buildRegistryDescriptor( Element element )
throws Exception
+ private RegistryDescriptor buildRegistryDescriptor( Element element )
throws DecodingException
{
Element[] elements = ElementHelper.getChildren( element );
Entry[] entries = new Entry[ elements.length ];
@@ -99,7 +100,7 @@
{
final String error =
"Missing 'key' attribute in application element.";
- throw new BuilderException( elem, error );
+ throw new DecodingException( elem, error );
}
ApplicationDescriptor descriptor = buildApplicationDescriptor(
elem );
entries[i] = new Entry( key, descriptor );
@@ -107,7 +108,7 @@
return new RegistryDescriptor( entries );
}

- private ApplicationDescriptor buildApplicationDescriptor( Element
element ) throws Exception
+ private ApplicationDescriptor buildApplicationDescriptor( Element
element ) throws DecodingException
{
String title = ElementHelper.getAttribute( element, "title" );
StartupPolicy policy = buildStartupPolicy( element );
@@ -120,19 +121,7 @@
Element propertiesElement = ElementHelper.getChild( jvm,
"properties" );
Properties properties = buildProperties( propertiesElement );
Element codebase = ElementHelper.getChild( element, "codebase" );
- if( null == codebase )
- {
- final String error =
- "Missing codebase element.";
- throw new BuilderException( element, error );
- }
- String spec = ElementHelper.getAttribute( codebase, "uri" );
- if( null == spec )
- {
- final String error =
- "Missing codebase uri attribute.";
- throw new BuilderException( codebase, error );
- }
+ URI uri = decodeURI( codebase );
Element[] params = ElementHelper.getChildren( codebase, "param" );
ValueDirective[] values = buildValueDirectives( params );

@@ -140,11 +129,35 @@
// as an abstract type - e.g. net.dpml.part.CodeBaseDirective verus
// net.dpml.metro.CodeBaseDirective

- return new ApplicationDescriptor( spec, title, values, base, policy,
startup, shutdown, properties, null );
+ return new ApplicationDescriptor(
+ uri, title, values, base, policy, startup, shutdown, properties,
null );
}

- private StartupPolicy buildStartupPolicy( Element element ) throws
Exception
+ private URI decodeURI( Element element ) throws DecodingException
{
+ String uri = ElementHelper.getAttribute( element, "uri" );
+ if( null == uri )
+ {
+ final String error = "Missing uri attribute.";
+ throw new DecodingException( element, error );
+ }
+ else
+ {
+ try
+ {
+ return new URI( uri );
+ }
+ catch( Exception e )
+ {
+ final String error = "Bad uri argument [" + uri + "].";
+ throw new DecodingException( element, error );
+
+ }
+ }
+ }
+
+ private StartupPolicy buildStartupPolicy( Element element ) throws
DecodingException
+ {
String policy = ElementHelper.getAttribute( element, "policy" );
if( null == policy )
{
@@ -156,7 +169,7 @@
}
}

- private int buildTimeout( Element element, int fallback ) throws
Exception
+ private int buildTimeout( Element element, int fallback ) throws
DecodingException
{
if( null == element )
{
@@ -176,7 +189,7 @@
}
}

- private Properties buildProperties( Element element )
+ private Properties buildProperties( Element element ) throws
DecodingException
{
Properties properties = new Properties();
if( null == element )
@@ -194,7 +207,7 @@
{
final String error =
"Property declaration does not contain a 'name'
attribute.";
- throw new BuilderException( child, error );
+ throw new DecodingException( child, error );
}
else
{

Modified:
trunk/main/station/console/src/main/net/dpml/station/console/StationPlugin.java
===================================================================
---
trunk/main/station/console/src/main/net/dpml/station/console/StationPlugin.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/station/console/src/main/net/dpml/station/console/StationPlugin.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1055,16 +1055,11 @@
int startup, int shutdown, Properties properties, String base,
StartupPolicy policy,
URI config )
{
- String configPath = null;
- if( null != config )
- {
- configPath = config.toASCIIString();
- }
try
{
ApplicationDescriptor descriptor =
new ApplicationDescriptor(
- uri.toASCIIString(),
+ uri,
title,
new ValueDirective[0],
base,
@@ -1072,7 +1067,7 @@
startup,
shutdown,
properties,
- configPath );
+ config );
registry.addApplicationDescriptor( key, descriptor );
registry.flush();
System.out.println( "\nAdded new profile [" + key + "]" );
@@ -1151,16 +1146,11 @@
{
throw new NullPointerException( "properties" );
}
- String configPath = null;
- if( null != config )
- {
- configPath = config.toASCIIString();
- }
try
{
ApplicationDescriptor descriptor =
new ApplicationDescriptor(
- uri.toASCIIString(),
+ uri,
title,
new ValueDirective[0],
base,
@@ -1168,7 +1158,7 @@
startup,
shutdown,
properties,
- configPath );
+ config );
registry.updateApplicationDescriptor( key, descriptor );
registry.flush();
}

Modified:
trunk/main/station/server/src/test/net/dpml/station/server/RemoteApplicationRegistryTestCase.java
===================================================================
---
trunk/main/station/server/src/test/net/dpml/station/server/RemoteApplicationRegistryTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/station/server/src/test/net/dpml/station/server/RemoteApplicationRegistryTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -18,6 +18,7 @@

package net.dpml.station.server;

+import java.net.URI;
import java.net.URL;
import java.io.File;
import java.util.Properties;
@@ -101,7 +102,7 @@
{
ApplicationDescriptor profile =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.MANUAL, 10, 20, new Properties(), null );

RemoteApplicationRegistry registry =
@@ -119,7 +120,7 @@
{
ApplicationDescriptor profile =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.MANUAL, 10, 20, new Properties(), null );

RemoteApplicationRegistry registry =
@@ -138,14 +139,14 @@
{
ApplicationDescriptor profileOne =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.MANUAL, 10, 20, new Properties(), null );
-
+
ApplicationDescriptor profileTwo =
new ApplicationDescriptor(
- "link:plugin:acme/gizmo", "gizmo", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/gizmo" ), "gizmo", new
ValueDirective[0], ".",
StartupPolicy.AUTOMATIC, 10, 20, new Properties(), null );
-
+
RemoteApplicationRegistry registry =
new RemoteApplicationRegistry( m_logger, m_url );
registry.addApplicationDescriptor( "test-1", profileOne );
@@ -153,7 +154,7 @@
int n = registry.getApplicationDescriptorCount();
assertEquals( "double-count", 2, n );
registry.flush();
-
+
registry =
new RemoteApplicationRegistry( m_logger, m_url );
n = registry.getApplicationDescriptorCount();
@@ -168,12 +169,12 @@
{
ApplicationDescriptor profileOne =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.MANUAL, 10, 20, new Properties(), null );

ApplicationDescriptor profileTwo =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.DISABLED, 10, 20, new Properties(), null );

RemoteApplicationRegistry registry =
@@ -194,12 +195,12 @@
{
ApplicationDescriptor profileOne =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.MANUAL, 10, 20, new Properties(), null );

ApplicationDescriptor profileTwo =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.DISABLED, 10, 20, new Properties(), null );

RemoteApplicationRegistry registry =
@@ -220,7 +221,7 @@
{
ApplicationDescriptor profile =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.MANUAL, 10, 20, new Properties(), null );

try
@@ -245,7 +246,7 @@
{
ApplicationDescriptor profile =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.MANUAL, 10, 20, new Properties(), null );

try
@@ -270,7 +271,7 @@
{
ApplicationDescriptor profile =
new ApplicationDescriptor(
- "link:plugin:acme/widget", "widget", new ValueDirective[0], ".",
+ new URI( "link:plugin:acme/widget" ), "widget", new
ValueDirective[0], ".",
StartupPolicy.MANUAL, 10, 20, new Properties(), null );

RemoteApplicationRegistry registry =

Deleted: trunk/main/transit/core/src/main/net/dpml/lang/Builder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/Builder.java 2006-03-19
22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/lang/Builder.java 2006-03-20
09:50:38 UTC (rev 1230)
@@ -1,36 +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 net.dpml.lang;
-
-import org.w3c.dom.Element;
-
-/**
- * Interface implemented by generic builders.
- */
-public interface Builder
-{
- /**
- * Create an object using a supplied classloader and DOM element.
- * @param classloader the base classloader
- * @param element the DOM element
- * @return an object
- * @exception Exception if an error occurs
- */
- Object build( ClassLoader classloader, Element element ) throws
Exception;
-}

Deleted: trunk/main/transit/core/src/main/net/dpml/lang/BuilderException.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/BuilderException.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/lang/BuilderException.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,90 +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 net.dpml.lang;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- * Exception related to data construction from a DOM element.
- */
-public class BuilderException extends RuntimeException
-{
- private final Element m_element;
-
- /**
- * Create a new vuilder exception instance.
- * @param element the element representing the source of the error
- * @param message the exception message
- */
- public BuilderException( Element element, String message )
- {
- this( element, message, null );
- }
-
- /**
- * Create a new vuilder exception instance.
- * @param element the element representing the source of the error
- * @param message the exception message
- * @param cause the causal exception
- */
- public BuilderException( Element element, String message, Throwable
cause )
- {
- super( message, cause );
- m_element = element;
- }
-
- /**
- * Get the element that is the subject of this exception.
- * @return the subject element
- */
- public Element getElement()
- {
- return m_element;
- }
-
- /**
- * Return a string representation of the exception.
- * @return the string value
- */
- 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();
- }
- }
-}

Copied: trunk/main/transit/core/src/main/net/dpml/lang/Decoder.java (from rev
1216, trunk/main/transit/core/src/main/net/dpml/lang/Builder.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/Builder.java 2006-03-18
20:35:20 UTC (rev 1216)
+++ trunk/main/transit/core/src/main/net/dpml/lang/Decoder.java 2006-03-20
09:50:38 UTC (rev 1230)
@@ -0,0 +1,37 @@
+/*
+ * 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 net.dpml.lang;
+
+import org.w3c.dom.Element;
+
+/**
+ * Interface implemented by generic decoders.
+ */
+public interface Decoder
+{
+ /**
+ * Create an object using a supplied classloader and DOM element.
+ * @param classloader the base classloader
+ * @param element the DOM element
+ * @return the decoded object
+ * @exception DecodingException if an error occurs in the evaluation
+ * of the supplied element
+ */
+ Object decode( ClassLoader classloader, Element element ) throws
DecodingException;
+}

Copied: trunk/main/transit/core/src/main/net/dpml/lang/DecodingException.java
(from rev 1216,
trunk/main/transit/core/src/main/net/dpml/lang/BuilderException.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/BuilderException.java
2006-03-18 20:35:20 UTC (rev 1216)
+++ trunk/main/transit/core/src/main/net/dpml/lang/DecodingException.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,90 @@
+/*
+ * 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 net.dpml.lang;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Exception related to data decoding from a DOM element.
+ */
+public class DecodingException extends Exception
+{
+ private final Element m_element;
+
+ /**
+ * Create a new decoding exception.
+ * @param element the element representing the source of the error
+ * @param message the exception message
+ */
+ public DecodingException( Element element, String message )
+ {
+ this( element, message, null );
+ }
+
+ /**
+ * Create a new decoding exception.
+ * @param element the element representing the source of the error
+ * @param message the exception message
+ * @param cause the causal exception
+ */
+ public DecodingException( Element element, String message, Throwable
cause )
+ {
+ super( message, cause );
+ m_element = element;
+ }
+
+ /**
+ * Get the element that is the subject of this exception.
+ * @return the subject element
+ */
+ public Element getElement()
+ {
+ return m_element;
+ }
+
+ /**
+ * Return a string representation of the exception.
+ * @return the string value
+ */
+ 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/main/transit/core/src/main/net/dpml/lang/Encoder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/Encoder.java 2006-03-19
22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/lang/Encoder.java 2006-03-20
09:50:38 UTC (rev 1230)
@@ -0,0 +1,37 @@
+/*
+ * 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 net.dpml.lang;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * Interface implemented by generic encoders.
+ */
+public interface Encoder
+{
+ /**
+ * Externalize a object to XML.
+ * @param writer the output stream writer
+ * @param object the object to externalize
+ * @param pad the character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void encode( Writer writer, Object object, String pad ) throws
IOException;
+}

Deleted: trunk/main/transit/core/src/main/net/dpml/part/AbstractBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/AbstractBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/AbstractBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,335 +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 net.dpml.part;
-
-import java.net.URI;
-import java.util.Map;
-import java.util.Hashtable;
-
-import net.dpml.lang.Builder;
-import net.dpml.lang.BuilderException;
-
-import net.dpml.transit.Artifact;
-import net.dpml.transit.Transit;
-import net.dpml.transit.Repository;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.TypeInfo;
-
-/**
- * Utility class supporting resolution of element builders.
- */
-public class AbstractBuilder
-{
- static final String PART_XSD_URI = "@PART-XSD-URI@";
-
- static final URI LOCAL_URI = createURI( "local:dpml" );
-
- private final Map m_map; // maps namespace uris to builders
-
- /**
- * Creation of a new abstract builder.
- * @param map the naespace to builder uri map
- */
- public AbstractBuilder( Map map )
- {
- if( null == map )
- {
- m_map = new Hashtable();
- }
- else
- {
- m_map = map;
- }
- if( !m_map.containsKey( "dpml/lang/dpml-part" ) )
- {
- m_map.put( "dpml/lang/dpml-part", LOCAL_URI );
- }
- }
-
- /**
- * Return the namespace to builder uri map.
- * @return the map
- */
- protected Map getMap()
- {
- return m_map;
- }
-
- /**
- * Get the builder based on the namespace declared by the supplied
element.
- * @param element the DOM element
- * @return the builder
- * @exception Exception if an eror occurs
- */
- public Builder getBuilder( Element element ) throws Exception
- {
- return loadBuilder( element );
- }
-
- /**
- * Get a strategy builder based on the namespace declared by the supplied
element.
- * @param element the DOM element
- * @return the strategy builder
- * @exception Exception if an eror occurs
- */
- protected StrategyBuilder getStrategyBuilder( Element element ) throws
Exception
- {
- Builder builder = loadBuilder( element );
- if( builder instanceof StrategyBuilder )
- {
- return (StrategyBuilder) builder;
- }
- else
- {
- final String error =
- "Builder ["
- + builder.getClass().getName()
- + "] is not an instance of "
- + StrategyBuilder.class.getName()
- + ".";
- throw new BuilderException( element, error );
- }
- }
-
- /**
- * Get a strategy builder based on the namespace declared by the supplied
element.
- * @param element the DOM element
- * @return the strategy builder
- * @exception Exception if an eror occurs
- */
- protected Builder loadBuilder( Element element ) throws Exception
- {
- URI uri = getBuilderURI( element );
- if( LOCAL_URI.equals( uri ) )
- {
- TypeInfo info = element.getSchemaTypeInfo();
- String name = info.getTypeName();
- if( "plugin".equals( name ) || "resource".equals( name ) )
- {
- return new PartStrategyBuilder( m_map );
- }
- else if( "part".equals( name ) )
- {
- return new PartBuilder( m_map );
- }
- }
- return new DelegatingBuilder( uri );
- }
-
- /**
- * Internal utility to load a builder using the supplied uri and
validation
- * that the object established from the uri is type assignable to the
supplied class.
- *
- * @param uri the builder part uri
- * @param clazz the class to test the resolved instance for assignability
- * @return the object assignable to the supplied class
- * @exception Exception if an eror occurs
- */
- protected Object loadObjectFromURI( URI uri, Class clazz ) throws
Exception
- {
- if( LOCAL_URI.equals( uri ) )
- {
- if( StrategyBuilder.class.isAssignableFrom( clazz ) )
- {
- return new PartStrategyBuilder( m_map );
- }
- else
- {
- final String error =
- "Unexpected request to load a local object."
- + "\nClass: " + clazz.getName();
- throw new IllegalArgumentException( error );
- }
- }
- ClassLoader classloader = getClassLoader();
- Repository repository = Transit.getInstance().getRepository();
- Object object = repository.getPlugin( classloader, uri, new
Object[0] );
- if( clazz.isAssignableFrom( object.getClass() ) )
- {
- return object;
- }
- else
- {
- final String error =
- "Plugin ["
- + uri
- + "] is not assignable to "
- + clazz.getName()
- + ".";
- throw new IllegalArgumentException( error );
- }
- }
-
- /**
- * Resolve the builder uri from a supplied element.
- *
- * @param element the DOM element
- * @return the builder uri
- * @exception Exception if an eror occurs
- */
- protected URI getBuilderURI( Element element ) throws Exception
- {
- TypeInfo info = element.getSchemaTypeInfo();
- String namespace = info.getTypeNamespace();
- if( PART_XSD_URI.equals( namespace ) )
- {
- return LOCAL_URI;
- }
- else if( m_map.containsKey( namespace ) )
- {
- return (URI) m_map.get( namespace );
- }
- else
- {
- String name = info.getTypeName();
- String path = namespace + "#" + name;
- if( m_map.containsKey( path ) )
- {
- return (URI) m_map.get( path );
- }
- else
- {
- final String error =
- "Unable to resolve part builder."
- + "\nNamespace: " + namespace;
- throw new BuilderException( element, error );
- }
- }
- }
-
- /**
- * Delegating builder that defers resolution until required.
- */
- private class DelegatingBuilder implements Builder
- {
- private final URI m_uri;
- private Object m_delegate = null;
-
- /**
- * Creation of a new delegating builder instance.
- * @param uri the uri of the builder that operations will be
delegated to
- */
- DelegatingBuilder( URI uri )
- {
- m_uri = uri;
- }
-
- /**
- * Delegating implementation of the generic element build operation.
- * @param classloader the base classloader
- * @param element the subject element
- * @return the resulting object
- */
- public Object build( ClassLoader classloader, Element element )
throws Exception
- {
- Object delegate = getDelegate();
- if( delegate instanceof Builder )
- {
- Builder builder = (Builder) delegate;
- return builder.build( classloader, element );
- }
- else
- {
- final String error =
- "Builder delegate does not implement build operations."
- + "\nURI: " + m_uri;
- throw new UnsupportedOperationException( error );
- }
- }
-
- private Object getDelegate()
- {
- if( null != m_delegate )
- {
- return m_delegate;
- }
- else
- {
- try
- {
- ClassLoader classloader = getClassLoader();
- Repository repository =
Transit.getInstance().getRepository();
- return repository.getPlugin( classloader, m_uri, new
Object[0] );
- }
- catch( Exception e )
- {
- final String error =
- "Unable to establish delegate builder."
- + "\nURI: " + m_uri;
- throw new RuntimeException( error );
- }
- }
- }
-
- private ClassLoader getClassLoader()
- {
- ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
- if( null != classloader )
- {
- return classloader;
- }
- else
- {
- return getClass().getClassLoader();
- }
- }
- }
-
- private ClassLoader getClassLoader()
- {
- ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
- if( null != classloader )
- {
- return classloader;
- }
- else
- {
- return StrategyBuilder.class.getClassLoader();
- }
- }
-
- private URI getBuilderFromNamespaceURI( String urn ) throws Exception
- {
- URI raw = new URI( urn );
- 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();
-
- String path = "link:part:" + group + "/" + name;
- Artifact link = Artifact.createArtifact( path );
- return link.toURI();
- }
-
- private static URI createURI( String spec )
- {
- try
- {
- return new URI( spec );
- }
- catch( Throwable e )
- {
- e.printStackTrace();
- return null;
- }
- }
-}

Added: trunk/main/transit/core/src/main/net/dpml/part/DecoderFactory.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/DecoderFactory.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/DecoderFactory.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,302 @@
+/*
+ * 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 net.dpml.part;
+
+import java.io.IOException;
+import java.net.URI;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+import java.util.Hashtable;
+
+import net.dpml.lang.Encoder;
+import net.dpml.lang.DecodingException;
+import net.dpml.lang.Decoder;
+
+import net.dpml.transit.Artifact;
+import net.dpml.transit.Transit;
+import net.dpml.transit.Repository;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.TypeInfo;
+
+/**
+ * Utility class supporting resolution of element decoders.
+ */
+public final class DecoderFactory
+{
+ /**
+ * Constant uri used to refernce the internal package encoder.
+ */
+ static final URI LOCAL_URI = createURI( "local:dpml" );
+
+ static final String PART_XSD_URI = "@PART-XSD-URI@";
+
+ private static final DecoderFactory INSTANCE = new DecoderFactory();
+
+ private final Map m_map; // maps namespace uris to element handlers
+
+ /**
+ * Creation of a new helper factory using default mappings.
+ */
+ public DecoderFactory()
+ {
+ this( null );
+ }
+
+ /**
+ * Creation of a new decoder factory. The supplied map contains the
mapping
+ * of namespace urn to decoder plugin uris. If the "dpml/lang/dpml-part"
namespace
+ * is not included in the map a special uri will be assigned associating
the namespace
+ * with this package implementation.
+ *
+ * @param map the namespace to helper uri map
+ */
+ public DecoderFactory( Map map )
+ {
+ if( null == map )
+ {
+ m_map = new Hashtable();
+ }
+ else
+ {
+ m_map = map;
+ }
+ if( !m_map.containsKey( "dpml/lang/dpml-part" ) )
+ {
+ m_map.put( "dpml/lang/dpml-part", LOCAL_URI );
+ }
+ }
+
+ /**
+ * Internal utility to load an encoder using the supplied uri.
+ *
+ * @param uri the encoder uri
+ * @return the encoder
+ * @exception Exception if an eror occurs
+ */
+ public static Encoder loadEncoder( URI uri ) throws IOException,
InvocationTargetException
+ {
+ if( LOCAL_URI.equals( uri ) )
+ {
+ return new PartEncoder();
+ }
+ else
+ {
+ ClassLoader classloader = getClassLoader();
+ Repository repository = Transit.getInstance().getRepository();
+ Object[] args = new Object[]{INSTANCE};
+ Object object = repository.getPlugin( classloader, uri, args );
+ if( object instanceof Encoder )
+ {
+ return (Encoder) object;
+ }
+ else
+ {
+ final String error =
+ "URI ["
+ + uri
+ + "] does not resolve to an object assignable to "
+ + Encoder.class.getName()
+ + ".";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ }
+
+ /**
+ * Get an element helper based on the namespace declared by the supplied
element. If
+ * the element namespace is the dpml/part namespace then a local uri is
returned,
+ * otherwise evaluation is based on namespace to hanlder mappings
supplied to
+ * the factory constructor. If a map entry is resolved, a delegating
builder is
+ * established with the resolved helper uri, otherwise a helper uri is
resolved
+ * by substituting the namespace uri artifact type for "part" on the
assumption that
+ * a part implemenation will be available.
+ *
+ * @param element the DOM element
+ * @return the associated helper instance
+ * @exception Exception if an eror occurs
+ */
+ public Decoder loadDecoder( Element element ) throws Exception
+ {
+ URI uri = getDecoderURI( element );
+ if( LOCAL_URI.equals( uri ) )
+ {
+ return new PartDecoder( this );
+ }
+ else
+ {
+ return new DelegatingDecoder( this, uri );
+ }
+ }
+
+ /**
+ * Resolve the element helper uri from a supplied element.
+ *
+ * @param element the DOM element
+ * @return the builder uri
+ * @exception Exception if an eror occurs
+ */
+ public URI getDecoderURI( Element element ) throws Exception
+ {
+ TypeInfo info = element.getSchemaTypeInfo();
+ String namespace = info.getTypeNamespace();
+ if( PART_XSD_URI.equals( namespace ) )
+ {
+ return LOCAL_URI;
+ }
+ else if( m_map.containsKey( namespace ) )
+ {
+ return (URI) m_map.get( namespace );
+ }
+ else
+ {
+ return getDecoderURIFromNamespaceURI( namespace );
+ }
+ }
+
+ private URI getDecoderURIFromNamespaceURI( String urn ) throws Exception
+ {
+ URI raw = new URI( urn );
+ 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();
+
+ String path = "link:part:" + group + "/" + name;
+ Artifact link = Artifact.createArtifact( path );
+ return link.toURI();
+ }
+
+
+ /**
+ * Delegating builder that defers resolution until required.
+ */
+ private class DelegatingDecoder implements Decoder
+ {
+ private final DecoderFactory m_factory;
+ private final URI m_uri;
+ private Decoder m_delegate = null;
+
+ /**
+ * Creation of a new delegating builder instance.
+ * @param uri the uri of the builder that operations will be
delegated to
+ */
+ DelegatingDecoder( DecoderFactory factory, URI uri )
+ {
+ m_uri = uri;
+ m_factory = factory;
+ }
+
+ /**
+ * Delegating implementation of the decode operation.
+ * @param classloader the base classloader
+ * @param element the subject element
+ * @return the resulting object
+ */
+ public Object decode( ClassLoader classloader, Element element )
throws DecodingException
+ {
+ Decoder decoder = getDelegateDecoder();
+ return decoder.decode( classloader, element );
+ }
+
+ private Decoder getDelegateDecoder()
+ {
+ if( null != m_delegate )
+ {
+ return m_delegate;
+ }
+ else
+ {
+ Object instance = getInstance();
+ if( instance instanceof Decoder )
+ {
+ m_delegate = (Decoder) instance;
+ return m_delegate;
+ }
+ else
+ {
+ final String error =
+ "Object resolved from the uri does not provide
decoding services."
+ + "\nDelegate URI: " + m_uri
+ + "\nDelegate Class: " + instance.getClass().getName();
+ throw new IllegalStateException( error );
+ }
+ }
+ }
+
+ private Object getInstance()
+ {
+ try
+ {
+ ClassLoader classloader = getClassLoader();
+ Repository repository =
Transit.getInstance().getRepository();
+ Object[] args = new Object[]{m_factory};
+ return repository.getPlugin( classloader, m_uri, args );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error occured while attempting to establish
the delegate decoder."
+ + "\nDelegate URI: " + m_uri;
+ throw new RuntimeException( error, e ); // change to a
factory exception
+ }
+ }
+
+ private ClassLoader getClassLoader()
+ {
+ ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
+ if( null != classloader )
+ {
+ return classloader;
+ }
+ else
+ {
+ return getClass().getClassLoader();
+ }
+ }
+ }
+
+ static ClassLoader getClassLoader()
+ {
+ ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
+ if( null != classloader )
+ {
+ return classloader;
+ }
+ else
+ {
+ return DecoderFactory.class.getClassLoader();
+ }
+ }
+
+ private static URI createURI( String spec )
+ {
+ try
+ {
+ return new URI( spec );
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+}

Deleted: trunk/main/transit/core/src/main/net/dpml/part/PartBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,251 +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 net.dpml.part;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Map;
-
-import net.dpml.lang.Classpath;
-import net.dpml.lang.Builder;
-import net.dpml.lang.BuilderException;
-
-import net.dpml.transit.Transit;
-import net.dpml.transit.Repository;
-import net.dpml.transit.util.ElementHelper;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- * Construct a part.
- */
-public class PartBuilder extends PartWriter implements Builder
-{
- private static final DOM3DocumentBuilder BUILDER =
- new DOM3DocumentBuilder();
-
- /**
- * Creation of a new part builder.
- */
- public PartBuilder()
- {
- this( null );
- }
-
- /**
- * Creation of a new part builder.
- * @param map the namespace to part build uri map
- */
- public PartBuilder( Map map )
- {
- super( map );
- }
-
- /**
- * Load a part from a uri.
- * @param uri the part uri
- * @return the part definition
- * @exception IOException if an IO error occurs
- */
- public Part loadPart( URI uri ) throws IOException
- {
- ClassLoader base = Part.class.getClassLoader();
- return loadPart( base, uri );
- }
-
- /**
- * Load a part from a uri.
- * @param base the base classloader
- * @param uri the part uri
- * @return the part definition
- * @exception IOException if an IO error occurs
- */
- public Part loadPart( ClassLoader base, URI uri ) throws IOException
- {
- if( null == uri )
- {
- throw new NullPointerException( "uri" );
- }
- if( null == base )
- {
- throw new NullPointerException( "base" );
- }
-
- //System.out.println( "# LOAD PART: " + uri );
-
- try
- {
- final Document document = BUILDER.parse( uri );
- final Element root = document.getDocumentElement();
- return buildPart( base, root );
- }
- catch( Throwable e )
- {
- final String error =
- "An error while attempting to load a part."
- + "\nPart URI: " + uri;
- IOException exception = new IOException( error );
- exception.initCause( e );
- throw exception;
- }
- }
-
- /**
- * Resolve a part from a DOM element.
- * @param classloader the classloader
- * @param element the dom element
- * @return the part definition
- * @exception Exception if an error occurs
- */
- public Object build( ClassLoader classloader, Element element ) throws
Exception
- {
- return buildPart( classloader, element );
- }
-
- /**
- * Resolve a part from a DOM element.
- * @param base the classloader
- * @param root the dom element
- * @return the part definition
- * @exception Exception if an error occurs
- */
- public Part buildPart( ClassLoader base, Element root ) throws Exception
- {
- if( null == root )
- {
- throw new NullPointerException( "root" );
- }
- Info info = getInfo( root );
- Strategy strategy = getStrategy( base, root );
- Classpath classpath = getClasspath( root );
- return new Part( info, strategy, classpath );
- }
-
- private Strategy getStrategy( ClassLoader loader, Element root ) throws
Exception
- {
- Element[] children = ElementHelper.getChildren( root );
- if( children.length != 3 )
- {
- final String error =
- "Illegal number of child elements in <part>. Expecting 3,
found "
- + children.length
- + ".";
- throw new BuilderException( root, error );
- }
-
- Element strategy = children[1];
- Builder builder = getBuilder( strategy );
- Object result = builder.build( loader, strategy );
- if( result instanceof Strategy )
- {
- return (Strategy) result;
- }
- else
- {
- final String error =
- "Object returned from builder is not a strategy instance.";
- throw new BuilderException( strategy, error );
- }
- }
-
- private ClassLoader createClassLoader(
- ClassLoader base, URI uri, Classpath classpath ) throws IOException
- {
- Repository repository = Transit.getInstance().getRepository();
- return repository.createClassLoader( base, uri, classpath );
- }
-
- private Info getInfo( Element root )
- {
- Element element = ElementHelper.getChild( root, "info" );
- String title = ElementHelper.getAttribute( element, "title",
"Unknown" );
- Element descriptionElement = ElementHelper.getChild( element,
"description" );
- String description = ElementHelper.getValue( descriptionElement );
- return new Info( title, description );
- }
-
- /**
- * Construct the classpath defintion.
- * @param root the element containing a 'classpath' element.
- * @return the classpath defintion
- * @exception Exception if an error occurs
- */
- protected Classpath getClasspath( Element root ) throws Exception
- {
- Element classpath = ElementHelper.getChild( root, "classpath" );
- if( null == classpath )
- {
- final String error =
- "Required classpath element is not present in plugin
descriptor.";
- throw new IllegalStateException( error );
- }
-
- Element[] children = ElementHelper.getChildren( classpath );
- URI[] sys = buildURIs( classpath, "system" );
- URI[] pub = buildURIs( classpath, "public" );
- URI[] prot = buildURIs( classpath, "protected" );
- URI[] priv = buildURIs( classpath, "private" );
- Classpath cp = new Classpath( sys, pub, prot, priv );
- return cp;
- }
-
- private URI[] buildURIs( Element classpath, String key ) throws Exception
- {
- Element category = ElementHelper.getChild( classpath, key );
- if( null == category )
- {
- return new URI[0];
- }
- else
- {
- Element[] children = ElementHelper.getChildren( category, "uri"
);
- URI[] uris = new URI[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- String value = ElementHelper.getValue( child );
- uris[i] = new URI( value );
- }
- return uris;
- }
- }
-
- 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 );
- }
- }
- }
-}

Copied: trunk/main/transit/core/src/main/net/dpml/part/PartDecoder.java (from
rev 1216, trunk/main/transit/core/src/main/net/dpml/part/PartBuilder.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartBuilder.java
2006-03-18 20:35:20 UTC (rev 1216)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartDecoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,285 @@
+/*
+ * 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 net.dpml.part;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+
+import net.dpml.lang.Classpath;
+import net.dpml.lang.Decoder;
+import net.dpml.lang.DecodingException;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.Repository;
+import net.dpml.transit.util.ElementHelper;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.TypeInfo;
+
+/**
+ * Construct a part.
+ */
+public final class PartDecoder implements Decoder
+{
+ private static final DOM3DocumentBuilder DOCUMENT_BUILDER =
+ new DOM3DocumentBuilder();
+
+ private static final PartStrategyDecoder STRATEGY_DECODER = new
PartStrategyDecoder();
+
+ private final DecoderFactory m_factory;
+
+ /**
+ * Creation of a new part builder.
+ * @param factory the decoder factory
+ */
+ public PartDecoder( DecoderFactory factory )
+ {
+ m_factory = factory;
+ }
+
+ /**
+ * Load a part from a uri.
+ * @param uri the part uri
+ * @return the part definition
+ * @exception IOException if an IO error occurs
+ */
+ public Part loadPart( URI uri ) throws IOException
+ {
+ ClassLoader base = Part.class.getClassLoader();
+ return loadPart( base, uri );
+ }
+
+ /**
+ * Load a part from a uri.
+ * @param base the base classloader
+ * @param uri the part uri
+ * @return the part definition
+ * @exception IOException if an IO error occurs
+ */
+ public Part loadPart( ClassLoader base, URI uri ) throws IOException
+ {
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+ if( null == base )
+ {
+ throw new NullPointerException( "base" );
+ }
+
+ //System.out.println( "# LOAD PART: " + uri );
+
+ try
+ {
+ final Document document = DOCUMENT_BUILDER.parse( uri );
+ final Element root = document.getDocumentElement();
+ return decodePart( base, root );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "An error while attempting to load a part."
+ + "\nPart URI: " + uri;
+ IOException exception = new IOException( error );
+ exception.initCause( e );
+ throw exception;
+ }
+ }
+
+ /**
+ * Resolve a part from a DOM element.
+ * @param classloader the classloader
+ * @param element the dom element
+ * @return the part definition
+ * @exception Exception if an error occurs
+ */
+ public Object decode( ClassLoader classloader, Element element ) throws
DecodingException
+ {
+ TypeInfo info = element.getSchemaTypeInfo();
+ String name = info.getTypeName();
+ if( "plugin".equals( name ) || "resource".equals( name ) )
+ {
+ return STRATEGY_DECODER.decode( classloader, element );
+ }
+ else if( "part".equals( name ) )
+ {
+ return decodePart( classloader, element );
+ }
+ else
+ {
+ final String error =
+ "Element type name ["
+ + name
+ + "] is not recognized.";
+ throw new DecodingException( element, error );
+ }
+ }
+
+ /**
+ * Resolve a part from a DOM element.
+ * @param base the classloader
+ * @param root the dom element
+ * @return the part definition
+ * @exception Exception if an error occurs
+ */
+ public Part decodePart( ClassLoader base, Element root ) throws
DecodingException
+ {
+ if( null == root )
+ {
+ throw new NullPointerException( "root" );
+ }
+ Info info = getInfo( root );
+ Strategy strategy = getStrategy( base, root );
+ Classpath classpath = getClasspath( root );
+ return new Part( info, strategy, classpath );
+ }
+
+ private Strategy getStrategy( ClassLoader loader, Element root ) throws
DecodingException
+ {
+ Element[] children = ElementHelper.getChildren( root );
+ if( children.length != 3 )
+ {
+ final String error =
+ "Illegal number of child elements in <part>. Expecting 3,
found "
+ + children.length
+ + ".";
+ throw new DecodingException( root, error );
+ }
+
+ Element strategy = children[1];
+ Decoder decoder = getDocoder( strategy );
+ Object result = decoder.decode( loader, strategy );
+ if( result instanceof Strategy )
+ {
+ return (Strategy) result;
+ }
+ else
+ {
+ final String error =
+ "Decoded object is not assignable to "
+ + Strategy.class.getName()
+ + "."
+ + "\nDecoder: " + decoder.getClass().getName()
+ + "\nObject: " + result.getClass().getName();
+ throw new DecodingException( strategy, error );
+ }
+ }
+
+ private Decoder getDocoder( Element element ) throws DecodingException
+ {
+ try
+ {
+ return m_factory.loadDecoder( element );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to load decoder.";
+ throw new DecodingException( element, error );
+ }
+ }
+
+ private Info getInfo( Element root )
+ {
+ Element element = ElementHelper.getChild( root, "info" );
+ String title = ElementHelper.getAttribute( element, "title",
"Unknown" );
+ Element descriptionElement = ElementHelper.getChild( element,
"description" );
+ String description = ElementHelper.getValue( descriptionElement );
+ return new Info( title, description );
+ }
+
+ /**
+ * Construct the classpath defintion.
+ * @param root the element containing a 'classpath' element.
+ * @return the classpath defintion
+ * @exception Exception if an error occurs
+ */
+ protected Classpath getClasspath( Element root ) throws DecodingException
+ {
+ Element classpath = ElementHelper.getChild( root, "classpath" );
+ if( null == classpath )
+ {
+ final String error =
+ "Required classpath element is not present in plugin
descriptor.";
+ throw new DecodingException( root, error );
+ }
+
+ try
+ {
+ Element[] children = ElementHelper.getChildren( classpath );
+ URI[] sys = buildURIs( classpath, "system" );
+ URI[] pub = buildURIs( classpath, "public" );
+ URI[] prot = buildURIs( classpath, "protected" );
+ URI[] priv = buildURIs( classpath, "private" );
+ Classpath cp = new Classpath( sys, pub, prot, priv );
+ return cp;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to decode classpath due to an unexpected error.";
+ throw new DecodingException( classpath, error, e );
+ }
+ }
+
+ private URI[] buildURIs( Element classpath, String key ) throws Exception
+ {
+ Element category = ElementHelper.getChild( classpath, key );
+ if( null == category )
+ {
+ return new URI[0];
+ }
+ else
+ {
+ Element[] children = ElementHelper.getChildren( category, "uri"
);
+ URI[] uris = new URI[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ String value = ElementHelper.getValue( child );
+ uris[i] = new URI( value );
+ }
+ return uris;
+ }
+ }
+
+ 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 );
+ }
+ }
+ }
+}

Copied: trunk/main/transit/core/src/main/net/dpml/part/PartEncoder.java (from
rev 1216, trunk/main/transit/core/src/main/net/dpml/part/PartWriter.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartWriter.java
2006-03-18 20:35:20 UTC (rev 1216)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartEncoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,172 @@
+/*
+ * 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 net.dpml.part;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import java.net.URI;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+
+import net.dpml.lang.Category;
+import net.dpml.lang.Classpath;
+import net.dpml.lang.Encoder;
+
+/**
+ * Utility class that provides support for the externalization of a part
instance to XML.
+ */
+public class PartEncoder implements Encoder
+{
+ private static final PartStrategyEncoder STRATEGY_ENCODER = new
PartStrategyEncoder();
+
+ private static final String XML_HEADER =
+ "<?xml version=\"1.0\"?>";
+
+ private static final String PART_SCHEMA_URN = "@PART-XSD-URI@";
+
+ private static final String PART_HEADER =
+ "<part xmlns=\""
+ + PART_SCHEMA_URN
+ + "\""
+ + "\n xmlns:xsi=\""
+ + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
+ + "\">";
+
+ private static final String PART_FOOTER = "</part>";
+
+ /**
+ * Externalize the part to XML.
+ * @param writer the output stream writer
+ * @param object the object to encode
+ * @param pad the character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void encode( Writer writer, Object object, String pad ) throws
IOException
+ {
+ if( object instanceof Strategy )
+ {
+ STRATEGY_ENCODER.encode( writer, (Strategy) object, pad );
+ }
+ else
+ {
+ final String error =
+ "Object class ["
+ + object.getClass().getName()
+ + "] is not recognized.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Externalize the part to XML.
+ * @param part the part to externalize
+ * @param output the output stream
+ * @param pad the character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void encodePart( Part part, OutputStream output, String pad )
throws IOException
+ {
+ final Writer writer = new OutputStreamWriter( output );
+ writer.write( XML_HEADER );
+ writer.write( "\n\n" );
+ writer.write( PART_HEADER );
+ writer.write( "\n" );
+ encodeInfo( writer, part.getInfo() );
+ writer.write( "\n" );
+ encodeStrategy( writer, part.getStrategy(), " " );
+ writer.write( "\n" );
+ encodeClasspath( writer, part.getClasspath() );
+ writer.write( "\n\n" );
+ writer.write( PART_FOOTER );
+ writer.write( "\n" );
+ writer.flush();
+ output.close();
+ }
+
+ private void encodeInfo( Writer writer, Info info ) throws IOException
+ {
+ String title = info.getTitle();
+ String description = info.getDescription();
+ if( null == description )
+ {
+ writer.write( "\n <info title=\"" + title + "\"/>" );
+ }
+ else
+ {
+ writer.write( "\n <info title=\"" + title + "\">" );
+ writer.write( "\n <description>" + description +
"</description>" );
+ writer.write( "\n </info>" );
+ }
+ }
+
+ /**
+ * Write the strategy by delegating to a strategy writer.
+ * @param writer the output stream writer
+ * @param strategy the strategy
+ * @param pad the character offset
+ * @exception IOException if an IO error occurs
+ */
+ protected void encodeStrategy( Writer writer, Strategy strategy, String
pad ) throws IOException
+ {
+ URI uri = strategy.getBuilderURI();
+ try
+ {
+ Encoder encoder = DecoderFactory.loadEncoder( uri );
+ encoder.encode( writer, strategy, pad );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "An error occured during strategy externalization.";
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
+ }
+
+ private void encodeClasspath( Writer writer, Classpath classpath )
throws IOException
+ {
+ writer.write( "\n <classpath>" );
+ encodeClasspathCategory( writer, classpath, Category.SYSTEM );
+ encodeClasspathCategory( writer, classpath, Category.PUBLIC );
+ encodeClasspathCategory( writer, classpath, Category.PROTECTED );
+ encodeClasspathCategory( writer, classpath, Category.PRIVATE );
+ writer.write( "\n </classpath>" );
+ }
+
+ private void encodeClasspathCategory(
+ Writer writer, Classpath classpath, Category category ) throws
IOException
+ {
+ URI[] uris = classpath.getDependencies( category );
+ if( uris.length > 0 )
+ {
+ String name = category.getName();
+ writer.write( "\n <" + name + ">" );
+ for( int i=0; i<uris.length; i++ )
+ {
+ URI uri = uris[i];
+ writer.write( "\n <uri>" + uri.toASCIIString() +
"</uri>" );
+ }
+ writer.write( "\n </" + name + ">" );
+ }
+ }
+}

Modified:
trunk/main/transit/core/src/main/net/dpml/part/PartHandlerFactory.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartHandlerFactory.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartHandlerFactory.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -88,7 +88,7 @@
*/
public PartHandler getPartHandler( URI uri, Object[] args ) throws
Exception
{
- if( AbstractBuilder.LOCAL_URI.equals( uri ) )
+ if( DecoderFactory.LOCAL_URI.equals( uri ) )
{
return HANDLER;
}

Deleted:
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartStrategyBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartStrategyBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,116 +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 net.dpml.part;
-
-import java.util.Map;
-
-import net.dpml.lang.Value;
-import net.dpml.lang.Builder;
-
-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 extends PartStrategyWriter implements
Builder, StrategyBuilder
-{
- private static final PartDirective TRANSIT_DIRECTIVE =
- new PartDirective( AbstractBuilder.LOCAL_URI );
-
- /**
- * Creation of a new part strategy builder.
- */
- public PartStrategyBuilder()
- {
- this( null );
- }
-
- /**
- * Creation of a new part strategy builder.
- * @param map the namespace to part builder uri mapping
- */
- public PartStrategyBuilder( Map map )
- {
- super( map );
- }
-
- /**
- * Return the production type identifier.
- * @return the constant "part" id
- */
- public String getID()
- {
- return "part";
- }
-
- /**
- * Build a strategy from a supplied DOM element.
- * @param classloader the classloader
- * @param element the strategy element
- * @return the resolve instance
- * @exception Exception if an error occurs
- */
- public Object build( ClassLoader classloader, Element element ) throws
Exception
- {
- return buildStrategy( classloader, element );
- }
-
- /**
- * Build a strategy from a supplied DOM element.
- * @param classloader the classloader
- * @param element the strategy element
- * @return the resolve strategy
- * @exception Exception if an error occurs
- */
- public Strategy buildStrategy( ClassLoader classloader, Element element
) throws Exception
- {
- TypeInfo info = element.getSchemaTypeInfo();
- String type = info.getTypeName();
- boolean alias = ElementHelper.getBooleanAttribute( element, "alias",
false );
- if( "plugin".equals( type ) )
- {
- String classname = ElementHelper.getAttribute( element, "class"
);
- Element[] elements = ElementHelper.getChildren( element, "param"
);
- Value[] values = buildValues( elements );
- Plugin plugin = new Plugin( classname, values );
- return new Strategy( AbstractBuilder.LOCAL_URI,
TRANSIT_DIRECTIVE, plugin, alias );
- }
- else if( "resource".equals( type ) )
- {
- String urn = ElementHelper.getAttribute( element, "urn" );
- String path = ElementHelper.getAttribute( element, "path" );
- Resource resource = new Resource( urn, path );
- return new Strategy( AbstractBuilder.LOCAL_URI,
TRANSIT_DIRECTIVE, resource, alias );
- }
- else
- {
- final String error =
- "Strategy element ["
- + type
- + "] is not recognized.";
- throw new IllegalArgumentException( error );
- }
- }
-}

Copied:
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyDecoder.java (from
rev 1216,
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyBuilder.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartStrategyBuilder.java
2006-03-18 20:35:20 UTC (rev 1216)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartStrategyDecoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -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 net.dpml.part;
+
+import java.util.Map;
+
+import net.dpml.lang.Value;
+import net.dpml.lang.Decoder;
+import net.dpml.lang.DecodingException;
+
+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@
+ */
+class PartStrategyDecoder implements Decoder
+{
+ //
------------------------------------------------------------------------
+ // static
+ //
------------------------------------------------------------------------
+
+ private static final PartDirective TRANSIT_DIRECTIVE =
+ new PartDirective( DecoderFactory.LOCAL_URI );
+
+ private static final ValueDecoder VALUE_DECODER = new ValueDecoder();
+
+ //
------------------------------------------------------------------------
+ // Decoder
+ //
------------------------------------------------------------------------
+
+ /**
+ * Build a strategy from a supplied DOM element.
+ * @param classloader the classloader
+ * @param element the strategy element
+ * @return the resolve instance
+ * @exception Exception if an error occurs
+ */
+ public Object decode( ClassLoader classloader, Element element ) throws
DecodingException
+ {
+ return decodeStrategy( classloader, element );
+ }
+
+ //
------------------------------------------------------------------------
+ // PartStrategyDecoder
+ //
------------------------------------------------------------------------
+
+ /**
+ * Build a strategy from a supplied DOM element.
+ * @param classloader the classloader
+ * @param element the strategy element
+ * @return the resolve strategy
+ * @exception Exception if an error occurs
+ */
+ public Strategy decodeStrategy( ClassLoader classloader, Element element
) throws DecodingException
+ {
+ TypeInfo info = element.getSchemaTypeInfo();
+ String type = info.getTypeName();
+ boolean alias = ElementHelper.getBooleanAttribute( element, "alias",
false );
+ if( "plugin".equals( type ) )
+ {
+ String classname = ElementHelper.getAttribute( element, "class"
);
+ Element[] elements = ElementHelper.getChildren( element, "param"
);
+ Value[] values = VALUE_DECODER.decodeValues( elements );
+ Plugin plugin = new Plugin( classname, values );
+ return new Strategy( DecoderFactory.LOCAL_URI,
TRANSIT_DIRECTIVE, plugin, alias );
+ }
+ else if( "resource".equals( type ) )
+ {
+ String urn = ElementHelper.getAttribute( element, "urn" );
+ String path = ElementHelper.getAttribute( element, "path" );
+ Resource resource = new Resource( urn, path );
+ return new Strategy( DecoderFactory.LOCAL_URI,
TRANSIT_DIRECTIVE, resource, alias );
+ }
+ else
+ {
+ final String error =
+ "Strategy element type ["
+ + type
+ + "] is not recognized.";
+ throw new DecodingException( element, error );
+ }
+ }
+}

Copied:
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyEncoder.java (from
rev 1216,
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyWriter.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartStrategyWriter.java
2006-03-18 20:35:20 UTC (rev 1216)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartStrategyEncoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,117 @@
+/*
+ * 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 net.dpml.part;
+
+import java.io.Writer;
+import java.io.IOException;
+import java.util.Map;
+
+import net.dpml.lang.Value;
+import net.dpml.lang.Encoder;
+
+/**
+ * Utility used to build a plugin strategy from a DOM element.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class PartStrategyEncoder implements Encoder
+{
+ private ValueEncoder VALUE_ENCODER = new ValueEncoder();
+
+ /**
+ * Externalize a object to XML.
+ * @param writer the output stream writer
+ * @param object the object to externalize
+ * @param pad the character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void encode( Writer writer, Object object, String pad ) throws
IOException
+ {
+ if( object instanceof Strategy )
+ {
+ encodeStrategy( writer, (Strategy) object, pad );
+ }
+ else
+ {
+ final String error =
+ "Supplied object argument ["
+ + object.getClass().getName()
+ + "] is not recognized.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Externalize a strategy.
+ * @param writer the output stream writer
+ * @param strategy the strategy
+ * @exception IOException if an IO error occurs
+ */
+ //public void write( Writer writer, Strategy strategy ) throws
IOException
+ //{
+ // encodeStrategy( writer, strategy, "" );
+ //}
+
+ /**
+ * Externalize a strategy.
+ * @param writer the output stream writer
+ * @param strategy the strategy
+ * @param pad the character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void encodeStrategy( Writer writer, Strategy strategy, String pad
) throws IOException
+ {
+ Object data = strategy.getDeploymentData();
+ if( data instanceof Plugin )
+ {
+ Plugin plugin = (Plugin) data;
+ String classname = plugin.getClassname();
+ writer.write( "\n <strategy xsi:type=\"plugin\" class=\"" );
+ writer.write( classname );
+ writer.write( "\"" );
+ if( plugin.getValues().length > 0 )
+ {
+ Value[] values = plugin.getValues();
+ VALUE_ENCODER.encodeValues( writer, values, " " );
+ }
+ else
+ {
+ writer.write( "/>" );
+ }
+ }
+ else if( data instanceof Resource )
+ {
+ Resource resource = (Resource) data;
+ String urn = resource.getURN();
+ String path = resource.getPath();
+ writer.write( "\n <strategy xsi:type=\"resource\"" );
+ writer.write( " urn=\"" + urn );
+ writer.write( "\" path=\"" + path );
+ writer.write( "\"/>" );
+ }
+ else
+ {
+ final String error =
+ "Unsupported strategy datatype: "
+ + data.getClass().getName();
+ throw new IOException( error );
+ }
+ }
+}

Deleted:
trunk/main/transit/core/src/main/net/dpml/part/PartStrategyWriter.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartStrategyWriter.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartStrategyWriter.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,100 +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 net.dpml.part;
-
-import java.io.Writer;
-import java.io.IOException;
-import java.util.Map;
-
-import net.dpml.lang.Value;
-
-/**
- * Utility used to build a plugin strategy from a DOM element.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class PartStrategyWriter extends ValueBuilder
-{
- /**
- * Creation of a new part strategy writer.
- * @param map the map of namespace to builder uris
- */
- public PartStrategyWriter( Map map )
- {
- super( map );
- }
-
- /**
- * Externalize a strategy.
- * @param writer the output stream writer
- * @param strategy the strategy
- * @exception IOException if an IO error occurs
- */
- public void write( Writer writer, Strategy strategy ) throws IOException
- {
- writeStrategy( writer, strategy, "" );
- }
-
- /**
- * Externalize a strategy.
- * @param writer the output stream writer
- * @param strategy the strategy
- * @param pad the character offset
- * @exception IOException if an IO error occurs
- */
- public void writeStrategy( Writer writer, Strategy strategy, String pad
) throws IOException
- {
- Object data = strategy.getDeploymentData();
- if( data instanceof Plugin )
- {
- Plugin plugin = (Plugin) data;
- String classname = plugin.getClassname();
- writer.write( "\n <strategy xsi:type=\"plugin\" class=\"" );
- writer.write( classname );
- writer.write( "\"" );
- if( plugin.getValues().length > 0 )
- {
- Value[] values = plugin.getValues();
- writeValues( writer, values, " " );
- }
- else
- {
- writer.write( "/>" );
- }
- }
- else if( data instanceof Resource )
- {
- Resource resource = (Resource) data;
- String urn = resource.getURN();
- String path = resource.getPath();
- writer.write( "\n <strategy xsi:type=\"resource\"" );
- writer.write( " urn=\"" + urn );
- writer.write( "\" path=\"" + path );
- writer.write( "\"/>" );
- }
- else
- {
- final String error =
- "Unsupported strategy datatype: "
- + data.getClass().getName();
- throw new IOException( error );
- }
- }
-}

Deleted: trunk/main/transit/core/src/main/net/dpml/part/PartWriter.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/PartWriter.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/PartWriter.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,155 +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 net.dpml.part;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.io.OutputStreamWriter;
-import java.net.URI;
-import java.util.Map;
-
-import javax.xml.XMLConstants;
-
-import net.dpml.lang.Category;
-import net.dpml.lang.Classpath;
-
-/**
- * Part externalization to XML.
- */
-public class PartWriter extends ValueBuilder
-{
- private static final String XML_HEADER =
- "<?xml version=\"1.0\"?>";
-
- private static final String PART_SCHEMA_URN = "@PART-XSD-URI@";
-
- private static final String PART_HEADER =
- "<part xmlns=\""
- + PART_SCHEMA_URN
- + "\""
- + "\n xmlns:xsi=\""
- + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
- + "\">";
-
- private static final String PART_FOOTER = "</part>";
-
- /**
- * Creation of a new part writer.
- * @param map the map of namespace to builder uris
- */
- public PartWriter( Map map )
- {
- super( map );
- }
-
- /**
- * Externalize the part to XML.
- * @param part the part to externalize
- * @param output the output stream
- * @param pad the character offset
- * @exception IOException if an IO error occurs
- */
- public void writePart( Part part, OutputStream output, String pad )
throws IOException
- {
- final Writer writer = new OutputStreamWriter( output );
- writer.write( XML_HEADER );
- writer.write( "\n\n" );
- writer.write( PART_HEADER );
- writer.write( "\n" );
- writeInfo( writer, part.getInfo() );
- writer.write( "\n" );
- writeStrategy( writer, part.getStrategy(), " " );
- writer.write( "\n" );
- writeClasspath( writer, part.getClasspath() );
- writer.write( "\n\n" );
- writer.write( PART_FOOTER );
- writer.write( "\n" );
- writer.flush();
- output.close();
- }
-
- private void writeInfo( Writer writer, Info info ) throws IOException
- {
- String title = info.getTitle();
- String description = info.getDescription();
- if( null == description )
- {
- writer.write( "\n <info title=\"" + title + "\"/>" );
- }
- else
- {
- writer.write( "\n <info title=\"" + title + "\">" );
- writer.write( "\n <description>" + description +
"</description>" );
- writer.write( "\n </info>" );
- }
- }
-
- /**
- * Write the strategy by delegating to a strategy writer.
- * @param writer the output stream writer
- * @param strategy the strategy
- * @param pad the character offset
- * @exception IOException if an IO error occurs
- */
- protected void writeStrategy( Writer writer, Strategy strategy, String
pad ) throws IOException
- {
- URI uri = strategy.getBuilderURI();
- try
- {
- StrategyBuilder builder = (StrategyBuilder) loadObjectFromURI(
uri, StrategyBuilder.class );
- builder.writeStrategy( writer, strategy, pad );
- }
- catch( Exception e )
- {
- final String error =
- "An error occured during strategy externalization.";
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
- }
- }
-
- private void writeClasspath( Writer writer, Classpath classpath ) throws
IOException
- {
- writer.write( "\n <classpath>" );
- writeClasspathCategory( writer, classpath, Category.SYSTEM );
- writeClasspathCategory( writer, classpath, Category.PUBLIC );
- writeClasspathCategory( writer, classpath, Category.PROTECTED );
- writeClasspathCategory( writer, classpath, Category.PRIVATE );
- writer.write( "\n </classpath>" );
- }
-
- private void writeClasspathCategory(
- Writer writer, Classpath classpath, Category category ) throws
IOException
- {
- URI[] uris = classpath.getDependencies( category );
- if( uris.length > 0 )
- {
- String name = category.getName();
- writer.write( "\n <" + name + ">" );
- for( int i=0; i<uris.length; i++ )
- {
- URI uri = uris[i];
- writer.write( "\n <uri>" + uri.toASCIIString() +
"</uri>" );
- }
- writer.write( "\n </" + name + ">" );
- }
- }
-}

Deleted: trunk/main/transit/core/src/main/net/dpml/part/StrategyBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/StrategyBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/StrategyBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,51 +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 net.dpml.part;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import org.w3c.dom.Element;
-
-/**
- * Construct an Strategy instance from a DOM Element.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public interface StrategyBuilder
-{
- /**
- * Build a strategy from a supplied DOM element.
- * @param classloader the classloader
- * @param element the strategy element
- * @return the resolved strategy
- * @exception Exception if an error occurs
- */
- Strategy buildStrategy( ClassLoader classloader, Element element )
throws Exception;
-
- /**
- * Externalize a strategy.
- * @param writer the output stream writer
- * @param strategy the strategy
- * @param pad the character offset
- * @exception IOException if an IO error occurs
- */
- void writeStrategy( Writer writer, Strategy strategy, String pad )
throws IOException;
-}

Deleted: trunk/main/transit/core/src/main/net/dpml/part/ValueBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/ValueBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/ValueBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,82 +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 net.dpml.part;
-
-import java.util.Map;
-
-import net.dpml.lang.Value;
-import net.dpml.lang.Construct;
-import net.dpml.transit.util.ElementHelper;
-
-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 ValueBuilder extends ValueWriter
-{
- /**
- * Creation of a new value builder.
- * @param map the namespace to part builder uri mapping
- */
- public ValueBuilder( Map map )
- {
- super( map );
- }
-
- /**
- * Build an array of values for the supplied element array.
- * @param elements the elements
- * @return the resolved values
- */
- protected Value[] buildValues( Element[] elements )
- {
- Value[] values = new Value[ elements.length ];
- for( int i=0; i<elements.length; i++ )
- {
- values[i] = buildValue( elements[i] );
- }
- return values;
- }
-
- /**
- * Build a single value instance from a supplied element.
- * @param element the element
- * @return the resolved value
- */
- protected Value buildValue( Element element )
- {
- String classname = ElementHelper.getAttribute( element, "class" );
- String method = ElementHelper.getAttribute( element, "method" );
- Element[] elements = ElementHelper.getChildren( element, "param" );
- if( elements.length > 0 )
- {
- Value[] values = buildValues( elements );
- return new Construct( classname, method, values );
- }
- else
- {
- String value = ElementHelper.getAttribute( element, "value" );
- return new Construct( classname, method, value );
- }
- }
-}

Copied: trunk/main/transit/core/src/main/net/dpml/part/ValueDecoder.java
(from rev 1216,
trunk/main/transit/core/src/main/net/dpml/part/ValueBuilder.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/ValueBuilder.java
2006-03-18 20:35:20 UTC (rev 1216)
+++ trunk/main/transit/core/src/main/net/dpml/part/ValueDecoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,73 @@
+/*
+ * 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 net.dpml.part;
+
+import java.util.Map;
+
+import net.dpml.lang.Value;
+import net.dpml.lang.Construct;
+import net.dpml.transit.util.ElementHelper;
+
+import org.w3c.dom.Element;
+
+/**
+ * Utility used to decode values from DOM elements.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class ValueDecoder
+{
+ /**
+ * Build an array of values for the supplied element array.
+ * @param elements the elements
+ * @return the resolved values
+ */
+ public Value[] decodeValues( Element[] elements )
+ {
+ Value[] values = new Value[ elements.length ];
+ for( int i=0; i<elements.length; i++ )
+ {
+ values[i] = decodeValue( elements[i] );
+ }
+ return values;
+ }
+
+ /**
+ * Build a single value instance from a supplied element.
+ * @param element the element
+ * @return the resolved value
+ */
+ public Value decodeValue( Element element )
+ {
+ String classname = ElementHelper.getAttribute( element, "class" );
+ String method = ElementHelper.getAttribute( element, "method" );
+ Element[] elements = ElementHelper.getChildren( element, "param" );
+ if( elements.length > 0 )
+ {
+ Value[] values = decodeValues( elements );
+ return new Construct( classname, method, values );
+ }
+ else
+ {
+ String value = ElementHelper.getAttribute( element, "value" );
+ return new Construct( classname, method, value );
+ }
+ }
+}

Copied: trunk/main/transit/core/src/main/net/dpml/part/ValueEncoder.java
(from rev 1216,
trunk/main/transit/core/src/main/net/dpml/part/ValueWriter.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/ValueWriter.java
2006-03-18 20:35:20 UTC (rev 1216)
+++ trunk/main/transit/core/src/main/net/dpml/part/ValueEncoder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -0,0 +1,103 @@
+/*
+ * 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 net.dpml.part;
+
+import java.io.Writer;
+import java.io.IOException;
+import java.util.Map;
+
+import net.dpml.lang.Value;
+import net.dpml.lang.Construct;
+
+/**
+ * Utility used to write value instances to an output stream as XML.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class ValueEncoder
+{
+ /**
+ * Write an array of values to XML.
+ * @param writer the output stream writer
+ * @param values the value array
+ * @param pad the character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void encodeValues( Writer writer, Value[] values, String pad )
throws IOException
+ {
+ for( int i=0; i<values.length; i++ )
+ {
+ Value value = values[i];
+ encodeValue( writer, value, pad );
+ }
+ }
+
+
+ /**
+ * Write a value to XML.
+ * @param writer the output stream writer
+ * @param value the value
+ * @param pad the character offset
+ * @exception IOException if an IO error occurs
+ */
+ public void encodeValue( Writer writer, Value value, String pad ) throws
IOException
+ {
+ if( value instanceof Construct )
+ {
+ Construct construct = (Construct) value;
+ String method = construct.getMethodName();
+ String target = construct.getTargetExpression();
+
+ writer.write( "\n" + pad + "<param" );
+ if( null != target )
+ {
+ writer.write( " class=\"" + target + "\"" );
+ }
+ if( null != method )
+ {
+ writer.write( " method=\"" + method + "\"" );
+ }
+ if( construct.isCompound() )
+ {
+ writer.write( ">" );
+ Value[] values = construct.getValues();
+ encodeValues( writer, values, pad + " " );
+ writer.write( "\n" + pad + "</param>" );
+ }
+ else
+ {
+ String v = construct.getBaseValue();
+ if( null != value )
+ {
+ writer.write( " value=\"" + v + "\"" );
+ }
+ writer.write( "/>" );
+ }
+ }
+ else
+ {
+ final String error =
+ "Value class ["
+ + value.getClass().getName()
+ + "] not supported.";
+ throw new IOException( error );
+ }
+ }
+}

Deleted: trunk/main/transit/core/src/main/net/dpml/part/ValueWriter.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/part/ValueWriter.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/part/ValueWriter.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,120 +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 net.dpml.part;
-
-import java.io.Writer;
-import java.io.IOException;
-import java.util.Map;
-
-import net.dpml.lang.Value;
-import net.dpml.lang.Construct;
-
-/**
- * Utility used to build a plugin strategy from a DOM element.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class ValueWriter extends AbstractBuilder
-{
- /**
- * Creation of a new value writer.
- */
- public ValueWriter()
- {
- this( null );
- }
-
- /**
- * Creation of a new value writer.
- * @param map the namespace to part builder uri mapping
- */
- public ValueWriter( Map map )
- {
- super( map );
- }
-
- /**
- * Write an array of values to XML.
- * @param writer the output stream writer
- * @param values the value array
- * @param pad the character offset
- * @exception IOException if an IO error occurs
- */
- protected void writeValues( Writer writer, Value[] values, String pad )
throws IOException
- {
- for( int i=0; i<values.length; i++ )
- {
- Value value = values[i];
- writeValue( writer, value, pad );
- }
- }
-
-
- /**
- * Write a value to XML.
- * @param writer the output stream writer
- * @param value the value
- * @param pad the character offset
- * @exception IOException if an IO error occurs
- */
- protected void writeValue( Writer writer, Value value, String pad )
throws IOException
- {
- if( value instanceof Construct )
- {
- Construct construct = (Construct) value;
- String method = construct.getMethodName();
- String target = construct.getTargetExpression();
-
- writer.write( "\n" + pad + "<param" );
- if( null != target )
- {
- writer.write( " class=\"" + target + "\"" );
- }
- if( null != method )
- {
- writer.write( " method=\"" + method + "\"" );
- }
- if( construct.isCompound() )
- {
- writer.write( ">" );
- Value[] values = construct.getValues();
- writeValues( writer, values, pad + " " );
- writer.write( "\n" + pad + "</param>" );
- }
- else
- {
- String v = construct.getBaseValue();
- if( null != value )
- {
- writer.write( " value=\"" + v + "\"" );
- }
- writer.write( "/>" );
- }
- }
- else
- {
- final String error =
- "Value class ["
- + value.getClass().getName()
- + "] not supported.";
- throw new IOException( error );
- }
- }
-}

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -40,7 +40,8 @@
import net.dpml.part.PartDirective;
import net.dpml.part.PartHandler;
import net.dpml.part.PartHandlerFactory;
-import net.dpml.part.PartBuilder;
+import net.dpml.part.PartDecoder;
+import net.dpml.part.DecoderFactory;
import net.dpml.part.Strategy;
import net.dpml.part.Plugin;

@@ -54,7 +55,8 @@
class StandardLoader implements Repository
{
private final Logger m_logger;
- private final PartBuilder m_builder = new PartBuilder( null );
+ private final DecoderFactory m_factory = new DecoderFactory();
+ private final PartDecoder m_decoder = new PartDecoder( m_factory );

private static final PartHandlerFactory FACTORY =
PartHandlerFactory.getInstance();

@@ -82,7 +84,7 @@
{
try
{
- return m_builder.loadPart( uri );
+ return m_decoder.loadPart( uri );
}
catch( Exception e )
{
@@ -158,7 +160,7 @@
{
try
{
- Part part = m_builder.loadPart( parent, uri );
+ Part part = m_decoder.loadPart( parent, uri );
return getPluginClass( parent, part );
}
catch( Exception e )
@@ -243,7 +245,7 @@
{
try
{
- net.dpml.part.Part part = m_builder.loadPart( parent, uri );
+ net.dpml.part.Part part = m_decoder.loadPart( parent, uri );
Classpath classpath = part.getClasspath();
net.dpml.part.Strategy strategy = part.getStrategy();
net.dpml.part.PartDirective directive =
strategy.getPartDirective();

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -18,6 +18,7 @@

package net.dpml.transit;

+import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.io.InputStream;
@@ -37,6 +38,7 @@
import net.dpml.transit.info.LayoutDirective;

import net.dpml.lang.ValueDirective;
+import net.dpml.lang.DecodingException;
import net.dpml.lang.Logger;

import org.xml.sax.ErrorHandler;
@@ -227,11 +229,34 @@
String id = ElementHelper.getAttribute( element, "id" );
String title = ElementHelper.getAttribute( element, "title" );
Element codebase = ElementHelper.getChild( element, "codebase" );
- String uri = ElementHelper.getAttribute( codebase, "uri" );
+ URI uri = decodeURI( codebase );
ValueDirective[] values = getValueDirectives( codebase );
return new LayoutDirective( id, title, uri, values );
}

+ private URI decodeURI( Element element ) throws DecodingException
+ {
+ String uri = ElementHelper.getAttribute( element, "uri" );
+ if( null == uri )
+ {
+ final String error = "Missing uri attribute.";
+ throw new DecodingException( element, error );
+ }
+ else
+ {
+ try
+ {
+ return new URI( uri );
+ }
+ catch( Exception e )
+ {
+ final String error = "Bad uri argument [" + uri + "].";
+ throw new DecodingException( element, error );
+
+ }
+ }
+ }
+
private ValueDirective[] getValueDirectives( Element element )
{
if( null == element )

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/info/CodeBaseDirective.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/info/CodeBaseDirective.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/transit/core/src/main/net/dpml/transit/info/CodeBaseDirective.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -43,13 +43,13 @@
* @param parameters an array of plugin parameter descriptors
* @exception URISyntaxException if the codebase URI is invalid
*/
- public CodeBaseDirective( String codebase, ValueDirective[] parameters )
throws URISyntaxException
+ public CodeBaseDirective( URI codebase, ValueDirective[] parameters )
{
if( null == codebase )
{
throw new NullPointerException( "codebase" );
}
- m_codebase = new URI( codebase );
+ m_codebase = codebase;
if( null == parameters )
{
throw new NullPointerException( "parameters" );

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/info/ContentDirective.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/info/ContentDirective.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/transit/core/src/main/net/dpml/transit/info/ContentDirective.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -18,7 +18,7 @@

package net.dpml.transit.info;

-import java.net.URISyntaxException;
+import java.net.URI;

import net.dpml.lang.ValueDirective;

@@ -40,12 +40,11 @@
* @param title the handler title
* @param codebase the codebase uri
* @param parameters an array of plugin parameter descriptors
- * @exception URISyntaxException if the codebase URI is invalid
* @exception NullPointerException if the id is null
*/
public ContentDirective(
- String id, String title, String codebase, ValueDirective[] parameters
)
- throws URISyntaxException, NullPointerException
+ String id, String title, URI codebase, ValueDirective[] parameters )
+ throws NullPointerException
{
super( codebase, parameters );
if( null == id )

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/info/LayoutDirective.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/info/LayoutDirective.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/transit/core/src/main/net/dpml/transit/info/LayoutDirective.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -18,7 +18,7 @@

package net.dpml.transit.info;

-import java.net.URISyntaxException;
+import java.net.URI;

import net.dpml.lang.ValueDirective;

@@ -44,8 +44,8 @@
* @exception NullPointerException if the id is null
*/
public LayoutDirective(
- String id, String title, String codebase, ValueDirective[] parameters
)
- throws URISyntaxException, NullPointerException
+ String id, String title, URI codebase, ValueDirective[] parameters )
+ throws NullPointerException
{
super( codebase, parameters );
if( null == id )

Modified: trunk/main/transit/core/src/main/net/dpml/transit/link/Handler.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/link/Handler.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/main/net/dpml/transit/link/Handler.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -1,5 +1,7 @@
/*
* Copyright 2005 Niclas Hedhman
+ * 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

Modified: trunk/main/transit/core/src/test/net/dpml/part/PartTestCase.java
===================================================================
--- trunk/main/transit/core/src/test/net/dpml/part/PartTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++ trunk/main/transit/core/src/test/net/dpml/part/PartTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -36,7 +36,8 @@
System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
}

- private PartBuilder m_builder;
+ private PartDecoder m_decoder;
+ private PartEncoder m_encoder;

/**
* Test the demo class.
@@ -44,7 +45,8 @@
*/
public void setUp() throws Exception
{
- m_builder = new PartBuilder( null );
+ m_decoder = new PartDecoder( new DecoderFactory() );
+ m_encoder = new PartEncoder();
}

/**
@@ -72,11 +74,11 @@
File file = new File( test, path );
System.out.println( "source: " + file + " (" + file.exists() + ")" );

- Part part = m_builder.loadPart( file.toURI() );
+ Part part = m_decoder.loadPart( file.toURI() );
File out = new File( test, "export-" + path );
FileOutputStream output = new FileOutputStream( out );
- m_builder.writePart( part, output, "" );
- Part newPart = m_builder.loadPart( out.toURI() );
+ m_encoder.encodePart( part, output, "" );
+ Part newPart = m_decoder.loadPart( out.toURI() );
assertEquals( "part", part, newPart );
}
}

Modified:
trunk/main/transit/core/src/test/net/dpml/transit/info/CodeBaseDirectiveTestCase.java
===================================================================
---
trunk/main/transit/core/src/test/net/dpml/transit/info/CodeBaseDirectiveTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/transit/core/src/test/net/dpml/transit/info/CodeBaseDirectiveTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -30,14 +30,14 @@
*/
public class CodeBaseDirectiveTestCase extends AbstractTestCase
{
- private String m_codebase;
+ private URI m_codebase;
private ValueDirective[] m_values;

/**
* Return the test codebase value.
* @return the codebase spec
*/
- protected String getCodebaseValue()
+ protected URI getCodebaseValue()
{
return m_codebase;
}
@@ -57,7 +57,7 @@
*/
public void setUp() throws Exception
{
- m_codebase = "link:test:whatever";
+ m_codebase = new URI( "link:test:whatever" );
ValueDirective v1 = new ValueDirective( "abc" );
ValueDirective v2 = new ValueDirective( "def" );
m_values = new ValueDirective[]{v1, v2};
@@ -70,7 +70,7 @@
public void testGetCodeBaseURISpec() throws Exception
{
CodeBaseDirective directive = new CodeBaseDirective( m_codebase,
m_values );
- assertEquals( "codebase-spec", m_codebase,
directive.getCodeBaseURISpec() );
+ assertEquals( "codebase-spec", m_codebase.toASCIIString(),
directive.getCodeBaseURISpec() );
}

/**
@@ -79,9 +79,8 @@
*/
public void testGetCodeBaseURI() throws Exception
{
- URI uri = new URI( m_codebase );
CodeBaseDirective directive = new CodeBaseDirective( m_codebase,
m_values );
- assertEquals( "codebase-spec", uri, directive.getCodeBaseURI() );
+ assertEquals( "codebase", m_codebase, directive.getCodeBaseURI() );
}

/**

Modified:
trunk/main/transit/core/src/test/net/dpml/transit/info/ContentDirectiveTestCase.java
===================================================================
---
trunk/main/transit/core/src/test/net/dpml/transit/info/ContentDirectiveTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/transit/core/src/test/net/dpml/transit/info/ContentDirectiveTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -18,6 +18,8 @@

package net.dpml.transit.info;

+import java.net.URI;
+
import net.dpml.lang.ValueDirective;

/**
@@ -37,7 +39,7 @@
*/
public void testID() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
ContentDirective directive =
new ContentDirective( m_id, m_title, codebase, values );
@@ -51,7 +53,7 @@
*/
public void testTitle() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
ContentDirective directive =
new ContentDirective( m_id, m_title, codebase, values );
@@ -65,7 +67,7 @@
*/
public void testNullID() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
try
{
@@ -85,7 +87,7 @@
*/
public void testNullTitle() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
ContentDirective directive =
new ContentDirective( m_id, null, codebase, values );
@@ -98,7 +100,7 @@
*/
public void testSerialization() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
ContentDirective directive =
new ContentDirective( m_id, m_title, codebase, values );

Modified:
trunk/main/transit/core/src/test/net/dpml/transit/info/LayoutDirectiveTestCase.java
===================================================================
---
trunk/main/transit/core/src/test/net/dpml/transit/info/LayoutDirectiveTestCase.java
2006-03-19 22:13:51 UTC (rev 1229)
+++
trunk/main/transit/core/src/test/net/dpml/transit/info/LayoutDirectiveTestCase.java
2006-03-20 09:50:38 UTC (rev 1230)
@@ -18,6 +18,8 @@

package net.dpml.transit.info;

+import java.net.URI;
+
import net.dpml.lang.ValueDirective;

/**
@@ -37,7 +39,7 @@
*/
public void testID() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
LayoutDirective directive =
new LayoutDirective( m_id, m_title, codebase, values );
@@ -51,7 +53,7 @@
*/
public void testTitle() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
LayoutDirective directive =
new LayoutDirective( m_id, m_title, codebase, values );
@@ -65,7 +67,7 @@
*/
public void testNullID() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
try
{
@@ -85,7 +87,7 @@
*/
public void testNullTitle() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
LayoutDirective directive =
new LayoutDirective( m_id, null, codebase, values );
@@ -98,7 +100,7 @@
*/
public void testSerialization() throws Exception
{
- String codebase = getCodebaseValue();
+ URI codebase = getCodebaseValue();
ValueDirective[] values = getValueDirectives();
LayoutDirective directive =
new LayoutDirective( m_id, m_title, codebase, values );




  • r1230 - in trunk/main: depot/library/src/main/net/dpml/library/impl depot/tools/builder/src/main/net/dpml/tools/tasks metro metro/builder/src/main/net/dpml/metro/builder metro/builder/src/test/net/dpml/metro/builder metro/runtime/src/main/net/dpml/metro/runtime metro/state/impl/src/main/net/dpml/state/impl metro/state/impl/src/test/net/dpml/state metro/state/impl/src/test/net/dpml/state/test metro/tools/src/main/net/dpml/metro/tools planet/http/server station/api/src/main/net/dpml/station/info station/api/src/test/net/dpml/station/info station/builder/src/main/net/dpml/station/builder station/console/src/main/net/dpml/station/console station/server/src/test/net/dpml/station/server transit/core/src/main/net/dpml/lang transit/core/src/main/net/dpml/part transit/core/src/main/net/dpml/transit transit/core/src/main/net/dpml/transit/info transit/core/src/main/net/dpml/transit/link transit/core/src/test/net/dpml/part transit/core/src/test/net/dpml/transit/info, mcconnell at BerliOS, 03/20/2006

Archive powered by MHonArc 2.6.24.

Top of Page