Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2051 - in development/laboratory/plus: api/builder/src/main/net/dpml/metro/builder standard/builder/src/main/net/dpml/metro/builder/impl test/example/impl

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2051 - in development/laboratory/plus: api/builder/src/main/net/dpml/metro/builder standard/builder/src/main/net/dpml/metro/builder/impl test/example/impl
  • Date: Sun, 13 Mar 2005 05:32:42 -0500

Author: mcconnell AT dpml.net
Date: Sun Mar 13 05:32:42 2005
New Revision: 2051

Added:

development/laboratory/plus/api/builder/src/main/net/dpml/metro/builder/Builder.java

development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/CatalogTask.java

development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentDescriptorDataType.java

development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/MarshalledObjectHelper.java
Modified:
development/laboratory/plus/test/example/impl/build.xml
Log:
shaking and baking

Added:
development/laboratory/plus/api/builder/src/main/net/dpml/metro/builder/Builder.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/api/builder/src/main/net/dpml/metro/builder/Builder.java
Sun Mar 13 05:32:42 2005
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.builder;
+
+import java.net.URI;
+
+import net.dpml.metro.part.Type;
+
+/**
+ * The contract for builders that create component part.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public interface Builder
+{
+ /**
+ * Return a uri identitifying the builder.
+ *
+ * @return the builder uri
+ */
+ URI getBuilderURI();
+
+ /**
+ * Return a urn identitifying the strategy.
+ *
+ * @return a strategy uri
+ */
+ URI getStrategyURI();
+
+}

