Skip to Content.
Sympa Menu

notify-dpml - r1156 - in trunk/lab: . component/src/main/dpmlx/component lang/src/main/dpmlx/lang lang/src/main/dpmlx/schema test test/etc/test test/src/test/dpmlx/schema/test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1156 - in trunk/lab: . component/src/main/dpmlx/component lang/src/main/dpmlx/lang lang/src/main/dpmlx/schema test test/etc/test test/src/test/dpmlx/schema/test
  • Date: Wed, 1 Mar 2006 06:14:22 +0100

Author: mcconnell
Date: 2006-03-01 06:14:18 +0100 (Wed, 01 Mar 2006)
New Revision: 1156

Added:
trunk/lab/component/src/main/dpmlx/component/ComponentStrategy.java
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
trunk/lab/lang/src/main/dpmlx/lang/Info.java
trunk/lab/lang/src/main/dpmlx/lang/Part.java
trunk/lab/lang/src/main/dpmlx/lang/Strategy.java
trunk/lab/lang/src/main/dpmlx/lang/StrategyBuilder.java
trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java
trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
Removed:
trunk/lab/component/src/main/dpmlx/component/ComponentPartHandler.java
Modified:
trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java
trunk/lab/lang/src/main/dpmlx/schema/StandardBuilder.java
trunk/lab/library.xml
trunk/lab/test/build.xml
trunk/lab/test/etc/test/component.xml
trunk/lab/test/etc/test/plugin.xml
trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
Log:
move test content into functional classes

Deleted:
trunk/lab/component/src/main/dpmlx/component/ComponentPartHandler.java
===================================================================
--- trunk/lab/component/src/main/dpmlx/component/ComponentPartHandler.java
2006-03-01 00:08:43 UTC (rev 1155)
+++ trunk/lab/component/src/main/dpmlx/component/ComponentPartHandler.java
2006-03-01 05:14:18 UTC (rev 1156)
@@ -1,53 +0,0 @@
-/*
- * Copyright 2006 Stephen J. McConnell.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package dpmlx.component;
-
-import java.net.URI;
-
-import dpmlx.lang.PartHandler;
-
-import org.w3c.dom.Element;
-
-/**
- * Component part handler.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class ComponentPartHandler implements PartHandler
-{
- private Element m_element;
-
- public ComponentPartHandler( Element element )
- {
- m_element = element;
- }
-
- /**
- * Handle the deployment of a part.
- *
- * @param classloader the classloader
- * @param args supplimentary deployment arguments
- * @exception Exception if an error occurs
- */
- public Object getInstance( ClassLoader classloader, Object[] args )
throws Exception
- {
- return null;
- }
-}

Added: trunk/lab/component/src/main/dpmlx/component/ComponentStrategy.java
===================================================================
--- trunk/lab/component/src/main/dpmlx/component/ComponentStrategy.java
2006-03-01 00:08:43 UTC (rev 1155)
+++ trunk/lab/component/src/main/dpmlx/component/ComponentStrategy.java
2006-03-01 05:14:18 UTC (rev 1156)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dpmlx.component;
+
+import java.io.Serializable;
+import java.net.URI;
+
+import dpmlx.lang.Strategy;
+
+/**
+ * Part deployment strategy description.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ComponentStrategy extends Strategy
+{
+ public ComponentStrategy( Serializable data ) throws Exception
+ {
+ super( new URI( "link:plugin:dpml/metro/dpml-metro-runtime" ), data
);
+ }
+}

Added:
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
===================================================================
---
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
2006-03-01 00:08:43 UTC (rev 1155)
+++
trunk/lab/component/src/main/dpmlx/component/ComponentStrategyBuilder.java
2006-03-01 05:14:18 UTC (rev 1156)
@@ -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 dpmlx.component;
+
+import java.net.URI;
+
+import dpmlx.lang.Strategy;
+import dpmlx.lang.StrategyBuilder;
+
+import org.w3c.dom.Element;
+
+/**
+ * Component part handler.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class ComponentStrategyBuilder implements StrategyBuilder
+{
+ /**
+ * Return a deployment strategy.
+ *
+ * @return the deployment strategy
+ * @exception Exception if an error occurs
+ */
+ public Strategy buildStrategy( Element element ) throws Exception
+ {
+ return new ComponentStrategy( "Hello World" );
+ }
+}

