Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2947 - in development/main/metro: composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/runtime part/src/main/net/dpml/part/control part/src/main/net/dpml/part/manager

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: r2947 - in development/main/metro: composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/runtime part/src/main/net/dpml/part/control part/src/main/net/dpml/part/manager
  • Date: Fri, 01 Jul 2005 19:11:41 -0400

Author: mcconnell AT dpml.net
Date: Fri Jul 1 19:11:41 2005
New Revision: 2947

Added:

development/main/metro/part/src/main/net/dpml/part/manager/ClassLoadingContext.java
Modified:

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

development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ComponentHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/runtime/CompositionHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ContextMap.java

development/main/metro/composition/control/src/main/net/dpml/composition/runtime/PartsTable.java

development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ValueHandler.java
development/main/metro/part/src/main/net/dpml/part/control/Controller.java
Log:
Remove expose of the ClassLoader in component creation.

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
Fri Jul 1 19:11:41 2005
@@ -53,6 +53,7 @@
import net.dpml.part.control.PartNotFoundException;
import net.dpml.part.control.UnsupportedPartTypeException;
import net.dpml.part.manager.Component;
+import net.dpml.part.manager.ClassLoadingContext;
import net.dpml.part.manager.ComponentException;
import net.dpml.part.manager.Container;
import net.dpml.part.part.Part;
@@ -229,29 +230,18 @@
}
}

- //public File getWorkingDirectory()
- //{
- // return m_context.getWorkingDirectory();
- //}
-
- //public File getTempDirectory()
- //{
- // return m_context.getTempDirectory();
- //}
-
- //public String getName()
- //{
- // return getPartition().toASCIIString();
- //}
-
/**
* Construct a new top-level component.
*
- * @param uri a uri identifying the part
- * @param key the key to assign to the model
- * @return the model of the part
+ * @param uri a uri identifying a part from which the component will be
created.
+ * @return the new component
+ * @exception ComponentException is an error occurs during component
establishment
+ * @exception IOException if an error occurs while attempting to resolve
the component part uri
+ * @exception PartNotFoundException if the uri could not be resolved to a
physical resource
+ * @exception HandlerNotFoundException if the part references a handler
but the handler could not be found
+ * @exception DelegationException if an error occurs following handover
of control to a foreign controller
*/
- public Component newComponent( URI uri )
+ public Component newComponent( URI uri )
throws IOException, ComponentException, PartNotFoundException,
HandlerNotFoundException, DelegationException
{
m_logger.debug( "loading component " + uri );
@@ -261,28 +251,35 @@
Part part = loadPart( uri );
if( isRecognizedPart( part ) )
{
- return newComponent( classloader, null, part, null );
+ return newComponent( null, part, null );
}
else
{
Controller controller = getPartHandler( part );
- return controller.newComponent( classloader, null, part, null );
+ return controller.newComponent( uri );
}
}

