Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2691 - in development/main/transit/core/handler/src/main/net/dpml/transit: content layout

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: r2691 - in development/main/transit/core/handler/src/main/net/dpml/transit: content layout
  • Date: Thu, 02 Jun 2005 00:14:55 -0400

Author: mcconnell AT dpml.net
Date: Thu Jun 2 00:14:53 2005
New Revision: 2691

Modified:

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

development/main/transit/core/handler/src/main/net/dpml/transit/layout/DefaultLayoutRegistry.java
Log:
Work-in-progress on content handler management.

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentRegistry.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentRegistry.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentRegistry.java
Thu Jun 2 00:14:53 2005
@@ -52,8 +52,12 @@

private final Logger m_logger;

+ private final Map m_plugins = new WeakHashMap();
+
private final Map m_links = new WeakHashMap();

+ private final Map m_handlers = new Hashtable();
+
private final RegistryModel m_model;

//
------------------------------------------------------------------------
@@ -99,7 +103,22 @@
*/
public void contentAdded( RegistryEvent event )
{
- // TODO: load and validate
+ synchronized( m_handlers )
+ {
+ ContentModel model = event.getContentModel();
+ try
+ {
+ getContentHandler( model ); // setup cached reference
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Internal error while attempting to add a content
handler."
+ + "\nContent Type: " + model.getContentType()
+ + "\nPlugin URI: " + model.getPluginURI();
+ m_logger.warn( error, e );
+ }
+ }
}

/**
@@ -108,9 +127,22 @@
*/
public void contentRemoved( RegistryEvent event )
{
- ContentModel model = event.getContentModel();
- URI uri = model.getPluginURI();
- m_links.remove( uri );
+ synchronized( m_handlers )
+ {
+ ContentModel model = event.getContentModel();
+ try
+ {
+ m_handlers.remove( model );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Internal error while attempting to remove a content
handler."
+ + "\nContent Type: " + model.getContentType()
+ + "\nPlugin URI: " + model.getPluginURI();
+ m_logger.warn( error, e );
+ }
+ }
}

//
------------------------------------------------------------------------
@@ -119,35 +151,36 @@

protected ContentHandler getContentHandler( ContentModel model ) throws
IOException
{
- String type = model.getContentType();
- URI uri = model.getPluginURI();
- ContentHandler handler = (ContentHandler) m_links.get( uri );
- if( null != handler )
+ synchronized( m_handlers )
{
+ ContentHandler handler = (ContentHandler) m_handlers.get( model
);
+ if( null == handler )
+ {
+ Class clazz = loadContentHandlerClass( model );
+ Repository loader = Transit.getInstance().getRepository();
+ handler = (ContentHandler) loader.instantiate( clazz, new
Object[]{ model } );
+ m_handlers.put( model, handler );
+ }
return handler;
}
+ }
+
+ protected Class loadContentHandlerClass( ContentModel model ) throws
IOException
+ {
+ URI uri = model.getPluginURI();
+ Class clazz = (Class) m_plugins.get( uri );
+ if( null != clazz )
+ {
+ return clazz;
+ }
else
{
try
{
- m_logger.debug( "loading content handler for: " + type );
+ m_logger.debug( "loading content handler plugin: " + uri );
Repository loader = Transit.getInstance().getRepository();
ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
- Object plugin = loader.getPlugin( classloader, uri, new
Object[]{ model } );
- 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 );
- }
+ clazz = loader.getPluginClass( classloader, uri );
}
catch( Exception e )
{
@@ -155,6 +188,20 @@
"Unable to load a content handler plugin due to an
unexpected exception.";
throw new TransitException( error, e );
}
+
+ if( ContentHandler.class.isAssignableFrom( clazz ) )
+ {
+ m_plugins.put( uri, clazz );
+ return clazz;
+ }
+ else
+ {
+ final String error =
+ "Plugin is not assignable to a java.net.ContentHandler."
+ + "\nPlugin URI: " + uri
+ + "\nPlugin Class: " + clazz.getName();
+ throw new TransitException( error );
+ }
}
}
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/layout/DefaultLayoutRegistry.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/layout/DefaultLayoutRegistry.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/layout/DefaultLayoutRegistry.java
Thu Jun 2 00:14:53 2005
@@ -150,7 +150,7 @@
catch( Exception e )
{
final String error =
- "Unable to load a content handler plugin due to an
unexpected exception.";
+ "Unable to load a layout plugin due to an unexpected
exception.";
throw new TransitException( error, e );
}




  • svn commit: r2691 - in development/main/transit/core/handler/src/main/net/dpml/transit: content layout, mcconnell, 06/01/2005

Archive powered by MHonArc 2.6.24.

Top of Page