Added: trunk/lab/lang/src/main/dpmlx/lang/Info.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/Info.java 2006-03-01 00:08:43
UTC (rev 1155)
+++ trunk/lab/lang/src/main/dpmlx/lang/Info.java 2006-03-01 05:14:18
UTC (rev 1156)
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dpmlx.lang;
+
+import java.io.Serializable;
+import java.net.URI;
+
+/**
+ * Part info description.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class Info implements Serializable
+{
+ private final String m_title;
+ private final String m_description;
+
+ public Info( String title, String description )
+ {
+ if( null == title )
+ {
+ m_title = "Untitled";
+ }
+ else
+ {
+ m_title = title;
+ }
+ if( null == description )
+ {
+ m_description = "";
+ }
+ else
+ {
+ m_description = description;
+ }
+ }
+
+ /**
+ * Get the part title.
+ *
+ * @return the title
+ */
+ public String getTitle()
+ {
+ return m_title;
+ }
+
+ /**
+ * Get the part description.
+ *
+ * @return the description
+ */
+ public String getDescription()
+ {
+ return m_description;
+ }
+
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else if( other instanceof Info )
+ {
+ Info info = (Info) other;
+ if( !m_title.equals( info.m_title ) )
+ {
+ return false;
+ }
+ else
+ {
+ return m_description.equals( info.m_description );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ int hash = m_title.hashCode();
+ hash ^= m_description.hashCode();
+ return hash;
+ }
+}

Added: trunk/lab/lang/src/main/dpmlx/lang/Part.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/Part.java 2006-03-01 00:08:43
UTC (rev 1155)
+++ trunk/lab/lang/src/main/dpmlx/lang/Part.java 2006-03-01 05:14:18
UTC (rev 1156)
@@ -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 dpmlx.lang;
+
+import java.io.Serializable;
+import java.net.URI;
+
+import net.dpml.lang.Classpath;
+
+/**
+ * Interface implemented by part handlers.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class Part implements Serializable
+{
+ private final Info m_info;
+ private final Strategy m_strategy;
+ private final Classpath m_classpath;
+
+ public Part( Info info, Strategy strategy, Classpath classpath )
+ {
+ if( null == info )
+ {
+ throw new NullPointerException( "info" );
+ }
+ if( null == strategy )
+ {
+ throw new NullPointerException( "strategy" );
+ }
+ if( null == classpath )
+ {
+ throw new NullPointerException( "classpath" );
+ }
+ m_info = info;
+ m_strategy = strategy;
+ m_classpath = classpath;
+ }
+
+ /**
+ * Get the part info descriptor.
+ *
+ * @return the part info datastructure
+ */
+ public Info getInfo()
+ {
+ return m_info;
+ }
+
+ /**
+ * Get the part deployment strategy.
+ *
+ * @return the strategy definition
+ */
+ public Strategy getStrategy()
+ {
+ return m_strategy;
+ }
+
+ /**
+ * Get the part classpath definition.
+ *
+ * @return the classpath definition
+ */
+ public Classpath getClasspath()
+ {
+ return m_classpath;
+ }
+
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else if( other instanceof Part )
+ {
+ Part part = (Part) other;
+ if( !m_info.equals( part.m_info ) )
+ {
+ return false;
+ }
+ else if( !m_strategy.equals( part.m_strategy ) )
+ {
+ return false;
+ }
+ else
+ {
+ return m_classpath.equals( part.m_classpath );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ int hash = m_info.hashCode();
+ hash ^= m_strategy.hashCode();
+ hash ^= m_classpath.hashCode();
+ return hash;
+ }
+}

