Skip to Content.
Sympa Menu

notify-dpml - r951 - in trunk/main/metro/part: api/src/main/net/dpml/part/local content/src/main/net/dpml/part/content test/src/test/net/dpml/test/part

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: r951 - in trunk/main/metro/part: api/src/main/net/dpml/part/local content/src/main/net/dpml/part/content test/src/test/net/dpml/test/part
  • Date: Mon, 23 Jan 2006 04:43:10 +0100

Author: mcconnell
Date: 2006-01-23 04:42:57 +0100 (Mon, 23 Jan 2006)
New Revision: 951

Removed:
trunk/main/metro/part/api/src/main/net/dpml/part/local/PartManager.java
Modified:
trunk/main/metro/part/api/src/main/net/dpml/part/local/Controller.java
trunk/main/metro/part/api/src/main/net/dpml/part/local/InitialContext.java

trunk/main/metro/part/content/src/main/net/dpml/part/content/PartContentHandler.java

trunk/main/metro/part/test/src/test/net/dpml/test/part/PartLoadingTestCase.java
Log:
tweaking controller creation

Modified:
trunk/main/metro/part/api/src/main/net/dpml/part/local/Controller.java
===================================================================
--- trunk/main/metro/part/api/src/main/net/dpml/part/local/Controller.java
2006-01-23 02:14:34 UTC (rev 950)
+++ trunk/main/metro/part/api/src/main/net/dpml/part/local/Controller.java
2006-01-23 03:42:57 UTC (rev 951)
@@ -39,7 +39,12 @@
/**
* Static default controller.
*/
- static final Controller STANDARD = InitialContext.CONTROLLER;
+ static final Controller STANDARD = InitialContext.createController();
+
+ /**
+ * Static default controller.
+ */
+ //static final Controller STANDARD = InitialContext.CONTROLLER;

/**
* Returns the identity of the object implementing this interface.

Modified:
trunk/main/metro/part/api/src/main/net/dpml/part/local/InitialContext.java
===================================================================
---
trunk/main/metro/part/api/src/main/net/dpml/part/local/InitialContext.java
2006-01-23 02:14:34 UTC (rev 950)
+++
trunk/main/metro/part/api/src/main/net/dpml/part/local/InitialContext.java
2006-01-23 03:42:57 UTC (rev 951)
@@ -20,6 +20,9 @@

import java.io.File;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.net.URI;
import java.util.EventObject;
import java.util.EventListener;
@@ -46,51 +49,91 @@
// static

//----------------------------------------------------------------------------

- private static final InitialContext CONTEXT = new InitialContext();
+ private static InitalContext m_CONTEXT;

/**
- * Create a shutdown hook that will trigger shutdown of the supplied
plugin.
- * @param thread the application thread
+ * Create the default controller.
*/
- static
+ public static Controller createController()
{
- //
- // Create a shutdown hook to trigger clean disposal of the
- // controller
- //
+ return createController( null );
+ }
+
+ /**
+ * Create the default controller.
+ * @param context the controller context
+ */
+ public static Controller createController( InitialContext context )
+ {
+ ControllerInvocationHandler handler = new
ControllerInvocationHandler( context );
+ return (Controller) Proxy.newProxyInstance(
+ Controller.class.getClassLoader(), new Class[]{Controller.class},
handler );
+ }
+
+ private static class ControllerInvocationHandler implements
InvocationHandler
+ {
+ private InitialContext m_context;
+ private Controller m_controller;

- Runtime.getRuntime().addShutdownHook(
- new Thread()
- {
- public void run()
- {
- try
- {
- CONTEXT.dispose();
- }
- catch( Throwable e )
- {
- boolean ignorable = true;
- }
- System.runFinalization();
- }
- }
- );
+ private ControllerInvocationHandler( InitialContext context )
+ {
+ m_context = context;
+ }
+
+ /**
+ * Invoke the specified method on underlying object.
+ * This is called by the proxy object.
+ *
+ * @param proxy the proxy object
+ * @param method the method invoked on proxy object
+ * @param args the arguments supplied to method
+ * @return the return value of method
+ * @throws Throwable if an error occurs
+ */
+ public Object invoke(
+ final Object proxy, final Method method, final Object[] args )
throws Throwable
+ {
+ Controller controller = getController();
+ return method.invoke( controller, args );
+ }
+
+ private synchronized Controller getController()
+ {
+ if( null != m_controller )
+ {
+ return m_controller;
+ }
+ else
+ {
+ m_controller = InitialContext.newController( m_context );
+ return m_controller;
+ }
+ }
}
-
- public static final Controller CONTROLLER = newController( CONTEXT );

