Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2495 - in development/main/transit/core/handler/src: main/net/dpml/transit main/net/dpml/transit/artifact main/net/dpml/transit/content main/net/dpml/transit/images main/net/dpml/transit/logging main/net/dpml/transit/prefs test/net/dpml/transit/test

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: r2495 - in development/main/transit/core/handler/src: main/net/dpml/transit main/net/dpml/transit/artifact main/net/dpml/transit/content main/net/dpml/transit/images main/net/dpml/transit/logging main/net/dpml/transit/prefs test/net/dpml/transit/test
  • Date: Tue, 10 May 2005 14:47:13 +0000

Author: mcconnell AT dpml.net
Date: Tue May 10 14:47:13 2005
New Revision: 2495

Added:

development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerDescriptor.java
- copied, changed from r2485,
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerDescriptor.java

development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerRegistry.java
- copied, changed from r2485,
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerRegistry.java

development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerDescriptor.java

development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerRegistry.java

development/main/transit/core/handler/src/main/net/dpml/transit/images/misc.png
(contents, props changed)

development/main/transit/core/handler/src/main/net/dpml/transit/images/server.png
(contents, props changed)

development/main/transit/core/handler/src/main/net/dpml/transit/images/source.png
(contents, props changed)

development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ContentHandlerControllerPanel.java

development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ContentHandlerPanel.java

development/main/transit/core/handler/src/main/net/dpml/transit/prefs/GenericTable.java
- copied, changed from r2485,
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostsTable.java

development/main/transit/core/handler/src/main/net/dpml/transit/prefs/NodeTableModel.java
- copied, changed from r2485,
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostsTableModel.java
Removed:

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/prefs/HostsTable.java

development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostsTableModel.java
Modified:

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/artifact/ArtifactURLConnection.java

development/main/transit/core/handler/src/main/net/dpml/transit/logging/StandardFormatter.java

development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostPanel.java

development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ResourcePanel.java

development/main/transit/core/handler/src/main/net/dpml/transit/prefs/TransitDialog.java

development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java

development/main/transit/core/handler/src/test/net/dpml/transit/test/OfflineTestCase.java

development/main/transit/core/handler/src/test/net/dpml/transit/test/OnlineTestCase.java
Log:
Add support for custom content handler controllers. This updates introduce a
initialization phase to the singleton transit instance during which the
sub-systems established by the SecuredTransitContext may be updated within a
context within which an initial Transit instance has been established.

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 14:47:13 2005
@@ -21,6 +21,8 @@
import net.dpml.io.ResourceHelper;
import net.dpml.lang.NullArgumentException;
import net.dpml.transit.cache.CacheHandler;
+import net.dpml.transit.content.ContentHandlerRegistry;
+import net.dpml.transit.content.DefaultContentHandlerRegistry;
import net.dpml.transit.host.ResourceManager;
import net.dpml.transit.link.FileLinkManager;
import net.dpml.transit.link.LinkManager;
@@ -28,6 +30,7 @@
import net.dpml.transit.network.RequestIdentifier;
import net.dpml.transit.network.TransitAuthenticator;
import net.dpml.transit.network.TransitAuthenticatorImpl;
+import net.dpml.transit.repository.StandardLoader;
import net.dpml.transit.util.Util;

import java.io.File;
@@ -36,6 +39,7 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.logging.Logger;
@@ -55,20 +59,6 @@
// 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.
*/
@@ -144,6 +134,18 @@
*/
private static final String DEFAULT_REMOTE_AUTHORITY =
"http://repository.dpml.net";;

+ /**
+ * Return the singleton context.
+ * @return the secure context
+ */
+ public static SecuredTransitContext getInstance()
+ {
+ synchronized( SecuredTransitContext.class )
+ {
+ return m_CONTEXT;
+ }
+ }
+
//------------------------------------------------------------------
// state
//------------------------------------------------------------------
@@ -169,19 +171,62 @@
private URL m_authorativeHost;

/**
- * Return the singleton context.
- * @return the secure context
+ * Logging channel.
*/
- public static SecuredTransitContext getInstance()
+ private Logger m_logger;
+
+ /**
+ * Prefs enabled flag.
+ */
+ private boolean m_prefsEnabled = false;
+
+ //------------------------------------------------------------------
+ // constructors
+ //------------------------------------------------------------------
+
+ /**
+ * 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(
+ boolean flag, URL authorative, ContentHandlerRegistry registry,
CacheHandler handler, Properties props )
+ throws TransitException
{
- synchronized( SecuredTransitContext.class )
+ this( flag, handler, registry );
+ try
{
- return m_CONTEXT;
+ setupAuthenticator( props );
}
+ catch( IOException e )
+ {
+ throw new TransitException( "Unable to read Transit
configuration at " + authorative, e );
+ }
+ }
+
+ /**
+ * Creation of a new secured transit context using a remote service.
+ * @param handler the cache handler
+ */
+ private SecuredTransitContext( boolean flag, CacheHandler handler,
ContentHandlerRegistry registry )
+ {
+ m_prefsEnabled = flag;
+ m_authorativeHost = null;
+ m_cacheHandler = handler;
+ m_contentHandlerRegistry = registry;
+
+ m_logger = Logger.getLogger( "transit" );
+
+ // 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();
}

//------------------------------------------------------------------
- // implementation
+ // SecuredTransitContext
//------------------------------------------------------------------

