Skip to Content.
Sympa Menu

notify-dpml - r1157 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/process transit/core/src/main/net/dpml/lang transit/core/src/main/net/dpml/transit transit/core/src/test/net/dpml/transit

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1157 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/process transit/core/src/main/net/dpml/lang transit/core/src/main/net/dpml/transit transit/core/src/test/net/dpml/transit
  • Date: Wed, 1 Mar 2006 06:15:19 +0100

Author: mcconnell
Date: 2006-03-01 06:15:17 +0100 (Wed, 01 Mar 2006)
New Revision: 1157

Removed:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultClasspath.java
Modified:

trunk/main/depot/tools/builder/src/main/net/dpml/tools/process/PluginProcess.java
trunk/main/transit/core/src/main/net/dpml/lang/Classpath.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginBuilder.java
trunk/main/transit/core/src/main/net/dpml/transit/Repository.java
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
trunk/main/transit/core/src/test/net/dpml/transit/PluginTestCase.java
Log:
update transit to use an immutable Classpath descriptor

Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/process/PluginProcess.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/process/PluginProcess.java
2006-03-01 05:14:18 UTC (rev 1156)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/process/PluginProcess.java
2006-03-01 05:15:17 UTC (rev 1157)
@@ -39,7 +39,6 @@
import net.dpml.transit.StandardHandler;
import net.dpml.transit.DefaultPluginFactory;
import net.dpml.transit.DefaultStrategy;
-import net.dpml.transit.DefaultClasspath;

import net.dpml.library.info.Scope;
import net.dpml.library.model.Resource;
@@ -221,7 +220,7 @@
URI[] publicUris = getURIs( resource, Category.PUBLIC );
URI[] protectedUris = getURIs( resource, Category.PROTECTED );
URI[] privateUris = getURIs( resource, Category.PRIVATE, true );
- return new DefaultClasspath( sysUris, publicUris, protectedUris,
privateUris );
+ return new Classpath( sysUris, publicUris, protectedUris,
privateUris );
}

private URI[] getURIs( Resource resource, Category category ) throws
IOException

Modified: trunk/main/transit/core/src/main/net/dpml/lang/Classpath.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/lang/Classpath.java
2006-03-01 05:14:18 UTC (rev 1156)
+++ trunk/main/transit/core/src/main/net/dpml/lang/Classpath.java
2006-03-01 05:15:17 UTC (rev 1157)
@@ -19,21 +19,171 @@
package net.dpml.lang;

import java.net.URI;
+import java.io.Serializable;
+import java.util.Arrays;

+import net.dpml.lang.Category;
+
/**
- * Interface implements by classpath definitions.
+ * A Plugin class contains immutable data about a plugin based on a
descriptor resolved
+ * from a 'plugin' artifact.
*
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public interface Classpath
+public final class Classpath implements Serializable
{
+ private final URI[] m_system;
+ private final URI[] m_public;
+ private final URI[] m_protected;
+ private final URI[] m_private;
+
/**
+ * Creation of a new classpath definition.
+ * @param systemUris an array of uris representing the system classpath
extensions
+ * @param publicUris an array of uris representing the public classpath
entries
+ * @param protectedUris an array of uris representing protected classpath
entries
+ * @param privateUris an array of uris representing private classpath
entries
+ */
+ public Classpath(
+ URI[] systemUris, URI[] publicUris, URI[] protectedUris, URI[]
privateUris )
+ {
+ if( null == systemUris )
+ {
+ m_system = EMPTY_URIS;
+ }
+ else
+ {
+ m_system = systemUris;
+ }
+
+ if( null == publicUris )
+ {
+ m_public = EMPTY_URIS;
+ }
+ else
+ {
+ m_public = publicUris;
+ }
+
+ if( null == protectedUris )
+ {
+ m_protected = EMPTY_URIS;
+ }
+ else
+ {
+ m_protected = protectedUris;
+ }
+
+ if( null == privateUris )
+ {
+ m_private = EMPTY_URIS;
+ }
+ else
+ {
+ m_private = privateUris;
+ }
+ }
+
+ /**
* Return the classloader dependencies relative to a supplied classloader
category.
*
* @param category the classloader category
* @return an array of uris defining the classloader classpath for the
supplied category
*/
- URI[] getDependencies( Category category );
+ public URI[] getDependencies( final Category category )
+ {
+ if( Category.SYSTEM.equals( category ) )
+ {
+ return m_system;
+ }
+ else if( Category.PUBLIC.equals( category ) )
+ {
+ return m_public;
+ }
+ else if( Category.PROTECTED.equals( category ) )
+ {
+ return m_protected;
+ }
+ else if( Category.PRIVATE.equals( category ) )
+ {
+ return m_private;
+ }
+ else
+ {
+ final String error =
+ "Category not recognized."
+ + "\nCategory: " + category;
+ throw new IllegalArgumentException( error );
+ }
+ }

