Skip to Content.
Sympa Menu

notify-dpml - r1053 - in trunk/main/transit: console/src/main/net/dpml/transit/console core/src/main/net/dpml/transit

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1053 - in trunk/main/transit: console/src/main/net/dpml/transit/console core/src/main/net/dpml/transit
  • Date: Wed, 8 Feb 2006 09:09:25 +0100

Author: mcconnell
Date: 2006-02-08 09:09:12 +0100 (Wed, 08 Feb 2006)
New Revision: 1053

Modified:

trunk/main/transit/console/src/main/net/dpml/transit/console/TransitConsoleHandler.java
trunk/main/transit/core/src/main/net/dpml/transit/Repository.java
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
Log:
- add plugin loading support
- improve error reporting

Modified:
trunk/main/transit/console/src/main/net/dpml/transit/console/TransitConsoleHandler.java
===================================================================
---
trunk/main/transit/console/src/main/net/dpml/transit/console/TransitConsoleHandler.java
2006-02-07 06:11:07 UTC (rev 1052)
+++
trunk/main/transit/console/src/main/net/dpml/transit/console/TransitConsoleHandler.java
2006-02-08 08:09:12 UTC (rev 1053)
@@ -28,6 +28,7 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
+import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URL;
import java.util.List;
@@ -51,6 +52,8 @@

import net.dpml.transit.Logger;
import net.dpml.transit.Transit;
+import net.dpml.transit.RepositoryException;
+import net.dpml.transit.UnsupportedSchemeException;
import net.dpml.transit.DefaultTransitModel;
import net.dpml.transit.info.TransitDirective;
import net.dpml.transit.info.ProxyDirective;
@@ -59,6 +62,7 @@
import net.dpml.transit.info.LayoutDirective;
import net.dpml.transit.info.ContentDirective;
import net.dpml.transit.info.ValueDirective;
+import net.dpml.transit.util.ExceptionHelper;

import net.dpml.lang.UnknownKeyException;