/**
@@ -230,16 +275,15 @@
classname = getResourceManagerClassname( props ); //
using properties
}

- Preferences prefs = Preferences.userNodeForPackage(
SecuredTransitContext.class );
- Preferences content = prefs.node( "content" );
- ContentHandlerRegistry registry = new
ContentHandlerRegistry( logger, content );
+ Preferences prefs = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
+ ContentHandlerRegistry registry = new
DefaultContentHandlerRegistry( logger, prefs );
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,
registry, ch, props );
+ m_CONTEXT = new SecuredTransitContext( flag, authorative,
registry, ch, props );
}
catch( Exception e )
{
@@ -251,6 +295,161 @@
}
}

+ /**
+ * Return cache handler directory.
+ * @return the cache handler
+ */
+ public CacheHandler getCacheHandler()
+ {
+ return m_cacheHandler;
+ }
+
+ public LinkManager getLinkManager()
+ {
+ 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
+ */
+ public URL getAuthorativeHost()
+ {
+ return m_authorativeHost;
+ }
+
+ /**
+ * Initialization of any sub-systems following the establishment of the
initial
+ * transit system. As a general principal any subsystems that cannot be
established
+ * for technical reasons (security or permission restrictions, etc.)
should log
+ * an appropriate message and fallback to the initial setup thereby
ensuring that
+ * an operable transit system is available.
+ *
+ * @exception TransitException if an initialization error occurs
+ */
+ protected void initialize() throws TransitException
+ {
+ if( false == m_prefsEnabled )
+ {
+ return;
+ }
+ Preferences prefs = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
+ String path = prefs.get( "uri", null );
+ if( null != path )
+ {
+ m_logger.info( "assigning custom content handler registry" );
+ try
+ {
+ URI uri = new URI( path );
+ StandardLoader loader = new StandardLoader();
+ Object[] args = new Object[]{ prefs, m_logger };
+ ClassLoader classloader = Transit.class.getClassLoader();
+ ContentHandlerRegistry registry = (ContentHandlerRegistry)
loader.getPlugin( classloader, uri, args );
+ m_contentHandlerRegistry = registry;
+ m_logger.info( "registry uri: " + path );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Bypassing custom content hander registry assignment due
to internal error.";
+ m_logger.log( Level.WARNING, error, e );
+ }
+ }
+ }
+
+ //------------------------------------------------------------------
+ // internals
+ //------------------------------------------------------------------
+
+ /**
+ * Setup the transit authenticator.
+ * @param properties the transit properties
+ * @exception UnknownHostException if a proxy host is declared but is
unknown
+ */
+ private void setupAuthenticator( Properties properties )
+ throws UnknownHostException
+ {
+ TransitAuthenticator ta = createProxyAuthenticator( properties );
+ if( ta != null )
+ {
+ RequestIdentifier id = createProxyRequestIdentifier( properties
);
+ DelegatingAuthenticator da =
DelegatingAuthenticator.getInstance();
+ da.addTransitAuthenticator( ta, id );
+ }
+ }
+
+ /**
+ * Creation of a new transit authenticator.
+ * @param properties the transit properties
+ * @return the transit authenticator
+ */
+ private TransitAuthenticator createProxyAuthenticator( Properties
properties )
+ {
+ String username = Util.getProperty( properties, PROXY_USERNAME_KEY,
null );
+ String password = Util.getProperty( properties, PROXY_PASSWORD_KEY,
null );
+ if( null == username )
+ {
+ return null;
+ }
+ return new TransitAuthenticatorImpl( username, password );
+ }
+
+ /**
+ * Creation of a new request identifier.
+ * @param properties the transit properties
+ * @return the request identifier
+ * @exception UnknownHostException if a proxy host is declared but is
unknown
+ * @exception IllegalArgumentException if a proxy host is declared and
+ * either the proxy scheme or proxy prompt property values are undefined
+ */
+ private RequestIdentifier createProxyRequestIdentifier( Properties
properties )
+ throws UnknownHostException, IllegalArgumentException
+ {
+ String proxy = Util.getProperty( properties, PROXY_HOST_KEY, null );
+ if( null == proxy )
+ {
+ return null;
+ }
+
+ String protocol = Util.getProperty( properties, PROXY_PROTOCOL_KEY,
"http" );
+ String scheme = Util.getProperty( properties, PROXY_SCHEME_KEY, null
);
+ if( scheme == null )
+ {
+ throw new IllegalArgumentException( "Missing " +
PROXY_SCHEME_KEY + " in properties." );
+ }
+ String prompt = Util.getProperty( properties, PROXY_PROMPT_KEY, null
);
+ if( prompt == null )
+ {
+ throw new IllegalArgumentException( "Missing " +
PROXY_PROMPT_KEY + " in properties." );
+ }
+
+ String portText = Util.getProperty( properties, PROXY_PORT_KEY, "0"
);
+ int port = Integer.parseInt( portText );
+ Properties system = System.getProperties();
+ system.put( "http.proxyHost", proxy );
+ system.put( "http.proxyPort", "" + port );
+ String excludes = Util.getProperty( properties, PROXY_EXCLUDES_KEY,
null );
+ if( null != excludes )
+ {
+ system.put( "http.nonProxyHosts", excludes );
+ }
+ RequestIdentifier id = new RequestIdentifier( proxy, port, protocol,
scheme, prompt );
+ return id;
+ }
+
+ //------------------------------------------------------------------
+ // internal static utilities
+ //------------------------------------------------------------------
+
/**
* Create the resource manager that will be responsible for the
establishment
* of the transit cache handler. The class implementating the resource
manager
@@ -337,43 +536,6 @@
ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME ) );
}

- /**
- * 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, ContentHandlerRegistry
registry, CacheHandler handler, Properties props )
- throws TransitException
- {
- this( handler, registry );
- try
- {
- setupAuthenticator( props );
- }
- catch( IOException e )
- {
- throw new TransitException( "Unable to read Transit
configuration at " + authorative, e );
- }
- }
-
- /**
- * 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
@@ -389,38 +551,6 @@
}
}

- /**
- * Return cache handler directory.
- * @return the cache handler
- */
- public CacheHandler getCacheHandler()
- {
- return m_cacheHandler;
- }
-
- public LinkManager getLinkManager()
- {
- 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
- */
- public URL getAuthorativeHost()
- {
- return m_authorativeHost;
- }
-
/**
* Resolve the authorative url. The implementation will check for a
* system property named "dpml.transit.authority.file". If the value
@@ -641,79 +771,4 @@
}
}

- /**
- * Setup the transit authenticator.
- * @param properties the transit properties
- * @exception UnknownHostException if a proxy host is declared but is
unknown
- */
- private void setupAuthenticator( Properties properties )
- throws UnknownHostException
- {
- TransitAuthenticator ta = createProxyAuthenticator( properties );
- if( ta != null )
- {
- RequestIdentifier id = createProxyRequestIdentifier( properties
);
- DelegatingAuthenticator da =
DelegatingAuthenticator.getInstance();
- da.addTransitAuthenticator( ta, id );
- }
- }
-
- /**
- * Creation of a new transit authenticator.
- * @param properties the transit properties
- * @return the transit authenticator
- */
- private TransitAuthenticator createProxyAuthenticator( Properties
properties )
- {
- String username = Util.getProperty( properties, PROXY_USERNAME_KEY,
null );
- String password = Util.getProperty( properties, PROXY_PASSWORD_KEY,
null );
- if( null == username )
- {
- return null;
- }
- return new TransitAuthenticatorImpl( username, password );
- }
-
- /**
- * Creation of a new request identifier.
- * @param properties the transit properties
- * @return the request identifier
- * @exception UnknownHostException if a proxy host is declared but is
unknown
- * @exception IllegalArgumentException if a proxy host is declared and
- * either the proxy scheme or proxy prompt property values are undefined
- */
- private RequestIdentifier createProxyRequestIdentifier( Properties
properties )
- throws UnknownHostException, IllegalArgumentException
- {
- String proxy = Util.getProperty( properties, PROXY_HOST_KEY, null );
- if( null == proxy )
- {
- return null;
- }
-
- String protocol = Util.getProperty( properties, PROXY_PROTOCOL_KEY,
"http" );
- String scheme = Util.getProperty( properties, PROXY_SCHEME_KEY, null
);
- if( scheme == null )
- {
- throw new IllegalArgumentException( "Missing " +
PROXY_SCHEME_KEY + " in properties." );
- }
- String prompt = Util.getProperty( properties, PROXY_PROMPT_KEY, null
);
- if( prompt == null )
- {
- throw new IllegalArgumentException( "Missing " +
PROXY_PROMPT_KEY + " in properties." );
- }
-
- String portText = Util.getProperty( properties, PROXY_PORT_KEY, "0"
);
- int port = Integer.parseInt( portText );
- Properties system = System.getProperties();
- system.put( "http.proxyHost", proxy );
- system.put( "http.proxyPort", "" + port );
- String excludes = Util.getProperty( properties, PROXY_EXCLUDES_KEY,
null );
- if( null != excludes )
- {
- system.put( "http.nonProxyHosts", excludes );
- }
- RequestIdentifier id = new RequestIdentifier( proxy, port, protocol,
scheme, prompt );
- return id;
- }
}

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 14:47:13 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 Stephen McConnell.
+ * Copyright 2004-2005 Stephen McConnell.
* Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -45,6 +45,10 @@
*/
public final class Transit
{
+ //------------------------------------------------------------------
+ // static
+ //------------------------------------------------------------------
+
/**
* DPML home key.
*/
@@ -76,39 +80,6 @@
public static final String SYSTEM_SYMBOL = "DPML_SYSTEM";

/**
- * Singleton transit instance.
- */
- private static Transit m_INSTANCE;
-
- /**
- * Repository established by transit.
- */
- private Repository m_repository;
-
- /**
- * Singleton repository monitor router.
- */
- private RepositoryMonitorRouter m_repositoryMonitor;
-
- /**
- * Singleton cache monitor router.
- */
- private CacheMonitorRouter m_cacheMonitor;
-
- /**
- * Singleton network monitor router.
- */
- private NetworkMonitorRouter m_networkMonitor;
-
- /**
- * PrintWriter where operations troubleshooting messages
- * can be written to.
- */
- private PrintWriter m_logWriter;
-
- private SecuredTransitContext m_context;
-
- /**
* The DPML home directory established via assesment of the the
${dpml.home}
* system property and the DPML_HOME environment variable. If neither are
* defined the behaviour is platform specific. If the os is Windows,
@@ -170,11 +141,50 @@
if( m_INSTANCE == null )
{
m_INSTANCE = new Transit();
+
+ // before returning from this method we need to give the
transit
+ // subsystems a chance to complete initialization actions
that
+ // are themselves dependent on an establish Transit instance
+
+ m_INSTANCE.getTransitContext().initialize();
}
return m_INSTANCE;
}
}

+ //------------------------------------------------------------------
+ // state
+ //------------------------------------------------------------------
+
+ /**
+ * Repository established by transit.
+ */
+ private Repository m_repository;
+
+ /**
+ * Singleton repository monitor router.
+ */
+ private RepositoryMonitorRouter m_repositoryMonitor;
+
+ /**
+ * Singleton cache monitor router.
+ */
+ private CacheMonitorRouter m_cacheMonitor;
+
+ /**
+ * Singleton network monitor router.
+ */
+ private NetworkMonitorRouter m_networkMonitor;
+
+ /**
+ * PrintWriter where operations troubleshooting messages
+ * can be written to.
+ */
+ private PrintWriter m_logWriter;
+
+ private SecuredTransitContext m_context;
+
+
SecuredTransitContext getTransitContext()
{
return m_context;
@@ -508,4 +518,13 @@
"net.dpml.transit.logging.ConfigurationHandler" ) );
}

