Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2854 - in development/main: magic/core/src/main/net/dpml/magic magic/core/src/main/net/dpml/magic/builder magic/core/src/main/net/dpml/magic/model magic/core/src/main/net/dpml/magic/project magic/core/src/main/net/dpml/magic/tasks metro metro/composition/control/src/main/net/dpml/composition/control metro/composition/control/src/main/net/dpml/composition/data metro/parameters/impl/src/main/net/dpml/parameters/impl transit/core/handler/src/main/net/dpml/lang transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/network transit/core/handler/src/main/net/dpml/transit/repository transit/core/handler/src/main/net/dpml/transit/runtime transit/core/handler/src/main/net/dpml/transit/unit transit/core/handler/src/main/net/dpml/transit/util transit/core/tools/src/main/net/dpml/transit/tools

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: r2854 - in development/main: magic/core/src/main/net/dpml/magic magic/core/src/main/net/dpml/magic/builder magic/core/src/main/net/dpml/magic/model magic/core/src/main/net/dpml/magic/project magic/core/src/main/net/dpml/magic/tasks metro metro/composition/control/src/main/net/dpml/composition/control metro/composition/control/src/main/net/dpml/composition/data metro/parameters/impl/src/main/net/dpml/parameters/impl transit/core/handler/src/main/net/dpml/lang transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/network transit/core/handler/src/main/net/dpml/transit/repository transit/core/handler/src/main/net/dpml/transit/runtime transit/core/handler/src/main/net/dpml/transit/unit transit/core/handler/src/main/net/dpml/transit/util transit/core/tools/src/main/net/dpml/transit/tools
  • Date: Tue, 14 Jun 2005 01:44:50 -0400

Author: mcconnell AT dpml.net
Date: Tue Jun 14 01:44:50 2005
New Revision: 2854

Added:

development/main/metro/composition/control/src/main/net/dpml/composition/control/DefaultInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/DelegationRuntimeException.java

development/main/transit/core/handler/src/main/net/dpml/transit/NullArgumentException.java
- copied, changed from r2845,
development/main/transit/core/handler/src/main/net/dpml/lang/NullArgumentException.java
Removed:
development/main/transit/core/handler/src/main/net/dpml/lang/
development/main/transit/core/handler/src/main/net/dpml/transit/Main.java

development/main/transit/core/handler/src/main/net/dpml/transit/util/Dictionary.java
Modified:
development/main/magic/core/src/main/net/dpml/magic/AntFileIndex.java

development/main/magic/core/src/main/net/dpml/magic/builder/AntFileIndexBuilder.java

development/main/magic/core/src/main/net/dpml/magic/builder/ElementHelper.java

development/main/magic/core/src/main/net/dpml/magic/builder/PropertyResolver.java

development/main/magic/core/src/main/net/dpml/magic/builder/XMLDefinitionBuilder.java
development/main/magic/core/src/main/net/dpml/magic/model/Definition.java
development/main/magic/core/src/main/net/dpml/magic/model/Info.java
development/main/magic/core/src/main/net/dpml/magic/model/Module.java
development/main/magic/core/src/main/net/dpml/magic/model/Resource.java
development/main/magic/core/src/main/net/dpml/magic/project/Context.java

development/main/magic/core/src/main/net/dpml/magic/project/ProjectPath.java

development/main/magic/core/src/main/net/dpml/magic/tasks/InitializeTask.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/LifecycleHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ManagerInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/data/ValueDirective.java
development/main/metro/index.xml

development/main/metro/parameters/impl/src/main/net/dpml/parameters/impl/DefaultParameters.java

development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java

development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java

development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Artifact.java

development/main/transit/core/handler/src/main/net/dpml/transit/network/RequestIdentifier.java

development/main/transit/core/handler/src/main/net/dpml/transit/network/TransitAuthenticatorImpl.java

development/main/transit/core/handler/src/main/net/dpml/transit/repository/PropertiesPlugin.java

development/main/transit/core/handler/src/main/net/dpml/transit/repository/StandardLoader.java

development/main/transit/core/handler/src/main/net/dpml/transit/runtime/CacheHandler.java

development/main/transit/core/handler/src/main/net/dpml/transit/runtime/DefaultCacheHandler.java

development/main/transit/core/handler/src/main/net/dpml/transit/unit/TransitPreferences.java

development/main/transit/core/handler/src/main/net/dpml/transit/util/ExceptionHelper.java

development/main/transit/core/handler/src/main/net/dpml/transit/util/StreamUtils.java

development/main/transit/core/tools/src/main/net/dpml/transit/tools/PluginTask.java
Log:
Remove net.dpml.lang package on the basis that a single class
(NullArgumentException) is insufficient to justify the package namespace.
NullArgumentException has been moved down to net.dpml.transit package and
other lang classes related to proxy creation have been moved over to the
composition package.