Modified: trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java 2006-03-01 00:08:43
UTC (rev 1155)
+++ trunk/lab/lang/src/main/dpmlx/lang/PartHandler.java 2006-03-01 05:14:18
UTC (rev 1156)
@@ -29,11 +29,18 @@
public interface PartHandler
{
/**
+ * Return a deployment defintion.
+ *
+ * @param classloader the classloader
+ * @exception Exception if an error occurs
+ */
+ Strategy getStrategy() throws Exception;
+
+ /**
* Handle the deployment of a part.
*
- * @param classloader the classloader
* @param args supplimentary deployment arguments
* @exception Exception if an error occurs
*/
- Object getInstance( ClassLoader classloader, Object[] args ) throws
Exception;
+ Object getInstance( Object[] args ) throws Exception;
}

Added: trunk/lab/lang/src/main/dpmlx/lang/Strategy.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/Strategy.java 2006-03-01 00:08:43
UTC (rev 1155)
+++ trunk/lab/lang/src/main/dpmlx/lang/Strategy.java 2006-03-01 05:14:18
UTC (rev 1156)
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dpmlx.lang;
+
+import java.io.Serializable;
+import java.net.URI;
+
+/**
+ * Part deployment strategy description.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class Strategy implements Serializable
+{
+ private final URI m_controller;
+ private final Serializable m_data;
+
+ public Strategy( URI controller, Serializable data )
+ {
+ if( null == controller )
+ {
+ throw new NullPointerException( "controller" );
+ }
+ if( null == data )
+ {
+ throw new NullPointerException( "data" );
+ }
+ m_controller = controller;
+ m_data = data;
+ }
+
+ /**
+ * Get the uri identifying the deployment controller.
+ *
+ * @return the deployment controller uri
+ */
+ public URI getControllerURI()
+ {
+ return m_controller;
+ }
+
+ /**
+ * Get the deployment data.
+ *
+ * @return the deployment datastructure
+ */
+ public Object getDeploymentData()
+ {
+ return m_data;
+ }
+
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else if( other instanceof Strategy )
+ {
+ Strategy strategy = (Strategy) other;
+ if( !m_controller.equals( strategy.m_controller ) )
+ {
+ return false;
+ }
+ else
+ {
+ return m_data.equals( strategy.m_data );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ int hash = m_controller.hashCode();
+ hash ^= m_data.hashCode();
+ return hash;
+ }
+}

Added: trunk/lab/lang/src/main/dpmlx/lang/StrategyBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/lang/StrategyBuilder.java 2006-03-01
00:08:43 UTC (rev 1155)
+++ trunk/lab/lang/src/main/dpmlx/lang/StrategyBuilder.java 2006-03-01
05:14:18 UTC (rev 1156)
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dpmlx.lang;
+
+import org.w3c.dom.Element;
+
+/**
+ * Construct an Strategy instance from a DOM Element.
+ */
+public interface StrategyBuilder
+{
+ Strategy buildStrategy( Element element ) throws Exception;
+}

