notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2480 - in development/main: metro metro/composition/builder/src/main/net/dpml/composition/builder metro/composition/control/src/main/net/dpml/composition/control metro/composition/part/src/main/net/dpml/composition/data metro/composition/part/src/test/net/dpml/composition/info/test metro/composition/testing/workshop metro/composition/testing/workshop/src/main/net/dpml/test metro/composition/testing/workshop/src/test/net/dpml/test metro/composition/unit metro/composition/unit/src/main/net/dpml/composition/unit transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/adapter transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/logging transit/core/handler/src/main/net/dpml/transit/logging/nodes
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2480 - in development/main: metro metro/composition/builder/src/main/net/dpml/composition/builder metro/composition/control/src/main/net/dpml/composition/control metro/composition/part/src/main/net/dpml/composition/data metro/composition/part/src/test/net/dpml/composition/info/test metro/composition/testing/workshop metro/composition/testing/workshop/src/main/net/dpml/test metro/composition/testing/workshop/src/test/net/dpml/test metro/composition/unit metro/composition/unit/src/main/net/dpml/composition/unit transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/adapter transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/logging transit/core/handler/src/main/net/dpml/transit/logging/nodes
- Date: Tue, 10 May 2005 00:44:41 -0400
Author: mcconnell AT dpml.net
Date: Tue May 10 00:44:32 2005
New Revision: 2480
Added:
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/PartTestCase.java
development/main/metro/composition/unit/src/main/net/dpml/composition/unit/CompositionContentHandler.java
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerDescriptor.java
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerRegistry.java
development/main/transit/core/handler/src/main/net/dpml/transit/logging/ConfigurationHandler.java
- copied, changed from r2464,
development/main/transit/core/handler/src/main/net/dpml/transit/logging/LoggingController.java
development/main/transit/core/handler/src/main/net/dpml/transit/logging/LoggingManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/logging/nodes/
development/main/transit/core/handler/src/main/net/dpml/transit/logging/nodes/Nodes.java
Removed:
development/main/transit/core/handler/src/main/net/dpml/transit/logging/LoggingController.java
Modified:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/ComponentBuilderTask.java
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionClassLoader.java
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
development/main/metro/composition/control/src/main/net/dpml/composition/control/DefaultMonitor.java
development/main/metro/composition/part/src/main/net/dpml/composition/data/ClasspathDirective.java
development/main/metro/composition/part/src/test/net/dpml/composition/info/test/TypeTestCase.java
development/main/metro/composition/testing/workshop/build.xml
development/main/metro/composition/testing/workshop/src/main/net/dpml/test/WorkshopComponent.java
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/WorkshopTestCase.java
development/main/metro/composition/unit/build.xml
development/main/metro/index.xml
development/main/transit/core/handler/src/main/net/dpml/transit/Main.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/TransitException.java
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/LoggingAdapter.java
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ArtifactURLConnection.java
development/main/transit/core/handler/src/main/net/dpml/transit/logging/StandardFormatter.java
Log:
1. Update the adapter package to use java.util.logging as opposed to
System.out, get the logging configuration into basic shape (including the
addition of related system properties in the Transit class)
2. Add a hook in the SecuredTransitContext to trigger creation of a pluggable
content handler registry and add content handler descriptors and the registry
3. Update the FT classloader to provide more useful info about the
classloader role
4. Move internal logging in FT towards just plain java.util.logging.Logger
5. Update the FT Monitor to use java.util.logging.Logger
6. Add a new tresting subproject dealing with current topics
7. Add a FT content handler
9. Update the Transit adapter package to use java.util.logging as opposed to
System.out, get the logging configuration into basic shape (including the
addition of related system properties in the Transit class)
10. Add a hook in the SecuredTransitContext to trigger creation of a
pluggable content handler registry and add content handler descriptors and
the registry itself
Modified:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/ComponentBuilderTask.java
==============================================================================
---
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/ComponentBuilderTask.java
(original)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/ComponentBuilderTask.java
Tue May 10 00:44:32 2005
@@ -304,17 +304,17 @@
URI[] uris = createURISequence( ResourceRef.API );
if( uris.length > 0 )
{
- list.add( new ClasspathDirective( uris ) );
+ list.add( new ClasspathDirective( "api", uris ) );
}
uris = createURISequence( ResourceRef.SPI );
if( uris.length > 0 )
{
- list.add( new ClasspathDirective( uris ) );
+ list.add( new ClasspathDirective( "spi", uris ) );
}
uris = createURISequence( ResourceRef.IMPL );
if( uris.length > 0 )
{
- list.add( new ClasspathDirective( uris ) );
+ list.add( new ClasspathDirective( "impl", uris ) );
}
ClasspathDirective[] cps = (ClasspathDirective[]) list.toArray( new
ClasspathDirective[0] );
return new ClassLoaderDirective( cps );
Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionClassLoader.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionClassLoader.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionClassLoader.java
Tue May 10 00:44:32 2005
@@ -103,7 +103,7 @@
}
int index = cl.getIndex();
URI partition = cl.getPartition();
- buffer.append( "\n metro: " + partition + " (" + index + ")" );
+ buffer.append( "\n " + partition + " (" + index + ")" );
appendEntries( buffer, cl );
}
else if( classloader instanceof StandardClassLoader )
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
Tue May 10 00:44:32 2005
@@ -31,6 +31,7 @@
import java.util.Observer;
import java.util.Map.Entry;
import java.util.logging.Logger;
+import java.util.logging.Level;
import net.dpml.composition.data.ClassLoaderDirective;
import net.dpml.composition.data.ClasspathDirective;
@@ -85,21 +86,46 @@
private final URI m_partition;
private final ValueController m_valueController;
+ private final Logger m_logger;
+
//--------------------------------------------------------------------
// constructor
//--------------------------------------------------------------------
- CompositionController( Monitor monitor, SystemContext system, URI
partition )
+ CompositionController( SystemContext system, URI partition )
{
super();
- m_monitor = monitor;
+ m_logger = getLoggerForURI( partition );
+ if( system.getDebugMode() )
+ {
+ m_logger.setLevel( Level.FINE );
+ }
+ m_logger.info( "metro controller established" );
+ m_monitor = new DefaultMonitor( m_logger );
m_system = system;
m_partition = partition;
m_valueController = new ValueController( this );
- ComponentController manager = new ComponentController( monitor,
system, this );
- m_lifestyleHandler = new LifestyleHandler( monitor, manager );
+ ComponentController manager = new ComponentController( m_monitor,
system, this );
+ m_lifestyleHandler = new LifestyleHandler( m_monitor, manager );
}
+ Logger getLoggerForURI( URI uri )
+ {
+ String path = uri.getSchemeSpecificPart();
+ if( path.endsWith( "/" ) )
+ {
+ path = path.substring( 0, path.length() - 1 );
+ }
+ path.replace( '/', '.' );
+ return Logger.getLogger( path );
+ }
+
+ Logger getLogger()
+ {
+ return m_logger;
+ }
+
+
//--------------------------------------------------------------------
// PartHandler
//--------------------------------------------------------------------
@@ -240,8 +266,10 @@
throws IOException, DelegationException, ModelException,
PartNotFoundException,
HandlerNotFoundException, DelegationException
{
+ m_logger.fine( "loading part " + uri );
Part part = loadPart( uri );
- ClassLoader anchor =
net.dpml.composition.info.Type.class.getClassLoader();
+ ClassLoader anchor = net.dpml.parts.part.Part.class.getClassLoader();
+ //ClassLoader anchor =
net.dpml.composition.info.Type.class.getClassLoader();
return getModel( anchor, part, key );
}
@@ -485,7 +513,6 @@
return m_system.getLoggingManager().getLoggerForCategory( path );
}
-
/**
* Return the monitor assigned to this controller.
*
@@ -523,13 +550,16 @@
final String name = profile.getName();
final ClassLoaderDirective cld = profile.getClassLoaderDirective();
final ClasspathDirective[] cpds = cld.getClasspathDirectives();
- for( int i=(cpds.length - 1); i>-1; i-- )
+ for( int i=0; i<cpds.length; i++ )
{
ClasspathDirective cpd = cpds[i];
+ String tag = cpd.getCategoryName();
+ URI id = createInstanceURI( partition, tag );
URI[] uris = filter( cpd.getURIs(), parent );
if( uris.length > 0 )
{
- parent = new CompositionClassLoader( m_monitor, partition,
i, uris, parent );
+ getLogger().fine( "creating " + tag + " classloader with " +
uris.length + " entries" );
+ parent = new CompositionClassLoader( m_monitor, id, i, uris,
parent );
}
}
return parent;
Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
Tue May 10 00:44:32 2005
@@ -78,7 +78,7 @@
public CompositionManager( SystemContext system, String[] args ) throws
Exception
{
- super( new DefaultMonitor( system.getLogger() ), system,
createPartition( system ) );
+ super( system, createPartition( system ) );
m_context = system;
m_partition = createPartition( system );
@@ -141,25 +141,26 @@
public synchronized void start() throws Exception
{
- getMonitor().debug( "initiating startup in " + getURI() );
+ getLogger().info( "initiating startup in " + getURI() );
Component[] components = getManagedComponents();
for( int i=(components.length-1); i>-1; i-- )
{
Component component = components[i];
- getMonitor().debug( "starting " + component.getURI() );
+ getLogger().info( "starting " + component.getURI() );
Object instance = component.resolve();
+ getLogger().info( "resolved: " + instance );
m_instances.put( component, instance );
}
}
public synchronized void stop()
{
- getMonitor().debug( "initiating shutdown in " + getURI() );
+ getLogger().info( "initiating shutdown in " + getURI() );
Component[] components = (Component[]) m_instances.keySet().toArray(
new Component[0] );
for( int i=0; i<components.length; i++ )
{
Component component = components[i];
- getMonitor().debug( "stopping " + component.getURI() );
+ getLogger().info( "stopping " + component.getURI() );
Object instance = m_instances.get( component );
component.release( instance );
m_instances.remove( component );
@@ -254,6 +255,7 @@
private void addRootPart( URI uri )
{
+ getLogger().info( "adding root part: " + uri );
try
{
addComponent( uri, "root" );
Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/DefaultMonitor.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/DefaultMonitor.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/DefaultMonitor.java
Tue May 10 00:44:32 2005
@@ -18,7 +18,8 @@
package net.dpml.composition.control;
-import net.dpml.logging.Logger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import net.dpml.parts.control.Monitor;
@@ -44,7 +45,7 @@
*/
public boolean isDebugEnabled()
{
- return m_logger.isDebugEnabled();
+ return m_logger.isLoggable( Level.FINE );
}
/**
@@ -54,7 +55,7 @@
*/
public boolean isInfoEnabled()
{
- return m_logger.isInfoEnabled();
+ return m_logger.isLoggable( Level.INFO );
}
/**
@@ -64,7 +65,7 @@
*/
public boolean isWarnEnabled()
{
- return m_logger.isWarnEnabled();
+ return m_logger.isLoggable( Level.WARNING );
}
/**
@@ -74,7 +75,7 @@
*/
public boolean isErrorEnabled()
{
- return m_logger.isErrorEnabled();
+ return m_logger.isLoggable( Level.SEVERE );
}
/**
@@ -83,7 +84,10 @@
*/
public void debug( String message )
{
- m_logger.debug( message );
+ if( isDebugEnabled() )
+ {
+ m_logger.fine( message );
+ }
}
/**
@@ -92,7 +96,10 @@
*/
public void info( String message )
{
- m_logger.info( message );
+ if( isInfoEnabled() )
+ {
+ m_logger.info( message );
+ }
}
/**
@@ -101,7 +108,10 @@
*/
public void warn( String message )
{
- m_logger.warn( message );
+ if( isWarnEnabled() )
+ {
+ m_logger.warning( message );
+ }
}
/**
@@ -110,7 +120,10 @@
*/
public void warn( String message, Throwable throwable )
{
- m_logger.warn( message, throwable );
+ if( isWarnEnabled() )
+ {
+ m_logger.log( Level.WARNING, message, throwable );
+ }
}
/**
@@ -120,7 +133,10 @@
*/
public void error( String message, Throwable throwable )
{
- m_logger.error( message, throwable );
+ if( isErrorEnabled() )
+ {
+ m_logger.log( Level.SEVERE, message, throwable );
+ }
}
/**
@@ -130,7 +146,7 @@
*/
public void notifyCompletion( boolean status )
{
- m_logger.debug( "completion notification (" + status + ")" );
+ debug( "completion notification (" + status + ")" );
}
/**
@@ -139,6 +155,6 @@
*/
public void notifyFailure( Throwable throwable )
{
- m_logger.warn( "failure notification", throwable );
+ warn( "failure notification", throwable );
}
}
Modified:
development/main/metro/composition/part/src/main/net/dpml/composition/data/ClasspathDirective.java
==============================================================================
---
development/main/metro/composition/part/src/main/net/dpml/composition/data/ClasspathDirective.java
(original)
+++
development/main/metro/composition/part/src/main/net/dpml/composition/data/ClasspathDirective.java
Tue May 10 00:44:32 2005
@@ -43,11 +43,16 @@
private URI[] m_uris;
/**
+ * The resource references
+ */
+ private String m_name;
+
+ /**
* Create a empty ClasspathDirective.
*/
public ClasspathDirective()
{
- this( null );
+ this( "?", null );
}
/**
@@ -55,9 +60,9 @@
*
* @param uris the set of artifact uris
*/
- public ClasspathDirective( final URI[] uris )
+ public ClasspathDirective( final String name, final URI[] uris )
{
- this( null, uris );
+ this( name, null, uris );
}
/**
@@ -67,9 +72,11 @@
* @param uris the set of artifact uris
*/
public ClasspathDirective(
+ final String name,
final FilesetDirective[] filesets,
final URI[] uris )
{
+ m_name = name;
if( filesets == null )
{
m_filesets = EMPTY_FILESETS;
@@ -90,6 +97,16 @@
}
/**
+ * Return the category name.
+ * @return the category name
+ */
+ public String getCategoryName()
+ {
+ return m_name;
+ }
+
+
+ /**
* Return the default status of this directive. If TRUE
* the enclosed repository and fileset directives are empty.
*/
@@ -130,7 +147,11 @@
if( other instanceof ClasspathDirective )
{
ClasspathDirective directive = (ClasspathDirective) other;
- if( getURIs().length != directive.getURIs().length )
+ if( false == getCategoryName().equals(
directive.getCategoryName() ) )
+ {
+ return false;
+ }
+ else if( getURIs().length != directive.getURIs().length )
{
return false;
}
@@ -181,7 +202,7 @@
*/
public int hashCode()
{
- int hash = 0;
+ int hash = m_name.hashCode();
for( int i=0; i<m_filesets.length; i++ )
{
hash ^= m_filesets[i].hashCode();
Modified:
development/main/metro/composition/part/src/test/net/dpml/composition/info/test/TypeTestCase.java
==============================================================================
---
development/main/metro/composition/part/src/test/net/dpml/composition/info/test/TypeTestCase.java
(original)
+++
development/main/metro/composition/part/src/test/net/dpml/composition/info/test/TypeTestCase.java
Tue May 10 00:44:32 2005
@@ -43,8 +43,6 @@
import net.dpml.configuration.Configuration;
-import net.dpml.configuration.impl.DefaultConfiguration;
-
/**
* TypeTestCase does XYZ
@@ -59,7 +57,6 @@
private ContextDescriptor m_context;
private ServiceDescriptor[] m_services;
private DependencyDescriptor[] m_dependencies;
- private Configuration m_defaults;
private PartDescriptor[] m_parts;
private ReferenceDescriptor m_reference;
private String m_key;
@@ -85,7 +82,6 @@
m_dependencies = new DependencyDescriptor[] {
new DependencyDescriptor("role", m_reference)
};
- m_defaults = new DefaultConfiguration("default");
m_parts = new PartDescriptor[] {
new PartDescriptor( "key", new Operation[]{ new Operation(
PartDescriptor.GET, ReferenceDescriptor.class.getName() ) } )
};
@@ -95,7 +91,6 @@
{
assertNotNull(type);
checkArray( m_loggers, type.getCategories());
- assertEquals( m_defaults, type.getConfiguration() );
assertEquals( m_context, type.getContext());
checkArray( m_dependencies, type.getDependencies());
assertEquals( m_dependencies[0],
type.getDependency(m_dependencies[0].getKey()));
@@ -122,7 +117,7 @@
Type type =
new Type(
m_descriptor, m_loggers, m_context, m_services, m_dependencies,
- m_defaults, m_parts );
+ null, m_parts );
checkType(type);
}
@@ -131,7 +126,7 @@
Type type =
new Type(
m_descriptor, m_loggers, m_context, m_services, m_dependencies,
- m_defaults, m_parts );
+ null, m_parts );
checkType( type );
Modified: development/main/metro/composition/testing/workshop/build.xml
==============================================================================
--- development/main/metro/composition/testing/workshop/build.xml
(original)
+++ development/main/metro/composition/testing/workshop/build.xml Tue
May 10 00:44:32 2005
@@ -17,6 +17,12 @@
name="demo">
</component>
+ <component
+ xmlns="plugin:dpml/composition/dpml-composition-builder"
+ type="net.dpml.test.WorkshopComponent"
+ name="demo">
+ </component>
+
</target>
</project>
Modified:
development/main/metro/composition/testing/workshop/src/main/net/dpml/test/WorkshopComponent.java
==============================================================================
---
development/main/metro/composition/testing/workshop/src/main/net/dpml/test/WorkshopComponent.java
(original)
+++
development/main/metro/composition/testing/workshop/src/main/net/dpml/test/WorkshopComponent.java
Tue May 10 00:44:32 2005
@@ -18,6 +18,9 @@
package net.dpml.test;
+import java.io.File;
+import java.net.URL;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -48,7 +51,7 @@
*
* @param logger the logging channel assigned by the container
*/
- public WorkshopComponent( final Logger logger )
+ public WorkshopComponent( final Logger logger ) throws Exception
{
m_logger = logger;
m_logger.info( "instantiation" );
Added:
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/PartTestCase.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/PartTestCase.java
Tue May 10 00:44:32 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * 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.test;
+
+import java.net.URL;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+import junit.framework.TestCase;
+
+import net.dpml.parts.part.Part;
+
+/**
+ * Test a simple component case.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta
+ * Library</a>
+ */
+public class PartTestCase extends TestCase
+{
+ static
+ {
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.logging.ConfigurationHandler" );
+ }
+
+ /**
+ * Check that the loading of a url results in the loading of the Part
class from the same classloader.
+ * (i.e. validate that the caching of plugins in Transit is doing what it
should be doing).
+ */
+ public void testPartLoading() throws Exception
+ {
+ URL urlA = new URL(
"artifact:part:dpml/test/dpml-composition-testing-test#SNAPSHOT" );
+ Part partA = (Part) urlA.getContent();
+ URL urlB = new URL(
"artifact:part:dpml/test/dpml-composition-testing-acme#SNAPSHOT" );
+ Part partB = (Part) urlB.getContent();
+ assertEquals( "same class", partA.getClass(), partB.getClass() );
+ }
+}
Modified:
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/WorkshopTestCase.java
==============================================================================
---
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/WorkshopTestCase.java
(original)
+++
development/main/metro/composition/testing/workshop/src/test/net/dpml/test/WorkshopTestCase.java
Tue May 10 00:44:32 2005
@@ -19,15 +19,13 @@
package net.dpml.test;
-import java.net.URI;
+import java.net.URL;
+import java.util.prefs.Preferences;
import junit.framework.TestCase;
-import net.dpml.composition.unit.CompositionHelper;
-
-import net.dpml.parts.control.Manager;
-import net.dpml.parts.model.Component;
-import net.dpml.parts.model.Model;
+import net.dpml.transit.logging.nodes.Nodes;
+import net.dpml.parts.model.Provider;
/**
* Test a simple component case.
@@ -37,41 +35,36 @@
*/
public class WorkshopTestCase extends TestCase
{
- /**
- * Test the construction of the example component and the invocation of
- * the provided controller via </code>the
net.dpml.parts.state.StateManager</code> interface
- */
- public void testComponent() throws Exception
+ static
+ {
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.logging.ConfigurationHandler" );
+ }
+
+ private ClassLoader m_classloader;
+
+ public void setUp()
{
- CompositionHelper helper = new CompositionHelper( false );
- URI uri = helper.toURI( "test.part" );
- Model model = helper.getCompositionManager().getModel( uri );
- Object instance = model.getProvider( "123" ).resolve();
- for( int i=0; i<10; i++ )
- {
- model.getProvider( "123" ).resolve();
- }
-
- System.gc();
- System.out.println( "# a: " + instance );
- instance = null;
- System.gc();
- sleep( 100 );
- System.out.println( "# b" );
- model = null;
- System.gc();
- sleep( 100 );
- System.out.println( "# c" );
+ ClassLoader current = Thread.currentThread().getContextClassLoader();
+ ClassLoader classloader = Provider.class.getClassLoader();
+ Thread.currentThread().setContextClassLoader( classloader );
}
- private void sleep( int time )
+ public void tearDown()
{
- try
- {
- Thread.currentThread().sleep( time );
- }
- catch( Throwable e )
- {
- }
+ Thread.currentThread().setContextClassLoader( m_classloader );
}
+
+ /**
+ * Test creation of a component using a url.
+ */
+ public void testAcmeComponent() throws Exception
+ {
+ URL url = new URL(
"artifact:part:dpml/test/dpml-composition-testing-test#SNAPSHOT" );
+ Provider provider = (Provider) url.getContent( new Class[]{
Provider.class } );
+ Object instance = provider.resolve( false );
+ System.out.println( "" + instance );
+ assertEquals( "component class",
"net.dpml.test.state.ManagingContainer", instance.getClass().getName() );
+ }
+
}
Modified: development/main/metro/composition/unit/build.xml
==============================================================================
--- development/main/metro/composition/unit/build.xml (original)
+++ development/main/metro/composition/unit/build.xml Tue May 10 00:44:32
2005
@@ -9,4 +9,8 @@
<x:filter key="dpml-system-impl" feature="plugin"
token="SYSTEM-PLUGIN-URI"/>
</target>
+ <target name="package" depends="standard.package">
+ <x:export class="net.dpml.composition.unit.CompositionContentHandler"/>
+ </target>
+
</project>
Added:
development/main/metro/composition/unit/src/main/net/dpml/composition/unit/CompositionContentHandler.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/unit/src/main/net/dpml/composition/unit/CompositionContentHandler.java
Tue May 10 00:44:32 2005
@@ -0,0 +1,275 @@
+/*
+ * 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.unit;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLConnection;
+import java.net.ContentHandler;
+import java.net.UnknownServiceException;
+import java.util.Hashtable;
+import java.util.Map;
+
+import net.dpml.composition.control.CompositionManager;
+
+import net.dpml.system.SystemContext;
+import net.dpml.system.SystemContextFactory;
+import net.dpml.system.SystemCriteria;
+
+import net.dpml.transit.repository.Repository;
+import net.dpml.transit.repository.StandardLoader;
+
+import net.dpml.parts.control.ControlRuntimeException;
+
+import net.dpml.parts.part.Part;
+import net.dpml.parts.model.Model;
+import net.dpml.parts.model.Provider;
+import net.dpml.parts.model.Component;
+
+
+/**
+ * A utility class used for the deployment of components in embedded
scenarios
+ * includuing but not limited to test-cases.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ */
+public class CompositionContentHandler extends ContentHandler
+{
+ //------------------------------------------------------------------
+ // static
+ //------------------------------------------------------------------
+
+ public static File getWorkingDir()
+ {
+ String dir = System.getProperty( "user.dir" );
+ try
+ {
+ return new File( dir ).getCanonicalFile();
+ }
+ catch( IOException e )
+ {
+ return new File( dir );
+ }
+ }
+
+ //------------------------------------------------------------------
+ // state
+ //------------------------------------------------------------------
+
+ private SystemContext m_system;
+ private CompositionManager m_manager;
+
+ //------------------------------------------------------------------
+ // constructor
+ //------------------------------------------------------------------
+
+ public CompositionContentHandler() throws Exception
+ {
+ this( getWorkingDir() );
+ }
+
+ public CompositionContentHandler( File base ) throws Exception
+ {
+ this( base, new Hashtable() );
+ }
+
+ public CompositionContentHandler( Map map ) throws Exception
+ {
+ this( getWorkingDir(), map );
+ }
+
+ public CompositionContentHandler( boolean debug ) throws Exception
+ {
+ this( getWorkingDir(), getSystemContextMap( debug ) );
+ }
+
+ public CompositionContentHandler( File base, Map map ) throws Exception
+ {
+ m_system = createSystemContext( map, base );
+ m_manager = new CompositionManager( m_system, new String[0] );
+ }
+
+ //------------------------------------------------------------------
+ // ContentHandler
+ //------------------------------------------------------------------
+
+ public Object getContent( URLConnection connection )
+ {
+ return getContent( connection, new Class[0] );
+ }
+
+ public Object getContent( URLConnection connection, Class[] classes )
+ {
+ URL url = connection.getURL();
+ if( classes.length == 0 )
+ {
+ return getPart( url );
+ }
+ else
+ {
+ for( int i=0; i<classes.length; i++ )
+ {
+ Class c = classes[i];
+ if( Part.class.isAssignableFrom( c ) )
+ {
+ return getPart( url );
+ }
+ else if( Model.class.isAssignableFrom( c ) )
+ {
+ return getModel( url );
+ }
+ else if( Provider.class.isAssignableFrom( c ) )
+ {
+ Model model = getModel( url );
+ return model.getProvider();
+ }
+ else if( Object.class.equals( c ) )
+ {
+ Model model = getModel( url );
+ try
+ {
+ return model.getProvider().resolve( false );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to load part due: " + url;
+ throw new ControlRuntimeException(
m_manager.getURI(), error, e );
+ }
+ }
+ else
+ {
+ final String error =
+ "Unsupported class argument: " + c.getName();
+ throw new ControlRuntimeException( m_manager.getURI(),
error );
+ }
+ }
+ return null;
+ }
+ }
+
+ private Part getPart( URL url )
+ {
+ try
+ {
+ String path = url.toExternalForm();
+ URI uri = new URI( path );
+ return (Part) m_manager.loadPart( uri );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Error occured while attempting to load part: " + url;
+ throw new ControlRuntimeException( m_manager.getURI(), error, e
);
+ }
+ }
+
+ private Model getModel( URL url )
+ {
+ try
+ {
+ String path = url.toExternalForm();
+ URI uri = new URI( path );
+ return m_manager.getModel( uri );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Error occured while attempting to load part: " + url;
+ throw new ControlRuntimeException( m_manager.getURI(), error, e
);
+ }
+ }
+
+ //------------------------------------------------------------------
+ // internal
+ //------------------------------------------------------------------
+
+ public CompositionManager getCompositionManager()
+ {
+ return m_manager;
+ }
+
+ public URI toURI( String path )
+ {
+ try
+ {
+ File base = m_system.getWorkingDirectory();
+ File target = new File( base, path );
+ return target.toURI();
+ }
+ catch( Throwable e )
+ {
+ return null;
+ }
+ }
+
+ public void dispose()
+ {
+ getCompositionManager().dispose();
+ System.gc();
+ }
+
+ /**
+ * Setup the system context.
+ *
+ * @param map a map of supplimentary factory criteria that will be
+ * applied to the system context factory
+ */
+ private SystemContext createSystemContext( Map map, File dir )
+ throws Exception
+ {
+ ClassLoader classloader = CompositionHelper.class.getClassLoader();
+ Repository repository = new StandardLoader();
+ SystemContextFactory factory =
+ (SystemContextFactory) repository.getPlugin( classloader,
SYSTEM_PLUGIN_URI, new Object[]{ map } );
+ SystemCriteria criteria = factory.createDefaultSystemCriteria();
+
+ criteria.setWorkingDirectory( dir );
+ criteria.setAnchorDirectory( dir );
+ return factory.createSystemContext( criteria );
+ }
+
+ private static final URI SYSTEM_PLUGIN_URI = createStaticURI(
"@SYSTEM-PLUGIN-URI@" );
+
+ private static URI createStaticURI( String path )
+ {
+ try
+ {
+ return new URI( path );
+ }
+ catch( Throwable e )
+ {
+ return null;
+ }
+ }
+
+ private static Map getSystemContextMap( boolean debug )
+ {
+ Hashtable map = new Hashtable();
+ if( debug )
+ {
+ map.put( "urn:transit.debug.policy", "true" );
+ }
+ return map;
+ }
+
+}
Modified: development/main/metro/index.xml
==============================================================================
--- development/main/metro/index.xml (original)
+++ development/main/metro/index.xml Tue May 10 00:44:32 2005
@@ -229,6 +229,7 @@
<dependencies>
<include key="dpml-logging-api" tag="api"/>
<include key="dpml-activity-api" tag="api"/>
+ <!--<include key="dpml-parts-api" tag="api"/>-->
<include key="dpml-context-api" tag="api"/>
<include key="dpml-transit-main" tag="api"/>
<include key="dpml-system-api" tag="spi"/>
@@ -388,8 +389,10 @@
<include key="dpml-parameters-api"/>
<include key="dpml-logging-api"/>
<include key="dpml-logging-data"/>
+ <!--
<include key="dpml-configuration-impl" build="false" test="true"
runtime="false"/>
<include key="dpml-parameters-impl" build="false" test="true"
runtime="false"/>
+ -->
</dependencies>
</project>
@@ -505,15 +508,15 @@
</info>
<dependencies>
<include key="dpml-parts-api"/>
+ <include key="dpml-transit-main"/>
<include key="dpml-activity-api"/>
- <include key="dpml-composition-unit" runtime="false"/>
+ <include key="dpml-composition-part"/>
</dependencies>
<plugins>
<include key="dpml-composition-builder"/>
</plugins>
</project>
-
<!-- Utilities -->
<project basedir="util/defaults">
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerDescriptor.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerDescriptor.java
Tue May 10 00:44:32 2005
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2004 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.transit;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.Preferences;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+/**
+ * A description of a pluggable content handler. This class wraps an
underlying
+ * preference node that describes a content handler plugin. It exposes
operations
+ * through which the plugin name and URI can be retrieved without directly
accessing
+ * the underlying Preferences instance.
+ */
+public class ContentHandlerDescriptor implements PreferenceChangeListener
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private Preferences m_preferences;
+
+ private String m_type;
+
+ private String m_title;
+
+ private URI m_uri;
+
+ private Logger m_logger;
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ /**
+ * A description of a pluggable part handler including the part handler
title
+ * and a uri referencing a plugin that is castable to a ContentHandler
instance.
+ *
+ * @param logger an internal logging channel
+ * @param prefs the preferences node containing part handler description
+ */
+ public ContentHandlerDescriptor( Logger logger, Preferences prefs )
+ {
+ m_logger = logger;
+ m_preferences = prefs;
+ prefs.addPreferenceChangeListener( this );
+ m_type = prefs.name();
+ m_title = prefs.get( "title", m_type );
+ String path = prefs.get( "uri", null );
+ m_uri = setURI( path );
+ }
+
+ //
------------------------------------------------------------------------
+ // PreferencesChangeListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Listen to changes in the preferences object that defines this
descriptor
+ * and reflect the changes in the state of the descriptor class.
+ *
+ * @param event the preference change event
+ */
+ public void preferenceChange( PreferenceChangeEvent event )
+ {
+ String key = event.getKey();
+ String value = event.getNewValue();
+ Preferences prefs = event.getNode();
+ if( "title".equals( key ) )
+ {
+ m_title = value;
+ }
+ else if( "uri".equals( key ) )
+ {
+ m_uri = setURI( value );
+ }
+ else
+ {
+ final String warning =
+ "A content handler plugin description preference node change
event references an unrecognized key."
+ + "\nPreference Node: " + m_preferences
+ + "\nKey: " + key;
+ m_logger.log( Level.SEVERE, warning );
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // ContenthandlerDescriptor
+ //
------------------------------------------------------------------------
+
+ public String getContentType()
+ {
+ return m_type;
+ }
+
+ public String getPluginTitle()
+ {
+ return m_title;
+ }
+
+ public URI getPluginURI()
+ {
+ return m_uri;
+ }
+
+ //
------------------------------------------------------------------------
+ // internals
+ //
------------------------------------------------------------------------
+
+ protected void dispose()
+ {
+ m_preferences.removePreferenceChangeListener( this );
+ }
+
+ private URI setURI( String path )
+ {
+ if( null == path )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return new URI( path );
+ }
+ catch( URISyntaxException e )
+ {
+ final String error =
+ "A content handler plugin description preference node
contains an invalid uri attribute."
+ + "\nPreference Node: " + m_preferences
+ + "\nURI Value: " + path;
+ m_logger.log( Level.SEVERE, error, e );
+ return null;
+ }
+ }
+ }
+}
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerRegistry.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerRegistry.java
Tue May 10 00:44:32 2005
@@ -0,0 +1,249 @@
+/*
+ * Copyright 2004 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.transit;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.net.ContentHandler;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.prefs.Preferences;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.BackingStoreException;
+import java.util.logging.Logger;
+
+import net.dpml.io.CascadingIOException;
+
+import net.dpml.transit.repository.StandardLoader;
+
+/**
+ * A registry of descriptions of plugable content handlers. This
implementation
+ * maps user defined preferences to instance of ContentHandlerDescriptor.
+ */
+public class ContentHandlerRegistry implements NodeChangeListener
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private final Map m_descriptors = new Hashtable();
+
+ private final Preferences m_preferences;
+
+ private Logger m_logger;
+
+ private final Map m_links = new WeakHashMap();
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ /**
+ * Responsible for the establishment of a map containing keys that
correspond to
+ * artifact types, and values that correspond to the description of a
+ * content type handler plugins.
+ */
+ public ContentHandlerRegistry( Logger logger, Preferences prefs ) throws
BackingStoreException
+ {
+ m_logger = logger;
+ m_preferences = prefs;
+ synchronized( m_descriptors )
+ {
+ prefs.addNodeChangeListener( this );
+ String[] names = prefs.childrenNames();
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ Preferences p = prefs.node( name );
+ addContentHandlerDescriptor( p );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // ContentHandlerRegistry
+ //
------------------------------------------------------------------------
+
+ public ContentHandler getContentHandler( final URL url, final String
type ) throws IOException
+ {
+ URI uri = getContentHandlerDescriptorURI( type );
+ if( null == uri )
+ {
+ return null;
+ }
+ else
+ {
+ ContentHandler handler = (ContentHandler) m_links.get( uri );
+ if( null != handler )
+ {
+ return handler;
+ }
+
+ try
+ {
+ m_logger.info( "loading content handler for: " + type );
+ StandardLoader loader = new StandardLoader();
+ ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
+ Object plugin = loader.getPlugin( classloader, uri, new
Object[0] );
+ if( plugin instanceof ContentHandler )
+ {
+ handler = (ContentHandler) plugin;
+ m_links.put( uri, handler );
+ //m_links.put( url, handler );
+ return handler;
+ }
+ else
+ {
+ final String error =
+ "Content handler plugin uri does not resolve to a
java.net.ContentHandler."
+ + "\nHandler URI: " + uri
+ + "\nHandler Class: " + plugin.getClass().getName();
+ throw new TransitException( error );
+ }
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to load a content handler plugin.";
+ throw new CascadingIOException( error, e );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // NodeChangeListener (listens to host prefs addition and removal)
+ //
------------------------------------------------------------------------
+
+ /**
+ * Handle the addition of a content handler mapping.
+ *
+ * @param event the node addition event
+ */
+ public void childAdded( NodeChangeEvent event )
+ {
+ Preferences prefs = event.getChild();
+ addContentHandlerDescriptor( prefs );
+ }
+
+ public void childRemoved( NodeChangeEvent event )
+ {
+ Preferences prefs = event.getChild();
+ removeContentHandlerDescriptor( prefs );
+ }
+
+ //
------------------------------------------------------------------------
+ // internals
+ //
------------------------------------------------------------------------
+
+ private URI getContentHandlerDescriptorURI( final String type )
+ {
+ ContentHandlerDescriptor descriptor = getContentHandlerDescriptor(
type );
+ if( null == descriptor )
+ {
+ return null;
+ }
+ else
+ {
+ return descriptor.getPluginURI();
+ }
+ }
+
+ public ContentHandlerDescriptor getContentHandlerDescriptor( final
String type )
+ {
+ if( null == type )
+ {
+ throw new NullPointerException( "type" );
+ }
+ synchronized( m_descriptors )
+ {
+ ContentHandlerDescriptor descriptor = (ContentHandlerDescriptor)
m_descriptors.get( type );
+ if( null == descriptor )
+ {
+ return null;
+ }
+ else if( null == descriptor.getPluginURI() )
+ {
+ return null;
+ }
+ else
+ {
+ return descriptor;
+ }
+ }
+ }
+
+ /**
+ * Add a description of a content handler based on a supplied
+ * prefernces object. The name of the preferences object
+ * corresponds to an artifact type. Request for the resolution
+ * of URL content may be resolved by locating a content handler
+ * plugin for the type exposed by the URL.
+ */
+ private void addContentHandlerDescriptor( ContentHandlerDescriptor
descriptor )
+ {
+ String type = descriptor.getContentType();
+ if( m_descriptors.containsKey( type ) )
+ {
+ final String error =
+ "Duplicate content handler descriptor type."
+ + "\nContentHandlerDescriptor: " + descriptor
+ + "\nContent Type: " + type;
+ throw new IllegalStateException( error );
+ }
+ else
+ {
+ m_logger.fine( "registering '" + type + "' content handler" );
+ m_descriptors.put( type, descriptor );
+ }
+ }
+
+ /**
+ * Add a description of a content handler based on a supplied
+ * prefernces object. The name of the preferences object
+ * corresponds to an artifact type. Request for the resolution
+ * of URL content may be resolved by locating a content handler
+ * plugin for the type exposed by the URL.
+ */
+ private void addContentHandlerDescriptor( Preferences prefs )
+ {
+ ContentHandlerDescriptor descriptor = new ContentHandlerDescriptor(
m_logger, prefs );
+ addContentHandlerDescriptor( descriptor );
+ }
+
+ /**
+ * Remove a content handler descriptor.
+ * @param prefs the preferences node
+ */
+ private void removeContentHandlerDescriptor( Preferences prefs )
+ {
+ synchronized( m_descriptors )
+ {
+ String type = prefs.name();
+ ContentHandlerDescriptor descriptor =
getContentHandlerDescriptor( type );
+ if( descriptor != null )
+ {
+ m_descriptors.remove( type );
+ descriptor.dispose();
+ }
+ }
+ }
+}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/Main.java
==============================================================================
--- development/main/transit/core/handler/src/main/net/dpml/transit/Main.java
(original)
+++ development/main/transit/core/handler/src/main/net/dpml/transit/Main.java
Tue May 10 00:44:32 2005
@@ -30,7 +30,6 @@
import net.dpml.transit.monitors.RepositoryMonitor;
import net.dpml.transit.util.Dictionary;
import net.dpml.transit.prefs.TransitDialog;
-import net.dpml.transit.logging.LoggingController;
import java.io.File;
import java.io.FileInputStream;
@@ -40,6 +39,9 @@
import java.util.Map;
import java.util.logging.Logger;
import java.util.logging.Level;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.LogManager;
import java.util.prefs.Preferences;
/**
@@ -123,16 +125,22 @@
}
}
+ Logger logger = Logger.getLogger( "transit" );
+
if( debug )
{
+ Logger root = LogManager.getLogManager().getLogger( "" );
+ root.setLevel( Level.FINE );
+ Handler[] handlers = root.getHandlers();
+ for( int i=0; i<handlers.length; i++ )
+ {
+ Handler handler = handlers[i];
+ handler.setLevel( Level.FINE );
+ }
+
System.getProperties().list( System.out );
}
- // configure logging
-
- new LoggingController( debug );
- Logger logger = Logger.getLogger( "transit" );
-
//
// check if a prefs reset has been requested
//
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 May 10 00:44:32 2005
@@ -55,6 +55,20 @@
// static
//------------------------------------------------------------------
+ // The following static operations is here simply to setup an example
content
+ // handler plugin declaration that we can use for testing. This will be
+ // removed once a proper installation strategy is established for
content
+ // handler plugins.
+
+ static
+ {
+ Preferences prefs = Preferences.userNodeForPackage(
SecuredTransitContext.class );
+ Preferences content = prefs.node( "content" );
+ Preferences p = content.node( "part" );
+ p.put( "title", "Part Content Handler" );
+ p.put( "uri",
"artifact:plugin:dpml/tools/dpml-composition-unit#SNAPSHOT" );
+ }
+
/**
* The namespace string for transit related properties.
*/
@@ -145,6 +159,11 @@
private LinkManager m_linkManager;
/**
+ * The ContentHandler plugin registry.
+ */
+ private ContentHandlerRegistry m_contentHandlerRegistry;
+
+ /**
* The authoritive anchor url.
*/
private URL m_authorativeHost;
@@ -210,15 +229,19 @@
{
classname = getResourceManagerClassname( props ); //
using properties
}
+
+ Preferences prefs = Preferences.userNodeForPackage(
SecuredTransitContext.class );
+ Preferences content = prefs.node( "content" );
+ ContentHandlerRegistry registry = new
ContentHandlerRegistry( logger, content );
ResourceManager manager = createResourceManager( classname,
authorative );
CacheHandler ch = manager.createCacheHandler();
if( logger.isLoggable( Level.FINE ) )
{
logger.fine( "establish cache: " +
ch.getClass().getName() );
}
- m_CONTEXT = new SecuredTransitContext( authorative, ch,
props );
+ m_CONTEXT = new SecuredTransitContext( authorative,
registry, ch, props );
}
- catch( IOException e )
+ catch( Exception e )
{
String error = "Unable to establish the
SecuredTransitContext.";
logger.log( Level.SEVERE, error, e );
@@ -315,31 +338,16 @@
}
/**
- * Creation of a new secured transit context using a remote service.
- * @param handler the cache handler
- */
- private SecuredTransitContext( CacheHandler handler )
- {
- m_authorativeHost = null;
- m_cacheHandler = handler;
-
- // Niclas; Hardcoding the LinkManager for now. When/If pluggable
- // LinkManagers becomes a reality, we'll worry about how
- // to install them.
- m_linkManager = new FileLinkManager();
- }
-
- /**
* Creation of a new secured transit context.
* @param authorative the authorative url.
* @param props the properties for the secured transit context.
* @param handler the cache handler.
* @exception TransitException if a context creation error occurs.
*/
- private SecuredTransitContext( URL authorative, CacheHandler handler,
Properties props )
+ private SecuredTransitContext( URL authorative, ContentHandlerRegistry
registry, CacheHandler handler, Properties props )
throws TransitException
{
- this( handler );
+ this( handler, registry );
try
{
setupAuthenticator( props );
@@ -350,6 +358,22 @@
}
}
+ /**
+ * Creation of a new secured transit context using a remote service.
+ * @param handler the cache handler
+ */
+ private SecuredTransitContext( CacheHandler handler,
ContentHandlerRegistry registry )
+ {
+ m_authorativeHost = null;
+ m_cacheHandler = handler;
+ m_contentHandlerRegistry = registry;
+
+ // Niclas; Hardcoding the LinkManager for now. When/If pluggable
+ // LinkManagers becomes a reality, we'll worry about how
+ // to install them.
+ m_linkManager = new FileLinkManager();
+ }
+
private static Properties getTransitProperties( URL authorative ) throws
IOException
{
try
@@ -367,7 +391,6 @@
/**
* Return cache handler directory.
- *
* @return the cache handler
*/
public CacheHandler getCacheHandler()
@@ -380,6 +403,15 @@
return m_linkManager;
}
+ /**
+ * Return the registry of pluggable content handlers.
+ * @return the content handler registry
+ */
+ public ContentHandlerRegistry getContentHandlerRegistry()
+ {
+ return m_contentHandlerRegistry;
+ }
+
/**
* Return the authorative host URL.
* @return the authorative host url
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 May 10 00:44:32 2005
@@ -141,6 +141,11 @@
static
{
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ }
+
+ static
+ {
DPML_HOME = resolveHomeDirectory();
DPML_SYSTEM = resolveSystemDirectory( DPML_HOME );
DPML_DATA = resolveDataDirectory( DPML_HOME );
@@ -462,4 +467,45 @@
}
}
+
//--------------------------------------------------------------------------
+ // static utilities for setup of logging manager
+
//--------------------------------------------------------------------------
+
+ // The following keys and static operations are needed to trigger the
loading
+ // of a custom LogManager. The log manager is loader by requesting the
loading
+ // of a class named under the LOG_MANAGER_KEY key. This will fail with
a
+ // ClassNotFound but the LogManager impl checks for the class in the
context
+ // classloader if and only if the first property request fails (which is
really
+ // strange). We also include a custom logging configuration handler
declaration
+ // for the setup and maintenance of the logging configuration.
+
+ /**
+ * Java Logging Manager impl key that is used to trigger a ClassNotFound
+ * exception which in turn triggers evaluation of LOG_MANAGER_ALT_KEY.
+ */
+ private static final String LOG_MANAGER_KEY =
"java.util.logging.manager";
+
+ /**
+ * The key used to resolve the logging manager class from the context
classloader.
+ */
+ private static final String LOG_MANAGER_ALT_KEY =
"java.util.logging.manager.altclassloader";
+
+ /**
+ * The key used to declare the custom logging configuration handler class.
+ */
+ private static final String LOG_CONFIG_CLASS_KEY =
"java.util.logging.config.class";
+
+ static
+ {
+ System.setProperty( LOG_MANAGER_KEY,
+ System.getProperty( LOG_MANAGER_KEY,
+ "net.dpml.transit.logging.LoggingManager" ) );
+ System.setProperty( LOG_MANAGER_ALT_KEY,
+ System.getProperty( LOG_MANAGER_ALT_KEY,
+ "net.dpml.transit.logging.LoggingManager" ) );
+ System.setProperty( LOG_CONFIG_CLASS_KEY,
+ System.getProperty( LOG_CONFIG_CLASS_KEY,
+ "net.dpml.transit.logging.ConfigurationHandler" ) );
+ }
+
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/TransitException.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/TransitException.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/TransitException.java
Tue May 10 00:44:32 2005
@@ -19,7 +19,7 @@
package net.dpml.transit;
-import java.io.IOException;
+import java.net.ProtocolException;
/**
* Exception to indicate that there was a transit artifact related error.
@@ -27,7 +27,7 @@
* @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
* @version $Id$
*/
-public class TransitException extends IOException
+public class TransitException extends ProtocolException
{
/**
* The exception causing this exception.
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/LoggingAdapter.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/LoggingAdapter.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/LoggingAdapter.java
Tue May 10 00:44:32 2005
@@ -159,8 +159,7 @@
* @param e the causal exception
*/
public void error( String message, Throwable e )
- {
-
+ {
if( isErrorEnabled() )
{
String error = ExceptionHelper.packException( message, e, true );
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ArtifactURLConnection.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ArtifactURLConnection.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ArtifactURLConnection.java
Tue May 10 00:44:32 2005
@@ -22,19 +22,23 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.File;
-
+import java.net.ContentHandler;
import java.net.UnknownServiceException;
+import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URISyntaxException;
+import java.util.prefs.Preferences;
import net.dpml.transit.Transit;
+import net.dpml.transit.TransitException;
import net.dpml.transit.SecuredTransitContext;
+import net.dpml.transit.ContentHandlerRegistry;
+import net.dpml.transit.cache.CacheHandler;
import net.dpml.transit.layout.ClassicResolver;
import net.dpml.transit.layout.LocationResolver;
import net.dpml.transit.util.MimeTypeHandler;
import net.dpml.transit.util.StreamUtils;
-import net.dpml.transit.cache.CacheHandler;
/**
* Artifact URL protocol connection processor.
@@ -157,6 +161,25 @@
/**
* Return the content for this artifact.
+ * @return the content object (possibly null)
+ * @exception IOException is an error occurs
+ */
+ public Object getContent( )
+ throws IOException
+ {
+ Object content = getContent( new Class[0] );
+ if( content != null )
+ {
+ return content;
+ }
+ else
+ {
+ return super.getContent();
+ }
+ }
+
+ /**
+ * Return the content for this artifact.
* @param classes a sequence of classes against which the
* implementation will attempt to establish a known match
* @return the content object (possibly null)
@@ -165,6 +188,22 @@
public Object getContent( Class[] classes )
throws IOException
{
+ //
+ // check to see if we have a content handler plugin declared for the
artifact type
+ //
+
+ String type = m_artifact.getType();
+ ContentHandlerRegistry registry =
m_context.getContentHandlerRegistry();
+ ContentHandler handler = registry.getContentHandler( getURL(), type
);
+ if( null != handler )
+ {
+ return handler.getContent( this, classes );
+ }
+
+ //
+ // otherwise fallback on the default jvm content handling
+ //
+
try
{
Object content = super.getContent( classes );
@@ -179,7 +218,8 @@
}
//
- // attempt to resolve this locally
+ // and if all else fails, attempt to resolve this locally as we may
be dealing
+ // with Magic references to the artifact File
//
for( int i=0; i < classes.length; i++ )
@@ -190,23 +230,6 @@
InputStream content = getInputStream();
LocationResolver resolver = new ClassicResolver();
String name = resolver.resolvePath( m_artifact );
-
- // DISABLED FOLLOWING CODE AS IT BREAKS MAGIC
- // (IN PARTICULAR - REPLICATE TASK BREAKS WHICH IN TURN
BREAKS
- // DISTRIBUTION BUILDS)
-
- /*
- File tempDir = new File( Transit.DPML_DATA, "temp" );
- File destFile = new File( tempDir, name );
- File parent = destFile.getParentFile();
- parent.mkdirs();
- FileOutputStream output = new FileOutputStream( destFile );
- StreamUtils.copyStream( content, output, true );
- return destFile;
- */
-
- // WORKAROUND
-
File cache = new File( Transit.DPML_DATA, "cache" );
return new File( cache, name );
}
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/logging/ConfigurationHandler.java
(from r2464,
development/main/transit/core/handler/src/main/net/dpml/transit/logging/LoggingController.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/logging/LoggingController.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/logging/ConfigurationHandler.java
Tue May 10 00:44:32 2005
@@ -24,6 +24,9 @@
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.Level;
+import java.util.prefs.Preferences;
+
+import net.dpml.transit.logging.nodes.Nodes;
/**
* Utility class used to establish the logging configuration. The contents
of
@@ -32,22 +35,16 @@
* logging configuration info from preferences (and initialization of prefs
if
* required).
*/
- public class LoggingController
- {
+public class ConfigurationHandler
+{
/**
* Creation of the logging controller.
*/
- public LoggingController()
+ public ConfigurationHandler()
{
- this( false );
- }
+ Preferences prefs = Preferences.userNodeForPackage( Nodes.class );
+ String rootLevel = prefs.get( "level", "INFO" );
- /**
- * Creation of a new bootstrap monitor.
- * @param monitor the trace monitor
- */
- public LoggingController( boolean debug )
- {
Properties properties = new Properties();
properties.setProperty(
"handlers",
@@ -55,24 +52,21 @@
properties.setProperty(
"java.util.logging.ConsoleHandler.formatter",
"net.dpml.transit.logging.StandardFormatter" );
- if( debug )
- {
- properties.setProperty(
- ".level",
- "FINE" );
- properties.setProperty(
- "java.util.logging.ConsoleHandler.level",
- "FINE" );
- }
- else
- {
- properties.setProperty(
- ".level",
- "INFO" );
- properties.setProperty(
+
+ //
+ // set the default level by setting the root logger level
+ //
+
+ properties.setProperty( ".level", rootLevel );
+
+ //
+ // set the level that the console handler will handle
+ //
+
+ properties.setProperty(
"java.util.logging.ConsoleHandler.level",
- "INFO" );
- }
+ "FINEST" );
+
try
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -88,5 +82,3 @@
}
}
}
-
-
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/logging/LoggingManager.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/logging/LoggingManager.java
Tue May 10 00:44:32 2005
@@ -0,0 +1,27 @@
+/*
+ * 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.transit.logging;
+
+import java.util.logging.LogManager;
+
+public class LoggingManager extends LogManager
+{
+
+}
+
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/logging/StandardFormatter.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/logging/StandardFormatter.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/logging/StandardFormatter.java
Tue May 10 00:44:32 2005
@@ -18,8 +18,6 @@
package net.dpml.transit.logging;
-//import java.io.*;
-//import java.text.*;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/logging/nodes/Nodes.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/logging/nodes/Nodes.java
Tue May 10 00:44:32 2005
@@ -0,0 +1,27 @@
+/*
+ * 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.transit.logging.nodes;
+
+/**
+ * An empty class that serves as the access point for preferences related to
+ * logging nodes.
+ */
+public class Nodes
+{
+}
- svn commit: r2480 - in development/main: metro metro/composition/builder/src/main/net/dpml/composition/builder metro/composition/control/src/main/net/dpml/composition/control metro/composition/part/src/main/net/dpml/composition/data metro/composition/part/src/test/net/dpml/composition/info/test metro/composition/testing/workshop metro/composition/testing/workshop/src/main/net/dpml/test metro/composition/testing/workshop/src/test/net/dpml/test metro/composition/unit metro/composition/unit/src/main/net/dpml/composition/unit transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/adapter transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/logging transit/core/handler/src/main/net/dpml/transit/logging/nodes, mcconnell, 05/09/2005
Archive powered by MHonArc 2.6.24.