@@ -149,6 +153,10 @@
{
export( TransitDirective.CLASSIC_PROFILE );
}
+ else if( line.hasOption( LOAD_COMMAND ) )
+ {
+ processLoad( line );
+ }
else
{
processHelp();
@@ -159,6 +167,54 @@
// command handling
//
------------------------------------------------------------------------

+ private void processLoad( CommandLine line )
+ {
+ try
+ {
+ URI uri = (URI) line.getValue( LOAD_COMMAND, null );
+ ClassLoader loader = ClassLoader.getSystemClassLoader();
+ Object instance =
+ Transit.getInstance().getRepository().getPlugin( loader, uri,
new Object[0] );
+ if( instance instanceof Runnable )
+ {
+ Runnable runnable = (Runnable) instance;
+ runnable.run();
+ }
+ }
+ catch( RepositoryException e )
+ {
+ boolean stack = isDebugEnabled();
+ String message = ExceptionHelper.packException( e, stack );
+ System.out.println( message );
+ }
+ catch( Throwable e )
+ {
+ processException( e );
+ }
+ }
+
+ private void processException( Throwable e )
+ {
+ if( e instanceof InvocationTargetException )
+ {
+ InvocationTargetException ite = (InvocationTargetException) e;
+ Throwable cause = ite.getCause();
+ processException( cause );
+ }
+ else
+ {
+ final String error =
+ "Plugin exception.";
+ String message = ExceptionHelper.packException( error, e, true
);
+ System.out.println( message );
+ }
+ }
+
+ private boolean isDebugEnabled()
+ {
+ return "true".equals( System.getProperty( "dpml.debug", "false" ) );
+ }
+
private void processInfo( CommandLine line )
{
StringBuffer buffer = new StringBuffer();
@@ -1430,6 +1486,19 @@
.withDescription( "Set configuration to default." )
.create();

+ private static final Option LOAD_COMMAND =
+ COMMAND_BUILDER
+ .withName( "load" )
+ .withDescription( "Load a transit plugin." )
+ .withArgument(
+ ARGUMENT_BUILDER
+ .withName( "uri" )
+ .withMinimum( 1 )
+ .withMaximum( 1 )
+ .withValidator( new URIValidator() )
+ .create() )
+ .create();
+
private static final Group COMMAND_GROUP =
GROUP_BUILDER
.withOption( INFO_COMMAND )
@@ -1437,6 +1506,7 @@
.withOption( SET_COMMAND )
.withOption( REMOVE_COMMAND )
.withOption( REVERT_COMMAND )
+ .withOption( LOAD_COMMAND )
.withOption( HELP_COMMAND )
.withMinimum( 1 )
.withMaximum( 1 )

Modified: trunk/main/transit/core/src/main/net/dpml/transit/Repository.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/Repository.java
2006-02-07 06:11:07 UTC (rev 1052)
+++ trunk/main/transit/core/src/main/net/dpml/transit/Repository.java
2006-02-08 08:09:12 UTC (rev 1053)
@@ -20,6 +20,7 @@

import java.io.IOException;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;

import java.net.URI;

@@ -71,9 +72,10 @@
* @param args instantiation arguments
* @return the plugin instance
* @exception IOException if plugin loading exception occurs
+ * @exception InvocationTargetException if the plugin constructor
invocation error occurs
*/
Object getPlugin( ClassLoader parent, URI uri, Object[] args )
- throws IOException;
+ throws IOException, InvocationTargetException;

/**
* Instantiate an instance of a class using the supplied array of
constructor

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-02-07 06:11:07 UTC (rev 1052)
+++ trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-02-08 08:09:12 UTC (rev 1053)
@@ -137,11 +137,12 @@
* @param args commandline arguments
* @return the plugin instance
* @exception IOException if a plugin creation error occurs
+ * @exception InvocationTargetException if the plugin constructor
invocation error occurs
* @exception NullArgumentException if the supplied parent classloader,
* uri or args are null
*/
public Object getPlugin( ClassLoader parent, URI uri, Object[] args )
- throws IOException, NullArgumentException
+ throws IOException, InvocationTargetException, NullArgumentException
{
if( null == uri )
{
@@ -184,11 +185,15 @@
{
throw re;
}
+ catch( InvocationTargetException e )
+ {
+ throw e;
+ }
catch( Exception ce )
{
String error = "Unable to create a plugin using [" + uri + "].";
getMonitor().exceptionOccurred( "getPlugin", ce );
- throw new RepositoryException( error, ce );
+ throw new InvocationTargetException( ce );
}
}

@@ -293,11 +298,12 @@
* @param args the command line args
* @return the plugin instance
* @exception IOException if a plugin creation error occurs
+ * @exception InvocationTargetException if a plugin constructor
invocation error occurs
* @exception NullArgumentException if the any one of supplied
classloader, descriptor,
* class arguments are null
*/
private Object createPlugin( ClassLoader classloader, Plugin descriptor,
Class clazz, Object[] args )
- throws IOException, NullArgumentException
+ throws IOException, NullArgumentException, InvocationTargetException
{
if( null == clazz )
{
@@ -327,7 +333,7 @@
return instantiate( clazz, args );
}

- public Object instantiate( Class clazz, Object[] args ) throws
RepositoryException
+ public Object instantiate( Class clazz, Object[] args ) throws
RepositoryException, InvocationTargetException
{
if( null == clazz )
{
@@ -364,6 +370,14 @@
Expression expression = new Expression( clazz, "new", args );
return expression.getValue();
}
+ catch( InvocationTargetException e )
+ {
+ throw e;
+ }
+ catch( RepositoryException e )
+ {
+ throw e;
+ }
catch( Throwable e )
{
final String error =
@@ -372,13 +386,13 @@
}
}
}
-
- public Object instantiate( Constructor constructor, Object[] args )
throws RepositoryException
+
+ public Object instantiate( Constructor constructor, Object[] args )
throws RepositoryException, InvocationTargetException
{
Object[] arguments = populate( constructor, args );
return newInstance( constructor, arguments );
}
-
+
protected Object[] populate( Constructor constructor, Object[] args )
throws RepositoryException
{
if( null == constructor )
@@ -389,7 +403,7 @@
{
throw new NullArgumentException( "args" );
}
-
+
Class[] classes = constructor.getParameterTypes();
Object[] arguments = new Object[ classes.length ];
ArrayList list = new ArrayList();
@@ -495,7 +509,8 @@
}
}

- private Object newInstance( Constructor constructor, Object[] arguments
) throws RepositoryException
+ private Object newInstance( Constructor constructor, Object[] arguments )
+ throws RepositoryException, InvocationTargetException
{
try
{
@@ -505,12 +520,7 @@
}
catch( InvocationTargetException e )
{
- final String error =
- "Cannot create an instance of ["
- + constructor.getDeclaringClass().getName()
- + "] due to an invocation failure.";
- Throwable cause = e.getTargetException();
- throw new RepositoryException( error, cause );
+ throw e;
}
catch( Throwable e )
{




  • r1053 - in trunk/main/transit: console/src/main/net/dpml/transit/console core/src/main/net/dpml/transit, mcconnell at BerliOS, 02/08/2006

Archive powered by MHonArc 2.6.24.

Top of Page