Skip to Content.
Sympa Menu

notify-dpml - r1143 - in trunk/main/transit/core: . src/main/net/dpml/lang src/main/net/dpml/transit src/test/net/dpml/lang/test src/test/net/dpml/transit

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: r1143 - in trunk/main/transit/core: . src/main/net/dpml/lang src/main/net/dpml/transit src/test/net/dpml/lang/test src/test/net/dpml/transit
  • Date: Tue, 28 Feb 2006 12:02:05 +0100

Author: mcconnell
Date: 2006-02-28 12:02:01 +0100 (Tue, 28 Feb 2006)
New Revision: 1143

Added:
trunk/main/transit/core/src/main/net/dpml/lang/PluginFactory.java
trunk/main/transit/core/src/main/net/dpml/lang/SaxMonitor.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultClasspath.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPlugin.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginBuilder.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginFactory.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultStrategy.java
trunk/main/transit/core/src/test/net/dpml/transit/PluginTestCase.java
Removed:
trunk/main/transit/core/src/main/net/dpml/lang/DefaultClasspath.java
trunk/main/transit/core/src/main/net/dpml/lang/DefaultPlugin.java
trunk/main/transit/core/src/main/net/dpml/lang/DefaultPluginHelper.java
trunk/main/transit/core/src/main/net/dpml/lang/DefaultStrategy.java
trunk/main/transit/core/src/main/net/dpml/lang/PluginBuilder.java
trunk/main/transit/core/src/main/net/dpml/lang/PluginHelper.java
trunk/main/transit/core/src/test/net/dpml/lang/test/PluginTestCase.java
Modified:
trunk/main/transit/core/build.properties
trunk/main/transit/core/build.xml
trunk/main/transit/core/src/main/net/dpml/lang/Handler.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
trunk/main/transit/core/src/main/net/dpml/transit/Logger.java
trunk/main/transit/core/src/main/net/dpml/transit/StandardHandler.java
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
Log:
schronizing changes from the past week in prep for changes supporting
migration to XML Schema

Modified: trunk/main/transit/core/build.properties
===================================================================
--- trunk/main/transit/core/build.properties 2006-02-28 10:57:01 UTC (rev
1142)
+++ trunk/main/transit/core/build.properties 2006-02-28 11:02:01 UTC (rev
1143)
@@ -2,4 +2,6 @@
home = ..
project.test.fork = true
project.jar.main.class=net.dpml.transit.Main
-project.specification.version = 1.0
\ No newline at end of file
+project.specification.version = 1.0
+project.schema.version = 1.0
+

Modified: trunk/main/transit/core/build.xml
===================================================================
--- trunk/main/transit/core/build.xml 2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/build.xml 2006-02-28 11:02:01 UTC (rev 1143)
@@ -37,12 +37,13 @@
</target>

<target name="init" depends="bootstrap.init">
+ <filter token="PROJECT-NAME" value="${project.name}"/>
+ <filter token="PROJECT-GROUP" value="${project.group}"/>
<filter token="PROJECT-VERSION" value="${project.version}"/>
<filter token="PROJECT-URI"

value="artifact:plugin:dpml/transit/dpml-transit-main#${project.version}"/>
<filter token="TRANSIT-CONTROLLER-PLUGIN"

value="artifact:plugin:dpml/transit/dpml-transit-plugin#${project.version}"/>
- <filter token="PROJECT-NAME" value="${project.name}"/>
</target>

<target name="build" depends="bootstrap.build">
@@ -85,6 +86,10 @@
<copy preservelastmodified="true" toDir="${dpml.prefs}/dpml/transit">
<fileset dir="${basedir}/target/prefs"/>
</copy>
+ <move file="${target.deliverables.dir}/xsds/part.xsd"
+
toFile="${target.deliverables.dir}/xsds/${project.name}-${project.version}.xsd"/>
+ <move file="${target.deliverables.dir}/xsds/part.xsd.link"
+ toFile="${target.deliverables.dir}/xsds/${project.name}.xsd.link"/>
</target>

<target name="install" depends="bootstrap.install">