Modified:
development/main/magic/core/src/main/net/dpml/magic/AntFileIndex.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/AntFileIndex.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/AntFileIndex.java
Tue Jun 14 01:44:50 2005
@@ -1,788 +1,790 @@
-/*
- * Copyright 2004 Stephen 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.magic;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Hashtable;
-
-import net.dpml.lang.NullArgumentException;
-import net.dpml.magic.builder.ElementHelper;
-import net.dpml.magic.builder.AntFileIndexBuilder;
-import net.dpml.magic.builder.XMLDefinitionBuilder;
-import net.dpml.magic.model.Definition;
-import net.dpml.magic.model.Info;
-import net.dpml.magic.model.Module;
-import net.dpml.magic.model.Resource;
-import net.dpml.magic.model.ResourceRef;
-import net.dpml.transit.Transit;
-import net.dpml.transit.TransitException;
-import net.dpml.transit.artifact.Handler;
-import net.dpml.transit.repository.Repository;
-import net.dpml.transit.repository.StandardLoader;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Location;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.Property;
-import org.apache.tools.ant.types.DataType;
-import org.w3c.dom.Element;
-
-/**
- * A Index is an immutable data object that aggregates a suite of buildable
- * project defintions relative to local and external dependencies.
- *
- * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
- * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
- */
-public class AntFileIndex extends DataType implements Index
-{
- //-------------------------------------------------------------
- // static
- //-------------------------------------------------------------
-
- public static final String BANNER =
-
"------------------------------------------------------------------------";
-
- public static final String HOME_KEY = "project.home";
- public static final String INDEX_KEY = "project.index";
- public static final String HOSTS_KEY = "project.hosts";
- public static final String GPG_EXE_KEY = "project.gpg.exe";
-
- //-------------------------------------------------------------
- // immutable state
- //-------------------------------------------------------------
-
- private final File m_index;
- private final Hashtable m_resources = new Hashtable();
- private final ArrayList m_includes = new ArrayList();
- private final AntFileIndexBuilder m_builder;
- private Repository m_repository;
-
- //-------------------------------------------------------------
- // constructor
- //-------------------------------------------------------------
-
- /**
- * Creation of a new home using a supplied index.
- * @param proj the ant project establishing the home
- * @param system the magic system instance
- * @param index the magic project index
- * @exception NullArgumentException if any of the supplied arguments are
null.
- */
- public AntFileIndex( Project proj, AntFileIndexBuilder system, File
index )
- throws TransitException, NullArgumentException
- {
- if( null == proj )
- {
- throw new NullArgumentException( "project" );
- }
-
- if( null == system )
- {
- throw new NullArgumentException( "system" );
- }
-
- if( null == index )
- {
- throw new NullArgumentException( "index" );
- }
-
- setProject( proj );
-
- if( !index.exists() )
- {
- throw new BuildException(
- new FileNotFoundException( index.toString() ) );
- }
-
- m_builder = system;
-
- m_index = resolveIndex( index );
-
- final File user = new File( System.getProperty( "user.home" ) );
- final File props = new File( user, "magic.properties" );
- loadProperties( proj, props );
-
- File base = m_index.getParentFile();
- processModuleProperties( proj, base );
-
- //
- // load the initial context
- //
-
- m_repository = new StandardLoader();
- File home = getHomeDirectory();
- if( null == proj.getProperty( HOME_KEY ) )
- {
- proj.setNewProperty( HOME_KEY, home.getAbsolutePath() );
- }
- File magic = new File( home, "magic.properties" );
- loadProperties( proj, magic );
-
- //
- // load the system wide properties
- //
-
- File siteUserProperties = new File( Transit.DPML_PREFS,
"magic/user.properties" );
- loadProperties( proj, siteUserProperties );
-
- File siteProperties = new File( Transit.DPML_PREFS,
"magic/magic.properties" );
- loadProperties( proj, siteProperties );
-
- //
- // build the index
- //
-
- buildList( m_index );
- int n = m_resources.size();
- log( "Resources: " + n, Project.MSG_VERBOSE );
- }
-
- private void processModuleProperties( Project proj, File base )
- {
- if( null == base )
- {
- return;
- }
- File module = new File( base, "module.properties" );
- loadProperties( proj, module );
- File parent = base.getParentFile();
- processModuleProperties( proj, parent );
- }
-
- //-------------------------------------------------------------
- // implementation
- //-------------------------------------------------------------
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getHomeDirectory()
- */
- public File getHomeDirectory()
- {
- return new File( Transit.DPML_PREFS, "transit" );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getCacheDirectory()
- */
- public File getCacheDirectory()
- {
- return new File( Transit.DPML_DATA, "cache" );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getDocsDirectory()
- */
- public File getDocsDirectory()
- {
- return new File( Transit.DPML_DATA, "docs" );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getRepository()
- */
- public Repository getRepository()
- {
- return m_repository;
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getIndexFile()
- */
- public File getIndexFile()
- {
- return m_index;
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getIndexLastModified()
- */
- public long getIndexLastModified()
- {
- return m_index.lastModified();
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getProperty(java.lang.String)
- */
- public String getProperty( String key )
- {
- return getProperty( key, null );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getProperty(java.lang.String, java.lang.String)
- */
- public String getProperty( String key, String fallback )
- {
- String value = getProject().getProperty( key );
- if( null == value )
- {
- return fallback;
- }
- else
- {
- return value;
- }
- }
-
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#isaResourceKey(java.lang.String)
- */
- public boolean isaResourceKey( String key )
- {
- return ( null != m_resources.get( key ) );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#isaRelease()
- */
- public boolean isaRelease()
- {
- return m_builder.isaRelease();
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getReleaseSignature()
- */
- public String getReleaseSignature()
- {
- return m_builder.getReleaseSignature();
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getResources()
- */
- public Resource[] getResources()
- {
- return (Resource[]) m_resources.values().toArray( new Resource[0] );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#isaDefinition(net.dpml.magic.model.ResourceRef)
- */
- public boolean isaDefinition( final ResourceRef reference )
- {
- return ( getResource( reference ) instanceof Definition );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getDefinitions()
- */
- public Definition[] getDefinitions()
- throws BuildException
- {
- final ArrayList list = new ArrayList();
- final Resource[] resources = getResources();
- for( int i=0; i<resources.length; i++ )
- {
- final Resource resource = resources[i];
- if( resource instanceof Definition )
- {
- list.add( resource );
- }
- }
- return (Definition[]) list.toArray( new Definition[0] );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getSubsidiaryRefs(net.dpml.magic.model.Resource)
- */
- public ResourceRef[] getSubsidiaryRefs( Resource module )
- throws BuildException
- {
- if( !"module".equals( module.getInfo().getType() ) )
- {
- final String error =
- "Resource argument [" + module + "] is not a module.";
- throw new BuildException( error );
- }
-
- final String group = module.getInfo().getGroup();
- final ArrayList list = new ArrayList();
- Resource[] resources = getResources();
- for( int i=0; i<resources.length; i++ )
- {
- Resource resource = resources[i];
- if( resource.getInfo().getGroup().startsWith( group + "/" ) )
- {
- list.add( new ResourceRef( resource.getKey() ) );
- }
- else if( resource.getInfo().getGroup().equals( group )
- && !resource.getKey().equals( module.getKey() ) )
- {
- list.add( new ResourceRef( resource.getKey() ) );
- }
- }
- if( module instanceof Definition )
- {
- Definition def = (Definition) module;
- ResourceRef[] parts = def.getPartRefs();
- for( int i=0; i<parts.length; i++ )
- {
- list.add( parts[i] );
- }
- }
- return (ResourceRef[]) list.toArray( new ResourceRef[0] );
- }
-
- /* (non-Javadoc)
- * @see
net.dpml.magic.Index#getSubsidiaryDefinitions(net.dpml.magic.model.Resource)
- */
- public Definition[] getSubsidiaryDefinitions( Resource module )
- throws BuildException
- {
- final String group = module.getInfo().getGroup();
- final ArrayList list = new ArrayList();
- Definition[] defs = getDefinitions();
- for( int i=0; i<defs.length; i++ )
- {
- Definition d = defs[i];
- if( d.getInfo().getGroup().startsWith( group + "/" ) )
- {
- list.add( d );
- }
- else if( d.getInfo().getGroup().equals( group )
- && !d.getKey().equals( module.getKey() ) )
- {
- list.add( d );
- }
- }
- return (Definition[]) list.toArray( new Definition[0] );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getResource(java.lang.String)
- */
- public Resource getResource( final String key )
- throws BuildException
- {
- final ResourceRef reference = new ResourceRef( key );
- return getResource( reference );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getResource(net.dpml.magic.model.ResourceRef)
- */
- public Resource getResource( final ResourceRef reference )
- throws BuildException
- {
- final String key = reference.getKey();
- final Resource resource = (Resource) m_resources.get( key );
- if( null == resource )
- {
- throw new UnknownResourceException( key );
- }
- return resource;
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getDefinition(java.lang.String)
- */
- public Definition getDefinition( final String key )
- throws BuildException
- {
- final ResourceRef reference = new ResourceRef( key );
- return getDefinition( reference );
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#getDefinition(net.dpml.magic.model.ResourceRef)
- */
- public Definition getDefinition( final ResourceRef reference )
- throws BuildException
- {
- final Resource resource = getResource( reference );
- if( resource instanceof Definition )
- {
- return (Definition) resource;
- }
- else
- {
- final String error =
- "Reference [" + reference + "] does not refer to a projects.";
- throw new BuildException( error );
- }
- }
-
- //-------------------------------------------------------------
- // internal
- //-------------------------------------------------------------
-
- /**
- * Populate the index from the contents of the supplied XML source.
- * @param source the index source file
- */
- private void buildList( final File source )
- {
- buildList( source, null );
- }
-
- private void buildList( final File source, String uri )
- {
- final String filename = source.toString();
- final boolean exists = m_includes.contains( filename );
- if( exists )
- {
- return;
- }
-
- log( "import: " + source, Project.MSG_DEBUG );
- m_includes.add( filename );
-
- try
- {
- final Element root = ElementHelper.getRootElement( source );
- final String rootElementName = root.getTagName();
- if( "index".equals( rootElementName ) )
- {
- buildIndex( source, root, uri );
- }
- else if( "module".equals( rootElementName ) )
- {
- buildModule( root, source );
- }
- else
- {
- final String error =
- "Unrecognized root element [" + rootElementName + "].";
- throw new BuildException( error );
- }
- }
- catch( Throwable e )
- {
- throw new BuildException( e, new Location( source.toString() ) );
- }
- }
-
- private void buildIndex( File source, Element root, String uri )
- {
- //
- // its a native magic index
- //
-
- String key = ElementHelper.getAttribute( root, "key", null );
- final Element[] elements = ElementHelper.getChildren( root );
- final File anchor = source.getParentFile();
-
- if( ( null != key ) && ( key.length() > 0 ) )
- {
- buildLocalList( anchor, elements, "key:" + key );
- }
- else if( ( null != uri ) && uri.length() > 0 )
- {
- buildLocalList( anchor, elements, uri );
- }
- else
- {
- buildLocalList( anchor, elements, "key:UNKNOWN" );
- }
- }
-
- /* (non-Javadoc)
- * @see net.dpml.magic.Index#buildModule(java.io.File)
- */
- public Module buildModule( File source )
- {
- try
- {
- final Element root = ElementHelper.getRootElement( source );
- final String rootElementName = root.getTagName();
- if( "module".equals( rootElementName ) )
- {
- return buildModule( root, source );
- }
- else
- {
- final String error =
- "Unexpected root module element name ["
- + rootElementName
- + "] while reading source ["
- + source + "].";
- throw new BuildException( error );
- }
- }
- catch( Throwable e )
- {
- final String error =
- "Module construction failure using source ["
- + source
- + "]";
- throw new BuildException( error, e );
- }
- }
-
- private Module buildModule( String uri )
- {
- try
- {
- URL artifact = new URL( null, uri, new Handler() );
- File local = (File) artifact.getContent( new Class[]{ File.class
} );
- final Element root = ElementHelper.getRootElement( local );
- return buildModule( root, local );
- }
- catch( IOException ioe )
- {
- final String error =
- "Failed to load module ["
- + uri
- + "]."
- + ioe.toString();
- throw new BuildException( error, ioe );
- }
- }
-
- private Module buildModule( Element root, File source )
- {
- //
- // its a module definition so we need to add the module as an
available
- // resources and add all of the resources defined by the module
- //
-
- final String moduleUri = ElementHelper.getAttribute( root, "uri" );
- if( "".equals( moduleUri ) || ( null == moduleUri ) )
- {
- String mess =
- "Modules must contain a \"uri\" attribute in the root module
element: "
- + source;
- throw new BuildException( mess );
- }
-
- Info info = createInfo( moduleUri );
- String key = info.getName();
-
- if( m_resources.containsKey( key ) )
- {
- Resource resource = getResource( key );
- if( resource instanceof Module )
- {
- return (Module) resource;
- }
- else
- {
- final String error =
- "Source index or module ["
- + source
- + "] declares the key ["
- + key
- + "] that is already bound.";
- throw new BuildException( error );
- }
- }
-
- Module.Header header = Module.Header.create( root );
- String[] imports = Module.createImports( root );
- ResourceRef[] refs = new ResourceRef[ imports.length ];
- for( int i=0; i < imports.length; i++ )
- {
- String spec = imports[i];
- Module link = buildModule( spec );
- refs[i] = new ResourceRef( link.getKey() );
- }
-
- final Element resources = ElementHelper.getChild( root, "resources"
);
- final ResourceRef[] children = buildResources( resources, source,
moduleUri );
-
- Module module = new Module( this, key, info, refs, "key:NULL",
header, children );
- m_resources.put( key, module );
- log( "module: " + module, Project.MSG_VERBOSE );
-
- return module;
- }
-
- private ResourceRef[] buildResources( final Element resources, File
source, final String moduleUri )
- {
- final Element[] elements = ElementHelper.getChildren( resources,
"resource" );
- final File anchor = source.getParentFile();
- final ResourceRef[] children = new ResourceRef[ elements.length ];
- for( int i=0; i < elements.length; i++ )
- {
- final Resource resource = createResource( elements[i], anchor,
moduleUri );
- final String k = resource.getKey();
- if( !m_resources.containsKey( k ) )
- {
- m_resources.put( k, resource );
- log( "resource: " + resource, Project.MSG_VERBOSE );
- }
- }
- return children;
- }
-
- private Info createInfo( String uri )
- {
- try
- {
- return Info.create( uri );
- }
- catch( Exception e )
- {
- throw new BuildException( e );
- }
- }
-
- private File resolveIndex( File file )
- {
- if( file.isDirectory() )
- {
- return new File( file, "index.xml" );
- }
- else
- {
- return file;
- }
- }
-
- private void buildLocalList( final File anchor, final Element[]
children, String uri )
- {
- log( "entries: " + children.length, Project.MSG_VERBOSE );
- for( int i = 0; i < children.length; i++ )
- {
- final Element element = children[i];
- final String tag = element.getTagName();
- if( "import".equals( element.getTagName() ) )
- {
- buildImport( element, anchor, uri );
- }
- else if( isaResource( tag ) )
- {
- buildResource( element, anchor, uri );
- }
- else
- {
- final String error =
- "Unrecognized element type \"" + tag + "\" found in
index.";
- throw new BuildException( error );
- }
- }
- }
-
- private void buildResource(final Element element, final File anchor,
String uri)
- {
- final Resource resource = createResource( element, anchor, uri );
- final String key = resource.getKey();
- if( !m_resources.containsKey( key ) )
- {
- m_resources.put( key, resource );
- if( key.equals( resource.getInfo().getName() ) )
- {
- log( "resource: " + resource, Project.MSG_VERBOSE );
- }
- else
- {
- log( "resource: " + resource + " key=" + key,
Project.MSG_VERBOSE );
- }
- }
- else
- {
- Resource r = (Resource) m_resources.get( key );
- if( !r.equals( resource ) )
- {
- final String error =
- "WARNING: Ignoring duplicate key reference ["
- + key
- + "].";
- log( error, Project.MSG_WARN );
- }
- }
- }
-
- private void buildImport(final Element element, final File anchor,
String uri)
- {
- final String filename = element.getAttribute( "index" );
- final String uriAttribute = element.getAttribute( "uri" );
- String urn = parse( uriAttribute );
- if(( null != filename ) && ( !"".equals( filename )))
- {
- final File index = AntFileIndexBuilder.getFile( anchor, filename
);
- buildList( index, uri );
- }
- else if(null == urn || "".equals(urn))
- {
- final String error =
- "Invalid import statement. No uri, index attribute.";
- throw new BuildException( error );
- }
- else
- {
- // switch to artifact
- if( !m_includes.contains( urn ) )
- {
- m_includes.add( urn );
- try
- {
- URL artifact = new URL( null, urn, new Handler() );
- File local = (File) artifact.getContent( new Class[]{
File.class } );
- buildList( local, urn );
- }
- catch( IOException ioe )
- {
- final String error =
- "Failed to load module ["
- + urn
- + "]."
- + ioe.toString();
- throw new BuildException( error, ioe );
- }
- }
- }
- }
-
- private String parse( String value )
- {
- if( null == value )
- {
- return value;
- }
- String result = getProject().replaceProperties( value );
- if( !result.equals( value ) )
- {
- return parse( result );
- }
- else
- {
- return result;
- }
- }
-
- private Resource createResource( final Element element, final File
anchor, String uri )
- {
- return XMLDefinitionBuilder.createResource( this, element, anchor,
uri );
- }
-
- private boolean isaResource( final String tag )
- {
- return (
- "resource".equals( tag )
- || "project".equals( tag ) );
- }
-
- protected void loadProperties( final Project proj, final File file )
- throws BuildException
- {
- final Property props = (Property) proj.createTask( "property" );
- props.init();
- props.setFile( file );
- props.execute();
- }
-}
+/*
+ * Copyright 2004 Stephen 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.magic;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Hashtable;
+
+import net.dpml.magic.builder.ElementHelper;
+import net.dpml.magic.builder.AntFileIndexBuilder;
+import net.dpml.magic.builder.XMLDefinitionBuilder;
+import net.dpml.magic.model.Definition;
+import net.dpml.magic.model.Info;
+import net.dpml.magic.model.Module;
+import net.dpml.magic.model.Resource;
+import net.dpml.magic.model.ResourceRef;
+
+import net.dpml.transit.NullArgumentException;
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitException;
+import net.dpml.transit.artifact.Handler;
+import net.dpml.transit.repository.Repository;
+import net.dpml.transit.repository.StandardLoader;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Location;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Property;
+import org.apache.tools.ant.types.DataType;
+
+import org.w3c.dom.Element;
+
+/**
+ * A Index is an immutable data object that aggregates a suite of buildable
+ * project defintions relative to local and external dependencies.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class AntFileIndex extends DataType implements Index
+{
+ //-------------------------------------------------------------
+ // static
+ //-------------------------------------------------------------
+
+ public static final String BANNER =
+
"------------------------------------------------------------------------";
+
+ public static final String HOME_KEY = "project.home";
+ public static final String INDEX_KEY = "project.index";
+ public static final String HOSTS_KEY = "project.hosts";
+ public static final String GPG_EXE_KEY = "project.gpg.exe";
+
+ //-------------------------------------------------------------
+ // immutable state
+ //-------------------------------------------------------------
+
+ private final File m_index;
+ private final Hashtable m_resources = new Hashtable();
+ private final ArrayList m_includes = new ArrayList();
+ private final AntFileIndexBuilder m_builder;
+ private Repository m_repository;
+
+ //-------------------------------------------------------------
+ // constructor
+ //-------------------------------------------------------------
+
+ /**
+ * Creation of a new home using a supplied index.
+ * @param proj the ant project establishing the home
+ * @param system the magic system instance
+ * @param index the magic project index
+ * @exception NullArgumentException if any of the supplied arguments are
null.
+ */
+ public AntFileIndex( Project proj, AntFileIndexBuilder system, File
index )
+ throws TransitException, NullArgumentException
+ {
+ if( null == proj )
+ {
+ throw new NullArgumentException( "project" );
+ }
+
+ if( null == system )
+ {
+ throw new NullArgumentException( "system" );
+ }
+
+ if( null == index )
+ {
+ throw new NullArgumentException( "index" );
+ }
+
+ setProject( proj );
+
+ if( !index.exists() )
+ {
+ throw new BuildException(
+ new FileNotFoundException( index.toString() ) );
+ }
+
+ m_builder = system;
+
+ m_index = resolveIndex( index );
+
+ final File user = new File( System.getProperty( "user.home" ) );
+ final File props = new File( user, "magic.properties" );
+ loadProperties( proj, props );
+
+ File base = m_index.getParentFile();
+ processModuleProperties( proj, base );
+
+ //
+ // load the initial context
+ //
+
+ m_repository = new StandardLoader();
+ File home = getHomeDirectory();
+ if( null == proj.getProperty( HOME_KEY ) )
+ {
+ proj.setNewProperty( HOME_KEY, home.getAbsolutePath() );
+ }
+ File magic = new File( home, "magic.properties" );
+ loadProperties( proj, magic );
+
+ //
+ // load the system wide properties
+ //
+
+ File siteUserProperties = new File( Transit.DPML_PREFS,
"magic/user.properties" );
+ loadProperties( proj, siteUserProperties );
+
+ File siteProperties = new File( Transit.DPML_PREFS,
"magic/magic.properties" );
+ loadProperties( proj, siteProperties );
+
+ //
+ // build the index
+ //
+
+ buildList( m_index );
+ int n = m_resources.size();
+ log( "Resources: " + n, Project.MSG_VERBOSE );
+ }
+
+ private void processModuleProperties( Project proj, File base )
+ {
+ if( null == base )
+ {
+ return;
+ }
+ File module = new File( base, "module.properties" );
+ loadProperties( proj, module );
+ File parent = base.getParentFile();
+ processModuleProperties( proj, parent );
+ }
+
+ //-------------------------------------------------------------
+ // implementation
+ //-------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getHomeDirectory()
+ */
+ public File getHomeDirectory()
+ {
+ return new File( Transit.DPML_PREFS, "transit" );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getCacheDirectory()
+ */
+ public File getCacheDirectory()
+ {
+ return new File( Transit.DPML_DATA, "cache" );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getDocsDirectory()
+ */
+ public File getDocsDirectory()
+ {
+ return new File( Transit.DPML_DATA, "docs" );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getRepository()
+ */
+ public Repository getRepository()
+ {
+ return m_repository;
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getIndexFile()
+ */
+ public File getIndexFile()
+ {
+ return m_index;
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getIndexLastModified()
+ */
+ public long getIndexLastModified()
+ {
+ return m_index.lastModified();
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getProperty(java.lang.String)
+ */
+ public String getProperty( String key )
+ {
+ return getProperty( key, null );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getProperty(java.lang.String, java.lang.String)
+ */
+ public String getProperty( String key, String fallback )
+ {
+ String value = getProject().getProperty( key );
+ if( null == value )
+ {
+ return fallback;
+ }
+ else
+ {
+ return value;
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#isaResourceKey(java.lang.String)
+ */
+ public boolean isaResourceKey( String key )
+ {
+ return ( null != m_resources.get( key ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#isaRelease()
+ */
+ public boolean isaRelease()
+ {
+ return m_builder.isaRelease();
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getReleaseSignature()
+ */
+ public String getReleaseSignature()
+ {
+ return m_builder.getReleaseSignature();
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getResources()
+ */
+ public Resource[] getResources()
+ {
+ return (Resource[]) m_resources.values().toArray( new Resource[0] );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#isaDefinition(net.dpml.magic.model.ResourceRef)
+ */
+ public boolean isaDefinition( final ResourceRef reference )
+ {
+ return ( getResource( reference ) instanceof Definition );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getDefinitions()
+ */
+ public Definition[] getDefinitions()
+ throws BuildException
+ {
+ final ArrayList list = new ArrayList();
+ final Resource[] resources = getResources();
+ for( int i=0; i<resources.length; i++ )
+ {
+ final Resource resource = resources[i];
+ if( resource instanceof Definition )
+ {
+ list.add( resource );
+ }
+ }
+ return (Definition[]) list.toArray( new Definition[0] );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getSubsidiaryRefs(net.dpml.magic.model.Resource)
+ */
+ public ResourceRef[] getSubsidiaryRefs( Resource module )
+ throws BuildException
+ {
+ if( !"module".equals( module.getInfo().getType() ) )
+ {
+ final String error =
+ "Resource argument [" + module + "] is not a module.";
+ throw new BuildException( error );
+ }
+
+ final String group = module.getInfo().getGroup();
+ final ArrayList list = new ArrayList();
+ Resource[] resources = getResources();
+ for( int i=0; i<resources.length; i++ )
+ {
+ Resource resource = resources[i];
+ if( resource.getInfo().getGroup().startsWith( group + "/" ) )
+ {
+ list.add( new ResourceRef( resource.getKey() ) );
+ }
+ else if( resource.getInfo().getGroup().equals( group )
+ && !resource.getKey().equals( module.getKey() ) )
+ {
+ list.add( new ResourceRef( resource.getKey() ) );
+ }
+ }
+ if( module instanceof Definition )
+ {
+ Definition def = (Definition) module;
+ ResourceRef[] parts = def.getPartRefs();
+ for( int i=0; i<parts.length; i++ )
+ {
+ list.add( parts[i] );
+ }
+ }
+ return (ResourceRef[]) list.toArray( new ResourceRef[0] );
+ }
+
+ /* (non-Javadoc)
+ * @see
net.dpml.magic.Index#getSubsidiaryDefinitions(net.dpml.magic.model.Resource)
+ */
+ public Definition[] getSubsidiaryDefinitions( Resource module )
+ throws BuildException
+ {
+ final String group = module.getInfo().getGroup();
+ final ArrayList list = new ArrayList();
+ Definition[] defs = getDefinitions();
+ for( int i=0; i<defs.length; i++ )
+ {
+ Definition d = defs[i];
+ if( d.getInfo().getGroup().startsWith( group + "/" ) )
+ {
+ list.add( d );
+ }
+ else if( d.getInfo().getGroup().equals( group )
+ && !d.getKey().equals( module.getKey() ) )
+ {
+ list.add( d );
+ }
+ }
+ return (Definition[]) list.toArray( new Definition[0] );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getResource(java.lang.String)
+ */
+ public Resource getResource( final String key )
+ throws BuildException
+ {
+ final ResourceRef reference = new ResourceRef( key );
+ return getResource( reference );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getResource(net.dpml.magic.model.ResourceRef)
+ */
+ public Resource getResource( final ResourceRef reference )
+ throws BuildException
+ {
+ final String key = reference.getKey();
+ final Resource resource = (Resource) m_resources.get( key );
+ if( null == resource )
+ {
+ throw new UnknownResourceException( key );
+ }
+ return resource;
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getDefinition(java.lang.String)
+ */
+ public Definition getDefinition( final String key )
+ throws BuildException
+ {
+ final ResourceRef reference = new ResourceRef( key );
+ return getDefinition( reference );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#getDefinition(net.dpml.magic.model.ResourceRef)
+ */
+ public Definition getDefinition( final ResourceRef reference )
+ throws BuildException
+ {
+ final Resource resource = getResource( reference );
+ if( resource instanceof Definition )
+ {
+ return (Definition) resource;
+ }
+ else
+ {
+ final String error =
+ "Reference [" + reference + "] does not refer to a projects.";
+ throw new BuildException( error );
+ }
+ }
+
+ //-------------------------------------------------------------
+ // internal
+ //-------------------------------------------------------------
+
+ /**
+ * Populate the index from the contents of the supplied XML source.
+ * @param source the index source file
+ */
+ private void buildList( final File source )
+ {
+ buildList( source, null );
+ }
+
+ private void buildList( final File source, String uri )
+ {
+ final String filename = source.toString();
+ final boolean exists = m_includes.contains( filename );
+ if( exists )
+ {
+ return;
+ }
+
+ log( "import: " + source, Project.MSG_DEBUG );
+ m_includes.add( filename );
+
+ try
+ {
+ final Element root = ElementHelper.getRootElement( source );
+ final String rootElementName = root.getTagName();
+ if( "index".equals( rootElementName ) )
+ {
+ buildIndex( source, root, uri );
+ }
+ else if( "module".equals( rootElementName ) )
+ {
+ buildModule( root, source );
+ }
+ else
+ {
+ final String error =
+ "Unrecognized root element [" + rootElementName + "].";
+ throw new BuildException( error );
+ }
+ }
+ catch( Throwable e )
+ {
+ throw new BuildException( e, new Location( source.toString() ) );
+ }
+ }
+
+ private void buildIndex( File source, Element root, String uri )
+ {
+ //
+ // its a native magic index
+ //
+
+ String key = ElementHelper.getAttribute( root, "key", null );
+ final Element[] elements = ElementHelper.getChildren( root );
+ final File anchor = source.getParentFile();
+
+ if( ( null != key ) && ( key.length() > 0 ) )
+ {
+ buildLocalList( anchor, elements, "key:" + key );
+ }
+ else if( ( null != uri ) && uri.length() > 0 )
+ {
+ buildLocalList( anchor, elements, uri );
+ }
+ else
+ {
+ buildLocalList( anchor, elements, "key:UNKNOWN" );
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#buildModule(java.io.File)
+ */
+ public Module buildModule( File source )
+ {
+ try
+ {
+ final Element root = ElementHelper.getRootElement( source );
+ final String rootElementName = root.getTagName();
+ if( "module".equals( rootElementName ) )
+ {
+ return buildModule( root, source );
+ }
+ else
+ {
+ final String error =
+ "Unexpected root module element name ["
+ + rootElementName
+ + "] while reading source ["
+ + source + "].";
+ throw new BuildException( error );
+ }
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Module construction failure using source ["
+ + source
+ + "]";
+ throw new BuildException( error, e );
+ }
+ }
+
+ private Module buildModule( String uri )
+ {
+ try
+ {
+ URL artifact = new URL( null, uri, new Handler() );
+ File local = (File) artifact.getContent( new Class[]{ File.class
} );
+ final Element root = ElementHelper.getRootElement( local );
+ return buildModule( root, local );
+ }
+ catch( IOException ioe )
+ {
+ final String error =
+ "Failed to load module ["
+ + uri
+ + "]."
+ + ioe.toString();
+ throw new BuildException( error, ioe );
+ }
+ }
+
+ private Module buildModule( Element root, File source )
+ {
+ //
+ // its a module definition so we need to add the module as an
available
+ // resources and add all of the resources defined by the module
+ //
+
+ final String moduleUri = ElementHelper.getAttribute( root, "uri" );
+ if( "".equals( moduleUri ) || ( null == moduleUri ) )
+ {
+ String mess =
+ "Modules must contain a \"uri\" attribute in the root module
element: "
+ + source;
+ throw new BuildException( mess );
+ }
+
+ Info info = createInfo( moduleUri );
+ String key = info.getName();
+
+ if( m_resources.containsKey( key ) )
+ {
+ Resource resource = getResource( key );
+ if( resource instanceof Module )
+ {
+ return (Module) resource;
+ }
+ else
+ {
+ final String error =
+ "Source index or module ["
+ + source
+ + "] declares the key ["
+ + key
+ + "] that is already bound.";
+ throw new BuildException( error );
+ }
+ }
+
+ Module.Header header = Module.Header.create( root );
+ String[] imports = Module.createImports( root );
+ ResourceRef[] refs = new ResourceRef[ imports.length ];
+ for( int i=0; i < imports.length; i++ )
+ {
+ String spec = imports[i];
+ Module link = buildModule( spec );
+ refs[i] = new ResourceRef( link.getKey() );
+ }
+
+ final Element resources = ElementHelper.getChild( root, "resources"
);
+ final ResourceRef[] children = buildResources( resources, source,
moduleUri );
+
+ Module module = new Module( this, key, info, refs, "key:NULL",
header, children );
+ m_resources.put( key, module );
+ log( "module: " + module, Project.MSG_VERBOSE );
+
+ return module;
+ }
+
+ private ResourceRef[] buildResources( final Element resources, File
source, final String moduleUri )
+ {
+ final Element[] elements = ElementHelper.getChildren( resources,
"resource" );
+ final File anchor = source.getParentFile();
+ final ResourceRef[] children = new ResourceRef[ elements.length ];
+ for( int i=0; i < elements.length; i++ )
+ {
+ final Resource resource = createResource( elements[i], anchor,
moduleUri );
+ final String k = resource.getKey();
+ if( !m_resources.containsKey( k ) )
+ {
+ m_resources.put( k, resource );
+ log( "resource: " + resource, Project.MSG_VERBOSE );
+ }
+ }
+ return children;
+ }
+
+ private Info createInfo( String uri )
+ {
+ try
+ {
+ return Info.create( uri );
+ }
+ catch( Exception e )
+ {
+ throw new BuildException( e );
+ }
+ }
+
+ private File resolveIndex( File file )
+ {
+ if( file.isDirectory() )
+ {
+ return new File( file, "index.xml" );
+ }
+ else
+ {
+ return file;
+ }
+ }
+
+ private void buildLocalList( final File anchor, final Element[]
children, String uri )
+ {
+ log( "entries: " + children.length, Project.MSG_VERBOSE );
+ for( int i = 0; i < children.length; i++ )
+ {
+ final Element element = children[i];
+ final String tag = element.getTagName();
+ if( "import".equals( element.getTagName() ) )
+ {
+ buildImport( element, anchor, uri );
+ }
+ else if( isaResource( tag ) )
+ {
+ buildResource( element, anchor, uri );
+ }
+ else
+ {
+ final String error =
+ "Unrecognized element type \"" + tag + "\" found in
index.";
+ throw new BuildException( error );
+ }
+ }
+ }
+
+ private void buildResource(final Element element, final File anchor,
String uri)
+ {
+ final Resource resource = createResource( element, anchor, uri );
+ final String key = resource.getKey();
+ if( !m_resources.containsKey( key ) )
+ {
+ m_resources.put( key, resource );
+ if( key.equals( resource.getInfo().getName() ) )
+ {
+ log( "resource: " + resource, Project.MSG_VERBOSE );
+ }
+ else
+ {
+ log( "resource: " + resource + " key=" + key,
Project.MSG_VERBOSE );
+ }
+ }
+ else
+ {
+ Resource r = (Resource) m_resources.get( key );
+ if( !r.equals( resource ) )
+ {
+ final String error =
+ "WARNING: Ignoring duplicate key reference ["
+ + key
+ + "].";
+ log( error, Project.MSG_WARN );
+ }
+ }
+ }
+
+ private void buildImport(final Element element, final File anchor,
String uri)
+ {
+ final String filename = element.getAttribute( "index" );
+ final String uriAttribute = element.getAttribute( "uri" );
+ String urn = parse( uriAttribute );
+ if(( null != filename ) && ( !"".equals( filename )))
+ {
+ final File index = AntFileIndexBuilder.getFile( anchor, filename
);
+ buildList( index, uri );
+ }
+ else if(null == urn || "".equals(urn))
+ {
+ final String error =
+ "Invalid import statement. No uri, index attribute.";
+ throw new BuildException( error );
+ }
+ else
+ {
+ // switch to artifact
+ if( !m_includes.contains( urn ) )
+ {
+ m_includes.add( urn );
+ try
+ {
+ URL artifact = new URL( null, urn, new Handler() );
+ File local = (File) artifact.getContent( new Class[]{
File.class } );
+ buildList( local, urn );
+ }
+ catch( IOException ioe )
+ {
+ final String error =
+ "Failed to load module ["
+ + urn
+ + "]."
+ + ioe.toString();
+ throw new BuildException( error, ioe );
+ }
+ }
+ }
+ }
+
+ private String parse( String value )
+ {
+ if( null == value )
+ {
+ return value;
+ }
+ String result = getProject().replaceProperties( value );
+ if( !result.equals( value ) )
+ {
+ return parse( result );
+ }
+ else
+ {
+ return result;
+ }
+ }
+
+ private Resource createResource( final Element element, final File
anchor, String uri )
+ {
+ return XMLDefinitionBuilder.createResource( this, element, anchor,
uri );
+ }
+
+ private boolean isaResource( final String tag )
+ {
+ return (
+ "resource".equals( tag )
+ || "project".equals( tag ) );
+ }
+
+ protected void loadProperties( final Project proj, final File file )
+ throws BuildException
+ {
+ final Property props = (Property) proj.createTask( "property" );
+ props.init();
+ props.setFile( file );
+ props.execute();
+ }
+}

Modified:
development/main/magic/core/src/main/net/dpml/magic/builder/AntFileIndexBuilder.java
==============================================================================
---
development/main/magic/core/src/main/net/dpml/magic/builder/AntFileIndexBuilder.java
(original)
+++
development/main/magic/core/src/main/net/dpml/magic/builder/AntFileIndexBuilder.java
Tue Jun 14 01:44:50 2005
@@ -1,322 +1,323 @@
-/*
- * Copyright 2004-2005 Stephen McConnell
- * Copyright 2005 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.magic.builder;
-
-import net.dpml.lang.NullArgumentException;
-
-import net.dpml.magic.AntFileIndex;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.DataType;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-/**
- * The Magic class is the application root of the magic system. It is
responsible
- * for the onetime establishment of an index
- *
- * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
- * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
- */
-public class AntFileIndexBuilder extends DataType
-{
- //-------------------------------------------------------------
- // static
- //-------------------------------------------------------------
-
- /**
- * Immutable key to the signature identifier used.
- */
- private static final String RELEASE_SIGNATURE_KEY =
"dpml.release.signature";
-
- /**
- * Immutable key to the build identifier.
- */
- private static final String BUILD_SIGNATURE_KEY = "dpml.build.signature";
-
- /**
- * Immutable key to the magic docs cache directory.
- */
- public static final String DOCS_KEY = "magic.docs";
-
- //-------------------------------------------------------------
- // immutable state
- //-------------------------------------------------------------
-
- private final AntFileIndex m_index;
-
- //-------------------------------------------------------------
- // constructor
- //-------------------------------------------------------------
-
- public AntFileIndexBuilder( final Project proj )
- throws BuildException
- {
- this( proj, null );
- }
-
- public AntFileIndexBuilder( final Project proj, File index )
- throws BuildException
- {
- setProject( proj );
-
- log( "magic builder established", Project.MSG_VERBOSE );
-
- String signature = getBuildSignature();
-
- if( null == signature )
- {
- signature = "SNAPSHOT";
- }
-
- proj.setProperty( BUILD_SIGNATURE_KEY, signature );
- log( "release: " + signature, Project.MSG_VERBOSE );
-
- if( null == index )
- {
- log( "locating index", Project.MSG_VERBOSE );
- File file = getIndexFile( proj );
- m_index = constructIndex( proj, file );
- }
- else
- {
- m_index = constructIndex( proj, index );
- }
- }
-
- private AntFileIndex constructIndex( Project proj, File file )
- {
- try
- {
- return new AntFileIndex( proj, this, file );
- }
- catch( Throwable e )
- {
- e.printStackTrace();
- final String error =
- "Internal error while attempting to construct index."+
- "file:" + file.getAbsolutePath() +
- "project:" + proj.toString();
- throw new BuildException( error );
- }
- }
-
- //-------------------------------------------------------------
- // public
- //-------------------------------------------------------------
-
- /**
- * Return the index.
- * @return the index instance
- */
- public AntFileIndex getIndex()
- {
- return m_index;
- }
-
- /**
- * Return TRUE if this is a release build.
- * @return the release build flag
- */
- public boolean isaRelease()
- {
- String signature = getReleaseSignature();
- return signature != null;
- }
-
- /**
- * Return the signature.
- *
- * @return the release signature
- */
- public String getReleaseSignature()
- {
- Project project = getProject();
- String signature = project.getProperty( BUILD_SIGNATURE_KEY );
- return signature;
- }
-
- //-------------------------------------------------------------
- // implementation
- //-------------------------------------------------------------
-
- private String getBuildSignature()
- {
- String signature = System.getProperty( BUILD_SIGNATURE_KEY );
- if( null != signature )
- {
- return signature;
- }
- else
- {
- Project proj = getProject();
- signature = proj.getProperty( RELEASE_SIGNATURE_KEY );
- return signature;
- }
- }
-
- private File getIndexFile( Project proj )
- {
- File basedir = proj.getBaseDir();
- return resolve( basedir, true );
- }
-
- private File resolve( File index, boolean traverse )
- {
- if( index.isFile() )
- return index;
- if( index.isDirectory() )
- {
- File file = new File( index, "index.xml" );
- if( file.isFile() )
- return file;
- if( traverse )
- {
- File resolved = traverse( index );
- if( resolved != null )
- return resolved;
- }
- }
-
- final FileNotFoundException fnfe =
- new FileNotFoundException( index.toString() );
- throw new BuildException( fnfe );
- }
-
- private File traverse( File dir )
- {
- File file = new File( dir, "index.xml" );
- if( file.isFile() )
- return file;
- File parent = dir.getParentFile();
- if( null != parent )
- return traverse( parent );
- return null;
- }
-
- /**
- * Return a file using a supplied root and path. If the path is absolute
- * an absolute file is retured relative to the supplied path otherwise the
- * path is resolved relative to the supplied root directory.
- *
- * @param root the root directory
- * @param path the absolute or relative file path
- * @return the file instance
- */
- public static File getFile( final File root, final String path )
- {
- return getFile( root, path, false );
- }
-
- /**
- * Return a file using a supplied root and path. If the path is absolute
- * an absolute file is retured relative to the supplied path otherwise the
- * path is resolved relative to the supplied root directory. If the
create
- * parameter is TRUE then the file will be created if it does not exist.
- *
- * @param root the root directory
- * @param path the absolute or relative file path
- * @param create flag to indicate creation policy if the file does not
exists
- * @return the file instance
- * @throws NullArgumentException if the path argument is null, or if the
path
- * argument is not an absolute path and the root argument is null.
- */
- public static File getFile( final File root, final String path, boolean
create )
- throws NullArgumentException
- {
- if( null == path )
- {
- throw new NullArgumentException( "path" );
- }
- final File file = new File( path );
-
- if( file.isAbsolute() )
- {
- return getCanonicalFile( file, create );
- }
-
- if( null == root )
- {
- throw new NullArgumentException( "root" );
- }
- return getCanonicalFile( new File( root, path ), create );
- }
-
- /**
- * Return the concatonal variant of a file.
- * @param file the file argument
- * @return the concatonal variant
- */
- public static File getCanonicalFile( final File file ) throws
BuildException
- {
- return getCanonicalFile( file, false );
- }
-
- /**
- * Return the concatonal variant of a file and ensure that the parent
directory
- * path is created.
- *
- * @param file the file argument
- * @return the concatonal variant
- */
- public static File getCanonicalFile( final File file, boolean create )
throws BuildException
- {
- try
- {
- File result = file.getCanonicalFile();
- if( create )
- {
- if( result.isDirectory() )
- {
- result.mkdirs();
- }
- else
- {
- result.getParentFile().mkdirs();
- }
- }
- return result;
- }
- catch( IOException ioe )
- {
- throw new BuildException( ioe );
- }
- }
-
- /**
- * Return the concatonal path of a file.
- * @param file the file argument
- * @return the concatonal path
- */
- public static String getCanonicalPath( final File file ) throws
BuildException
- {
- try
- {
- return file.getCanonicalPath();
- }
- catch( IOException ioe )
- {
- throw new BuildException( ioe );
- }
- }
-}
+/*
+ * Copyright 2004-2005 Stephen McConnell
+ * Copyright 2005 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.magic.builder;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import net.dpml.magic.AntFileIndex;
+
+import net.dpml.transit.NullArgumentException;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.DataType;
+
+
+/**
+ * The Magic class is the application root of the magic system. It is
responsible
+ * for the onetime establishment of an index
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class AntFileIndexBuilder extends DataType
+{
+ //-------------------------------------------------------------
+ // static
+ //-------------------------------------------------------------
+
+ /**
+ * Immutable key to the signature identifier used.
+ */
+ private static final String RELEASE_SIGNATURE_KEY =
"dpml.release.signature";
+
+ /**
+ * Immutable key to the build identifier.
+ */
+ private static final String BUILD_SIGNATURE_KEY = "dpml.build.signature";
+
+ /**
+ * Immutable key to the magic docs cache directory.
+ */
+ public static final String DOCS_KEY = "magic.docs";
+
+ //-------------------------------------------------------------
+ // immutable state
+ //-------------------------------------------------------------
+
+ private final AntFileIndex m_index;
+
+ //-------------------------------------------------------------
+ // constructor
+ //-------------------------------------------------------------
+
+ public AntFileIndexBuilder( final Project proj )
+ throws BuildException
+ {
+ this( proj, null );
+ }
+
+ public AntFileIndexBuilder( final Project proj, File index )
+ throws BuildException
+ {
+ setProject( proj );
+
+ log( "magic builder established", Project.MSG_VERBOSE );
+
+ String signature = getBuildSignature();
+
+ if( null == signature )
+ {
+ signature = "SNAPSHOT";
+ }
+
+ proj.setProperty( BUILD_SIGNATURE_KEY, signature );
+ log( "release: " + signature, Project.MSG_VERBOSE );
+
+ if( null == index )
+ {
+ log( "locating index", Project.MSG_VERBOSE );
+ File file = getIndexFile( proj );
+ m_index = constructIndex( proj, file );
+ }
+ else
+ {
+ m_index = constructIndex( proj, index );
+ }
+ }
+
+ private AntFileIndex constructIndex( Project proj, File file )
+ {
+ try
+ {
+ return new AntFileIndex( proj, this, file );
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ final String error =
+ "Internal error while attempting to construct index."+
+ "file:" + file.getAbsolutePath() +
+ "project:" + proj.toString();
+ throw new BuildException( error );
+ }
+ }
+
+ //-------------------------------------------------------------
+ // public
+ //-------------------------------------------------------------
+
+ /**
+ * Return the index.
+ * @return the index instance
+ */
+ public AntFileIndex getIndex()
+ {
+ return m_index;
+ }
+
+ /**
+ * Return TRUE if this is a release build.
+ * @return the release build flag
+ */
+ public boolean isaRelease()
+ {
+ String signature = getReleaseSignature();
+ return signature != null;
+ }
+
+ /**
+ * Return the signature.
+ *
+ * @return the release signature
+ */
+ public String getReleaseSignature()
+ {
+ Project project = getProject();
+ String signature = project.getProperty( BUILD_SIGNATURE_KEY );
+ return signature;
+ }
+
+ //-------------------------------------------------------------
+ // implementation
+ //-------------------------------------------------------------
+
+ private String getBuildSignature()
+ {
+ String signature = System.getProperty( BUILD_SIGNATURE_KEY );
+ if( null != signature )
+ {
+ return signature;
+ }
+ else
+ {
+ Project proj = getProject();
+ signature = proj.getProperty( RELEASE_SIGNATURE_KEY );
+ return signature;
+ }
+ }
+
+ private File getIndexFile( Project proj )
+ {
+ File basedir = proj.getBaseDir();
+ return resolve( basedir, true );
+ }
+
+ private File resolve( File index, boolean traverse )
+ {
+ if( index.isFile() )
+ return index;
+ if( index.isDirectory() )
+ {
+ File file = new File( index, "index.xml" );
+ if( file.isFile() )
+ return file;
+ if( traverse )
+ {
+ File resolved = traverse( index );
+ if( resolved != null )
+ return resolved;
+ }
+ }
+
+ final FileNotFoundException fnfe =
+ new FileNotFoundException( index.toString() );
+ throw new BuildException( fnfe );
+ }
+
+ private File traverse( File dir )
+ {
+ File file = new File( dir, "index.xml" );
+ if( file.isFile() )
+ return file;
+ File parent = dir.getParentFile();
+ if( null != parent )
+ return traverse( parent );
+ return null;
+ }
+
+ /**
+ * Return a file using a supplied root and path. If the path is absolute
+ * an absolute file is retured relative to the supplied path otherwise the
+ * path is resolved relative to the supplied root directory.
+ *
+ * @param root the root directory
+ * @param path the absolute or relative file path
+ * @return the file instance
+ */
+ public static File getFile( final File root, final String path )
+ {
+ return getFile( root, path, false );
+ }
+
+ /**
+ * Return a file using a supplied root and path. If the path is absolute
+ * an absolute file is retured relative to the supplied path otherwise the
+ * path is resolved relative to the supplied root directory. If the
create
+ * parameter is TRUE then the file will be created if it does not exist.
+ *
+ * @param root the root directory
+ * @param path the absolute or relative file path
+ * @param create flag to indicate creation policy if the file does not
exists
+ * @return the file instance
+ * @throws NullArgumentException if the path argument is null, or if the
path
+ * argument is not an absolute path and the root argument is null.
+ */
+ public static File getFile( final File root, final String path, boolean
create )
+ throws NullArgumentException
+ {
+ if( null == path )
+ {
+ throw new NullArgumentException( "path" );
+ }
+ final File file = new File( path );
+
+ if( file.isAbsolute() )
+ {
+ return getCanonicalFile( file, create );
+ }
+
+ if( null == root )
+ {
+ throw new NullArgumentException( "root" );
+ }
+ return getCanonicalFile( new File( root, path ), create );
+ }
+
+ /**
+ * Return the concatonal variant of a file.
+ * @param file the file argument
+ * @return the concatonal variant
+ */
+ public static File getCanonicalFile( final File file ) throws
BuildException
+ {
+ return getCanonicalFile( file, false );
+ }
+
+ /**
+ * Return the concatonal variant of a file and ensure that the parent
directory
+ * path is created.
+ *
+ * @param file the file argument
+ * @return the concatonal variant
+ */
+ public static File getCanonicalFile( final File file, boolean create )
throws BuildException
+ {
+ try
+ {
+ File result = file.getCanonicalFile();
+ if( create )
+ {
+ if( result.isDirectory() )
+ {
+ result.mkdirs();
+ }
+ else
+ {
+ result.getParentFile().mkdirs();
+ }
+ }
+ return result;
+ }
+ catch( IOException ioe )
+ {
+ throw new BuildException( ioe );
+ }
+ }
+
+ /**
+ * Return the concatonal path of a file.
+ * @param file the file argument
+ * @return the concatonal path
+ */
+ public static String getCanonicalPath( final File file ) throws
BuildException
+ {
+ try
+ {
+ return file.getCanonicalPath();
+ }
+ catch( IOException ioe )
+ {
+ throw new BuildException( ioe );
+ }
+ }
+}

Modified:
development/main/magic/core/src/main/net/dpml/magic/builder/ElementHelper.java
==============================================================================
---
development/main/magic/core/src/main/net/dpml/magic/builder/ElementHelper.java
(original)
+++
development/main/magic/core/src/main/net/dpml/magic/builder/ElementHelper.java
Tue Jun 14 01:44:50 2005
@@ -17,15 +17,6 @@

package net.dpml.magic.builder;

-import org.apache.tools.ant.BuildException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -33,6 +24,16 @@
import java.util.ArrayList;
import java.util.Properties;

+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tools.ant.BuildException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
/**
* Utility class supporting the translation of DOM content into local child,
children,
* attribute and value values.

Modified:
development/main/magic/core/src/main/net/dpml/magic/builder/PropertyResolver.java
==============================================================================
---
development/main/magic/core/src/main/net/dpml/magic/builder/PropertyResolver.java
(original)
+++
development/main/magic/core/src/main/net/dpml/magic/builder/PropertyResolver.java
Tue Jun 14 01:44:50 2005
@@ -21,7 +21,6 @@
import java.util.Stack;
import java.util.StringTokenizer;

-
public class PropertyResolver
{
static public String resolve( Properties props, String value )

Modified:
development/main/magic/core/src/main/net/dpml/magic/builder/XMLDefinitionBuilder.java
==============================================================================
---
development/main/magic/core/src/main/net/dpml/magic/builder/XMLDefinitionBuilder.java
(original)
+++
development/main/magic/core/src/main/net/dpml/magic/builder/XMLDefinitionBuilder.java
Tue Jun 14 01:44:50 2005
@@ -17,16 +17,19 @@

package net.dpml.magic.builder;

+import java.io.File;
+
import net.dpml.magic.AntFileIndex;
import net.dpml.magic.model.Definition;
import net.dpml.magic.model.Info;
import net.dpml.magic.model.Policy;
import net.dpml.magic.model.Resource;
import net.dpml.magic.model.ResourceRef;
+
import org.apache.tools.ant.BuildException;
+
import org.w3c.dom.Element;

-import java.io.File;

/**
* Definition of a project.

Modified:
development/main/magic/core/src/main/net/dpml/magic/model/Definition.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/model/Definition.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/model/Definition.java
Tue Jun 14 01:44:50 2005
@@ -17,10 +17,10 @@

package net.dpml.magic.model;

-import net.dpml.lang.NullArgumentException;
-
import net.dpml.magic.AntFileIndex;

+import net.dpml.transit.NullArgumentException;
+
import org.apache.tools.ant.Location;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;

Modified: development/main/magic/core/src/main/net/dpml/magic/model/Info.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/model/Info.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/model/Info.java Tue
Jun 14 01:44:50 2005
@@ -19,7 +19,7 @@

import java.net.URISyntaxException;

-import net.dpml.lang.NullArgumentException;
+import net.dpml.transit.NullArgumentException;
import net.dpml.transit.artifact.Artifact;

/**

Modified:
development/main/magic/core/src/main/net/dpml/magic/model/Module.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/model/Module.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/model/Module.java
Tue Jun 14 01:44:50 2005
@@ -17,11 +17,11 @@

package net.dpml.magic.model;

+import java.net.URL;
+
import net.dpml.magic.AntFileIndex;
import net.dpml.magic.builder.ElementHelper;

-import java.net.URL;
-
import org.apache.tools.ant.BuildException;

import org.w3c.dom.Element;

Modified:
development/main/magic/core/src/main/net/dpml/magic/model/Resource.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/model/Resource.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/model/Resource.java
Tue Jun 14 01:44:50 2005
@@ -23,9 +23,10 @@
import java.util.ArrayList;
import java.util.List;

-import net.dpml.lang.NullArgumentException;
import net.dpml.magic.AntFileIndex;
import net.dpml.magic.UnknownResourceException;
+
+import net.dpml.transit.NullArgumentException;
import net.dpml.transit.artifact.Handler;

import org.apache.tools.ant.BuildException;

Modified:
development/main/magic/core/src/main/net/dpml/magic/project/Context.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/project/Context.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/project/Context.java
Tue Jun 14 01:44:50 2005
@@ -18,13 +18,13 @@

package net.dpml.magic.project;

-import net.dpml.lang.NullArgumentException;
-
import net.dpml.magic.AntFileIndex;
import net.dpml.magic.UnknownResourceException;
import net.dpml.magic.builder.AntFileIndexBuilder;
import net.dpml.magic.model.Definition;

+import net.dpml.transit.NullArgumentException;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Property;

Modified:
development/main/magic/core/src/main/net/dpml/magic/project/ProjectPath.java
==============================================================================
---
development/main/magic/core/src/main/net/dpml/magic/project/ProjectPath.java
(original)
+++
development/main/magic/core/src/main/net/dpml/magic/project/ProjectPath.java
Tue Jun 14 01:44:50 2005
@@ -20,6 +20,7 @@
import net.dpml.magic.AntFileIndex;
import net.dpml.magic.model.Policy;
import net.dpml.magic.model.Resource;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;

Modified:
development/main/magic/core/src/main/net/dpml/magic/tasks/InitializeTask.java
==============================================================================
---
development/main/magic/core/src/main/net/dpml/magic/tasks/InitializeTask.java
(original)
+++
development/main/magic/core/src/main/net/dpml/magic/tasks/InitializeTask.java
Tue Jun 14 01:44:50 2005
@@ -19,12 +19,11 @@

import java.net.URI;

-import net.dpml.lang.NullArgumentException;
-
import net.dpml.magic.model.Definition;
import net.dpml.magic.model.Resource;
import net.dpml.magic.model.ResourceRef;

+import net.dpml.transit.NullArgumentException;
import net.dpml.transit.tools.PluginTask;
import net.dpml.transit.repository.Plugin;


Added:
development/main/metro/composition/control/src/main/net/dpml/composition/control/DefaultInvocationHandler.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/DefaultInvocationHandler.java
Tue Jun 14 01:44:50 2005
@@ -0,0 +1,136 @@
+/*
+ * Copyright 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.composition.control;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.lang.reflect.Method;
+
+/**
+ * The ConfigurationInvocationHandler class handles the isolation of a
configuration
+ * implementation behind the Configuration class.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Id: ApplianceInvocationHandler.java 2106 2005-03-21 18:46:10Z
mcconnell AT dpml.net $
+ */
+public final class DefaultInvocationHandler
+ implements InvocationHandler
+{
+ //-------------------------------------------------------------------
+ // state
+ //-------------------------------------------------------------------
+
+ private final Object m_instance;
+
+ //-------------------------------------------------------------------
+ // constructor
+ //-------------------------------------------------------------------
+
+ /**
+ * Create a proxy invocation handler.
+ *
+ * @param instance the instance
+ */
+ public DefaultInvocationHandler( Object instance )
+ {
+ assertNotNull( instance, "instance" );
+ m_instance = instance;
+ }
+
+ //-------------------------------------------------------------------
+ // InvocationHandler
+ //-------------------------------------------------------------------
+
+ /**
+ * Invoke the specified method on underlying object.
+ * This is called by the proxy object.
+ *
+ * @param proxy the proxy object
+ * @param method the method invoked on proxy object
+ * @param args the arguments supplied to method
+ * @return the return value of method
+ * @throws Throwable if an error occurs
+ */
+ public Object invoke( final Object proxy, final Method method, final
Object[] args )
+ throws Throwable
+ {
+ try
+ {
+ return method.invoke( m_instance, args );
+ }
+ catch( Throwable e )
+ {
+ throw handleInvocationThrowable( method, e );
+ }
+ }
+
+ private Throwable handleInvocationThrowable( Method method, Throwable e )
+ {
+ final String name = method.getName();
+ final String error =
+ "Delegation error while attempting to invoke the operation [" +
name + "].";
+
+ while( true )
+ {
+ if( e instanceof UndeclaredThrowableException )
+ {
+ UndeclaredThrowableException utException =
(UndeclaredThrowableException) e;
+ Throwable cause = utException.getUndeclaredThrowable();
+ if( cause == null )
+ {
+ return new DelegationRuntimeException( error, e );
+ }
+ else
+ {
+ e = cause;
+ }
+ }
+ else if( e instanceof InvocationTargetException )
+ {
+ final InvocationTargetException targetException =
(InvocationTargetException) e;
+ final Throwable cause = targetException.getTargetException();
+ if( cause == null )
+ {
+ return new DelegationRuntimeException( error, e );
+ }
+ else
+ {
+ e = cause;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ return e;
+ }
+
+
+
+ private void assertNotNull( Object object, String key )
+ throws NullPointerException
+ {
+ if( null == object )
+ {
+ throw new NullPointerException( key );
+ }
+ }
+}

Added:
development/main/metro/composition/control/src/main/net/dpml/composition/control/DelegationRuntimeException.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/DelegationRuntimeException.java
Tue Jun 14 01:44:50 2005
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2005 Stephen 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.composition.control;
+
+/**
+ * Exception thrown in response to a unexpected error in an invocation
handler.
+ *
+ */
+public class DelegationRuntimeException extends RuntimeException
+{
+ /**
+ * Creation of a new delegation exception.
+ * @param message the message
+ * @param cause the causal exception
+ */
+ public DelegationRuntimeException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+}
\ No newline at end of file

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifecycleHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifecycleHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifecycleHandler.java
Tue Jun 14 01:44:50 2005
@@ -31,8 +31,6 @@

import net.dpml.configuration.Configuration;

-import net.dpml.lang.DefaultInvocationHandler;
-
import net.dpml.parameters.Parameters;

import net.dpml.parts.control.LifecycleException;

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ManagerInvocationHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ManagerInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ManagerInvocationHandler.java
Tue Jun 14 01:44:50 2005
@@ -24,7 +24,7 @@
import java.lang.reflect.UndeclaredThrowableException;

import net.dpml.composition.model.ComponentEntry;
-import net.dpml.lang.DelegationRuntimeException;
+
import net.dpml.parts.state.State;

/**

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/data/ValueDirective.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/data/ValueDirective.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/data/ValueDirective.java
Tue Jun 14 01:44:50 2005
@@ -22,8 +22,6 @@
import java.net.URI;
import java.net.URISyntaxException;

-import net.dpml.lang.NullArgumentException;
-
import net.dpml.parts.part.Part;

/**
@@ -257,10 +255,8 @@
* Creation of a new entry directive using a supplied classname and
value.
* @param classname the classname of the value
* @param value the value constructor value
- * @exception NullArgumentException if the classname argument is
null.
*/
public Value( final String classname, final String value )
- throws NullArgumentException
{
if( null == classname )
{
@@ -283,21 +279,21 @@
* children array is null.
*/
public Value( final String classname, final Value[] children )
- throws NullArgumentException
+ throws NullPointerException
{
if( null == classname )
{
- throw new NullArgumentException( "classname" );
+ throw new NullPointerException( "classname" );
}
if( null == children )
{
- throw new NullArgumentException( "children" );
+ throw new NullPointerException( "children" );
}
for( int i = 0; i < children.length; i++ )
{
if( children[ i ] == null )
{
- throw new NullArgumentException( "child [" + i + "]" );
+ throw new NullPointerException( "child [" + i + "]" );
}
}
m_classname = classname;

Modified: development/main/metro/index.xml
==============================================================================
--- development/main/metro/index.xml (original)
+++ development/main/metro/index.xml Tue Jun 14 01:44:50 2005
@@ -95,7 +95,6 @@
<dependencies>
<include key="dpml-parameters-api"/>
<include key="dpml-configuration-api"/>
- <include key="dpml-transit-main"/>
</dependencies>
</project>


Modified:
development/main/metro/parameters/impl/src/main/net/dpml/parameters/impl/DefaultParameters.java
==============================================================================
---
development/main/metro/parameters/impl/src/main/net/dpml/parameters/impl/DefaultParameters.java
(original)
+++
development/main/metro/parameters/impl/src/main/net/dpml/parameters/impl/DefaultParameters.java
Tue Jun 14 01:44:50 2005
@@ -26,8 +26,6 @@

import net.dpml.configuration.Configuration;

-import net.dpml.lang.NullArgumentException;
-
import net.dpml.parameters.Parameters;
import net.dpml.parameters.ParameterException;

@@ -709,16 +707,16 @@
* @param elementName the element name for the parameters
* @return This <code>Parameters</code> instance.
* @throws ConfigurationException if an error occurs
- * @throws NullArgumentException if the configuration argument is null.
+ * @throws NullPointerException if the configuration argument is null.
* @since 4.1
*/
public static Parameters fromConfiguration( final Configuration
configuration,
final String elementName )
- throws ParameterException, NullArgumentException
+ throws ParameterException, NullPointerException
{
if( null == configuration )
{
- throw new NullArgumentException( "configuration" );
+ throw new NullPointerException( "configuration" );
}

final Configuration[] parameters = configuration.getChildren(
elementName );

Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/NullArgumentException.java
(from r2845,
development/main/transit/core/handler/src/main/net/dpml/lang/NullArgumentException.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/lang/NullArgumentException.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/NullArgumentException.java
Tue Jun 14 01:44:50 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.lang;
+package net.dpml.transit;


/** Exception thrown when the argument to a method or constructor is

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
Tue Jun 14 01:44:50 2005
@@ -18,8 +18,6 @@

package net.dpml.transit;

-import net.dpml.lang.NullArgumentException;
-
import net.dpml.transit.link.FileLinkManager;
import net.dpml.transit.link.LinkManager;
import net.dpml.transit.model.Logger;

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
Tue Jun 14 01:44:50 2005
@@ -28,23 +28,18 @@
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

-import net.dpml.lang.NullArgumentException;
-
+import net.dpml.transit.adapter.LoggingAdapter;
+import net.dpml.transit.home.TransitHome;
import net.dpml.transit.monitors.Monitor;
import net.dpml.transit.monitors.RepositoryMonitorRouter;
import net.dpml.transit.monitors.CacheMonitorRouter;
import net.dpml.transit.monitors.NetworkMonitorRouter;
-
-import net.dpml.transit.repository.Repository;
-import net.dpml.transit.repository.StandardLoader;
-
import net.dpml.transit.link.LinkManager;
-
-import net.dpml.transit.adapter.LoggingAdapter;
-import net.dpml.transit.home.TransitHome;
import net.dpml.transit.model.Logger;
import net.dpml.transit.model.TransitModel;
import net.dpml.transit.model.DefaultTransitModel;
+import net.dpml.transit.repository.Repository;
+import net.dpml.transit.repository.StandardLoader;
import net.dpml.transit.unit.TransitStorageUnit;

/**
@@ -342,47 +337,6 @@
return getTransitContext().getRepository();
}

- /**
- * Start a plugin defined by the supplied uri using the
- * command-line argumements and monitors as optional plugin constructor
- * arguments. If the supplied plugin class implements the runnable
interface,
- * the start operation will attempt to start a new thread for the plugin.
If
- * the Transit handler detects a shutdown request it will attempt to
interrupt
- * the thread as part of an assigned shutdown hook.
- *
- * @param uri the plugin descriptor uri
- * @param args the set of constructor args
- * @return the plugin instance
- * @exception TransitException if plugin deployment error occurs
- * @exception URISyntaxException if the supplied uri not a valid uri
- * @exception IOException if an io related error occurs
- * @exception NullArgumentException if the uri argument is null.
- */
- public Object start( URI uri, Object[] args )
- throws TransitException, URISyntaxException, IOException,
NullArgumentException
- {
- if( null == uri )
- {
- throw new NullArgumentException( "uri" );
- }
-
- m_repositoryMonitor.sequenceInfo( "Loading : " + uri );
-
- //
- // load the controller
- //
-
- ClassLoader classloader = Main.class.getClassLoader();
- Object object = getRepository().getPlugin( classloader, uri, args );
- if( object instanceof Runnable )
- {
- Thread thread = new Thread( (Runnable) object );
- thread.start();
- setShutdownHook( thread );
- }
- return object;
- }
-
/** Returns the LogWriter for the Transit system.
* This writer should only be used to report information that
* should not be output to the user in the course of normal
@@ -398,39 +352,6 @@
}

/**
- * Create a shutdown hook that will trigger shutdown of the supplied
plugin.
- * @param thread the application thread
- */
- private void setShutdownHook( final Thread thread )
- {
- //
- // Create a shutdown hook to trigger clean disposal of the
- // controller
- //
-
- Runtime.getRuntime().addShutdownHook(
- new Thread()
- {
- public void run()
- {
- try
- {
- thread.interrupt();
- }
- catch( Throwable e )
- {
- // ignore it
- }
- finally
- {
- System.runFinalization();
- }
- }
- }
- );
- }
-
- /**
* Resolve the DPML home directory using assesment of the the ${dpml.home}
* system property, the DPML_HOME environment variable. If DPML_HOME is
* not declared, the behaviour is platform specific. If the os is
Windows,

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Artifact.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Artifact.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Artifact.java
Tue Jun 14 01:44:50 2005
@@ -27,7 +27,7 @@
import java.net.URISyntaxException;
import java.net.URL;

-import net.dpml.lang.NullArgumentException;
+import net.dpml.transit.NullArgumentException;

/**
* An Artifact is a utility class the handles validation of
<code>artifact</code> uri

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/network/RequestIdentifier.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/network/RequestIdentifier.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/network/RequestIdentifier.java
Tue Jun 14 01:44:50 2005
@@ -21,7 +21,7 @@

import java.net.InetAddress;

-import net.dpml.lang.NullArgumentException;
+import net.dpml.transit.NullArgumentException;

/**
* A request identifier.

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/network/TransitAuthenticatorImpl.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/network/TransitAuthenticatorImpl.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/network/TransitAuthenticatorImpl.java
Tue Jun 14 01:44:50 2005
@@ -19,11 +19,11 @@

package net.dpml.transit.network;

-import net.dpml.lang.NullArgumentException;
-
import java.net.Authenticator;
import java.net.PasswordAuthentication;

+import net.dpml.transit.NullArgumentException;
+
/**
* Default authenticator that provides support for username password
* based authentication in conjunction with the repository proxy settings.

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/repository/PropertiesPlugin.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/repository/PropertiesPlugin.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/repository/PropertiesPlugin.java
Tue Jun 14 01:44:50 2005
@@ -26,8 +26,7 @@
import java.util.ArrayList;
import java.util.Properties;

-import net.dpml.lang.NullArgumentException;
-
+import net.dpml.transit.NullArgumentException;
import net.dpml.transit.artifact.Artifact;

/**

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/repository/StandardLoader.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/repository/StandardLoader.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/repository/StandardLoader.java
Tue Jun 14 01:44:50 2005
@@ -19,14 +19,6 @@

package net.dpml.transit.repository;

-import net.dpml.lang.NullArgumentException;
-import net.dpml.transit.Transit;
-import net.dpml.transit.TransitException;
-import net.dpml.transit.artifact.Artifact;
-import net.dpml.transit.artifact.ArtifactNotFoundException;
-import net.dpml.transit.artifact.Handler;
-import net.dpml.transit.monitors.RepositoryMonitorRouter;
-
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
@@ -39,6 +31,14 @@
import java.util.Properties;
import java.util.prefs.Preferences;

+import net.dpml.transit.NullArgumentException;
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitException;
+import net.dpml.transit.artifact.Artifact;
+import net.dpml.transit.artifact.ArtifactNotFoundException;
+import net.dpml.transit.artifact.Handler;
+import net.dpml.transit.monitors.RepositoryMonitorRouter;
+
/**
* Utility class supporting downloading of resources based on
* artifact references.

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/CacheHandler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/CacheHandler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/CacheHandler.java
Tue Jun 14 01:44:50 2005
@@ -19,16 +19,16 @@

package net.dpml.transit.runtime;

-import net.dpml.lang.NullArgumentException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import net.dpml.transit.NullArgumentException;
import net.dpml.transit.SecuredTransitContext;
import net.dpml.transit.TransitException;
import net.dpml.transit.artifact.Artifact;
import net.dpml.transit.artifact.ArtifactAlreadyExistsException;

-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
/**
* The CacheHandler interface defines the contract for classes capable of
* supporting the cache management aspects of a transit system. Cache
management

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/DefaultCacheHandler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/DefaultCacheHandler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/DefaultCacheHandler.java
Tue Jun 14 01:44:50 2005
@@ -37,8 +37,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

-import net.dpml.lang.NullArgumentException;
-
+import net.dpml.transit.NullArgumentException;
import net.dpml.transit.Handler;
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/unit/TransitPreferences.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/unit/TransitPreferences.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/unit/TransitPreferences.java
Tue Jun 14 01:44:50 2005
@@ -40,8 +40,7 @@
import java.util.logging.Level;
import java.util.Date;

-import net.dpml.lang.NullArgumentException;
-
+import net.dpml.transit.NullArgumentException;
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
import net.dpml.transit.runtime.Layout;

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/util/ExceptionHelper.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/util/ExceptionHelper.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/util/ExceptionHelper.java
Tue Jun 14 01:44:50 2005
@@ -23,8 +23,6 @@
import java.lang.reflect.Method;
import java.util.StringTokenizer;

-import net.dpml.lang.NullArgumentException;
-
/**
* General utilities supporting the packaging of exception messages.
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
@@ -255,14 +253,12 @@
* Get a causal exception using reflection.
* @param exception the exception
* @return the causal exception
- * @exception NullArgumentException if the exception argument is null.
*/
private static Throwable getCause( Throwable exception )
- throws NullArgumentException
{
- if( exception == null )
+ if( null == exception )
{
- throw new NullArgumentException( "exception" );
+ return null;
}

try

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/util/StreamUtils.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/util/StreamUtils.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/util/StreamUtils.java
Tue Jun 14 01:44:50 2005
@@ -26,7 +26,7 @@

import java.net.URL;

-import net.dpml.lang.NullArgumentException;
+import net.dpml.transit.NullArgumentException;

import net.dpml.transit.monitors.NetworkMonitor;


Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/PluginTask.java
==============================================================================
---
development/main/transit/core/tools/src/main/net/dpml/transit/tools/PluginTask.java
(original)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/PluginTask.java
Tue Jun 14 01:44:50 2005
@@ -25,17 +25,13 @@
import java.util.List;
import java.util.ArrayList;

-import net.dpml.lang.NullArgumentException;
-
+import net.dpml.transit.NullArgumentException;
import net.dpml.transit.TransitException;
-
import net.dpml.transit.Transit;
import net.dpml.transit.repository.Repository;
import net.dpml.transit.repository.StandardLoader;
import net.dpml.transit.repository.Plugin;
-
import net.dpml.transit.util.ElementHelper;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.Project;



  • svn commit: r2854 - in development/main: magic/core/src/main/net/dpml/magic magic/core/src/main/net/dpml/magic/builder magic/core/src/main/net/dpml/magic/model magic/core/src/main/net/dpml/magic/project magic/core/src/main/net/dpml/magic/tasks metro metro/composition/control/src/main/net/dpml/composition/control metro/composition/control/src/main/net/dpml/composition/data metro/parameters/impl/src/main/net/dpml/parameters/impl transit/core/handler/src/main/net/dpml/lang transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/network transit/core/handler/src/main/net/dpml/transit/repository transit/core/handler/src/main/net/dpml/transit/runtime transit/core/handler/src/main/net/dpml/transit/unit transit/core/handler/src/main/net/dpml/transit/util transit/core/tools/src/main/net/dpml/transit/tools, mcconnell, 06/14/2005

Archive powered by MHonArc 2.6.24.

Top of Page