+ //------------------------------------------------------------------
+ // static internal
+ //------------------------------------------------------------------
+
+ /**
+ * Singleton transit instance.
+ */
+ private static Transit m_INSTANCE;
+
}

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 14:47:13 2005
@@ -33,12 +33,14 @@
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
import net.dpml.transit.SecuredTransitContext;
-import net.dpml.transit.ContentHandlerRegistry;
+import net.dpml.transit.content.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.repository.StandardLoader;
+import net.dpml.transit.repository.Plugin;

/**
* Artifact URL protocol connection processor.
@@ -86,6 +88,9 @@
throws NullPointerException, IOException
{
super( url );
+
+ Transit.getInstance(); // make sure Transit is initialized
+
m_context = context;
m_reference = getReference( url );

@@ -194,12 +199,46 @@

String type = m_artifact.getType();
ContentHandlerRegistry registry =
m_context.getContentHandlerRegistry();
- ContentHandler handler = registry.getContentHandler( getURL(), type
);
+ ContentHandler handler = registry.getContentHandler( type );
if( null != handler )
{
return handler.getContent( this, classes );
}

+ //
+ // if the type is a plugin then hande this directly
+ //
+
+ if( "plugin".equals( type ) )
+ {
+ StandardLoader loader = new StandardLoader();
+ ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
+ URI uri = m_artifact.toURI();
+ if( classes.length == 0 )
+ {
+ return loader.getPlugin( classloader, uri, new Object[0] );
+ }
+ else
+ {
+ for( int i=0; i<classes.length; i++ )
+ {
+ Class c = classes[i];
+ if( ClassLoader.class.equals( c ) )
+ {
+ return loader.getPluginClassLoader( classloader, uri
);
+ }
+ else if( Class.class.equals( c ) )
+ {
+ return loader.getPluginClass( classloader, uri );
+ }
+ else if( Plugin.class.equals( c ) )
+ {
+ return loader.getPluginDescriptor( uri );
+ }
+ }
+ }
+ }
+
//
// otherwise fallback on the default jvm content handling
//

Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerDescriptor.java
(from r2485,
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerDescriptor.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerDescriptor.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerDescriptor.java
Tue May 10 14:47:13 2005
@@ -1,5 +1,6 @@
/*
- * Copyright 2004 Niclas Hedhman
+ * 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
@@ -15,142 +16,18 @@
* limitations under the License.
*/