+ /**
+ * Compare this object with another for equality.
+ * @param other the other object
+ * @return TRUE if equal else FALSE
+ */
+ public boolean equals( Object other )
+ {
+ if( other instanceof Classpath )
+ {
+ Classpath classpath = (Classpath) other;
+ if( !Arrays.equals( m_system, classpath.getDependencies(
Category.SYSTEM ) ) )
+ {
+ return false;
+ }
+ if( !Arrays.equals( m_public, classpath.getDependencies(
Category.PUBLIC ) ) )
+ {
+ return false;
+ }
+ if( !Arrays.equals( m_protected, classpath.getDependencies(
Category.PROTECTED ) ) )
+ {
+ return false;
+ }
+ else
+ {
+ return Arrays.equals( m_private, classpath.getDependencies(
Category.PRIVATE ) );
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Return the hashcode for the plugin definition.
+ * @return the hash code
+ */
+ public int hashCode()
+ {
+ int hash = hashArray( m_system );
+ hash ^= hashArray( m_public );
+ hash ^= hashArray( m_protected );
+ hash ^= hashArray( m_private );
+ return hash;
+ }
+
+ /**
+ * Utility to hash an array.
+ * @param array the array
+ * @return the hash value
+ */
+ protected int hashArray( Object[] array )
+ {
+ if( null == array )
+ {
+ return 0;
+ }
+ int hash = 0;
+ for( int i=0; i<array.length; i++ )
+ {
+ Object object = array[i];
+ hash ^= object.hashCode();
+ }
+ return hash;
+ }
+
+ private static final URI[] EMPTY_URIS = new URI[0];
+
}

Deleted:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultClasspath.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/DefaultClasspath.java
2006-03-01 05:14:18 UTC (rev 1156)
+++ trunk/main/transit/core/src/main/net/dpml/transit/DefaultClasspath.java
2006-03-01 05:15:17 UTC (rev 1157)
@@ -1,190 +0,0 @@
-/*
- * Copyright 2006 Stephen J. McConnell.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.dpml.transit;
-
-import java.net.URI;
-import java.io.OutputStream;
-import java.util.Arrays;
-
-import net.dpml.lang.Classpath;
-import net.dpml.lang.Category;
-
-/**
- * A Plugin class contains immutable data about a plugin based on a
descriptor resolved
- * from a 'plugin' artifact.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public final class DefaultClasspath implements Classpath
-{
- private final URI[] m_system;
- private final URI[] m_public;
- private final URI[] m_protected;
- private final URI[] m_private;
-
- /**
- * Creation of a new classpath definition.
- * @param systemUris an array of uris representing the system classpath
extensions
- * @param publicUris an array of uris representing the public classpath
entries
- * @param protectedUris an array of uris representing protected classpath
entries
- * @param privateUris an array of uris representing private classpath
entries
- */
- public DefaultClasspath(
- URI[] systemUris, URI[] publicUris, URI[] protectedUris, URI[]
privateUris )
- {
- if( null == systemUris )
- {
- m_system = EMPTY_URIS;
- }
- else
- {
- m_system = systemUris;
- }
-
- if( null == publicUris )
- {
- m_public = EMPTY_URIS;
- }
- else
- {
- m_public = publicUris;
- }
-
- if( null == protectedUris )
- {
- m_protected = EMPTY_URIS;
- }
- else
- {
- m_protected = protectedUris;
- }
-
- if( null == privateUris )
- {
- m_private = EMPTY_URIS;
- }
- else
- {
- m_private = privateUris;
- }
- }
-
- /**
- * Return the classloader dependencies relative to a supplied classloader
category.
- *
- * @param category the classloader category
- * @return an array of uris defining the classloader classpath for the
supplied category
- */
- public URI[] getDependencies( final Category category )
- {
- if( Category.SYSTEM.equals( category ) )
- {
- return m_system;
- }
- else if( Category.PUBLIC.equals( category ) )
- {
- return m_public;
- }
- else if( Category.PROTECTED.equals( category ) )
- {
- return m_protected;
- }
- else if( Category.PRIVATE.equals( category ) )
- {
- return m_private;
- }
- else
- {
- final String error =
- "Category not recognized."
- + "\nCategory: " + category;
- throw new IllegalArgumentException( error );
- }
- }
-
- /**
- * Compare this object with another for equality.
- * @param other the other object
- * @return TRUE if equal else FALSE
- */
- public boolean equals( Object other )
- {
- if( other instanceof Classpath )
- {
- Classpath classpath = (Classpath) other;
- if( !Arrays.equals( m_system, classpath.getDependencies(
Category.SYSTEM ) ) )
- {
- return false;
- }
- if( !Arrays.equals( m_public, classpath.getDependencies(
Category.PUBLIC ) ) )
- {
- return false;
- }
- if( !Arrays.equals( m_protected, classpath.getDependencies(
Category.PROTECTED ) ) )
- {
- return false;
- }
- else
- {
- return Arrays.equals( m_private, classpath.getDependencies(
Category.PRIVATE ) );
- }
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Return the hashcode for the plugin definition.
- * @return the hash code
- */
- public int hashCode()
- {
- int hash = hashArray( m_system );
- hash ^= hashArray( m_public );
- hash ^= hashArray( m_protected );
- hash ^= hashArray( m_private );
- return hash;
- }
-
- /**
- * Utility to hash an array.
- * @param array the array
- * @return the hash value
- */
- protected int hashArray( Object[] array )
- {
- if( null == array )
- {
- return 0;
- }
- int hash = 0;
- for( int i=0; i<array.length; i++ )
- {
- Object object = array[i];
- hash ^= object.hashCode();
- }
- return hash;
- }
-
- private static final URI[] EMPTY_URIS = new URI[0];
-
-}

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginBuilder.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginBuilder.java
2006-03-01 05:14:18 UTC (rev 1156)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultPluginBuilder.java
2006-03-01 05:15:17 UTC (rev 1157)
@@ -223,7 +223,7 @@
URI[] pub = buildURIs( classpath, "public" );
URI[] prot = buildURIs( classpath, "protected" );
URI[] priv = buildURIs( classpath, "private" );
- return new DefaultClasspath( sys, pub, prot, priv );
+ return new Classpath( sys, pub, prot, priv );
}

public Plugin resolve(

Modified: trunk/main/transit/core/src/main/net/dpml/transit/Repository.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/Repository.java
2006-03-01 05:14:18 UTC (rev 1156)
+++ trunk/main/transit/core/src/main/net/dpml/transit/Repository.java
2006-03-01 05:15:17 UTC (rev 1157)
@@ -25,6 +25,7 @@
import java.net.URI;

import net.dpml.lang.Plugin;
+import net.dpml.lang.Classpath;

/**
* A service that provides support for the establishment of classloaders and
plugin
@@ -108,4 +109,15 @@
*/
Object instantiate( Constructor constructor, Object[] params ) throws
Exception;

+ /**
+ * Create a classloader.
+ * @param base the parent classloader
+ * @param plugin the plugin uri
+ * @param classpath the classpath descriptor
+ * @return the classloader
+ * @exception IOException if a classloader construction error occurs
+ */
+ public ClassLoader createClassLoader( ClassLoader base, URI plugin,
Classpath classpath )
+ throws IOException;
+
}

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-03-01 05:14:18 UTC (rev 1156)
+++ trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-03-01 05:15:17 UTC (rev 1157)
@@ -605,8 +605,32 @@
}

URI plugin = descriptor.getURI();
-
Classpath classpath = descriptor.getClasspath();
+ return createClassLoader( base, plugin, classpath );
+ }
+
+ /**
+ * Returns a classloader.
+ * @param base the parent classloader
+ * @param plugin the plugin uri
+ * @param classpath the classpath descriptor
+ * @return the classloader
+ * @exception IOException if a classloader construction error occurs
+ * @exception NullArgumentException if either the base or the descriptor
+ * argument is null.
+ */
+ public ClassLoader createClassLoader( ClassLoader base, URI plugin,
Classpath classpath )
+ throws IOException, NullArgumentException
+ {
+ if( null == classpath )
+ {
+ throw new NullArgumentException( "classpath" );
+ }
+ if( null == base )
+ {
+ throw new NullArgumentException( "base" );
+ }
+
URI[] systemArtifacts = classpath.getDependencies( Category.SYSTEM );
URL[] sysUrls = getURLs( systemArtifacts );
if( sysUrls.length > 0 )
@@ -628,7 +652,7 @@

return classloader;
}
-
+
private void updateSystemClassLoader( URI plugin, URL[] urls ) throws
TransitException
{
ClassLoader parent = ClassLoader.getSystemClassLoader();

Modified:
trunk/main/transit/core/src/test/net/dpml/transit/PluginTestCase.java
===================================================================
--- trunk/main/transit/core/src/test/net/dpml/transit/PluginTestCase.java
2006-03-01 05:14:18 UTC (rev 1156)
+++ trunk/main/transit/core/src/test/net/dpml/transit/PluginTestCase.java
2006-03-01 05:15:17 UTC (rev 1157)
@@ -80,7 +80,7 @@
new URI( "thing:i" ),
new URI( "thing:j" )
};
- m_classpath = new DefaultClasspath( m_system, m_public, m_protected,
m_private );
+ m_classpath = new Classpath( m_system, m_public, m_protected,
m_private );
}

/**




  • r1157 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/process transit/core/src/main/net/dpml/lang transit/core/src/main/net/dpml/transit transit/core/src/test/net/dpml/transit, mcconnell at BerliOS, 03/01/2006

Archive powered by MHonArc 2.6.24.

Top of Page