Added:
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/CatalogTask.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/CatalogTask.java
Sun Mar 13 05:32:42 2005
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.builder.impl;
+
+import java.io.File;
+import java.io.Serializable;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.rmi.MarshalledObject;
+import java.util.Properties;
+import java.util.List;
+import java.util.LinkedList;
+
+import net.dpml.metro.part.Type;
+import net.dpml.metro.part.Catalog;
+import net.dpml.metro.part.CatalogEntry;
+import net.dpml.metro.builder.IntrospectionException;
+import net.dpml.metro.builder.TypeBuilder;
+
+import net.dpml.magic.tasks.ProjectTask;
+import net.dpml.magic.model.Policy;
+import net.dpml.magic.model.Definition;
+import net.dpml.magic.project.Context;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.AntClassLoader;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DynamicElementNS;
+
+/**
+ * Task that handles the construction of catalog entries.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class CatalogTask extends ProjectTask implements DynamicElementNS
+{
+ private List m_builders = new LinkedList();
+
+ public ComponentDescriptorDataType createEntry()
+ {
+ System.out.println( "# new catalog entry" );
+ URI base = getDefinition().getArtifactURI( "jar" );
+ Definition definition = getDefinition();
+ Context context = getContext();
+ ComponentDescriptorDataType data =
+ new ComponentDescriptorDataType( this, context, definition );
+ m_builders.add( data );
+ return data;
+ }
+
+ /**
+ * Operation used to construct a custom part type directive.
+ * @param uri the part handler uri
+ * @param name the element name
+ * @param qualified the qualified name
+ */
+ public Object createDynamicElement( String uri, String name, String
qualified )
+ {
+ String path = getProject().replaceProperties( uri );
+ System.out.println( "## creating type builder: " + path );
+ TypeBuilder builder = loadTypeHandler( path, name );
+ if( null == builder )
+ {
+ System.out.println( "## null builder" );
+ }
+ else
+ {
+ System.out.println( "## adding type builder: " + builder );
+ m_builders.add( builder );
+ }
+ return builder;
+ }
+
+ private TypeBuilder loadTypeHandler( String uri, String name ) throws
BuildException
+ {
+ String urn = uri + ":" + name;
+ Object builder = null;
+ TypeBuilder typeBuilder = null;
+ ClassLoader context = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(
getClass().getClassLoader() );
+ Project project = getProject();
+ builder = project.createDataType( urn );
+ typeBuilder = (TypeBuilder) builder;
+ return typeBuilder ;
+ }
+ catch( ClassCastException e )
+ {
+ final String error =
+ "The custom type builder ["
+ + builder.getClass().getName()
+ + "] established by the uri ["
+ + urn
+ + "] declared by the element <"
+ + name
+ + "' does not implement the net.dpml.metro.builder.TypeBuilder
interface.";
+ throw new BuildException( error, e, getLocation() );
+ }
+ catch( BuildException e )
+ {
+ final String error =
+ "Unable to load the plugin from the uri ["
+ + urn
+ + "] to handle the custom type declared by the element <"
+ + name
+ + ">.";
+ throw new BuildException( error, e, getLocation() );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected exception while attempting to load the custom type
handler with the uri ["
+ + urn
+ + "] declared by the element <"
+ + name
+ + ">.";
+ throw new BuildException( error, e, getLocation() );
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader( context );
+ }
+ }
+
+ public void execute()
+ {
+ System.out.println( "# execution" );
+
+ Project project = getProject();
+ Path path = getDefinition().getPath( project, Policy.RUNTIME );
+ File classes = getContext().getClassesDirectory();
+ path.createPathElement().setLocation( classes );
+ ClassLoader classloader = new AntClassLoader( project, path );
+ Catalog catalog = constructCatalog( classloader );
+ writeCatalog( catalog );
+ }
+
+ private void writeCatalog( Catalog catalog )
+ {
+ ObjectOutputStream output = null;
+ FileOutputStream stream = null;
+ File file = getOutputFile();
+ try
+ {
+ MarshalledObject marshalled = new MarshalledObject( catalog );
+ stream = new FileOutputStream( file );
+ output = new ObjectOutputStream( stream );
+ output.writeObject( marshalled );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to externalize a catalog."
+ + "\ndestination: " + file
+ + "\nclass: " + catalog.getClass().getName()
+ + "\nreason: " + e.toString();
+ throw new BuildException( error, e, getLocation() );
+ }
+ finally
+ {
+ closeStream( output );
+ }
+ }
+
+ private File getOutputFile()
+ {
+ File dir = getContext().getDeliverablesDirectory( "catalog" );
+ String filename = getDefinition().getFilename( "catalog" );
+ File file = new File( dir, filename );
+ File parent = file.getParentFile();
+ if( !parent.exists() )
+ {
+ parent.mkdirs();
+ }
+ return file;
+ }
+
+ private Catalog constructCatalog( ClassLoader classloader )
+ {
+ CatalogEntry[] entries = getCatalogEntries( classloader );
+ Catalog catalog = new Catalog( entries );
+ for( int i=0; i<entries.length; i++ )
+ {
+ CatalogEntry entry = entries[i];
+ System.out.println( "# entry: " + entry.toString() );
+ }
+ return catalog;
+ }
+
+ private CatalogEntry[] getCatalogEntries( ClassLoader classloader )
+ {
+ TypeBuilder[] builders = (TypeBuilder[]) m_builders.toArray( new
TypeBuilder[0] );
+ CatalogEntry[] entries = new CatalogEntry[ builders.length ];
+ for( int i=0; i<builders.length; i++ )
+ {
+ TypeBuilder builder = builders[i];
+ try
+ {
+ Type type = builder.buildType( classloader );
+ URI strategy = builder.getStrategyURI();
+ String path = builder.getResourcePath();
+ entries[i] = new CatalogEntry( strategy, path );
+ }
+ catch( IntrospectionException e )
+ {
+ final String error = "Introspection error: " +
e.getMessage();
+ throw new BuildException( error, e, getLocation() );
+ }
+ catch( BuildException e )
+ {
+ e.setLocation( getLocation() );
+ throw e;
+ }
+ }
+ return entries;
+ }
+
+ private void closeStream( OutputStream out )
+ {
+ if( null != out )
+ {
+ try
+ {
+ out.close();
+ }
+ catch( IOException ioe )
+ {
+ boolean ignoreMe = true;
+ }
+ }
+ }
+}