-package net.dpml.transit;
+package net.dpml.transit.content;

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.
+ * A description of a pluggable content handler.
*/
-public class ContentHandlerDescriptor implements PreferenceChangeListener
+public interface ContentHandlerDescriptor
{
- //
------------------------------------------------------------------------
- // 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
- //
------------------------------------------------------------------------
+ public String getContentType();

- protected void dispose()
- {
- m_preferences.removePreferenceChangeListener( this );
- }
+ public String getPluginTitle();

- 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;
- }
- }
- }
+ public URI getPluginURI();
}

Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerRegistry.java
(from r2485,
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerRegistry.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/ContentHandlerRegistry.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerRegistry.java
Tue May 10 14:47:13 2005
@@ -1,5 +1,6 @@
/*
- * Copyright 2004 Niclas Hedhman
+ * 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
@@ -15,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.transit;
+package net.dpml.transit.content;

import java.io.IOException;
import java.net.URI;
@@ -33,217 +34,22 @@

import net.dpml.io.CascadingIOException;

+import net.dpml.transit.TransitException;
import net.dpml.transit.repository.StandardLoader;

/**
- * A registry of descriptions of plugable content handlers. This
implementation
- * maps user defined preferences to instance of ContentHandlerDescriptor.
+ * A interface supporting access to pluggable content handlers. An
implementation
+ * may request a Logger and Preferences node as optional constructor
arguments.
*/
-public class ContentHandlerRegistry implements NodeChangeListener
+public interface ContentHandlerRegistry
{
- //
------------------------------------------------------------------------
- // 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.
+ * Return a content handler capable for supporting the supplied type. If
+ * the a handler is available the handler is returned otherwise the
returned
+ * value is null.
*
- * @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
+ * @param the artifact type
+ * @return the content handler or null if not available
*/
- 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();
- }
- }
- }
+ ContentHandler getContentHandler( final String type ) throws IOException;
}

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerDescriptor.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerDescriptor.java
Tue May 10 14:47:13 2005
@@ -0,0 +1,157 @@
+/*
+ * 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.content;
+
+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 DefaultContentHandlerDescriptor implements
ContentHandlerDescriptor, 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 DefaultContentHandlerDescriptor( 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/content/DefaultContentHandlerRegistry.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerRegistry.java
Tue May 10 14:47:13 2005
@@ -0,0 +1,273 @@
+/*
+ * 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.content;
+
+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.TransitException;
+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 DefaultContentHandlerRegistry implements
ContentHandlerRegistry, NodeChangeListener
+{
+ //
------------------------------------------------------------------------
+ // 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(
ContentHandlerRegistry.class );
+ Preferences p = prefs.node( "part" );
+ p.put( "title", "Part Content Handler" );
+ p.put( "uri",
"artifact:plugin:dpml/tools/dpml-composition-unit#SNAPSHOT" );
+ }
+
+ //
------------------------------------------------------------------------
+ // 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 DefaultContentHandlerRegistry( 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 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 );
+ 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.
+ */
+ protected 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.
+ */
+ protected void addContentHandlerDescriptor( Preferences prefs )
+ {
+ ContentHandlerDescriptor descriptor = new
DefaultContentHandlerDescriptor( m_logger, prefs );
+ addContentHandlerDescriptor( descriptor );
+ }
+
+ /**
+ * Remove a content handler descriptor.
+ * @param prefs the preferences node
+ * @return the content handler descriptor that was removed (possibly null)
+ */
+ protected ContentHandlerDescriptor removeContentHandlerDescriptor(
Preferences prefs )
+ {
+ synchronized( m_descriptors )
+ {
+ String type = prefs.name();
+ ContentHandlerDescriptor descriptor =
getContentHandlerDescriptor( type );
+ if( descriptor != null )
+ {
+ m_descriptors.remove( type );
+ if( descriptor instanceof DefaultContentHandlerDescriptor )
+ {
+ DefaultContentHandlerDescriptor d =
(DefaultContentHandlerDescriptor) descriptor;
+ d.dispose();
+ }
+ }
+ return descriptor;
+ }
+ }
+}

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/images/misc.png
==============================================================================
Binary file. No diff available.

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/images/server.png
==============================================================================
Binary file. No diff available.

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/images/source.png
==============================================================================
Binary file. No diff available.

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 14:47:13 2005
@@ -56,8 +56,9 @@
buffer.append( lineSeparator );
if( record.getThrown() != null )
{
+ boolean trace = record.getLevel().intValue() > 900;
Throwable cause = record.getThrown();
- String error = ExceptionHelper.packException( cause, true );
+ String error = ExceptionHelper.packException( cause, trace );
buffer.append( error );
}
return buffer.toString();

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ContentHandlerControllerPanel.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ContentHandlerControllerPanel.java
Tue May 10 14:47:13 2005
@@ -0,0 +1,425 @@
+/*
+ * 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.transit.prefs;
+
+import java.io.IOException;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.FlowLayout;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Insets;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+
+import javax.swing.Action;
+import javax.swing.AbstractAction;
+import javax.swing.BoxLayout;
+import javax.swing.JDialog;
+import javax.swing.JTable;
+import javax.swing.JScrollPane;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import javax.swing.JOptionPane;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.JFileChooser;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.content.ContentHandlerRegistry;
+import net.dpml.transit.repository.Plugin;
+
+
+/**
+ * Control panel for editing the cache preferences.
+ *
+ * @author <a href="mailto:mcconnell AT osm.net";>OSM</a>
+ */
+public class ContentHandlerControllerPanel extends JPanel implements
PreferenceChangeListener, PropertyChangeListener, DocumentListener
+{
+ //--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ static EmptyBorder border5 = new EmptyBorder( 5, 5, 5, 5);
+
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final JDialog m_parent;
+ private JTextField m_base;
+ private JButton m_ok;
+ private JButton m_revert;
+ private JButton m_settings;
+
+ private Preferences m_preferences;
+
+ private PropertyChangeSupport m_propertyChangeSupport;
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ public ContentHandlerControllerPanel( JDialog parent ) throws Exception
+ {
+ m_parent = parent;
+ m_propertyChangeSupport = new PropertyChangeSupport( this );
+
+ m_preferences = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
+
+ setLayout( new BorderLayout() );
+ setBackground( Color.white );
+
+ m_ok = new JButton( new OKAction( "OK" ) );
+ m_revert = new JButton( new RevertAction( "Undo" ) );
+ m_preferences.addPreferenceChangeListener( this );
+
+ // create a label containing an icon and label
+
+ {
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ Transit.class.getClassLoader(),
"net/dpml/transit/images/source.png", "URI", "Controller URI" );
+ label.setBorder( new EmptyBorder( 0, 5, 0, 0 ) );
+ JPanel panel = new JPanel();
+ panel.setLayout( new BorderLayout() );
+ panel.setBackground( Color.white );
+ panel.add( label, BorderLayout.WEST );
+ add( panel, BorderLayout.NORTH );
+ }
+
+ // add a test field containing the content handler artifact uri
+
+ {
+ JPanel holder = new JPanel();
+ holder.setBackground( Color.white );
+ holder.setLayout( new BorderLayout() );
+
+ JPanel panel = new JPanel();
+ panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ) );
+ panel.setBackground( Color.white );
+ panel.setBorder( new EmptyBorder( 10, 10, 10, 10 ) );
+ {
+ JPanel padding = new JPanel();
+ padding.setBackground( Color.white );
+ padding.setLayout( new BorderLayout() );
+ padding.setBorder( new EmptyBorder( 10, 2, 5, 2) );
+ String artifact = getControllerFieldTextFromPreferences();
+ m_base = new JTextField( artifact );
+ m_base.getDocument().addDocumentListener( this ); // listen
for changes
+ m_base.setBackground( Color.white );
+ padding.add( m_base );
+ panel.add( padding );
+ }
+ {
+ JPanel settingsPanel = new JPanel();
+ settingsPanel.setBorder(
+ new CompoundBorder(
+ new TitledBorder(
+ null, "Controller Settings", TitledBorder.LEFT,
TitledBorder.TOP),
+ new EmptyBorder( 5, 5, 5, 10)
+ )
+ );
+ settingsPanel.setBackground( Color.white );
+ settingsPanel.setLayout( new BorderLayout() );
+ m_settings = new JButton( new SettingsAction( "Controller
Settings" ) );
+ settingsPanel.add( m_settings, BorderLayout.EAST );
+ panel.add( settingsPanel );
+ }
+ holder.add( panel, BorderLayout.NORTH );
+ add( holder, BorderLayout.CENTER );
+ }
+
+ // add controls for modification of the registry controller
+
+ {
+ JPanel panel = new JPanel();
+ panel.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
+ panel.add( m_revert );
+ panel.add( m_ok );
+ panel.add( new JButton( new CloseAction( "Cancel" ) ) );
+ panel.setBorder( new EmptyBorder( 10, 10, 5, 0 ) );
+ panel.setBackground( Color.white );
+ add( panel, BorderLayout.SOUTH );
+ }
+
+ m_propertyChangeSupport.addPropertyChangeListener( this );
+ }
+
+ //--------------------------------------------------------------
+ // DocumentListener
+ //--------------------------------------------------------------
+
+ public void insertUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ public void removeUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ public void changedUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ private void fireBaseChangedEvent()
+ {
+ String artifact = getControllerFieldTextFromPreferences();
+ PropertyChangeEvent e =
+ new PropertyChangeEvent(
+ m_base, "base", artifact, m_base.getText() );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+
+ //--------------------------------------------------------------
+ // PropertyChangeListener
+ //--------------------------------------------------------------
+
+ /**
+ * The actions dealing with changes to the dialog raise change events
that
+ * are captured here. This listener checks changes and enables or
disabled
+ * the ok and undo buttons based on the state of controls relative to the
+ * underlying preferences for the cache.
+ */
+ public void propertyChange( PropertyChangeEvent event )
+ {
+ String artifact = getControllerFieldTextFromPreferences();
+ boolean flag = ( false == artifact.equals( m_base.getText() ) );
+ m_ok.setEnabled( flag );
+ m_revert.setEnabled( flag );
+ }
+
+ private String getControllerFieldTextFromPreferences()
+ {
+ return m_preferences.get( "uri", "artifact:plugin:" );
+ }
+
+ private String getControllerPathFromPreferences()
+ {
+ return m_preferences.get( "uri", null );
+ }
+
+ public void preferenceChange( PreferenceChangeEvent event )
+ {
+ String artifact = getControllerFieldTextFromPreferences();
+ m_base.setText( artifact );
+ }
+
+ private class CloseAction extends AbstractAction
+ {
+ CloseAction( String name )
+ {
+ super( name );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ m_parent.hide();
+ }
+ }
+
+ private class SettingsAction extends AbstractAction
+ {
+ SettingsAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+
+ }
+ }
+
+ private class RevertAction extends AbstractAction
+ {
+ RevertAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ String artifact = getControllerFieldTextFromPreferences();
+ String old = m_base.getText();
+ m_base.setText( artifact );
+ PropertyChangeEvent e =
+ new PropertyChangeEvent( this, "uri", old, artifact );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+ }
+
+ private class OKAction extends AbstractAction
+ {
+ OKAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ String text = m_base.getText();
+ String artifact = getControllerFieldTextFromPreferences();
+ if( false == text.equals( artifact ) )
+ {
+ if( "".equals( text ) )
+ {
+ m_preferences.remove( "uri" );
+ m_parent.hide();
+ }
+ else
+ {
+ boolean validated = validateControllerSpec( m_parent,
text );
+ if( validated )
+ {
+ m_parent.hide();
+ m_preferences.put( "uri", text );
+ }
+ }
+ }
+ }
+ }
+
+ private boolean validateControllerSpec( Component component, String spec
)
+ {
+ URI uri = createControllerURI( component, spec );
+ if( null == uri )
+ {
+ return false;
+ }
+ URL url = getURLFromURI( component, uri );
+ if( null == url )
+ {
+ return false;
+ }
+ Plugin plugin = getPluginFromURL( component, url );
+ if( null == plugin )
+ {
+ return false;
+ }
+ String classname = plugin.getClassname();
+ return checkPluginClass( component, url );
+ }
+
+ private URI createControllerURI( Component component, String spec )
+ {
+ try
+ {
+ return new URI( spec );
+ }
+ catch( URISyntaxException e )
+ {
+ final String title = "Controller URI Error";
+ final String message = "Invalid uri.";
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return null;
+ }
+ }
+
+ private URL getURLFromURI( Component component, URI uri )
+ {
+ try
+ {
+ String spec = uri.toString();
+ return new URL( spec );
+ }
+ catch( IOException e )
+ {
+ final String title = "Controller URI Error";
+ final String message = "Cannot convert the uri to a url.";
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return null;
+ }
+ }
+
+ private Plugin getPluginFromURL( Component component, URL url )
+ {
+ try
+ {
+ return (Plugin) url.getContent( new Class[]{ Plugin.class } );
+ }
+ catch( Throwable e )
+ {
+ final String title = "Controller URI Error";
+ final String message = e.getMessage();
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return null;
+ }
+ }
+
+ private boolean checkPluginClass( Component component, URL url )
+ {
+ Class c = null;
+ try
+ {
+ c = (Class) url.getContent( new Class[]{ Class.class } );
+ }
+ catch( Throwable e )
+ {
+ final String title = "Controller URI Error";
+ final String message = e.getMessage();
+ e.printStackTrace();
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return false;
+ }
+ if( ContentHandlerRegistry.class.isAssignableFrom( c ) )
+ {
+ return true;
+ }
+ else
+ {
+ final String title = "Controller URI Error";
+ final String message = "Plugin class does not implement " +
ContentHandlerRegistry.class.getName() + ".";
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return false;
+ }
+ }
+}

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ContentHandlerPanel.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ContentHandlerPanel.java
Tue May 10 14:47:13 2005
@@ -0,0 +1,404 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.transit.prefs;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.FlowLayout;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Insets;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+
+import javax.swing.Action;
+import javax.swing.AbstractAction;
+import javax.swing.BoxLayout;
+import javax.swing.JDialog;
+import javax.swing.JTable;
+import javax.swing.JScrollPane;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.ListSelectionModel;
+import javax.swing.JOptionPane;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.cache.CacheHandler;
+import net.dpml.transit.host.ResourceHost;
+import net.dpml.transit.util.Util;
+import net.dpml.transit.content.ContentHandlerRegistry;
+
+/**
+ * Runnable plugin that handles DPML environment setup.
+ *
+ * @author <a href="mailto:mcconnell AT osm.net";>OSM</a>
+ */
+public class ContentHandlerPanel extends JPanel implements
ListSelectionListener
+{
+ //--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ static EmptyBorder border5 = new EmptyBorder( 5, 5, 5, 5);
+
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final JDialog m_parent;
+
+ private GenericTable m_table;
+
+ private JButton m_edit;
+ private JButton m_delete;
+
+ private String m_selection; // selected hostname
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ public ContentHandlerPanel( JDialog parent ) throws Exception
+ {
+ m_parent = parent;
+
+ m_edit = new JButton( new EditAction( "Edit" ) );
+ m_delete = new JButton( new DeleteAction( "Delete" ) );
+
+ setLayout( new BorderLayout() );
+ setBorder( new EmptyBorder( 10, 6, 10, 6 ) );
+ setBackground( Color.white );
+
+ JPanel contentHandlerPanel = new JPanel();
+ contentHandlerPanel.setBackground( Color.white );
+
+ contentHandlerPanel.setLayout( new BorderLayout() );
+ TitledBorder tb =
+ new TitledBorder(
+ new EmptyBorder( 0,0,0,0 ), "Content Handlers",
TitledBorder.LEFT, TitledBorder.TOP );
+ contentHandlerPanel.setBorder( new CompoundBorder( tb, border5 ) );
+
+ Preferences prefs = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
+ TableColumnModel columns = createContentHandlerColumnModel();
+ NodeTableModel model = new NodeTableModel( prefs );
+ m_table = new GenericTable( model, columns );
+ m_table.setShowVerticalLines( false );
+ m_table.setShowHorizontalLines( false );
+ m_table.getSelectionModel().addListSelectionListener( this );
+
+ JScrollPane scroller = createScrollPanel( m_table );
+ contentHandlerPanel.add( scroller, BorderLayout.CENTER );
+ JPanel buttonHolder = new JPanel();
+ buttonHolder.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
+ buttonHolder.add( new JButton( new AddAction( "Add" ) ) );
+ buttonHolder.add( m_edit );
+ buttonHolder.add( m_delete );
+ buttonHolder.setBorder( new EmptyBorder( 10, 10, 5, 0 ) );
+ buttonHolder.setBackground( Color.white );
+ contentHandlerPanel.add( buttonHolder, BorderLayout.SOUTH );
+
+ JPanel controllerPanel = createContentHandlerControllerPanel( parent
);
+
+ add( controllerPanel, BorderLayout.NORTH );
+ add( contentHandlerPanel, BorderLayout.CENTER );
+ }
+
+ //--------------------------------------------------------------
+ // utilities
+ //--------------------------------------------------------------
+
+ private JPanel createContentHandlerControllerPanel( JDialog parent )
+ {
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ ResourcePanel.class.getClassLoader(),
+ "net/dpml/transit/images/misc.png",
+ "Artifact",
+ "Content Handler Controller settings." );
+ label.setBorder( new EmptyBorder( 0, 5, 0, 0 ) );
+
+ JPanel holder = new JPanel();
+ holder.setLayout( new BoxLayout( holder, BoxLayout.Y_AXIS ) );
+ holder.setBorder( new EmptyBorder( 0, 6, 0, 6 ) );
+ holder.setBackground( Color.white );
+ JPanel cache = new JPanel();
+ cache.setBackground( Color.white );
+ cache.setLayout( new BorderLayout() );
+ cache.add( label, BorderLayout.WEST );
+ cache.setBorder(
+ new CompoundBorder(
+ new TitledBorder( null, "Cache", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
+ JButton button = new JButton( new ControllerAction( parent,
"Controller" ) );
+ JPanel cacheButtonHolder = new JPanel();
+ cacheButtonHolder.setBackground( Color.white );
+ cacheButtonHolder.setLayout( new BorderLayout() );
+ cacheButtonHolder.add( button, BorderLayout.SOUTH );
+ cache.add( cacheButtonHolder, BorderLayout.EAST );
+ holder.add( cache );
+ return holder;
+ }
+
+ private static class ControllerAction extends AbstractAction
+ {
+ JDialog m_parent;
+
+ ControllerAction( JDialog parent, String name )
+ {
+ super( name );
+ m_parent = parent;
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Content Handler Controller" );
+ Dimension size = new Dimension( 400, 240 );
+
+ JPanel frame = new JPanel();
+ frame.setLayout( new BorderLayout() );
+ frame.setBackground( Color.white );
+ frame.setBorder( new EmptyBorder( 10, 6, 0, 6 ) );
+
+ JPanel panel = new ContentHandlerControllerPanel( dialog );
+ frame.add( panel, BorderLayout.CENTER );
+ dialog.setContentPane( frame );
+ dialog.setSize( size );
+ dialog.setLocationRelativeTo( (Component) event.getSource()
);
+ dialog.setResizable( true );
+ dialog.setVisible(true);
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to handle the
'Controller' action. "
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.err.println( message );
+ }
+ }
+
+ private static class CloseAction extends AbstractAction
+ {
+ private JDialog m_dialog;
+
+ CloseAction( String name, JDialog dialog )
+ {
+ super( name );
+ m_dialog = dialog;
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ m_dialog.hide();
+ }
+ }
+ }
+
+ /**
+ * Creation of a parameterized scroll pane.
+ * @param view the viewport view
+ * @return the scroll pane wrapping the supplied view
+ */
+ private static JScrollPane createScrollPanel( Component view )
+ {
+ JScrollPane scroller = new JScrollPane();
+ scroller.setVerticalScrollBarPolicy(
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
+ scroller.setHorizontalScrollBarPolicy(
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
+ scroller.getViewport().setBackground( Color.white );
+ scroller.setViewportView( view );
+ return scroller;
+ }
+
+ /**
+ * Utility method to construct the hosts table column model.
+ * @return the table
+ */
+ private static TableColumnModel createContentHandlerColumnModel()
+ {
+ TableColumn iconColumn = new TableColumn( 0, 30, new
DefaultCellRenderer(), null );
+ iconColumn.setHeaderValue( "" );
+ iconColumn.setMaxWidth( 30 );
+ iconColumn.setMinWidth( 30 );
+ TableColumn typeColumn = new TableColumn( 1, 100, new
DefaultCellRenderer(), null );
+ typeColumn.setHeaderValue( "Type" );
+ TableColumnModel model = new DefaultTableColumnModel();
+ model.addColumn( iconColumn );
+ model.addColumn( typeColumn );
+ return model;
+ }
+
+ private class AddAction extends AbstractAction
+ {
+ public AddAction( String name )
+ {
+ super( name );
+ setEnabled( true );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ String name = JOptionPane.showInputDialog( m_parent, "Content
Handler Name:" );
+ if( null == name )
+ {
+ return;
+ }
+
+ /*
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Resource Host: " + name );
+ JPanel panel = new HostPanel( dialog, name );
+ dialog.setContentPane( panel );
+ Dimension size = new Dimension( 400, 360 );
+ dialog.setSize( size );
+ dialog.setLocationRelativeTo( (Component) event.getSource()
);
+ dialog.setResizable( true );
+ dialog.setVisible( true );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to construct host
dialog."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ */
+ }
+ }
+
+ private class EditAction extends AbstractAction
+ {
+ public EditAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ /*
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Resource Host: " + m_selection );
+ JPanel panel = new HostPanel( dialog, m_selection );
+ dialog.setContentPane( panel );
+ Dimension size = new Dimension( 400, 360 );
+ dialog.setSize( size );
+ dialog.setLocationRelativeTo( (Component) event.getSource()
);
+ dialog.setResizable( true );
+ dialog.setVisible( true );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to construct host
dialog."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ */
+ }
+ }
+
+ private class DeleteAction extends AbstractAction
+ {
+ public DeleteAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ if( null == m_selection )
+ {
+ return;
+ }
+ /*
+ Preferences hosts = Preferences.userNodeForPackage(
ResourceHost.class );
+ Preferences target = hosts.node( m_selection );
+ try
+ {
+ target.removeNode();
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to delete a host
preferences node."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ */
+ }
+ }
+
+ public void valueChanged( ListSelectionEvent event )
+ {
+ if( !event.getValueIsAdjusting() )
+ {
+ ListSelectionModel model = m_table.getSelectionModel();
+ synchronized( model )
+ {
+ int n = model.getMinSelectionIndex();
+ if( ( n == model.getMaxSelectionIndex() ) && ( n > -1 ) )
+ {
+ m_selection = (String) m_table.getValueAt( n, 1 );
+ m_edit.setEnabled( true );
+ m_delete.setEnabled( true );
+ }
+ else
+ {
+ m_selection = null;
+ m_edit.setEnabled( false );
+ m_delete.setEnabled( false );
+ }
+ }
+ }
+ }
+}

Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/GenericTable.java
(from r2485,
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostsTable.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostsTable.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/GenericTable.java
Tue May 10 14:47:13 2005
@@ -34,7 +34,7 @@
/**
* A table mapping the collection of preference nodes to hosts.
*/
-public class HostsTable extends JTable implements ListSelectionListener,
FocusListener
+public class GenericTable extends JTable implements ListSelectionListener,
FocusListener
{

//--------------------------------------------------------------------------
// static
@@ -84,7 +84,7 @@
* @param data a table model containing the data to layout in view
* @param columns the table column model to apply
*/
- public HostsTable( TableModel data, TableColumnModel columns )
+ public GenericTable( TableModel data, TableColumnModel columns )
{
super( data, columns );


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostPanel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostPanel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostPanel.java
Tue May 10 14:47:13 2005
@@ -130,7 +130,7 @@

m_label =
IconHelper.createImageIconJLabel(
- Transit.class.getClassLoader(),
"net/dpml/transit/images/network.png", "Host", "Host: " + name );
+ Transit.class.getClassLoader(),
"net/dpml/transit/images/server.png", "Host", "Host: " + name );

m_label.setBorder( new EmptyBorder( 0, 5, 0, 10 ) );
JPanel labelPanel = new JPanel();

Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/NodeTableModel.java
(from r2485,
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostsTableModel.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/HostsTableModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/NodeTableModel.java
Tue May 10 14:47:13 2005
@@ -38,7 +38,7 @@
/**
* Table model used to manage features of an adapter.
*/
-class HostsTableModel extends AbstractTableModel implements
NodeChangeListener
+class NodeTableModel extends AbstractTableModel implements NodeChangeListener
{

//--------------------------------------------------------------------------
// static
@@ -70,6 +70,8 @@
private static final Icon FEATURE_ICON =
IconHelper.createImageIcon( Transit.class.getClassLoader(), ICON_PATH,
"Features" );

+ private final Preferences m_preferences;
+

//--------------------------------------------------------------------------
// constructor

//--------------------------------------------------------------------------
@@ -78,9 +80,10 @@
* Creation of a new feature table model.
* @param entity the reference entity
*/
- public HostsTableModel( Preferences prefs )
+ public NodeTableModel( Preferences prefs )
{
super();
+ m_preferences = prefs;
prefs.addNodeChangeListener( this );
}

@@ -104,7 +107,7 @@
}


//--------------------------------------------------------------------------
- // HostsTableModel
+ // NodeTableModel

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

/**
@@ -125,7 +128,7 @@
{
try
{
- return getHostPreferences().childrenNames().length;
+ return getPreferences().childrenNames().length;
}
catch( Throwable e )
{
@@ -162,7 +165,7 @@
{
try
{
- String[] names = getHostPreferences().childrenNames();
+ String[] names = getPreferences().childrenNames();
return names[ row ];
}
catch( Throwable e )
@@ -171,8 +174,8 @@
}
}

- Preferences getHostPreferences()
+ Preferences getPreferences()
{
- return Preferences.userNodeForPackage( ResourceHost.class );
+ return m_preferences;
}
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ResourcePanel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ResourcePanel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/ResourcePanel.java
Tue May 10 14:47:13 2005
@@ -82,7 +82,7 @@

private final JDialog m_parent;

- private HostsTable m_table;
+ private GenericTable m_table;

private JButton m_edit;
private JButton m_delete;
@@ -115,8 +115,8 @@

Preferences hosts = Preferences.userNodeForPackage(
ResourceHost.class );
TableColumnModel columns = createHostsColumnModel();
- HostsTableModel model = new HostsTableModel( hosts );
- m_table = new HostsTable( model, columns );
+ NodeTableModel model = new NodeTableModel( hosts );
+ m_table = new GenericTable( model, columns );
m_table.setShowVerticalLines( false );
m_table.setShowHorizontalLines( false );
m_table.getSelectionModel().addListSelectionListener( this );

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/TransitDialog.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/TransitDialog.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/prefs/TransitDialog.java
Tue May 10 14:47:13 2005
@@ -123,8 +123,9 @@
JPanel panel = new JPanel();

ResourcePanel transitPanel = new ResourcePanel( this );
- JPanel transitTab = createNamedPanel( "Transit Preferences" ,
transitPanel );
+ ContentHandlerPanel contentPanel = new ContentHandlerPanel( this );
tabbedPane.addTab( "Resources", transitPanel );
+ tabbedPane.addTab( "Content", contentPanel );
tabbedPane.addTab( "Logging", new JPanel() );
tabbedPane.addTab( "Properties", new JPanel() );


Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
Tue May 10 14:47:13 2005
@@ -38,6 +38,7 @@
protected void setUp() throws Exception
{
System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.logging.ConfigurationHandler" );
System.setProperty( "dpml.transit.secured.disable", "true" );
System.setProperty( "dpml.transit.authority.file",
"target/test/test.authority" );
String test = System.getProperty( "project.dir" );

Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/test/OfflineTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/test/OfflineTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/test/OfflineTestCase.java
Tue May 10 14:47:13 2005
@@ -42,6 +42,7 @@
throws Exception
{
System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.logging.ConfigurationHandler" );
System.setProperty( "dpml.transit.secured.disable", "true" );
System.setProperty( "dpml.transit.authority.file",
"target/test/test.authority" );
String test = System.getProperty( "project.dir" );

Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/test/OnlineTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/test/OnlineTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/test/OnlineTestCase.java
Tue May 10 14:47:13 2005
@@ -39,6 +39,7 @@
protected void setUp() throws Exception
{
System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.logging.ConfigurationHandler" );
}

public void testStackedJarUrl() throws Exception



  • svn commit: r2495 - in development/main/transit/core/handler/src: main/net/dpml/transit main/net/dpml/transit/artifact main/net/dpml/transit/content main/net/dpml/transit/images main/net/dpml/transit/logging main/net/dpml/transit/prefs test/net/dpml/transit/test, mcconnell, 05/10/2005

Archive powered by MHonArc 2.6.24.

Top of Page