/**
- * Creation of a new component using a supplied value directive and
identifier.
- * @param part the value directive
- * @param id the value handler identifier
- * @return the value handler component
- * @exception UnsupportedPartTypeException if the part type is recognized
but not supported
+ * Construct a new component using the supplied part as the defintion of
the
+ * component type and deployment criteria.
+ *
+ * @param parent the enclosing parent component (may be null)
+ * @param part component definition including type and deployment data
+ * @param name the name to assign to the new component
+ * @return a new component
+ * @exception ComponentException is an error occurs during component
establishment
+ * @exception HandlerNotFoundException if the part references a handler
but the handler could not be found
+ * @exception DelegationException if an error occurs following handover
of control to a foreign controller
+ * @exception UnsupportedPartTypeException if the component type is
recognized but not supported
*/
- public Component newComponent( ClassLoader classloader, Component
parent, Part part, String name )
+ public Component newComponent( Component parent, Part part, String name )
throws ComponentException, HandlerNotFoundException,
DelegationException
{
URI partition = getPartition( parent );
if( isRecognizedPart( part ) )
{
+ ClassLoader classloader = getClassLoader( parent );
if( part instanceof ValueDirective )
{
ValueDirective directive = (ValueDirective) part;
@@ -313,7 +310,20 @@
else
{
Controller controller = getPartHandler( part );
- return controller.newComponent( classloader, parent, part, name
);
+ return controller.newComponent( parent, part, name );
+ }
+ }
+
+ private ClassLoader getClassLoader( Component component )
+ {
+ if( component instanceof ClassLoadingContext )
+ {
+ ClassLoadingContext context = (ClassLoadingContext) component;
+ return context.getClassLoader();
+ }
+ else
+ {
+ return Part.class.getClassLoader();
}
}


Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ComponentHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ComponentHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ComponentHandler.java
Fri Jul 1 19:11:41 2005
@@ -65,6 +65,7 @@
import net.dpml.part.state.State;
import net.dpml.part.state.ResourceUnavailableException;
import net.dpml.part.manager.Component;
+import net.dpml.part.manager.ClassLoadingContext;
import net.dpml.part.manager.ComponentException;
import net.dpml.part.manager.ComponentRuntimeException;
import net.dpml.part.manager.AvailabilityEvent;
@@ -80,7 +81,7 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: LifestyleManager.java 259 2004-10-30 07:24:40Z mcconnell $
*/
-public class ComponentHandler extends WeakEventProducer implements
Component, Configurable, Parameterizable
+public class ComponentHandler extends WeakEventProducer implements
Component, ClassLoadingContext, Configurable, Parameterizable
{
private final Map m_proxies = new WeakHashMap();

@@ -216,6 +217,11 @@
}
}

+ public ClassLoader getClassLoader()
+ {
+ return m_classloader;
+ }
+
/**
* Return the short name of this component.
* @return the component name
@@ -245,11 +251,6 @@
return m_controller;
}

- ClassLoader getClassLoader()
- {
- return m_classloader;
- }
-
public void configure( Configuration configuration )
{
m_configuration = configuration;

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/CompositionHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/CompositionHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/CompositionHandler.java
Fri Jul 1 19:11:41 2005
@@ -76,8 +76,7 @@
{
CompositionController controller = getController();
Part part = controller.loadPart( uri );
- ClassLoader classloader = getClassLoader();
- Component component = controller.newComponent( classloader, this,
part, key );
+ Component component = controller.newComponent( this, part, key );
getPartsTable().addComponent( key, component );
return component;
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ContextMap.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ContextMap.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ContextMap.java
Fri Jul 1 19:11:41 2005
@@ -122,8 +122,7 @@
else
{
CompositionController controller = m_component.getController();
- ClassLoader classloader = m_component.getClassLoader();
- Component component = controller.newComponent( classloader,
m_component, part, key );
+ Component component = controller.newComponent( m_component,
part, key );
addEntry( key, component );
}
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/PartsTable.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/PartsTable.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/PartsTable.java
Fri Jul 1 19:11:41 2005
@@ -75,9 +75,8 @@
}
synchronized( m_parts )
{
- ClassLoader classloader = m_component.getClassLoader();
CompositionController controller = m_component.getController();
- Component component = controller.newComponent( classloader,
m_component, part, key );
+ Component component = controller.newComponent( m_component,
part, key );
addComponent( key, component );
}
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ValueHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ValueHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/runtime/ValueHandler.java
Fri Jul 1 19:11:41 2005
@@ -29,7 +29,9 @@
import net.dpml.logging.Logger;

import net.dpml.part.control.Controller;
+import net.dpml.part.control.ControllerContext;
import net.dpml.part.manager.Component;
+import net.dpml.part.manager.ClassLoadingContext;
import net.dpml.part.manager.ComponentException;
import net.dpml.part.manager.ComponentRuntimeException;
import net.dpml.part.state.State;
@@ -39,7 +41,7 @@
*
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
*/
-public class ValueHandler extends AbstractHandler implements Component
+public class ValueHandler extends AbstractHandler implements Component,
ClassLoadingContext
{
//--------------------------------------------------------------
// state
@@ -71,7 +73,7 @@
* @exception NullPointerException if a null value is supplied for any
argument
* other than the enclosing component
*/
- public ValueHandler(
+ public ValueHandler(
Logger logger, CompositionController controller, ClassLoader
classloader,
URI uri, ValueDirective part, Component parent )
{
@@ -95,6 +97,11 @@
m_manager = controller.getValueController();
}

+ public ClassLoader getClassLoader()
+ {
+ return m_classloader;
+ }
+
public String getName()
{
return m_directive.getKey();
@@ -613,119 +620,58 @@
}
else if ( argument.startsWith( "urn:system:" ) )
{
- String arg = argument.substring( 11 );
- URI urn = CompositionController.createURI( "system", arg );
- return getParentResource( urn );
+ ControllerContext context = m_controller.getControllerContext();
+ String key = argument.substring( 11 );
+ if( "context.uri".equals( key ) )
+ {
+ return context.getURI();
+ }
+ else if( "work.dir".equals( key ) )
+ {
+ return context.getWorkingDirectory();
+ }
+ else if( "temp.dir".equals( key ) )
+ {
+ return context.getTempDirectory();
+ }
+ else
+ {
+ final String error =
+ "Requested system resource urn ["
+ + key
+ + "] is not recognized.";
+ throw new IllegalArgumentException( error );
+ }
}
else if ( argument.startsWith( "urn:component:" ) )
{
- String arg = argument.substring( 14 );
- URI urn = CompositionController.createURI( "component", arg );
- return getParentResource( urn );
- }
- else
- {
- return null;
- }
- }
-
- private Object getParentResource( URI urn )
- {
- if( null != m_parent )
- {
- return m_controller.getResource( m_parent, urn );
- }
- else
- {
- final String error =
- "Cannot resolve a parent resource urn from a non-nested
component."
- + "\nQuery URN: " + urn
- + "\nComponent URI: " + getURI();
- throw new ComponentRuntimeException( error );
- }
- }
-
- /*
- private void validate()
- throws ComponentException
- {
- final String descriptorClassName = m_descriptor.getClassname();
- final String directiveClassName = m_directive.getClassname();
- validatePair( descriptorClassName, directiveClassName );
- }
-
- private void validatePair( String descriptorClassName, String
directiveClassName )
- throws ComponentException
- {
- if( "int".equals( descriptorClassName ) )
- {
- if( ( null == directiveClassName ) || "int".equals(
directiveClassName ) )
+ if( null == m_parent )
{
- return;
+ return null;
+ }
+ String key = argument.substring( 14 );
+ if( "name".equals( key ) )
+ {
+ return m_parent.getName();
+ }
+ else if( "uri".equals( key ) )
+ {
+ return m_parent.getURI();
}
else
{
final String error =
- "Descriptor class ["
- + descriptorClassName
- + "] does not match the supplied directive class ["
- + directiveClassName
- + "].";
- throw new ComponentException( error );
+ "Requested component resource urn ["
+ + key
+ + "] is not recognized.";
+ throw new IllegalArgumentException( error );
}
}
-
- if( null == directiveClassName )
- {
- return;
- }
-
- final String key = m_descriptor.getKey();
- Class target = null;
- try
- {
- target = getValueClass( classname );
- }
- catch( ClassNotFoundException e )
- {
- final String error =
- "Context entry return class ["
- + descriptorClassName
- + "] declared under the key ["
- + key
- + "] not found.";
- throw new ComponentException( error );
- }
-
- Class source = null;
- try
- {
- source = getValueClass( classname );
- //source = m_classloader.loadClass( directiveClassName );
- }
- catch( ClassNotFoundException e )
- {
- final String error =
- "Context entry implementation class ["
- + directiveClassName
- + "] declared under the key ["
- + key
- + "] not found.";
- throw new ComponentException( error );
- }
-
- if( !target.isAssignableFrom( source ) )
+ else
{
- final String error =
- "Context entry implementation class ["
- + directiveClassName
- + "] declared under the key ["
- + key
- + "] is not assignable to the context entry return type ["
- + descriptorClassName
- + "].";
- throw new ComponentException( error );
+ final String error =
+ "Context urn not recognized: " + argument;
+ throw new IllegalArgumentException( error );
}
}
- */
}

Modified:
development/main/metro/part/src/main/net/dpml/part/control/Controller.java
==============================================================================
---
development/main/metro/part/src/main/net/dpml/part/control/Controller.java
(original)
+++
development/main/metro/part/src/main/net/dpml/part/control/Controller.java
Fri Jul 1 19:11:41 2005
@@ -55,7 +55,7 @@
/**
* Construct a new top-level component.
*
- * @param uri a uri identifying a part from which the compoent will be
created.
+ * @param uri a uri identifying a part from which the component will be
created.
* @return the new component
* @exception ComponentException is an error occurs during component
establishment
* @exception IOException if an error occurs while attempting to resolve
the component part uri
@@ -68,10 +68,9 @@
DelegationException;

/**
- * Construct a new component under a supplied classloader using the
supplied part as the
- * defintion of the component type and deployment criteria.
+ * Construct a new component using the supplied part as the defintion of
the
+ * component type and deployment criteria.
*
- * @param classloder the classloader to use as the root classloader for
component construction
* @param parent the enclosing parent component (may be null)
* @param part component definition including type and deployment data
* @param name the name to assign to the new component
@@ -79,8 +78,9 @@
* @exception ComponentException is an error occurs during component
establishment
* @exception HandlerNotFoundException if the part references a handler
but the handler could not be found
* @exception DelegationException if an error occurs following handover
of control to a foreign controller
+ * @exception UnsupportedPartTypeException if the component type is
recognized but not supported
*/
- Component newComponent( ClassLoader classloader, Component parent, Part
part, String name )
+ Component newComponent( Component parent, Part part, String name )
throws ComponentException, HandlerNotFoundException,
DelegationException;

}

Added:
development/main/metro/part/src/main/net/dpml/part/manager/ClassLoadingContext.java
==============================================================================
--- (empty file)
+++
development/main/metro/part/src/main/net/dpml/part/manager/ClassLoadingContext.java
Fri Jul 1 19:11:41 2005
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.part.manager;
+
+/**
+ * Interfact implemented by local components.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public interface ClassLoadingContext
+{
+ ClassLoader getClassLoader();
+}



  • svn commit: r2947 - in development/main/metro: composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/runtime part/src/main/net/dpml/part/control part/src/main/net/dpml/part/manager, mcconnell, 07/01/2005

Archive powered by MHonArc 2.6.24.

Top of Page