Added:
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentDescriptorDataType.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/ComponentDescriptorDataType.java
Sun Mar 13 05:32:42 2005
@@ -0,0 +1,490 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.builder.impl;
+
+import java.io.File;
+import java.io.Serializable;
+import java.net.URISyntaxException;
+import java.util.Properties;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.ArrayList;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import net.dpml.metro.meta.ComponentDescriptor;
+import net.dpml.metro.meta.ServiceDescriptor;
+import net.dpml.metro.meta.DependencyDescriptor;
+import net.dpml.metro.meta.PartDescriptor;
+import net.dpml.metro.meta.InfoDescriptor;
+import net.dpml.metro.part.Part;
+import net.dpml.metro.part.Type;
+import net.dpml.metro.part.Descriptor;
+import net.dpml.metro.builder.TypeBuilder;
+import net.dpml.metro.builder.PartBuilder;
+import net.dpml.metro.builder.IntrospectionException;
+
+import net.dpml.magic.model.Definition;
+import net.dpml.magic.project.Context;
+
+import org.apache.tools.ant.ProjectComponent;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+/**
+ * Base class for all descriptors.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class ComponentDescriptorDataType extends ProjectComponent implements
TypeBuilder
+{
+ //---------------------------------------------------------------
+ // state
+ //---------------------------------------------------------------
+
+ private String m_classname;
+ private PartsDataType m_parts;
+ private Task m_task;
+ private Definition m_definition;
+ private Context m_context;
+
+ //---------------------------------------------------------------
+ // constructor
+ //---------------------------------------------------------------
+
+ public ComponentDescriptorDataType( Task task, Context context,
Definition definition )
+ {
+ super.setProject( task.getProject() );
+ m_task = task;
+ m_definition = definition;
+ m_context = context;
+ }
+
+ //---------------------------------------------------------------
+ // setters
+ //---------------------------------------------------------------
+
+ public void setClass( String classname )
+ {
+ m_classname = classname;
+ }
+
+ public PartsDataType createParts()
+ {
+ if( null == m_parts )
+ {
+System.out.println( "## creating parts element" );
+ m_parts = new PartsDataType( m_task );
+ }
+ return m_parts;
+ }
+
+ //---------------------------------------------------------------
+ // TypeBuilder
+ //---------------------------------------------------------------
+
+ /**
+ * Return a urn identitifying the component type strategy that this
+ * builder is supporting.
+ *
+ * @return a uri identifiying the type strategy
+ */
+ public URI getStrategyURI()
+ {
+ return STRATEGY_URI;
+ }
+
+ /**
+ * Return a uri identitifying the builder.
+ *
+ * @return a uri identifiying the type builder
+ */
+ public URI getBuilderURI()
+ {
+ return BUILDER_URI;
+ }
+
+ /**
+ * Return the path to the resource containing the defintion of the type.
+ * @return the resource path
+ */
+ public String getResourcePath()
+ {
+ if( null == m_classname )
+ {
+ throw new IllegalStateException( "classname" );
+ }
+ String path = m_classname.replace( '.', '/' );
+ return path + ".info";
+ }
+
+ public Type buildType( ClassLoader classloader ) throws
IntrospectionException
+ {
+ return buildComponentDescriptor( classloader );
+ }
+
+ //---------------------------------------------------------------
+ // internals
+ //---------------------------------------------------------------
+
+ public ComponentDescriptor buildComponentDescriptor( ClassLoader
classloader ) throws IntrospectionException
+ {
+ Class subject = loadSubjectClass( classloader );
+ System.out.println( "## component: " + subject.getName() );
+ InfoDescriptor info = createInfoDescriptor( subject );
+ ServiceDescriptor[] services = createServiceDescriptors( subject );
+ DependencyDescriptor[] dependencies = createDependencyDescriptors(
subject );
+ PartDescriptor[] parts = createPartDescriptors( subject );
+ return new ComponentDescriptor( info, services, dependencies, parts
);
+ }
+
+ private Class loadSubjectClass( ClassLoader classloader )
+ {
+ if( null == m_classname )
+ {
+ final String error =
+ "Missing component descriptor class attribute.";
+ throw new IllegalStateException( error );
+ }
+ try
+ {
+ return classloader.loadClass( m_classname );
+ }
+ catch( ClassNotFoundException e )
+ {
+ final String error =
+ "Component class reference ["
+ + m_classname
+ + "] is not present in the project path.";
+ throw new BuildException( error );
+ }
+ }
+
+ private InfoDescriptor createInfoDescriptor( Class subject )
+ {
+ String classname = subject.getName();
+ return new InfoDescriptor( classname );
+ }
+
+ /**
+ * If the class contains an inner class named "Dependencies" then
+ * resolve the key/inteterface clasname pairs based on the inner class
+ * method names.
+ * @param subject the component implmentation class
+ * @return an array of dependency descriptors
+ */
+ private DependencyDescriptor[] createDependencyDescriptors( Class
subject ) throws IntrospectionException
+ {
+ String classname = subject.getName();
+ Class[] classes = subject.getClasses();
+ Class dependencies = locateClass( "$Dependencies", classes );
+ if( null == dependencies )
+ {
+ return new DependencyDescriptor[0];
+ }
+ else
+ {
+ ArrayList list = new ArrayList();
+ Method[] methods = dependencies.getMethods();
+ for( int i=0; i<methods.length; i++ )
+ {
+ Method method = methods[i];
+ DependencyDescriptor dep = createDependencyDescriptor(
method );
+ list.add( dep );
+ }
+ return (DependencyDescriptor[]) list.toArray( new
DependencyDescriptor[0] );
+ }
+ }
+
+ private DependencyDescriptor createDependencyDescriptor( Method method )
throws IntrospectionException
+ {
+ validateMethodName( method );
+ Class returnType = method.getReturnType();
+ validateNonNullReturnType( method, returnType );
+ validateNonArrayReturnType( method, returnType );
+ validateInterfaceReturnType( method, returnType );
+ validateNoExceptions( method );
+ validateNoParameters( method );
+
+ String key = method.getName().substring( 3 );
+ String type = returnType.getName();
+ System.out.println( "### dep: " + key + ", " + type );
+ return new DependencyDescriptor( key, type );
+ }
+
+ private ServiceDescriptor[] createServiceDescriptors( Class subject )
+ {
+ ArrayList list = new ArrayList();
+ Class[] interfaces = subject.getInterfaces();
+ for( int i=0; i<interfaces.length; i++ )
+ {
+ Class service = interfaces[i];
+ ServiceDescriptor descriptor = createServiceDescriptor( service
);
+ if( null != descriptor )
+ {
+ list.add( descriptor );
+ }
+ }
+ return new ServiceDescriptor[0];
+ }
+
+ public ServiceDescriptor createServiceDescriptor( Class subject )
+ {
+ String type = subject.getName();
+ if( type.startsWith( "java." ) )
+ {
+ return null; // ignore java.* interfaces
+ }
+ else
+ {
+ System.out.println( "### service: " + type );
+ return new ServiceDescriptor( type );
+ }
+ }
+
+ private PartDescriptor[] createPartDescriptors( Class subject ) throws
IntrospectionException
+ {
+ String classname = subject.getName();
+ Class[] classes = subject.getClasses();
+ Class parts = locateClass( "$Parts", classes );
+ if( null == parts )
+ {
+ return new PartDescriptor[0];
+ }
+ else
+ {
+ //
+ // This is a component type that is declaring one or more
+ // internal parts. Each part is described relative to:
+ // (a) a get method declarared within the nested Parts
+ // interface that establishes the part key and type
+ // (b) a part construction directive in the build file
+ // If the number of get methods does not correspond to the
+ // number of part directives in the buildfile and exception
+ // is thrown.
+
+ PartBuilder[] builders = createParts().getPartBuilders();
+ ArrayList list = new ArrayList();
+ Method[] methods = parts.getMethods();
+ if( builders.length != methods.length )
+ {
+ final String error =
+ "The number of builders declared in the build file ["
+ + builders.length
+ + "] does not match the number of method entries in the
Parts interface ["
+ + methods.length
+ + "].";
+ throw new BuildException( error );
+ }
+
+ //
+ // For each method in the Parts interface we construct a part
+ // descriptor. The descriptor identifies the part key, the
return
+ // type, and the location of the serialized part directive.
+ //
+
+ for( int i=0; i<methods.length; i++ )
+ {
+ Method method = methods[i];
+ PartBuilder builder = builders[i];
+ PartDescriptor part = createPartDescriptor( method, builder
);
+ list.add( part );
+ }
+ return (PartDescriptor[]) list.toArray( new PartDescriptor[0] );
+ }
+ }
+
+ /**
+ * Creation of a new part descriptor using a supplied method and a part
builder.
+ * The method is the method used by the component implementation to get
the part
+ * runtime instance. The part builder establishes the deployment
solution for the
+ * part implementation.
+ */
+ private PartDescriptor createPartDescriptor( Method method, PartBuilder
builder )
+ throws IntrospectionException
+ {
+ validateMethodName( method );
+ validateNoExceptions( method );
+ validateNoParameters( method );
+
+ Class returnType = method.getReturnType();
+ validateNonNullReturnType( method, returnType );
+ validateNonArrayReturnType( method, returnType );
+
+ String key = getPartKey( method );
+ String type = returnType.getName();
+ System.out.println( "### part descriptor: " + key + ", " + type );
+
+ //
+ // The part descriptor contains a uri declaring the location
+ // of the part. If the part if a reference to an existing part
+ // we include the external uri, otherwise we colocate the part
+ // the class as a [classname]$[key].part
+ //
+
+ try
+ {
+ Part part = builder.buildPart();
+ System.out.println( "### part directive: " + part );
+ String path = getEmbeddedResourcePath( method );
+ File output = getEmbeddedOutputFile( path );
+ System.out.println( "### saving part to: " + output );
+ MarshalledObjectHelper.write( part, output );
+ URI base = m_definition.getArtifactURI( "jar" );
+ URI uri = base.resolve( "!/" + path );
+ System.out.println( "### registering part uri: " + uri );
+ return new PartDescriptor( key, type, uri );
+ }
+ catch( Exception e )
+ {
+ throw new BuildException( e );
+ }
+ }
+
+ private String getPartKey( Method method )
+ {
+ String name = method.getName();
+ String key = name.substring( 3 );
+ return key;
+ }
+
+ private String getEmbeddedResourcePath( Method method )
+ {
+ Class base = method.getDeclaringClass();
+ String classname = base.getName();
+ String path = classname.replace( '.', '/' );
+ String key = getPartKey( method );
+ String filename = path + "$" + key + ".part";
+ return filename;
+ }
+
+ private File getEmbeddedOutputFile( String filename )
+ {
+ File classes = m_context.getClassesDirectory();
+ File destination = new File( classes, filename );
+ return destination;
+ }
+
+ private Class locateClass( String postfix, Class[] classes )
+ {
+ for( int i=0; i<classes.length; i++ )
+ {
+ Class inner = classes[i];
+ String name = inner.getName();
+ if( name.endsWith( postfix ) )
+ {
+ return inner;
+ }
+ }
+ return null;
+ }
+
+ private void validateNonNullReturnType( Method method, Class returnType
) throws IntrospectionException
+ {
+ if( null == returnType )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] does not declare a return type.";
+ throw new IntrospectionException( error );
+ }
+ }
+
+ private void validateNonArrayReturnType( Method method, Class returnType
) throws IntrospectionException
+ {
+ if( null != returnType.getComponentType() )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] declares an array return type.";
+ throw new IntrospectionException( error );
+ }
+ }
+
+ private void validateInterfaceReturnType( Method method, Class
returnType ) throws IntrospectionException
+ {
+ if( returnType.isInterface() == false )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] declares a return type ["
+ + returnType.getName()
+ + "] that is not an interface.";
+ throw new IntrospectionException( error );
+ }
+ }
+
+ private void validateMethodName( Method method ) throws
IntrospectionException
+ {
+ if( method.getName().startsWith( "get" ) == false )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] does not start with 'get'.";
+ throw new IntrospectionException( error );
+ }
+ }
+
+ private void validateNoExceptions( Method method ) throws
IntrospectionException
+ {
+ Class[] exceptionTypes = method.getExceptionTypes();
+ if( exceptionTypes.length > 0 )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] declares one or more exceptions.";
+ throw new IntrospectionException( error );
+ }
+ }
+
+ private void validateNoParameters( Method method ) throws
IntrospectionException
+ {
+ Class[] parameterTypes = method.getParameterTypes();
+ if( parameterTypes.length > 0 )
+ {
+ final String error =
+ "Method ["
+ + method.getName()
+ + "] declares one or more parameters.";
+ throw new IntrospectionException( error );
+ }
+ }
+
+ private static URI STRATEGY_URI = setupURI( "@STRATEGY-URI@" );
+ private static URI BUILDER_URI = setupURI( "@BUILDER-URI@" );
+
+ private static URI setupURI( String spec )
+ {
+ try
+ {
+ return new URI( spec );
+ }
+ catch( URISyntaxException ioe )
+ {
+ return null;
+ }
+ }
+
+}