Deleted: trunk/main/transit/core/src/main/net/dpml/lang/DefaultClasspath.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/DefaultClasspath.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/lang/DefaultClasspath.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -1,187 +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 java.net.URI;
-import java.io.OutputStream;
-import java.util.Arrays;
-
-/**
- * A Plugin class contains immutable data about a plugin based on a
descriptor resolved
- * from a 'plugin' artifact.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class DefaultClasspath implements Classpath
-{
- private final URI[] m_system;
- private final URI[] m_public;
- private final URI[] m_protected;
- private final URI[] m_private;
-
- /**
- * Creation of a new classpath definition.
- * @param systemUris an array of uris representing the system classpath
extensions
- * @param publicUris an array of uris representing the public classpath
entries
- * @param protectedUris an array of uris representing protected classpath
entries
- * @param privateUris an array of uris representing private classpath
entries
- */
- public DefaultClasspath(
- URI[] systemUris, URI[] publicUris, URI[] protectedUris, URI[]
privateUris )
- {
- if( null == systemUris )
- {
- m_system = EMPTY_URIS;
- }
- else
- {
- m_system = systemUris;
- }
-
- if( null == publicUris )
- {
- m_public = EMPTY_URIS;
- }
- else
- {
- m_public = publicUris;
- }
-
- if( null == protectedUris )
- {
- m_protected = EMPTY_URIS;
- }
- else
- {
- m_protected = protectedUris;
- }
-
- if( null == privateUris )
- {
- m_private = EMPTY_URIS;
- }
- else
- {
- m_private = privateUris;
- }
- }
-
- /**
- * Return the classloader dependencies relative to a supplied classloader
category.
- *
- * @param category the classloader category
- * @return an array of uris defining the classloader classpath for the
supplied category
- */
- public URI[] getDependencies( final Category category )
- {
- if( Category.SYSTEM.equals( category ) )
- {
- return m_system;
- }
- else if( Category.PUBLIC.equals( category ) )
- {
- return m_public;
- }
- else if( Category.PROTECTED.equals( category ) )
- {
- return m_protected;
- }
- else if( Category.PRIVATE.equals( category ) )
- {
- return m_private;
- }
- else
- {
- final String error =
- "Category not recognized."
- + "\nCategory: " + category;
- throw new IllegalArgumentException( error );
- }
- }
-
- /**
- * Compare this object with another for equality.
- * @param other the other object
- * @return TRUE if equal else FALSE
- */
- public boolean equals( Object other )
- {
- if( other instanceof Classpath )
- {
- Classpath classpath = (Classpath) other;
- if( !Arrays.equals( m_system, classpath.getDependencies(
Category.SYSTEM ) ) )
- {
- return false;
- }
- if( !Arrays.equals( m_public, classpath.getDependencies(
Category.PUBLIC ) ) )
- {
- return false;
- }
- if( !Arrays.equals( m_protected, classpath.getDependencies(
Category.PROTECTED ) ) )
- {
- return false;
- }
- else
- {
- return Arrays.equals( m_private, classpath.getDependencies(
Category.PRIVATE ) );
- }
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Return the hashcode for the plugin definition.
- * @return the hash code
- */
- public int hashCode()
- {
- int hash = hashArray( m_system );
- hash ^= hashArray( m_public );
- hash ^= hashArray( m_protected );
- hash ^= hashArray( m_private );
- return hash;
- }
-
- /**
- * Utility to hash an array.
- * @param array the array
- * @return the hash value
- */
- protected int hashArray( Object[] array )
- {
- if( null == array )
- {
- return 0;
- }
- int hash = 0;
- for( int i=0; i<array.length; i++ )
- {
- Object object = array[i];
- hash ^= object.hashCode();
- }
- return hash;
- }
-
- private static final URI[] EMPTY_URIS = new URI[0];
-
-}

Deleted: trunk/main/transit/core/src/main/net/dpml/lang/DefaultPlugin.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/DefaultPlugin.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/lang/DefaultPlugin.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -1,322 +0,0 @@
-/*
- * Copyright 2004-2005 Stephen J. McConnell.
- * Copyright 2004 Niclas Hedhman.
- *
- * 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.net.URI;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.io.IOException;
-import java.util.Properties;
-
-/**
- * A Plugin class contains immutable data about a plugin based on a
descriptor resolved
- * from a 'plugin' artifact.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class DefaultPlugin implements Plugin
-{
- /**
- * The plugin builder version value that will be used when reading and
writing
- * plugin defintions.
- */
- public static final Version VERSION = new Version( 1, 0, 0 );
-
- public static final String XML_HEADER =
- "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
-
- public static final String STANDARD_NAME = "plugin";
-
- public static final String STANDARD_PUBLIC_ID =
- "-//DPML//DTD Standard Plugin Version 1.0//EN";
-
- public static final String STANDARD_SYSTEM_ID =
- "http://download.dpml.net/dtds/plugin_1_0.dtd";;
-
- public static final String STANDARD_RESOURCE =
- "net/dpml/lang/plugin_1_0.dtd";
-
- private static final String PLUGIN_DOCTYPE =
- "\n<!DOCTYPE "
- + STANDARD_NAME
- + " PUBLIC \""
- + STANDARD_PUBLIC_ID
- + "\" \""
- + STANDARD_SYSTEM_ID
- + "\" >";
-
- private final String m_title;
- private final String m_description;
- private final URI m_uri;
- private final Strategy m_strategy;
- private final Classpath m_classpath;
-
- /**
- * Creation of a new plugin definition.
- * @param title short title
- * @param description textual description
- * @param uri the uri from which the plugin was resolved
- * @param strategy the plugin instantiation strategy definition
- * @param classpath the classpath defintion
- */
- public DefaultPlugin(
- String title, String description, URI uri, Strategy strategy,
Classpath classpath )
- {
- if( null == uri )
- {
- throw new NullPointerException( "uri" );
- }
- if( null == strategy )
- {
- throw new NullPointerException( "strategy" );
- }
- if( null == classpath )
- {
- throw new NullPointerException( "classpath" );
- }
- m_uri = uri;
- m_strategy = strategy;
- m_title = title;
- m_description = description;
- m_classpath = classpath;
- }
-
- /**
- * Return the plugin title.
- * @return the plugin title
- */
- public String getTitle()
- {
- return m_title;
- }
-
- /**
- * Return the plugin description.
- * @return the plugin description
- */
- public String getDescription()
- {
- return m_description;
- }
-
- /**
- * Return the plugin version.
- * @return the plugin version identifier
- */
- public Version getVersion()
- {
- return VERSION;
- }
-
- /**
- * Return the uri to the plugin descriptor.
- * @return the plugin uri
- */
- public URI getURI()
- {
- return m_uri;
- }
-
- /**
- * Return the plugin strategy.
- * @return the plugin strategy
- */
- public Strategy getStrategy()
- {
- return m_strategy;
- }
-
- /**
- * Return the classpath definition.
- */
- public Classpath getClasspath()
- {
- return m_classpath;
- }
-
- /**
- * Write an XML representation of the plugin to the output stream.
- * @param output the output stream
- * @exception Exception if an error ocucrs during externalization
- */
- public void write( OutputStream output ) throws Exception
- {
- final Writer writer = new OutputStreamWriter( output );
- writer.write( XML_HEADER );
- writer.write( PLUGIN_DOCTYPE );
- writeHeader( writer, "plugin", null, VERSION );
- writeTitle( writer, getTitle() );
- writeDescription( writer, getDescription() );
- writeStrategy( writer, getStrategy() );
- writeClasspath( writer, getClasspath() );
- writeFooter( writer, "plugin" );
- writer.write( "\n" );
- writer.flush();
- writer.close();
- }
-
- protected void writeHeader( Writer writer, String root, String
namespace, Version version ) throws IOException
- {
- if( null == namespace )
- {
- writer.write( "\n\n<" + root + " version=\"" + version + "\">" );
- }
- else
- {
- writer.write( "\n\n<" + root + " xmlns=\"" + namespace + "\"
version=\"" + version + "\">" );
- }
- }
-
- protected void writeFooter( Writer writer, String root ) throws
IOException
- {
- writer.write( "\n</" + root + ">" );
- }
-
- protected void writeTitle( Writer writer, String title ) throws
IOException
- {
- if( null != title )
- {
- writer.write(
- "\n <title>"
- + title
- + "</title>" );
- }
- }
-
- protected void writeDescription( Writer writer, String description )
throws IOException
- {
- if( null != description )
- {
- writer.write(
- "\n <description>"
- + description
- + "</description>" );
- }
- }
-
- protected void writeStrategy( Writer writer, Strategy strategy ) throws
Exception
- {
- String handler = strategy.getHandlerClassname();
- Properties properties = strategy.getProperties();
- String[] keys = (String[]) properties.keySet().toArray( new
String[0] );
- if( DefaultPluginHelper.STANDARD_HANDLER.equals( handler ) )
- {
- writer.write( "\n <strategy>" );
- }
- else
- {
- writer.write( "\n <strategy class=\"" + handler + "\">" );
- }
- for( int i=0; i<keys.length; i++ )
- {
- String key = keys[i];
- String value = properties.getProperty( key );
- writer.write(
- "\n <property name=\""
- + key
- + "\" value=\""
- + value
- + "\"/>" );
- }
- writer.write( "\n </strategy>" );
- }
-
- protected void writeClasspath( Writer writer, Classpath classpath )
throws Exception
- {
- writer.write( "\n <classpath>" );
- URI[] sysUris = classpath.getDependencies( Category.SYSTEM );
- if( sysUris.length > 0 )
- {
- writer.write( "\n <system>" );
- for( int i=0; i<sysUris.length; i++ )
- {
- URI uri = sysUris[i];
- writer.write( "\n <uri>" + uri + "</uri>" );
- }
- writer.write( "\n </system>" );
- }
- URI[] publicUris = classpath.getDependencies( Category.PUBLIC );
- if( publicUris.length > 0 )
- {
- writer.write( "\n <public>" );
- for( int i=0; i<publicUris.length; i++ )
- {
- URI uri = publicUris[i];
- writer.write( "\n <uri>" + uri + "</uri>" );
- }
- writer.write( "\n </public>" );
- }
- URI[] protectedUris = classpath.getDependencies( Category.PROTECTED
);
- if( protectedUris.length > 0 )
- {
- writer.write( "\n <protected>" );
- for( int i=0; i<protectedUris.length; i++ )
- {
- URI uri = protectedUris[i];
- writer.write( "\n <uri>" + uri + "</uri>" );
- }
- writer.write( "\n </protected>" );
- }
- URI[] privateUris = classpath.getDependencies( Category.PRIVATE );
- if( privateUris.length > 0 )
- {
- writer.write( "\n <private>" );
- for( int i=0; i<privateUris.length; i++ )
- {
- URI uri = privateUris[i];
- writer.write( "\n <uri>" + uri + "</uri>" );
- }
- writer.write( "\n </private>" );
- }
- writer.write( "\n </classpath>" );
- }
-
- /**
- * Compare this object with another for equality.
- * @param other the other object
- * @return TRUE if equal else FALSE
- */
- public boolean equals( Object other )
- {
- if( other instanceof DefaultPlugin )
- {
- DefaultPlugin plugin = (DefaultPlugin) other;
- return m_uri.equals( plugin.getURI() );
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Return the hashcode for the plugin definition.
- * @return the hash code
- */
- public int hashCode()
- {
- return m_uri.hashCode();
- }
-
- private static final URI[] EMPTY_URIS = new URI[0];
-
-}

Deleted:
trunk/main/transit/core/src/main/net/dpml/lang/DefaultPluginHelper.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/DefaultPluginHelper.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/lang/DefaultPluginHelper.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -1,174 +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 java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.io.IOException;
-import java.util.Properties;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import net.dpml.transit.util.ElementHelper;
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-
-/**
- * Utility class supporting the reading and writing of standard plugins
definitions.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class DefaultPluginHelper implements PluginHelper
-{
- /**
- * The default runtime handler class name.
- */
- public static final String STANDARD_HANDLER =
"net.dpml.transit.StandardHandler";
-
- private static final Version VERSION = new Version( 1, 0, 0 );
-
- public Plugin resolve( URI uri, Element element ) throws Exception
- {
- final Element root = element;
- String name = root.getTagName();
- if( !"plugin".equals( name ) )
- {
- final String error =
- "Invalid root element name ["
- + name
- + "].";
- throw new IOException( error );
- }
-
- String versionSpec = ElementHelper.getAttribute( root, "version" );
- Version version = Version.getVersion( versionSpec );
- if( isRecognized( version ) )
- {
- String title = getTitle( ElementHelper.getChild( root, "title" )
);
- String description = getDescription( ElementHelper.getChild(
root, "description" ) );
- Element strategyElement = ElementHelper.getChild( root,
"strategy" );
- Strategy strategy = buildStrategy( strategyElement );
- Element classpathElement = ElementHelper.getChild( root,
"classpath" );
- Classpath classpath = getClasspath( classpathElement );
- return new DefaultPlugin( title, description, uri, strategy,
classpath );
- }
- else
- {
- final String error =
- "Incompatible plugin version ["
- + version
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- protected Classpath getClasspath( Element element ) throws Exception
- {
- URI[] sys = buildURIs( element, "system" );
- URI[] pub = buildURIs( element, "public" );
- URI[] prot = buildURIs( element, "protected" );
- URI[] priv = buildURIs( element, "private" );
- return new DefaultClasspath( sys, pub, prot, priv );
- }
-
- protected String getTitle( Element element )
- {
- if( null == element )
- {
- return null;
- }
- else
- {
- return ElementHelper.getValue( element );
- }
- }
-
- protected String getDescription( Element element )
- {
- if( null == element )
- {
- return null;
- }
- else
- {
- return ElementHelper.getValue( element );
- }
- }
-
- protected Strategy buildStrategy( Element strategy )
- {
- if( null == strategy )
- {
- final String error =
- "Required strategy element is not present in plugin
descriptor.";
- throw new IllegalStateException( error );
- }
-
- String classname = ElementHelper.getAttribute( strategy, "class",
STANDARD_HANDLER );
- Properties properties = new Properties();
- Element[] elements = ElementHelper.getChildren( strategy, "property"
);
- for( int i=0; i<elements.length; i++ )
- {
- Element element = elements[i];
- String name = ElementHelper.getAttribute( element, "name" );
- String value = ElementHelper.getAttribute( element, "value" );
- properties.setProperty( name, value );
- }
- return new DefaultStrategy( classname, properties );
- }
-
- private URI[] buildURIs( Element classpath, String key ) throws Exception
- {
- Element category = ElementHelper.getChild( classpath, key );
- if( null == category )
- {
- return null;
- }
- 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 boolean isRecognized( Version version )
- {
- return VERSION.complies( version );
- }
-}

Deleted: trunk/main/transit/core/src/main/net/dpml/lang/DefaultStrategy.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/DefaultStrategy.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/lang/DefaultStrategy.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -1,114 +0,0 @@
-/*
- * Copyright 2004-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.Serializable;
-import java.util.Properties;
-
-/**
- * Plugin strategy.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class DefaultStrategy implements Strategy
-{
- private final String m_handler;
- private final Properties m_properties;
-
- /**
- * Creation of a new strategy definition.
- * @param handler the plugin handler classname
- * @param properties the handler supplimentary properties
- */
- public DefaultStrategy( final String handler, final Properties
properties )
- {
- if( null == handler )
- {
- throw new NullPointerException( "handler" );
- }
- m_handler = handler;
- if( null == properties )
- {
- m_properties = new Properties();
- }
- else
- {
- m_properties = properties;
- }
- }
-
- /**
- * Return the classname of the custom plugin instantiation handler.
- * @return the handler classname
- */
- public String getHandlerClassname()
- {
- return m_handler;
- }
-
- /**
- * Return the the properties to be supplied to the handler.
- * @return the custom properties
- */
- public Properties getProperties()
- {
- return m_properties;
- }
-
- /**
- * Test this object for equality with the supplied object.
- * @param other the other object
- * @return true if the objects are equal
- */
- public boolean equals( Object other )
- {
- if( null == other )
- {
- return false;
- }
- else if( other instanceof Strategy )
- {
- Strategy strategy = (Strategy) other;
- if( !m_handler.equals( strategy.getHandlerClassname() ) )
- {
- return false;
- }
- else
- {
- return m_properties.equals( strategy.getProperties() );
- }
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Return the hashcode for the instance.
- * @return the instance hashcode
- */
- public int hashCode()
- {
- int hash = m_handler.hashCode();
- hash ^= m_properties.hashCode();
- return hash;
- }
-}

Modified: trunk/main/transit/core/src/main/net/dpml/lang/Handler.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/Handler.java 2006-02-28
10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/lang/Handler.java 2006-02-28
11:02:01 UTC (rev 1143)
@@ -32,21 +32,21 @@
* Instantiate the plugin.
*
* @param classloader the classloader
- * @param properties plugin strategy properties
+ * @param strategy the plugin strategy
* @param args commandline arguments
* @return the instance
* @exception Exception if an error occurs
*/
Object getPlugin(
- ClassLoader classloader, Properties properties, Object[] args )
throws Exception;
+ ClassLoader classloader, Strategy strategy, Object[] args ) throws
Exception;

/**
* Get a plugin class.
*
* @param classloader the plugin classloader
- * @param properties the supplimentary properties
+ * @param strategy the plugin strategy
* @return the plugin class
* @exception Exception if an error occurs
*/
- Class getPluginClass( ClassLoader classloader, Properties properties )
throws Exception;
+ Class getPluginClass( ClassLoader classloader, Strategy strategy )
throws Exception;
}

Deleted: trunk/main/transit/core/src/main/net/dpml/lang/PluginBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/PluginBuilder.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/lang/PluginBuilder.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -1,141 +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 java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import net.dpml.transit.Transit;
-import net.dpml.transit.util.ElementHelper;
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-
-/**
- * Utility class supporting the reading and writing of standard plugins
definitions.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class PluginBuilder
-{
- private static final DTD[] DTDS = new DTD[]
- {
- new DTD(
- DefaultPlugin.STANDARD_PUBLIC_ID,
- DefaultPlugin.STANDARD_SYSTEM_ID,
- DefaultPlugin.STANDARD_RESOURCE, null )
- };
-
- private static final DTDResolver DTD_RESOLVER =
- new DTDResolver( DTDS, PluginBuilder.class.getClassLoader() );
-
- private static final ErrorHandler ERROR_HANDLER =
- new InternalErrorHandler();
-
- /**
- * Construct a plugin from a supplied uri.
- * @param url the plugin url
- * @return the plugin
- * @exception Exception if an error occurs during plugin loading
- */
- public Plugin load( final URL url ) throws Exception
- {
- URLConnection connection = url.openConnection();
- InputStream input = connection.getInputStream();
-
- final DocumentBuilderFactory factory =
- DocumentBuilderFactory.newInstance();
- factory.setValidating( true );
- factory.setNamespaceAware( true );
- factory.setExpandEntityReferences( true );
- DocumentBuilder builder = factory.newDocumentBuilder();
- builder.setEntityResolver( DTD_RESOLVER );
- builder.setErrorHandler( ERROR_HANDLER );
-
- final Document document = builder.parse( input );
- final DocumentType docType = document.getDoctype();
- final Element root = document.getDocumentElement();
- String namespace = root.getNamespaceURI();
- final PluginHelper helper = getPluginHelper( namespace );
- URI uri = new URI( url.toString() );
- return helper.resolve( uri, root );
- }
-
- private PluginHelper getPluginHelper( String namespace ) throws Exception
- {
- if( null == namespace )
- {
- return new DefaultPluginHelper();
- }
- else
- {
- URI uri = new URI( namespace );
- ClassLoader classloader = Plugin.class.getClassLoader();
- Object[] args = new Object[0];
- Object instance =
- Transit.getInstance().getRepository().getPlugin( classloader,
uri, args );
- if( instance instanceof PluginHelper )
- {
- return (PluginHelper) instance;
- }
- else
- {
- final String error =
- "Namespace artifact argument ["
- + namespace
- + "] assigned as the plugin helper established an instance
of ["
- + instance.getClass().getName()
- + "] which is not assignable to the "
- + PluginHelper.class.getName()
- + " interface.";
- throw new IllegalArgumentException( error );
- }
- }
- }
-
- private static final class InternalErrorHandler implements ErrorHandler
- {
- public void error( SAXParseException e ) throws SAXException
- {
- System.out.println( "ERROR: " + e.getMessage() );
- }
- public void fatalError( SAXParseException e ) throws SAXException
- {
- System.out.println( "FATAL: " + e.getMessage() );
- }
- public void warning( SAXParseException e ) throws SAXException
- {
- System.out.println( "WARN: " + e.getMessage() );
- }
- }
-}

Copied: trunk/main/transit/core/src/main/net/dpml/lang/PluginFactory.java
(from rev 1133,
trunk/main/transit/core/src/main/net/dpml/lang/PluginBuilder.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/PluginBuilder.java
2006-02-24 15:30:02 UTC (rev 1133)
+++ trunk/main/transit/core/src/main/net/dpml/lang/PluginFactory.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -0,0 +1,42 @@
+/*
+ * 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.net.URI;
+
+/**
+ * Interface implemented by plugins helpers that provide support for the
+ * delegation of plugin definition creation from a DOM node.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public interface PluginFactory
+{
+ /**
+ * Construct a new plugin description instance using a supplied arguments
+ *
+ * @param uri the uri identifying the plugin
+ * @param element the root element definining the plugin
+ * @exception Exception if an error occurs
+ */
+ Plugin newPlugin(
+ String title, String description, URI uri, Strategy strategy,
Classpath classpath )
+ throws Exception;
+}

Deleted: trunk/main/transit/core/src/main/net/dpml/lang/PluginHelper.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/PluginHelper.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/lang/PluginHelper.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -1,41 +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 java.net.URI;
-import org.w3c.dom.Element;
-
-/**
- * Interface implemented by plugins that resolve plugins from XML files.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public interface PluginHelper
-{
- /**
- * Construct a plugin using a supplied element and uri.
- *
- * @param uri the uri identifying the plugin
- * @param element the root element definining the plugin
- * @exception Exception if an error occurs
- */
- Plugin resolve( URI uri, Element element ) throws Exception;
-
-}

Added: trunk/main/transit/core/src/main/net/dpml/lang/SaxMonitor.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/SaxMonitor.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/lang/SaxMonitor.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -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.lang;
+
+import java.net.URL;
+
+import net.dpml.transit.Logger;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Utility class supporting the reading and writing of standard plugins
definitions.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class SaxMonitor implements ErrorHandler
+{
+ private Logger m_logger;
+
+ public SaxMonitor( Logger logger )
+ {
+ if( null == logger )
+ {
+ throw new NullPointerException( "logger" );
+ }
+ m_logger = logger;
+ }
+
+ public void error( SAXParseException e ) throws SAXException
+ {
+ final String message = getMessage( e );
+ m_logger.warn( message );
+ }
+
+ public void fatalError( SAXParseException e ) throws SAXException
+ {
+ final String message = getMessage( e );
+ m_logger.error( message );
+ }
+
+ public void warning( SAXParseException e ) throws SAXException
+ {
+ final String message = getMessage( e );
+ m_logger.warn( message );
+ }
+
+ private String getMessage( SAXParseException e )
+ {
+ return e.getMessage()
+ + "(" + e.getLineNumber()
+ + "," + e.getColumnNumber()
+ + ")";
+ }
+}

Copied:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultClasspath.java (from
rev 1133,
trunk/main/transit/core/src/main/net/dpml/lang/DefaultClasspath.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/DefaultClasspath.java
2006-02-24 15:30:02 UTC (rev 1133)
+++ trunk/main/transit/core/src/main/net/dpml/transit/DefaultClasspath.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -0,0 +1,190 @@
+/*
+ * 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.transit;
+
+import java.net.URI;
+import java.io.OutputStream;
+import java.util.Arrays;
+
+import net.dpml.lang.Classpath;
+import net.dpml.lang.Category;
+
+/**
+ * A Plugin class contains immutable data about a plugin based on a
descriptor resolved
+ * from a 'plugin' artifact.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class DefaultClasspath implements Classpath
+{
+ private final URI[] m_system;
+ private final URI[] m_public;
+ private final URI[] m_protected;
+ private final URI[] m_private;
+
+ /**
+ * Creation of a new classpath definition.
+ * @param systemUris an array of uris representing the system classpath
extensions
+ * @param publicUris an array of uris representing the public classpath
entries
+ * @param protectedUris an array of uris representing protected classpath
entries
+ * @param privateUris an array of uris representing private classpath
entries
+ */
+ public DefaultClasspath(
+ URI[] systemUris, URI[] publicUris, URI[] protectedUris, URI[]
privateUris )
+ {
+ if( null == systemUris )
+ {
+ m_system = EMPTY_URIS;
+ }
+ else
+ {
+ m_system = systemUris;
+ }
+
+ if( null == publicUris )
+ {
+ m_public = EMPTY_URIS;
+ }
+ else
+ {
+ m_public = publicUris;
+ }
+
+ if( null == protectedUris )
+ {
+ m_protected = EMPTY_URIS;
+ }
+ else
+ {
+ m_protected = protectedUris;
+ }
+
+ if( null == privateUris )
+ {
+ m_private = EMPTY_URIS;
+ }
+ else
+ {
+ m_private = privateUris;
+ }
+ }
+
+ /**
+ * Return the classloader dependencies relative to a supplied classloader
category.
+ *
+ * @param category the classloader category
+ * @return an array of uris defining the classloader classpath for the
supplied category
+ */
+ public URI[] getDependencies( final Category category )
+ {
+ if( Category.SYSTEM.equals( category ) )
+ {
+ return m_system;
+ }
+ else if( Category.PUBLIC.equals( category ) )
+ {
+ return m_public;
+ }
+ else if( Category.PROTECTED.equals( category ) )
+ {
+ return m_protected;
+ }
+ else if( Category.PRIVATE.equals( category ) )
+ {
+ return m_private;
+ }
+ else
+ {
+ final String error =
+ "Category not recognized."
+ + "\nCategory: " + category;
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Compare this object with another for equality.
+ * @param other the other object
+ * @return TRUE if equal else FALSE
+ */
+ public boolean equals( Object other )
+ {
+ if( other instanceof Classpath )
+ {
+ Classpath classpath = (Classpath) other;
+ if( !Arrays.equals( m_system, classpath.getDependencies(
Category.SYSTEM ) ) )
+ {
+ return false;
+ }
+ if( !Arrays.equals( m_public, classpath.getDependencies(
Category.PUBLIC ) ) )
+ {
+ return false;
+ }
+ if( !Arrays.equals( m_protected, classpath.getDependencies(
Category.PROTECTED ) ) )
+ {
+ return false;
+ }
+ else
+ {
+ return Arrays.equals( m_private, classpath.getDependencies(
Category.PRIVATE ) );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Return the hashcode for the plugin definition.
+ * @return the hash code
+ */
+ public int hashCode()
+ {
+ int hash = hashArray( m_system );
+ hash ^= hashArray( m_public );
+ hash ^= hashArray( m_protected );
+ hash ^= hashArray( m_private );
+ return hash;
+ }
+
+ /**
+ * Utility to hash an array.
+ * @param array the array
+ * @return the hash value
+ */
+ protected int hashArray( Object[] array )
+ {
+ if( null == array )
+ {
+ return 0;
+ }
+ int hash = 0;
+ for( int i=0; i<array.length; i++ )
+ {
+ Object object = array[i];
+ hash ^= object.hashCode();
+ }
+ return hash;
+ }
+
+ private static final URI[] EMPTY_URIS = new URI[0];
+
+}

Copied: trunk/main/transit/core/src/main/net/dpml/transit/DefaultPlugin.java
(from rev 1136,
trunk/main/transit/core/src/main/net/dpml/lang/DefaultPlugin.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/DefaultPlugin.java
2006-02-24 17:52:10 UTC (rev 1136)
+++ trunk/main/transit/core/src/main/net/dpml/transit/DefaultPlugin.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -0,0 +1,328 @@
+/*
+ * Copyright 2004-2005 Stephen J. McConnell.
+ * Copyright 2004 Niclas Hedhman.
+ *
+ * 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.transit;
+
+import java.net.URI;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.io.IOException;
+import java.util.Properties;
+
+import net.dpml.lang.Plugin;
+import net.dpml.lang.Version;
+import net.dpml.lang.Classpath;
+import net.dpml.lang.Strategy;
+import net.dpml.lang.Category;
+
+/**
+ * A Plugin class contains immutable data about a plugin based on a
descriptor resolved
+ * from a 'plugin' artifact.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+class DefaultPlugin implements Plugin
+{
+ /**
+ * The plugin builder version value that will be used when reading and
writing
+ * plugin defintions.
+ */
+ public static final Version VERSION = new Version( 1, 0, 0 );
+
+ public static final String XML_HEADER =
+ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
+
+ public static final String STANDARD_NAME = "plugin";
+
+ public static final String STANDARD_PUBLIC_ID =
+ "-//DPML//DTD Standard Plugin Version 1.0//EN";
+
+ public static final String STANDARD_SYSTEM_ID =
+ "http://download.dpml.net/dtds/plugin_1_0.dtd";;
+
+ public static final String STANDARD_RESOURCE =
+ "net/dpml/lang/plugin_1_0.dtd";
+
+ private static final String PLUGIN_DOCTYPE =
+ "\n<!DOCTYPE "
+ + STANDARD_NAME
+ + " PUBLIC \""
+ + STANDARD_PUBLIC_ID
+ + "\" \""
+ + STANDARD_SYSTEM_ID
+ + "\" >";
+
+ private final String m_title;
+ private final String m_description;
+ private final URI m_uri;
+ private final Strategy m_strategy;
+ private final Classpath m_classpath;
+
+ /**
+ * Creation of a new plugin definition.
+ * @param title short title
+ * @param description textual description
+ * @param uri the uri from which the plugin was resolved
+ * @param strategy the plugin instantiation strategy definition
+ * @param classpath the classpath defintion
+ */
+ public DefaultPlugin(
+ String title, String description, URI uri, Strategy strategy,
Classpath classpath )
+ {
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+ if( null == strategy )
+ {
+ throw new NullPointerException( "strategy" );
+ }
+ if( null == classpath )
+ {
+ throw new NullPointerException( "classpath" );
+ }
+ m_uri = uri;
+ m_strategy = strategy;
+ m_title = title;
+ m_description = description;
+ m_classpath = classpath;
+ }
+
+ /**
+ * Return the plugin title.
+ * @return the plugin title
+ */
+ public String getTitle()
+ {
+ return m_title;
+ }
+
+ /**
+ * Return the plugin description.
+ * @return the plugin description
+ */
+ public String getDescription()
+ {
+ return m_description;
+ }
+
+ /**
+ * Return the plugin version.
+ * @return the plugin version identifier
+ */
+ public Version getVersion()
+ {
+ return VERSION;
+ }
+
+ /**
+ * Return the uri to the plugin descriptor.
+ * @return the plugin uri
+ */
+ public URI getURI()
+ {
+ return m_uri;
+ }
+
+ /**
+ * Return the plugin strategy.
+ * @return the plugin strategy
+ */
+ public Strategy getStrategy()
+ {
+ return m_strategy;
+ }
+
+ /**
+ * Return the classpath definition.
+ */
+ public Classpath getClasspath()
+ {
+ return m_classpath;
+ }
+
+ /**
+ * Write an XML representation of the plugin to the output stream.
+ * @param output the output stream
+ * @exception Exception if an error ocucrs during externalization
+ */
+ public void write( OutputStream output ) throws Exception
+ {
+ final Writer writer = new OutputStreamWriter( output );
+ writer.write( XML_HEADER );
+ writer.write( PLUGIN_DOCTYPE );
+ writeHeader( writer, "plugin", null, VERSION );
+ writeTitle( writer, getTitle() );
+ writeDescription( writer, getDescription() );
+ writeStrategy( writer, getStrategy() );
+ writeClasspath( writer, getClasspath() );
+ writeFooter( writer, "plugin" );
+ writer.write( "\n" );
+ writer.flush();
+ writer.close();
+ }
+
+ protected void writeHeader( Writer writer, String root, String
namespace, Version version ) throws IOException
+ {
+ if( null == namespace )
+ {
+ writer.write( "\n\n<" + root + " version=\"" + version + "\">" );
+ }
+ else
+ {
+ writer.write( "\n\n<" + root + " xmlns=\"" + namespace + "\"
version=\"" + version + "\">" );
+ }
+ }
+
+ protected void writeFooter( Writer writer, String root ) throws
IOException
+ {
+ writer.write( "\n</" + root + ">" );
+ }
+
+ protected void writeTitle( Writer writer, String title ) throws
IOException
+ {
+ if( null != title )
+ {
+ writer.write(
+ "\n <title>"
+ + title
+ + "</title>" );
+ }
+ }
+
+ protected void writeDescription( Writer writer, String description )
throws IOException
+ {
+ if( null != description )
+ {
+ writer.write(
+ "\n <description>"
+ + description
+ + "</description>" );
+ }
+ }
+
+ protected void writeStrategy( Writer writer, Strategy strategy ) throws
Exception
+ {
+ String handler = strategy.getHandlerClassname();
+ Properties properties = strategy.getProperties();
+ String[] keys = (String[]) properties.keySet().toArray( new
String[0] );
+ if( StandardHandler.class.getName().equals( handler ) )
+ {
+ writer.write( "\n <strategy>" );
+ }
+ else
+ {
+ writer.write( "\n <strategy class=\"" + handler + "\">" );
+ }
+ for( int i=0; i<keys.length; i++ )
+ {
+ String key = keys[i];
+ String value = properties.getProperty( key );
+ writer.write(
+ "\n <property name=\""
+ + key
+ + "\" value=\""
+ + value
+ + "\"/>" );
+ }
+ writer.write( "\n </strategy>" );
+ }
+
+ protected void writeClasspath( Writer writer, Classpath classpath )
throws Exception
+ {
+ writer.write( "\n <classpath>" );
+ URI[] sysUris = classpath.getDependencies( Category.SYSTEM );
+ if( sysUris.length > 0 )
+ {
+ writer.write( "\n <system>" );
+ for( int i=0; i<sysUris.length; i++ )
+ {
+ URI uri = sysUris[i];
+ writer.write( "\n <uri>" + uri + "</uri>" );
+ }
+ writer.write( "\n </system>" );
+ }
+ URI[] publicUris = classpath.getDependencies( Category.PUBLIC );
+ if( publicUris.length > 0 )
+ {
+ writer.write( "\n <public>" );
+ for( int i=0; i<publicUris.length; i++ )
+ {
+ URI uri = publicUris[i];
+ writer.write( "\n <uri>" + uri + "</uri>" );
+ }
+ writer.write( "\n </public>" );
+ }
+ URI[] protectedUris = classpath.getDependencies( Category.PROTECTED
);
+ if( protectedUris.length > 0 )
+ {
+ writer.write( "\n <protected>" );
+ for( int i=0; i<protectedUris.length; i++ )
+ {
+ URI uri = protectedUris[i];
+ writer.write( "\n <uri>" + uri + "</uri>" );
+ }
+ writer.write( "\n </protected>" );
+ }
+ URI[] privateUris = classpath.getDependencies( Category.PRIVATE );
+ if( privateUris.length > 0 )
+ {
+ writer.write( "\n <private>" );
+ for( int i=0; i<privateUris.length; i++ )
+ {
+ URI uri = privateUris[i];
+ writer.write( "\n <uri>" + uri + "</uri>" );
+ }
+ writer.write( "\n </private>" );
+ }
+ writer.write( "\n </classpath>" );
+ }
+
+ /**
+ * Compare this object with another for equality.
+ * @param other the other object
+ * @return TRUE if equal else FALSE
+ */
+ public boolean equals( Object other )
+ {
+ if( other instanceof DefaultPlugin )
+ {
+ DefaultPlugin plugin = (DefaultPlugin) other;
+ return m_uri.equals( plugin.getURI() );
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Return the hashcode for the plugin definition.
+ * @return the hash code
+ */
+ public int hashCode()
+ {
+ return m_uri.hashCode();
+ }
+
+ private static final URI[] EMPTY_URIS = new URI[0];
+
+}

Added:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginBuilder.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginBuilder.java
2006-02-28 10:57:01 UTC (rev 1142)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginBuilder.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -0,0 +1,255 @@
+/*
+ * 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.transit;
+
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import net.dpml.transit.util.ElementHelper;
+
+import net.dpml.lang.Plugin;
+import net.dpml.lang.Strategy;
+import net.dpml.lang.Classpath;
+import net.dpml.lang.SaxMonitor;
+import net.dpml.lang.DTD;
+import net.dpml.lang.DTDResolver;
+import net.dpml.lang.PluginFactory;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+
+/**
+ * Utility class supporting the reading of standard plugins definitions.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+class PluginBuilder
+{
+ private static final DTD[] DTDS = new DTD[]
+ {
+ new DTD(
+ DefaultPlugin.STANDARD_PUBLIC_ID,
+ DefaultPlugin.STANDARD_SYSTEM_ID,
+ DefaultPlugin.STANDARD_RESOURCE, null )
+ };
+
+ private static final DTDResolver DTD_RESOLVER =
+ new DTDResolver( DTDS, PluginBuilder.class.getClassLoader() );
+
+
+ private Logger m_logger;
+
+ public PluginBuilder( Logger logger )
+ {
+ m_logger = logger;
+ }
+
+ /**
+ * Construct a plugin from a supplied uri. Plugin construction will be
+ * delegated top a plugin helper identified by the xml ns urn of the root
+ * document (note - this is subject to review).
+ *
+ * @param url the plugin url
+ * @return the plugin
+ * @exception Exception if an error occurs during plugin loading
+ */
+ public Plugin load( final URL url ) throws Exception
+ {
+ URLConnection connection = url.openConnection();
+ InputStream input = connection.getInputStream();
+
+ final DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ factory.setValidating( true );
+ factory.setNamespaceAware( true );
+ factory.setExpandEntityReferences( true );
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver( DTD_RESOLVER );
+ ErrorHandler errors = new SaxMonitor( m_logger );
+ builder.setErrorHandler( errors );
+
+ final Document document = builder.parse( input );
+ final DocumentType docType = document.getDoctype();
+ final Element root = document.getDocumentElement();
+
+ String spec = root.getNamespaceURI(); // <------------ review !
+
+ String title = getTitle( root );
+ String description = getDescription( root );
+ URI uri = new URI( url.toString() );
+ Strategy strategy = getStrategy( root );
+ Classpath classpath = getClasspath( root );
+
+ if( null == spec )
+ {
+ return new DefaultPlugin( title, description, uri, strategy,
classpath );
+ }
+ else
+ {
+ PluginFactory pluginFactory = getPluginFactory( spec );
+ return pluginFactory.newPlugin( title, description, uri,
strategy, classpath );
+ }
+ }
+
+ private PluginFactory getPluginFactory( String spec ) throws Exception
+ {
+ URI uri = new URI( spec );
+ ClassLoader classloader = Plugin.class.getClassLoader();
+ Object[] args = new Object[]{m_logger};
+ Object instance =
+ Transit.getInstance().getRepository().getPlugin( classloader, uri,
args );
+ if( instance instanceof PluginFactory )
+ {
+ return (PluginFactory) instance;
+ }
+ else
+ {
+ final String error =
+ "Plugin factory artifact argument ["
+ + spec
+ + "] established an instance of ["
+ + instance.getClass().getName()
+ + "] which is not assignable to "
+ + PluginFactory.class.getName()
+ + ".";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ protected String getTitle( Element element )
+ {
+ if( null == element )
+ {
+ return null;
+ }
+ else
+ {
+ Element elem = ElementHelper.getChild( element, "title" );
+ if( null == elem )
+ {
+ return null;
+ }
+ else
+ {
+ return ElementHelper.getValue( element );
+ }
+ }
+ }
+
+ protected String getDescription( Element element )
+ {
+ if( null == element )
+ {
+ return null;
+ }
+ else
+ {
+ Element elem = ElementHelper.getChild( element, "description" );
+ if( null == elem )
+ {
+ return null;
+ }
+ else
+ {
+ return ElementHelper.getValue( element );
+ }
+ }
+ }
+
+ protected Strategy getStrategy( Element root )
+ {
+ Element strategy = ElementHelper.getChild( root, "strategy" );
+ if( null == strategy )
+ {
+ final String error =
+ "Required strategy element is not present in plugin
descriptor.";
+ throw new IllegalStateException( error );
+ }
+
+ String classname = ElementHelper.getAttribute( strategy, "class",
StandardHandler.class.getName() );
+ Properties properties = new Properties();
+ Element[] elements = ElementHelper.getChildren( strategy, "property"
);
+ for( int i=0; i<elements.length; i++ )
+ {
+ Element element = elements[i];
+ String name = ElementHelper.getAttribute( element, "name" );
+ String value = ElementHelper.getAttribute( element, "value" );
+ properties.setProperty( name, value );
+ }
+ return new DefaultStrategy( classname, properties );
+ }
+
+ 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 );
+ }
+
+ URI[] sys = buildURIs( classpath, "system" );
+ URI[] pub = buildURIs( classpath, "public" );
+ URI[] prot = buildURIs( classpath, "protected" );
+ URI[] priv = buildURIs( classpath, "private" );
+ return new DefaultClasspath( sys, pub, prot, priv );
+ }
+
+ public Plugin resolve(
+ String title, String description, URI uri, Strategy strategy,
Classpath classpath ) throws Exception
+ {
+ return new DefaultPlugin( title, description, uri, strategy,
classpath );
+ }
+
+ private URI[] buildURIs( Element classpath, String key ) throws Exception
+ {
+ Element category = ElementHelper.getChild( classpath, key );
+ if( null == category )
+ {
+ return null;
+ }
+ 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;
+ }
+ }
+}

Added:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginFactory.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginFactory.java
2006-02-28 10:57:01 UTC (rev 1142)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginFactory.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -0,0 +1,50 @@
+/*
+ * 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.transit;
+
+import java.net.URI;
+
+import net.dpml.lang.Plugin;
+import net.dpml.lang.Strategy;
+import net.dpml.lang.Classpath;
+import net.dpml.lang.PluginFactory;
+
+/**
+ * Default plugin factory.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class DefaultPluginFactory implements PluginFactory
+{
+ /**
+ * Construct a new plugin description instance using a supplied arguments
+ *
+ * @param uri the uri identifying the plugin
+ * @param element the root element definining the plugin
+ * @exception Exception if an error occurs
+ */
+ public Plugin newPlugin(
+ String title, String description, URI uri, Strategy strategy,
Classpath classpath )
+ throws Exception
+ {
+ return new DefaultPlugin( title, description, uri, strategy,
classpath );
+ }
+}
+

Copied:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultStrategy.java (from
rev 1133, trunk/main/transit/core/src/main/net/dpml/lang/DefaultStrategy.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/DefaultStrategy.java
2006-02-24 15:30:02 UTC (rev 1133)
+++ trunk/main/transit/core/src/main/net/dpml/transit/DefaultStrategy.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2004-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.transit;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import net.dpml.lang.Strategy;
+
+/**
+ * Plugin strategy.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class DefaultStrategy implements Strategy
+{
+ private final String m_handler;
+ private final Properties m_properties;
+
+ /**
+ * Creation of a new strategy definition.
+ * @param handler the plugin handler classname
+ * @param properties the handler supplimentary properties
+ */
+ public DefaultStrategy( final String handler, final Properties
properties )
+ {
+ if( null == handler )
+ {
+ throw new NullPointerException( "handler" );
+ }
+ m_handler = handler;
+ if( null == properties )
+ {
+ m_properties = new Properties();
+ }
+ else
+ {
+ m_properties = properties;
+ }
+ }
+
+ /**
+ * Return the classname of the custom plugin instantiation handler.
+ * @return the handler classname
+ */
+ public String getHandlerClassname()
+ {
+ return m_handler;
+ }
+
+ /**
+ * Return the the properties to be supplied to the handler.
+ * @return the custom properties
+ */
+ public Properties getProperties()
+ {
+ return m_properties;
+ }
+
+ /**
+ * Test this object for equality with the supplied object.
+ * @param other the other object
+ * @return true if the objects are equal
+ */
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else if( other instanceof Strategy )
+ {
+ Strategy strategy = (Strategy) other;
+ if( !m_handler.equals( strategy.getHandlerClassname() ) )
+ {
+ return false;
+ }
+ else
+ {
+ return m_properties.equals( strategy.getProperties() );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Return the hashcode for the instance.
+ * @return the instance hashcode
+ */
+ public int hashCode()
+ {
+ int hash = m_handler.hashCode();
+ hash ^= m_properties.hashCode();
+ return hash;
+ }
+}

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
2006-02-28 10:57:01 UTC (rev 1142)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -119,7 +119,7 @@
if( null != path )
{
URL url = Artifact.createArtifact( path ).toURL();
- TransitBuilder builder = new TransitBuilder();
+ TransitBuilder builder = new TransitBuilder( logger );
TransitDirective directive = builder.load( url );
return new DefaultTransitModel( logger, directive );
}
@@ -130,7 +130,7 @@
if( config.exists() )
{
URL url = config.toURL();
- TransitBuilder builder = new TransitBuilder();
+ TransitBuilder builder = new TransitBuilder( logger );
TransitDirective directive = builder.load( url );
return new DefaultTransitModel( logger, directive );
}

Modified: trunk/main/transit/core/src/main/net/dpml/transit/Logger.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/Logger.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/transit/Logger.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -20,8 +20,7 @@

/**
* Transit Logger is a interface through which different logging solutions
- * can be provided. Typical examples of logging implementations include
- * java.util.logging.Logger or Ant's Project.log() function.
+ * can be provided.
*
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/StandardHandler.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/StandardHandler.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/transit/StandardHandler.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -29,6 +29,7 @@
import java.util.Properties;

import net.dpml.lang.Handler;
+import net.dpml.lang.Strategy;

/**
* Default plugin instantiation handler.
@@ -42,15 +43,15 @@
* Instantiate the plugin.
*
* @param classloader the classloader
- * @param properties plugin strategy properties
+ * @param strategy the plugin strategy
* @param args commandline arguments
* @return the instance
* @exception Exception if an error occurs
*/
- public Object getPlugin( ClassLoader classloader, Properties properties,
Object[] args )
+ public Object getPlugin( ClassLoader classloader, Strategy strategy,
Object[] args )
throws Exception
{
- Class clazz = getPluginClass( classloader, properties );
+ Class clazz = getPluginClass( classloader, strategy );
return instantiate( clazz, args );
}

@@ -58,22 +59,23 @@
* Get a plugin class.
*
* @param classloader the plugin classloader
- * @param properties the supplimentary properties
+ * @param strategy the plugin strategy
* @return the plugin class
* @exception Exception if an error occurs
*/
- public Class getPluginClass( ClassLoader classloader, Properties
properties )
+ public Class getPluginClass( ClassLoader classloader, Strategy strategy )
throws Exception
{
if( null == classloader )
{
throw new NullArgumentException( "classloader" );
}
- if( null == properties )
+ if( null == strategy )
{
- throw new NullArgumentException( "properties" );
+ throw new NullArgumentException( "strategy" );
}

+ Properties properties = strategy.getProperties();
String target = properties.getProperty( "project.plugin.class" );
if( null == target )
{

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -40,7 +40,6 @@
import net.dpml.lang.Classpath;
import net.dpml.lang.Category;
import net.dpml.lang.Strategy;
-import net.dpml.lang.PluginBuilder;
import net.dpml.lang.Handler;

/**
@@ -178,8 +177,7 @@
ClassLoader classloader = createClassLoader( parent, descriptor
);
Strategy strategy = descriptor.getStrategy();
Handler handler = getHandler( classloader, strategy );
- Properties properties = strategy.getProperties();
- return handler.getPlugin( classloader, properties, args );
+ return handler.getPlugin( classloader, strategy, args );
}
catch( RepositoryException re )
{
@@ -249,8 +247,7 @@
ClassLoader classloader = createClassLoader( parent, descriptor
);
Strategy strategy = descriptor.getStrategy();
Handler handler = getHandler( classloader, strategy );
- Properties properties = strategy.getProperties();
- return handler.getPluginClass( classloader, properties );
+ return handler.getPluginClass( classloader, strategy );
}
catch( ClassNotFoundException e )
{
@@ -287,7 +284,7 @@

try
{
- PluginBuilder builder = new PluginBuilder();
+ PluginBuilder builder = new PluginBuilder( m_logger );
URL url = getURL( uri );
return builder.load( url );
}
@@ -299,30 +296,6 @@
+ "].";
throw new RepositoryException( error, e );
}
-
- /*
- Artifact artifact = getArtifact( uri );
-
- if( !"plugin".equals( artifact.getType() ) )
- {
- final String error =
- "Supplied artifact [" + artifact + "] is not a 'plugin' type.";
- throw new RepositoryException( error );
- }
- try
- {
- Properties attributes = getAttributes( artifact );
- return new PropertiesPlugin( attributes );
- }
- catch( RepositoryException ce )
- {
- final String error =
- "Unable to resolve a plugin descriptor for ["
- + artifact
- + "].";
- throw new RepositoryException( error, ce );
- }
- */
}

private URL getURL( URI uri ) throws IOException

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/main/net/dpml/transit/TransitBuilder.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -41,6 +41,7 @@

import net.dpml.lang.DTD;
import net.dpml.lang.DTDResolver;
+import net.dpml.lang.SaxMonitor;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
@@ -59,18 +60,18 @@
public class TransitBuilder
{
public static final String XML_HEADER =
- "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
+ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";

- public static final String NAME = "transit";
+ public static final String NAME = "transit";

public static final String PUBLIC_ID =
"-//DPML//DTD Transit Configuration Version 1.0//EN";
-
+
public static final String SYSTEM_ID =
- "http://download.dpml.net/dtds/transit_1_0.dtd";;
+ "http://download.dpml.net/dtds/transit_1_0.dtd";;

public static final String RESOURCE =
- "net/dpml/transit/transit_1_0.dtd";
+ "net/dpml/transit/transit_1_0.dtd";


private static final String DOCTYPE =
@@ -80,7 +81,7 @@
+ PUBLIC_ID
+ "\" \""
+ SYSTEM_ID
- + "\" >";
+ + "\" >";


private static final DTD[] DTDS = new DTD[]
@@ -94,8 +95,12 @@
private static final DTDResolver DTD_RESOLVER =
new DTDResolver( DTDS, TransitBuilder.class.getClassLoader() );

- private static final ErrorHandler ERROR_HANDLER =
- new InternalErrorHandler();
+ private Logger m_logger;
+
+ public TransitBuilder( Logger logger )
+ {
+ m_logger = logger;
+ }

/**
* Construct a transit configuration from a supplied uri.
@@ -115,7 +120,8 @@
factory.setExpandEntityReferences( true );
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver( DTD_RESOLVER );
- builder.setErrorHandler( ERROR_HANDLER );
+ ErrorHandler errors = new SaxMonitor( m_logger );
+ builder.setErrorHandler( errors );

final Document document = builder.parse( input );
//final DocumentType docType = document.getDoctype();
@@ -135,7 +141,7 @@
final Writer writer = new OutputStreamWriter( output );
try
{
- writer.write( XML_HEADER );
+ writer.write( XML_HEADER );
writer.write( DOCTYPE );

CacheDirective cache = directive.getCacheDirective();
@@ -512,24 +518,4 @@
return new String( password );
}
}
-
- //-------------------------------------------------------------
- // utilities
- //-------------------------------------------------------------
-
- private static final class InternalErrorHandler implements ErrorHandler
- {
- public void error( SAXParseException e ) throws SAXException
- {
- System.out.println( "ERROR: " + e.getMessage() );
- }
- public void fatalError( SAXParseException e ) throws SAXException
- {
- System.out.println( "FATAL: " + e.getMessage() );
- }
- public void warning( SAXParseException e ) throws SAXException
- {
- System.out.println( "WARN: " + e.getMessage() );
- }
- }
}

Deleted:
trunk/main/transit/core/src/test/net/dpml/lang/test/PluginTestCase.java
===================================================================
--- trunk/main/transit/core/src/test/net/dpml/lang/test/PluginTestCase.java
2006-02-28 10:57:01 UTC (rev 1142)
+++ trunk/main/transit/core/src/test/net/dpml/lang/test/PluginTestCase.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -1,136 +0,0 @@
-/*
- * Copyright 2004-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.test;
-
-import java.net.URI;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import net.dpml.lang.DefaultPlugin;
-import net.dpml.lang.Plugin;
-import net.dpml.lang.Strategy;
-import net.dpml.lang.DefaultStrategy;
-import net.dpml.lang.Category;
-import net.dpml.lang.PluginBuilder;
-import net.dpml.lang.Classpath;
-import net.dpml.lang.DefaultClasspath;
-
-/**
- * Plugin test case.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class PluginTestCase extends TestCase
-{
- private URI[] m_system;
- private URI[] m_public;
- private URI[] m_protected;
- private URI[] m_private;
- private Classpath m_classpath;
- private String m_title = "Sample Plugin";
- private String m_description = "Plugin generated via a testcase used for
validation of the externalization of a plugin definition to XML and the
subsequent reading in of the XML form and cronstruction of an equivalent
plugin definition.";
-
- /**
- * Testcase setup.
- * @exception Exception if an error occurs
- */
- public void setUp() throws Exception
- {
- m_system =
- new URI[]
- {
- new URI( "thing:a" ),
- new URI( "thing:b" )
- };
- m_public =
- new URI[]
- {
- new URI( "thing:c" ),
- new URI( "thing:d" ),
- new URI( "thing:e" )
- };
- m_protected =
- new URI[]
- {
- new URI( "thing:f" )
- };
- m_private =
- new URI[]
- {
- new URI( "thing:g" ),
- new URI( "thing:h" ),
- new URI( "thing:i" ),
- new URI( "thing:j" )
- };
- m_classpath = new DefaultClasspath( m_system, m_public, m_protected,
m_private );
- }
-
- /**
- * Test invalid null path argument.
- * @exception Exception if an unexpected error occurs
- */
- public void testPluginCreation() throws Exception
- {
- URI uri = new URI( "plugin:test" );
- Properties properties = new Properties();
- properties.setProperty( "foo", "bar" );
- properties.setProperty( "pi", "3.142" );
- Strategy strategy = new DefaultStrategy( "Test", properties );
- Plugin plugin =
- new DefaultPlugin(
- m_title, m_description, uri, strategy, m_classpath );
- assertEquals( "title", m_title, plugin.getTitle() );
- assertEquals( "description", m_description, plugin.getDescription()
);
- assertEquals( "uri", uri, plugin.getURI() );
- assertEquals( "strategy", strategy, plugin.getStrategy() );
- Classpath classpath = plugin.getClasspath();
- assertEquals( "classpath", m_classpath, classpath );
- assertEquals( "system", m_system.length, classpath.getDependencies(
Category.SYSTEM ).length );
- assertEquals( "public", m_public.length, classpath.getDependencies(
Category.PUBLIC ).length );
- assertEquals( "protected", m_protected.length,
classpath.getDependencies( Category.PROTECTED ).length );
- assertEquals( "private", m_private.length,
classpath.getDependencies( Category.PRIVATE ).length );
- }
-
- /**
- * Test the generation of a plugin xml file using the simple strategy.
- * @exception Exception if an unexpected error occurs
- */
- public void testSimpleStrategyExternalization() throws Exception
- {
- File file = new File( "target/test/plugin.xml" );
- Properties properties = new Properties();
- properties.setProperty( "foo", "bar" );
- properties.setProperty( "pi", "3.142" );
- URI uri = file.toURI();
- Strategy strategy = new DefaultStrategy( "Test", properties );
- Plugin plugin =
- new DefaultPlugin(
- m_title, m_description, uri, strategy, m_classpath );
- FileOutputStream output = new FileOutputStream( file );
- plugin.write( output );
- PluginBuilder builder = new PluginBuilder();
- Plugin p = builder.load( file.toURI().toURL() );
- assertEquals( "plugin", plugin, p );
- }
-
-}

Copied: trunk/main/transit/core/src/test/net/dpml/transit/PluginTestCase.java
(from rev 1133,
trunk/main/transit/core/src/test/net/dpml/lang/test/PluginTestCase.java)
===================================================================
--- trunk/main/transit/core/src/test/net/dpml/lang/test/PluginTestCase.java
2006-02-24 15:30:02 UTC (rev 1133)
+++ trunk/main/transit/core/src/test/net/dpml/transit/PluginTestCase.java
2006-02-28 11:02:01 UTC (rev 1143)
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2004-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.transit;
+
+import java.net.URI;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import net.dpml.lang.Plugin;
+import net.dpml.lang.Strategy;
+import net.dpml.lang.Category;
+import net.dpml.lang.Classpath;
+
+import net.dpml.transit.monitor.LoggingAdapter;
+
+/**
+ * Plugin test case.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class PluginTestCase extends TestCase
+{
+ private URI[] m_system;
+ private URI[] m_public;
+ private URI[] m_protected;
+ private URI[] m_private;
+ private Classpath m_classpath;
+ private String m_title = "Sample Plugin";
+ private String m_description = "Plugin generated via a testcase used for
validation of the externalization of a plugin definition to XML and the
subsequent reading in of the XML form and cronstruction of an equivalent
plugin definition.";
+
+ /**
+ * Testcase setup.
+ * @exception Exception if an error occurs
+ */
+ public void setUp() throws Exception
+ {
+ m_system =
+ new URI[]
+ {
+ new URI( "thing:a" ),
+ new URI( "thing:b" )
+ };
+ m_public =
+ new URI[]
+ {
+ new URI( "thing:c" ),
+ new URI( "thing:d" ),
+ new URI( "thing:e" )
+ };
+ m_protected =
+ new URI[]
+ {
+ new URI( "thing:f" )
+ };
+ m_private =
+ new URI[]
+ {
+ new URI( "thing:g" ),
+ new URI( "thing:h" ),
+ new URI( "thing:i" ),
+ new URI( "thing:j" )
+ };
+ m_classpath = new DefaultClasspath( m_system, m_public, m_protected,
m_private );
+ }
+
+ /**
+ * Test invalid null path argument.
+ * @exception Exception if an unexpected error occurs
+ */
+ public void testPluginCreation() throws Exception
+ {
+ URI uri = new URI( "plugin:test" );
+ Properties properties = new Properties();
+ properties.setProperty( "foo", "bar" );
+ properties.setProperty( "pi", "3.142" );
+ Strategy strategy = new DefaultStrategy( "Test", properties );
+ Plugin plugin =
+ new DefaultPlugin(
+ m_title, m_description, uri, strategy, m_classpath );
+ assertEquals( "title", m_title, plugin.getTitle() );
+ assertEquals( "description", m_description, plugin.getDescription()
);
+ assertEquals( "uri", uri, plugin.getURI() );
+ assertEquals( "strategy", strategy, plugin.getStrategy() );
+ Classpath classpath = plugin.getClasspath();
+ assertEquals( "classpath", m_classpath, classpath );
+ assertEquals( "system", m_system.length, classpath.getDependencies(
Category.SYSTEM ).length );
+ assertEquals( "public", m_public.length, classpath.getDependencies(
Category.PUBLIC ).length );
+ assertEquals( "protected", m_protected.length,
classpath.getDependencies( Category.PROTECTED ).length );
+ assertEquals( "private", m_private.length,
classpath.getDependencies( Category.PRIVATE ).length );
+ }
+
+ /**
+ * Test the generation of a plugin xml file using the simple strategy.
+ * @exception Exception if an unexpected error occurs
+ */
+ public void testSimpleStrategyExternalization() throws Exception
+ {
+ File file = new File( "target/test/plugin.xml" );
+ Properties properties = new Properties();
+ properties.setProperty( "foo", "bar" );
+ properties.setProperty( "pi", "3.142" );
+ URI uri = file.toURI();
+ Strategy strategy = new DefaultStrategy( "Test", properties );
+ Plugin plugin =
+ new DefaultPlugin(
+ m_title, m_description, uri, strategy, m_classpath );
+ FileOutputStream output = new FileOutputStream( file );
+ plugin.write( output );
+ PluginBuilder loader = new PluginBuilder( new LoggingAdapter() );
+ Plugin p = loader.load( file.toURI().toURL() );
+ assertEquals( "plugin", plugin, p );
+ }
+
+}




  • r1143 - in trunk/main/transit/core: . src/main/net/dpml/lang src/main/net/dpml/transit src/test/net/dpml/lang/test src/test/net/dpml/transit, mcconnell at BerliOS, 02/28/2006

Archive powered by MHonArc 2.6.24.

Top of Page