Added: trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java 2006-03-01
00:08:43 UTC (rev 1155)
+++ trunk/lab/lang/src/main/dpmlx/schema/PartBuilder.java 2006-03-01
05:14:18 UTC (rev 1156)
@@ -0,0 +1,269 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dpmlx.schema;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+
+import dpmlx.lang.Part;
+import dpmlx.lang.StrategyBuilder;
+import dpmlx.lang.Info;
+import dpmlx.lang.Strategy;
+
+import net.dpml.lang.Classpath;
+
+import net.dpml.transit.Artifact;
+import net.dpml.transit.Transit;
+import net.dpml.transit.Repository;
+import net.dpml.transit.util.ElementHelper;
+import net.dpml.transit.artifact.ArtifactNotFoundException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Construct a part.
+ */
+public class PartBuilder
+{
+ private static StandardBuilder BUILDER = new StandardBuilder();
+
+ public Part loadPart( URI uri ) throws Exception
+ {
+ ClassLoader base = Part.class.getClassLoader();
+ return loadPart( base, uri );
+ }
+
+ public Part loadPart( ClassLoader base, URI uri ) throws Exception
+ {
+ final Document document = BUILDER.parse( uri );
+ final Element root = document.getDocumentElement();
+ return buildPart( base, root );
+ }
+
+ public Part buildPart( ClassLoader base, Element root ) throws Exception
+ {
+ final String namespace = root.getNamespaceURI();
+ if( !isRecognized( namespace ) )
+ {
+ final String error =
+ "Element namespace is not recognized.";
+ throw new IllegalArgumentException( error );
+ }
+
+ 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 plugin = ElementHelper.getChild( root, "plugin" );
+ if( null != plugin )
+ {
+ // This is a standard transit plugin containing either
+ // a <class> element or a <resource> element as such is
+ // a concern private to the transit implementation to
+ // resolve the plugin strategy.
+
+ Element element = getSingleNestedElement( plugin );
+ PluginStrategyBuilder builder = new PluginStrategyBuilder();
+ return builder.buildStrategy( element );
+ }
+ else
+ {
+ // This is a custom deployment strategy defined under
+ // a <strategy> element and all we know is its namespace
+ // and that the nested element is the argument to a
+ // custom instantiation handler. On the grounds that the
+ // namespace is declared in the form of an artifact with
+ // the type 'xsd', we construct a new plugin artifact using
+ // the same group, name and version. If such a plugin
+ // exists using the link protocol we use otherwise we
+ // attempt to locate a plugin using the artifact protocol.
+
+ Element strategy = ElementHelper.getChild( root, "strategy" );
+ Element element = getSingleNestedElement( strategy );
+ String namespace = element.getNamespaceURI();
+ URI uri = getBuilderURI( namespace );
+ StrategyBuilder builder = loadStrategyBuilder( uri );
+ return builder.buildStrategy( element );
+ }
+ }
+
+ private ClassLoader createClassLoader(
+ ClassLoader base, URI uri, Classpath classpath ) throws IOException
+ {
+ Repository repository = Transit.getInstance().getRepository();
+ return repository.createClassLoader( base, uri, classpath );
+ }
+
+ private boolean isRecognized( String namespace )
+ {
+ return true; // to be done
+ }
+
+ private Info getInfo( Element root )
+ {
+ Element element = ElementHelper.getChild( root, "info" );
+ Element titleElement = ElementHelper.getChild( element, "title" );
+ Element descriptionElement = ElementHelper.getChild( element,
"description" );
+ String title = ElementHelper.getValue( titleElement );
+ String description = ElementHelper.getValue( descriptionElement );
+ return new Info( title, description );
+ }
+
+ 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 Classpath( sys, pub, prot, priv );
+ }
+
+ 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 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 );
+ }
+ }
+
+ }
+
+ private URI getBuilderURI( String urn ) throws Exception
+ {
+ URI raw = new URI( urn );
+ if( Artifact.isRecognized( raw ) )
+ {
+ 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();
+
+ try
+ {
+ String path = "link:plugin:" + group + "/" + name;
+ Artifact link = Artifact.createArtifact( path );
+ System.out.println( " checking: " + link );
+ URL linkUrl = link.toURL();
+ linkUrl.getContent( new Class[]{File.class} ); // test for
existance
+ return link.toURI();
+ }
+ catch( ArtifactNotFoundException e )
+ {
+ Artifact result = Artifact.createArtifact( group, name,
version, "plugin" );
+ try
+ {
+ System.out.println( " checking: " + result );
+ URL url = result.toURL();
+ url.getContent( new Class[]{File.class} );
+ return result.toURI();
+ }
+ catch( ArtifactNotFoundException anfe )
+ {
+ System.out.println( " unresolved" );
+ final String error =
+ "Unable to resolve a strategy handler for the urn ["
+ + urn
+ + "].";
+ throw new UnresolvableHandlerException( error,
result.toURI() );
+ }
+ }
+ }
+ else
+ {
+ final String error =
+ "Namespace urn ["
+ + urn
+ + "] is not a recognized artifact protocol.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private StrategyBuilder loadStrategyBuilder( URI uri ) throws Exception
+ {
+ ClassLoader classloader = StrategyBuilder.class.getClassLoader();
+ Repository repository = Transit.getInstance().getRepository();
+ Object[] args = new Object[0];
+ Object handler = repository.getPlugin( classloader, uri, args );
+ if( handler instanceof StrategyBuilder )
+ {
+ return (StrategyBuilder) handler;
+ }
+ else
+ {
+ final String error =
+ "Plugin ["
+ + uri
+ + "] does not implement the "
+ + StrategyBuilder.class.getName()
+ + " interface.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+}

Added: trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
2006-03-01 00:08:43 UTC (rev 1155)
+++ trunk/lab/lang/src/main/dpmlx/schema/PluginStrategyBuilder.java
2006-03-01 05:14:18 UTC (rev 1156)
@@ -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 dpmlx.schema;
+
+import java.io.Serializable;
+import java.net.URI;
+
+import dpmlx.lang.Strategy;
+import dpmlx.lang.StrategyBuilder;
+
+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 PluginStrategyBuilder implements StrategyBuilder
+{
+ public Strategy buildStrategy( Element element ) throws Exception
+ {
+ String name = element.getTagName();
+ if( "class".equals( name ) )
+ {
+ String classname = ElementHelper.getValue( element );
+ return new ClassStrategy( classname );
+ }
+ else if( "resource".equals( name ) )
+ {
+ Element urnElement = ElementHelper.getChild( element, "urn" );
+ Element pathElement = ElementHelper.getChild( element, "path" );
+ String urn = ElementHelper.getValue( urnElement );
+ String path = ElementHelper.getValue( pathElement );
+ Resource resource = new Resource( urn, path );
+ return new ResourceStrategy( resource );
+ }
+ else
+ {
+ final String error =
+ "Element [" + name + "] is not recognized.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Handle the deployment of a part.
+ *
+ * @param classloader the classloader
+ * @param args supplimentary deployment arguments
+ * @exception Exception if an error occurs
+ */
+ /*
+ public Object getInstance( Object[] args ) throws Exception
+ {
+ if( m_strategy instanceof ClassStrategy )
+ {
+ ClassStrategy strategy = (ClassStrategy) m_strategy;
+ Class c = strategy.getPluginClass( m_classloader );
+ Repository repository = Transit.getInstance().getRepository();
+ repository.instantiate( c, args );
+ }
+ else
+ {
+ final String error =
+ "Resource instantiation not supported.";
+ throw new UnsupportedOperationException( error );
+ }
+ }
+ */
+
+ private abstract static class PluginStrategy extends Strategy
+ {
+ PluginStrategy( URI uri, Serializable data ) throws Exception
+ {
+ super( uri, data );
+ }
+ }
+
+ private static class ClassStrategy extends PluginStrategy
+ {
+ ClassStrategy( String classname ) throws Exception
+ {
+ super( new URI( "plugin:class" ), classname );
+ }
+
+ public String getClassname()
+ {
+ return (String) super.getDeploymentData();
+ }
+
+ public Class getPluginClass( ClassLoader classloader ) throws
ClassNotFoundException
+ {
+ String classname = getClassname();
+ return classloader.loadClass( classname );
+ }
+ }
+
+ private static class ResourceStrategy extends PluginStrategy
+ {
+ ResourceStrategy( Resource resource ) throws Exception
+ {
+ super( new URI( "plugin:resource" ), resource );
+ }
+
+ public Resource getResource()
+ {
+ return (Resource) super.getDeploymentData();
+ }
+ }
+
+ private static class Resource implements Serializable
+ {
+ private final String m_urn;
+ private final String m_path;
+
+ public Resource( String urn, String path )
+ {
+ m_urn = urn;
+ m_path = path;
+ }
+
+ public boolean equals( Object other )
+ {
+ if( null == other )
+ {
+ return false;
+ }
+ else if( other instanceof Resource )
+ {
+ Resource resource = (Resource) other;
+ if( !m_urn.equals( resource.m_urn ) )
+ {
+ return false;
+ }
+ else
+ {
+ return m_path.equals( resource.m_path );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ int hash = m_urn.hashCode();
+ hash ^= m_path.hashCode();
+ return hash;
+ }
+ }
+}

Modified: trunk/lab/lang/src/main/dpmlx/schema/StandardBuilder.java
===================================================================
--- trunk/lab/lang/src/main/dpmlx/schema/StandardBuilder.java 2006-03-01
00:08:43 UTC (rev 1155)
+++ trunk/lab/lang/src/main/dpmlx/schema/StandardBuilder.java 2006-03-01
05:14:18 UTC (rev 1156)
@@ -19,13 +19,17 @@
package dpmlx.schema;

import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.stream.StreamSource;

+import net.dpml.transit.Artifact;
+
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
@@ -39,14 +43,15 @@

public class StandardBuilder extends DefaultHandler
{
- static final String PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
+ private static final String XML_CONSTANTS_CLASSNAME =
+ "javax.xml.XMLConstants";
+
+ private static final String SCHEMA_FACTORY_CLASSNAME =
+ "javax.xml.validation.SchemaFactory";
+
+ private static final String SCHEMA_CLASSNAME =
+ "javax.xml.validation.Schema";

- protected static final String DEFAULT_API_TO_USE = "sax";
-
- protected static final boolean DEFAULT_XINCLUDE = false;
-
- protected static final boolean DEFAULT_SECURE_PROCESSING = false;
-
private static final String FEATURE_SECURE_PROCESSING =
"http://javax.xml.XMLConstants/feature/secure-processing";;

@@ -56,57 +61,81 @@
private static boolean VALIDATING = isSchemaCapable();

//
- // Constructors
+ // implementation
//

- public StandardBuilder( String[] args ) throws Exception
+ public Document parse( String source ) throws Exception
{
- if (args.length == 1)
- {
- try
- {
- String source = args[0];
- parse( source );
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
+ DocumentBuilder db = getDocumentBuilder();
+ return db.parse( source );
}

- public Document parse( String source ) throws Exception
+ public Document parse( URI uri ) throws Exception
{
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware( true );
+ DocumentBuilder db = getDocumentBuilder();
+ return db.parse( uri.toASCIIString() );
+ }
+
+ private DocumentBuilder getDocumentBuilder() throws Exception
+ {
+ DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware( true );
if( VALIDATING )
{
- setupBuilderForSchemaValidation( dbf );
+ setupBuilderForSchemaValidation( factory );
}
- DocumentBuilder db = dbf.newDocumentBuilder();
- db.setErrorHandler( new ParserAPIUsage() );
- return db.parse( source );
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setErrorHandler( new ParserAPIUsage() );
+ return builder;
}

- private void setupBuilderForSchemaValidation( DocumentBuilderFactory dbf
) throws Exception
+ private void setupBuilderForSchemaValidation( DocumentBuilderFactory dbf
)
{
- Class schemaFactoryClass = getClass().getClassLoader().loadClass(
"javax.xml.validation.SchemaFactory" );
- Class schemaClass = getClass().getClassLoader().loadClass(
"javax.xml.validation.Schema" );
-
- Method newInstanceMethod = schemaFactoryClass.getMethod(
"newInstance", new Class[]{ String.class } );
- Object schemaFactory = newInstanceMethod.invoke( null, new Object[]{
W3C_XML_SCHEMA_NS_URI } );
- Method newSchemaMethod = schemaFactoryClass.getMethod( "newSchema",
new Class[0] );
- Object schemaObject = newSchemaMethod.invoke( schemaFactory, new
Object[0] );
- Method setSchemaMethod = DocumentBuilderFactory.class.getMethod(
"setSchema", new Class[]{ schemaClass } );
- setSchemaMethod.invoke( dbf, new Object[]{ schemaObject } );
+ try
+ {
+ ClassLoader classloader = getClass().getClassLoader();
+ Class schemaFactoryClass = classloader.loadClass(
SCHEMA_FACTORY_CLASSNAME );
+ Class schemaClass = classloader.loadClass( SCHEMA_CLASSNAME );
+
+ Method newInstanceMethod =
+ schemaFactoryClass.getMethod( "newInstance", new Class[]{
String.class } );
+ Object schemaFactory =
+ newInstanceMethod.invoke( null, new Object[]{
W3C_XML_SCHEMA_NS_URI } );
+ Method newSchemaMethod =
+ schemaFactoryClass.getMethod( "newSchema", new Class[0] );
+ Object schemaObject =
+ newSchemaMethod.invoke( schemaFactory, new Object[0] );
+ Method setSchemaMethod =
+ DocumentBuilderFactory.class.getMethod( "setSchema", new
Class[]{ schemaClass } );
+ setSchemaMethod.invoke( dbf, new Object[]{ schemaObject } );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while configuring XML parser for schema
validation.";
+ throw new RuntimeException( error, e );
+ }
}
+
+ private URL getURL( URI uri ) throws Exception
+ {
+ if( Artifact.isRecognized( uri ) )
+ {
+ return Artifact.createArtifact( uri ).toURL();
+ }
+ else
+ {
+ return uri.toURL();
+ }
+ }
+

private static boolean isSchemaCapable()
{
try
{
ClassLoader classloader = StandardBuilder.class.getClassLoader();
- classloader.loadClass( "javax.xml.XMLConstants" );
+ classloader.loadClass( XML_CONSTANTS_CLASSNAME );
System.out.println( "validating" );
return true;
}

Modified: trunk/lab/library.xml
===================================================================
--- trunk/lab/library.xml 2006-03-01 00:08:43 UTC (rev 1155)
+++ trunk/lab/library.xml 2006-03-01 05:14:18 UTC (rev 1156)
@@ -25,10 +25,6 @@
<project name="dpmlx-lang" basedir="lang">
<types>
<type id="jar"/>
- <type id="plugin" alias="true">
- <property name="project.plugin.class"
- value="dpmlx.schema.StandardBuilder"/>
- </type>
</types>
<dependencies scope="runtime">
<include ref="dpml/transit/dpml-transit-main"/>
@@ -41,7 +37,7 @@
<type id="jar"/>
<type id="plugin" alias="true">
<property name="project.plugin.class"
- value="dpmlx.component.ComponentPartHandler"/>
+ value="dpmlx.component.ComponentStrategyBuilder"/>
</type>
</types>
<dependencies scope="runtime">

Modified: trunk/lab/test/build.xml
===================================================================
--- trunk/lab/test/build.xml 2006-03-01 00:08:43 UTC (rev 1155)
+++ trunk/lab/test/build.xml 2006-03-01 05:14:18 UTC (rev 1156)
@@ -9,7 +9,6 @@
<target name="init" depends="standard.init">
<x:filter feature="uri" type="xsd" token="COMPONENT-XSD-URI"
ref="dpmlx/dpmlx-component"/>
<x:filter feature="uri" type="xsd" token="PART-XSD-URI"
ref="dpmlx/dpmlx-part"/>
- <x:filter feature="uri" type="plugin" token="LANG-PLUGIN-URI"
ref="dpmlx/dpmlx-lang"/>
</target>

</project>

Modified: trunk/lab/test/etc/test/component.xml
===================================================================
--- trunk/lab/test/etc/test/component.xml 2006-03-01 00:08:43 UTC (rev
1155)
+++ trunk/lab/test/etc/test/component.xml 2006-03-01 05:14:18 UTC (rev
1156)
@@ -26,8 +26,8 @@

<classpath>
<public>
- <uri>link:jar:fred/blogs"</uri>
- <uri>link:jar:peter/rabbit"</uri>
+ <uri>link:jar:fred/blogs</uri>
+ <uri>link:jar:peter/rabbit</uri>
</public>
</classpath>


Modified: trunk/lab/test/etc/test/plugin.xml
===================================================================
--- trunk/lab/test/etc/test/plugin.xml 2006-03-01 00:08:43 UTC (rev 1155)
+++ trunk/lab/test/etc/test/plugin.xml 2006-03-01 05:14:18 UTC (rev 1156)
@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="
@PART-XSD-URI@ @PART-XSD-URI@
- ">
+ " >

<info title="Demo Plugin">
<description>
@@ -23,8 +23,8 @@

<classpath>
<public>
- <uri>link:jar:fred/blogs"</uri>
- <uri>link:jar:peter/rabbit"</uri>
+ <uri>link:jar:fred/blogs</uri>
+ <uri>link:jar:peter/rabbit</uri>
</public>
</classpath>


Modified: trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
===================================================================
--- trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-03-01 00:08:43 UTC (rev 1155)
+++ trunk/lab/test/src/test/dpmlx/schema/test/SchemaTestCase.java
2006-03-01 05:14:18 UTC (rev 1156)
@@ -5,16 +5,10 @@
import java.net.URI;
import java.net.URL;

-import dpmlx.lang.PartHandler;
-import dpmlx.schema.StandardBuilder;
+import dpmlx.lang.Part;
+import dpmlx.schema.PartBuilder;
import dpmlx.schema.UnresolvableHandlerException;

-import net.dpml.transit.Artifact;
-import net.dpml.transit.Transit;
-import net.dpml.transit.Repository;
-import net.dpml.transit.artifact.ArtifactNotFoundException;
-import net.dpml.transit.util.ElementHelper;
-
import junit.framework.TestCase;

import org.w3c.dom.Document;
@@ -26,19 +20,19 @@
*/
public class SchemaTestCase extends TestCase
{
- StandardBuilder m_builder;
+ static
+ {
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ }

+ PartBuilder m_builder;
+
/**
* Test the demo class.
*/
public void setUp() throws Exception
{
- ClassLoader classloader = Transit.class.getClassLoader();
- URI uri = new URI( "@LANG-PLUGIN-URI@" );
- Object[] args = new Object[0];
- m_builder =
- (StandardBuilder) Transit.getInstance().getRepository().getPlugin(
- classloader, uri, args );
+ m_builder = new PartBuilder();
}

/**
@@ -46,24 +40,24 @@
*/
public void testPlugin() throws Exception
{
- evaluateDocument( "target/test/plugin.xml" );
+ evaluateDocument( "plugin.xml" );
}

public void testComponent() throws Exception
{
- try
- {
- evaluateDocument( "target/test/component.xml" );
- }
- catch( UnresolvableHandlerException e )
- {
- // expected
- }
+ evaluateDocument( "component.xml" );
}

private void evaluateDocument( String path ) throws Exception
{
- System.out.println( "source: " + path );
+ String base = System.getProperty( "project.test.dir" );
+ File test = new File( base );
+ File file = new File( test, path );
+ System.out.println( "source: " + file );
+ Part part = m_builder.loadPart( file.toURI() );
+ System.out.println( "# PART: " + part );
+
+ /*
Document doc = m_builder.parse( path );
final Element root = doc.getDocumentElement();
final String namespace = root.getNamespaceURI();
@@ -106,8 +100,10 @@
//Object instance = handler.getInstance( classloader, new
Object[0] );
System.out.println( "handler: " + handler.getClass().getName() );
}
+ */
}

+ /*
private Element getSingleNestedElement( Element parent ) throws Exception
{
if( null == parent )
@@ -204,4 +200,5 @@
throw new IllegalArgumentException( error );
}
}
+ */
}




  • r1156 - in trunk/lab: . component/src/main/dpmlx/component lang/src/main/dpmlx/lang lang/src/main/dpmlx/schema test test/etc/test test/src/test/dpmlx/schema/test, mcconnell at BerliOS, 03/01/2006

Archive powered by MHonArc 2.6.24.

Top of Page