+ private static URI getControllerURI() throws Exception
+ {
+ String spec =
+ System.getProperty(
+ "dpml.part.controller.uri",
+ "@PART-HANDLER-URI@" );
+ return new URI( spec );
+ }
+
/**
* Construct a controller.
* @param context the controller context
* @return the controller
*/
- public static Controller newController( final ControllerContext context )
+ private static Controller newController( final InitialContext context )
{
- if( null == context )
+ InitialContext control = context;
+ if( null == control )
{
- throw new NullPointerException( "context" );
+ control = new InitialContext();
+ Runtime.getRuntime().addShutdownHook( new ContextShutdownHook(
control ) );
}
+
try
{
URI uri = getControllerURI();
@@ -98,26 +141,17 @@
Repository repository = Transit.getInstance().getRepository();
Class c = repository.getPluginClass( classloader, uri );
Constructor constructor = c.getConstructor( new
Class[]{ControllerContext.class} );
- Controller controller = (Controller) constructor.newInstance(
new Object[]{context} );
+ Controller controller = (Controller) constructor.newInstance(
new Object[]{control} );
return controller;
}
catch( Throwable e )
{
final String error =
- "Internal error while attempting to establish the default part
handler.";
+ "Internal error while attempting to establish the standard
controller.";
throw new RuntimeException( error, e );
}
}

- private static URI getControllerURI() throws Exception
- {
- String spec =
- System.getProperty(
- "dpml.part.controller.uri",
- "@PART-HANDLER-URI@" );
- return new URI( spec );
- }
-

//----------------------------------------------------------------------------
// state

//----------------------------------------------------------------------------
@@ -414,4 +448,29 @@
}
}

+ private static class ContextShutdownHook extends Thread
+ {
+ private InitialContext m_context;
+
+ ContextShutdownHook( InitialContext context )
+ {
+ m_context = context;
+ }
+
+ public void run()
+ {
+ try
+ {
+ m_context.dispose();
+ }
+ catch( Throwable e )
+ {
+ boolean ignorable = true;
+ }
+ finally
+ {
+ System.runFinalization();
+ }
+ }
+ }
}

Deleted:
trunk/main/metro/part/api/src/main/net/dpml/part/local/PartManager.java
===================================================================
--- trunk/main/metro/part/api/src/main/net/dpml/part/local/PartManager.java
2006-01-23 02:14:34 UTC (rev 950)
+++ trunk/main/metro/part/api/src/main/net/dpml/part/local/PartManager.java
2006-01-23 03:42:57 UTC (rev 951)
@@ -1,133 +0,0 @@
-/*
- * 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.part.local;
-
-import java.net.URI;
-import java.lang.reflect.Constructor;
-import java.util.Date;
-
-import net.dpml.transit.Transit;
-import net.dpml.transit.Logger;
-import net.dpml.transit.monitor.LoggingAdapter;
-import net.dpml.transit.Repository;
-
-/**
- * Utility class through which the default controller is established. The
- * default controller is loaded using the System property
"dpml.part.controller.uri".
- * If undefined the default controller implementation plugin
"@PART-HANDLER-URI@"
- * will be selected.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public class PartManager
-{
- /**
- * Static reference to the default controller.
- */
- public static final Controller CONTROLLER = newController( new
LoggingAdapter( "" ) );
-
- /**
- * Construct a controller.
- * @param logger the assigned logging channel
- * @return the controller
- */
- public static Controller newController( final Logger logger )
- {
- if( null == logger )
- {
- throw new NullPointerException( "logger" );
- }
- try
- {
- long now = new Date().getTime();
- ClassLoader classloader = PartManager.class.getClassLoader();
- URI uri = getControllerURI();
- Repository repository = Transit.getInstance().getRepository();
- Class c = repository.getPluginClass( classloader, uri );
- Constructor constructor = c.getConstructor( new
Class[]{Logger.class} );
- Controller handler = (Controller) constructor.newInstance( new
Object[]{logger} );
- return handler;
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error while attempting to establish the default part
handler.";
- throw new RuntimeException( error, e );
- }
- }
-
- /**
- * Construct a controller.
- * @param context the controller context
- * @return the controller
- */
- public static Controller newController( final ControllerContext context )
- {
- if( null == context )
- {
- throw new NullPointerException( "context" );
- }
- try
- {
- long now = new Date().getTime();
- ClassLoader classloader = PartManager.class.getClassLoader();
- URI uri = getControllerURI();
- Repository repository = Transit.getInstance().getRepository();
- Class c = repository.getPluginClass( classloader, uri );
- Constructor constructor = c.getConstructor( new
Class[]{ControllerContext.class} );
- Controller controller = (Controller) constructor.newInstance(
new Object[]{context} );
- return controller;
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error while attempting to establish the default part
handler.";
- throw new RuntimeException( error, e );
- }
- }
-
- private final Logger m_logger;
- private final Controller m_handler;
-
- /**
- * Creation of a new <tt>PartManager</tt>.
- * @param logger the assigned logging channel
- */
- public PartManager( Logger logger )
- {
- m_logger = logger;
- m_handler = newController( logger );
- }
-
- /**
- * Return the default part controller.
- * @return the part controller
- */
- public Controller getController()
- {
- return m_handler;
- }
-
- private static URI getControllerURI() throws Exception
- {
- String spec = System.getProperty( "dpml.part.controller.uri",
"@PART-HANDLER-URI@" );
- return new URI( spec );
- }
-}