Added:
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/MarshalledObjectHelper.java
==============================================================================
--- (empty file)
+++
development/laboratory/plus/standard/builder/src/main/net/dpml/metro/builder/impl/MarshalledObjectHelper.java
Sun Mar 13 05:32:42 2005
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.metro.builder.impl;
+
+import java.io.File;
+import java.io.Serializable;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.rmi.MarshalledObject;
+
+/**
+ * A datatype that enables custom part builders.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class MarshalledObjectHelper
+{
+ private MarshalledObjectHelper()
+ {
+ // static utility class
+ }
+
+ public static void write( Object object, File file ) throws Exception
+ {
+ ObjectOutputStream output = null;
+ FileOutputStream stream = null;
+ try
+ {
+ MarshalledObject marshalled = new MarshalledObject( object );
+ stream = new FileOutputStream( file );
+ output = new ObjectOutputStream( stream );
+ output.writeObject( marshalled );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to marshall an object."
+ + "\ndestination: " + file
+ + "\nclass: " + object.getClass().getName()
+ + "\nreason: " + e.toString();
+ throw new Exception( error, e );
+ }
+ finally
+ {
+ closeStream( output );
+ }
+ }
+
+ private static void closeStream( OutputStream out )
+ {
+ if( null != out )
+ {
+ try
+ {
+ out.close();
+ }
+ catch( IOException ioe )
+ {
+ boolean ignoreMe = true;
+ }
+ }
+ }
+}

Modified: development/laboratory/plus/test/example/impl/build.xml
==============================================================================
--- development/laboratory/plus/test/example/impl/build.xml (original)
+++ development/laboratory/plus/test/example/impl/build.xml Sun Mar 13
05:32:42 2005
@@ -3,7 +3,7 @@
<project name="dpml-test-hello-impl" default="install" basedir="."
xmlns:transit="antlib:net.dpml.transit"
xmlns:x="plugin:dpml/magic/dpml-magic-core">
-
+
<transit:import uri="artifact:template:dpml/magic/standard"/>

<target name="package" depends="standard.package">



  • svn commit: r2051 - in development/laboratory/plus: api/builder/src/main/net/dpml/metro/builder standard/builder/src/main/net/dpml/metro/builder/impl test/example/impl, mcconnell, 03/12/2005

Archive powered by MHonArc 2.6.24.

Top of Page