Modified:
trunk/main/metro/part/content/src/main/net/dpml/part/content/PartContentHandler.java
===================================================================
---
trunk/main/metro/part/content/src/main/net/dpml/part/content/PartContentHandler.java
2006-01-23 02:14:34 UTC (rev 950)
+++
trunk/main/metro/part/content/src/main/net/dpml/part/content/PartContentHandler.java
2006-01-23 03:42:57 UTC (rev 951)
@@ -28,7 +28,7 @@

import net.dpml.part.Directive;
import net.dpml.part.local.Controller;
-import net.dpml.part.local.PartManager;
+import net.dpml.part.local.InitialContext;
import net.dpml.part.remote.Model;
import net.dpml.part.remote.Component;
import net.dpml.part.remote.Provider;
@@ -40,36 +40,9 @@
*/
public class PartContentHandler extends ContentHandler
{
- private final Logger m_logger;
- private final Controller m_handler;
+ private static final Controller CONTROLLER = Controller.STANDARD;

/**
- * Creation of a new <tt>PartContentHandler</tt>.
- * @param logger the assigned logging channel
- * @exception IOException if an IO error occurs
- */
- public PartContentHandler( Logger logger ) throws IOException
- {
- if( null == logger )
- {
- throw new NullPointerException( "logger" );
- }
- m_logger = logger;
- try
- {
- m_handler = PartManager.newController( logger );
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error while attempting to establish the part
handler.";
- IOException cause = new IOException( error );
- cause.initCause( e );
- throw cause;
- }
- }
-
- /**
* Return the content form the url connection.
* @param connection the url connection
* @return the content
@@ -104,23 +77,23 @@
Class c = classes[i];
if( Directive.class.isAssignableFrom( c ) )
{
- return m_handler.loadDirective( uri );
+ return CONTROLLER.loadDirective( uri );
}
else if( Model.class.isAssignableFrom( c ) )
{
- return m_handler.createModel( uri );
+ return CONTROLLER.createModel( uri );
}
else if( Component.class.isAssignableFrom( c ) )
{
- return m_handler.createComponent( uri );
+ return CONTROLLER.createComponent( uri );
}
else if( Provider.class.isAssignableFrom( c ) )
{
- Component component = m_handler.createComponent( uri );
+ Component component = CONTROLLER.createComponent( uri );
return component.getProvider();
}
}
- Component component = m_handler.createComponent( uri );
+ Component component = CONTROLLER.createComponent( uri );
Provider provider = component.getProvider();
return provider.getValue( false );
}

Modified:
trunk/main/metro/part/test/src/test/net/dpml/test/part/PartLoadingTestCase.java
===================================================================
---
trunk/main/metro/part/test/src/test/net/dpml/test/part/PartLoadingTestCase.java
2006-01-23 02:14:34 UTC (rev 950)
+++
trunk/main/metro/part/test/src/test/net/dpml/test/part/PartLoadingTestCase.java
2006-01-23 03:42:57 UTC (rev 951)
@@ -70,7 +70,7 @@
// initialize the controller

InitialContext context = new InitialContext();
- Controller controller = InitialContext.newController( context );
+ Controller controller = InitialContext.createController( context );

// do stuff





  • r951 - in trunk/main/metro/part: api/src/main/net/dpml/part/local content/src/main/net/dpml/part/content test/src/test/net/dpml/test/part, mcconnell at BerliOS, 01/22/2006

Archive powered by MHonArc 2.6.24.

Top of Page