Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2636 - in development/main/transit/core/handler: . src/main/net/dpml/transit/manager src/main/net/dpml/transit/model src/test/net/dpml/transit/manager

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: r2636 - in development/main/transit/core/handler: . src/main/net/dpml/transit/manager src/main/net/dpml/transit/model src/test/net/dpml/transit/manager
  • Date: Fri, 20 May 2005 19:22:07 +0000

Author: mcconnell AT dpml.net
Date: Fri May 20 19:22:04 2005
New Revision: 2636

Added:

development/main/transit/core/handler/src/main/net/dpml/transit/manager/ContentManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/ModelException.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/package.html
Removed:

development/main/transit/core/handler/src/test/net/dpml/transit/manager/RepositoryManagerTestCase.java
Modified:
development/main/transit/core/handler/build.xml

development/main/transit/core/handler/src/main/net/dpml/transit/manager/AbstractPluginManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/HostManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/RepositoryManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/CacheModel.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/HostModel.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/PluginChangeEvent.java

development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
Log:
Add manager implementation.

Modified: development/main/transit/core/handler/build.xml
==============================================================================
--- development/main/transit/core/handler/build.xml (original)
+++ development/main/transit/core/handler/build.xml Fri May 20 19:22:04
2005
@@ -25,19 +25,7 @@
<import file="${home}/standard.xml"/>

<target name="patch">
- <replace token="CacheDirector" value="CacheModel" dir=".">
- <include name="**/*.java"/>
- </replace>
- <replace token="HostDirector" value="HostModel" dir=".">
- <include name="**/*.java"/>
- </replace>
- <replace token="ContentDirector" value="ContentModel" dir=".">
- <include name="**/*.java"/>
- </replace>
- <replace token="RegistryDirector" value="RegistryModel" dir=".">
- <include name="**/*.java"/>
- </replace>
- <replace token="PluginDirector" value="PluginModel" dir=".">
+ <replace token="Modely" value="Directory" dir=".">
<include name="**/*.java"/>
</replace>
</target>

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/AbstractPluginManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/AbstractPluginManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/AbstractPluginManager.java
Fri May 20 19:22:04 2005
@@ -22,6 +22,10 @@
import java.util.EventListener;
import java.util.logging.Logger;
import java.util.logging.Level;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;

import net.dpml.transit.event.EventProducer;
import net.dpml.transit.model.PluginModel;
@@ -34,37 +38,108 @@
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
* @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
*/
-abstract class AbstractPluginManager extends EventProducer implements
PluginModel
+abstract class AbstractPluginManager extends EventProducer implements
PluginModel, PreferenceChangeListener
{
- private final Logger m_logger;
+ private final Preferences m_preferences;

private URI m_uri;
+ private Logger m_logger;

- public AbstractPluginManager( Logger logger, URI uri )
+ public AbstractPluginManager( Logger logger, Preferences prefs )
{
if( null == logger )
{
throw new NullPointerException( "logger" );
}
+ if( null == prefs )
+ {
+ throw new NullPointerException( "prefs" );
+ }
m_logger = logger;
- m_uri = uri;
+ m_preferences = prefs;
+ prefs.addPreferenceChangeListener( this );
+ try
+ {
+ m_uri = getPluginURI( prefs );
+ }
+ catch( IllegalArgumentException e )
+ {
+ m_uri = null;
+ final String message =
+ "Setting plugin uri to a null value.";
+ m_logger.log( Level.SEVERE, message, e );
+ }
}

- protected Logger getLogger()
+ //
------------------------------------------------------------------------
+ // PluginModel
+ //
------------------------------------------------------------------------
+
+ /**
+ * Return the plugin uri.
+ * @return the plugin uri
+ */
+ public URI getPluginURI()
{
- return m_logger;
+ synchronized( m_lock )
+ {
+ return m_uri;
+ }
+ }
+
+ /**
+ * Add a plugin listener to the director.
+ * @param listener the listener to add
+ */
+ public void addPluginListener( PluginListener listener )
+ {
+ super.addListener( listener );
+ }
+
+ /**
+ * Remove a plugin listener from the director.
+ * @param listener the listener to remove
+ */
+ public void removePluginListener( PluginListener listener )
+ {
+ super.removeListener( listener );
}

- public void notifyChange( PluginChangeEvent event )
+ //
------------------------------------------------------------------------
+ // PreferencesChangeListener (listens to changes to the uri attribute)
+ //
------------------------------------------------------------------------
+
+ public void preferenceChange( PreferenceChangeEvent event )
{
- synchronized( m_lock )
+ String key = event.getKey();
+ String value = event.getNewValue();
+ Preferences prefs = event.getNode();
+ if( "uri".equals( key ) )
{
- m_uri = event.getPluginURI();
- super.enqueueEvent( event );
+ synchronized( m_lock )
+ {
+ m_uri = getPluginURI( prefs );
+ PluginChangeEvent e = new PluginChangeEvent( this, m_uri );
+ super.enqueueEvent( e );
+ }
}
}

- public void processPluginChangeEvent( PluginChangeEvent event )
+ //
------------------------------------------------------------------------
+ // internals
+ //
------------------------------------------------------------------------
+
+ protected Logger getLogger()
+ {
+ return m_logger;
+ }
+
+ protected Preferences getPreferences()
+ {
+ return m_preferences;
+ }
+
+ protected void processPluginChangeEvent( PluginChangeEvent event )
{
EventListener[] listeners = super.listeners();
for( int i=0; i<listeners.length; i++ )
@@ -87,34 +162,51 @@
}
}

- /**
- * Return the plugin uri.
- * @return the plugin uri
- */
- public URI getPluginURI()
+ public void finalize()
{
- synchronized( m_lock )
+ if( null != m_preferences )
{
- return m_uri;
+ try
+ {
+ m_preferences.removePreferenceChangeListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
}
}

- /**
- * Add a plugin listener to the director.
- * @param listener the listener to add
- */
- public void addPluginListener( PluginListener listener )
+ protected static Logger getLogger( Logger logger, String name )
{
- super.addListener( listener );
+ String base = logger.getName();
+ String category = base = "." + name;
+ return Logger.getLogger( category );
}

- /**
- * Remove a plugin listener from the director.
- * @param listener the listener to remove
- */
- public void removePluginListener( PluginListener listener )
+ private static URI getPluginURI( Preferences prefs ) throws
IllegalArgumentException
{
- super.addListener( listener );
+ String path = prefs.get( "uri", null );
+ try
+ {
+ if( null == path )
+ {
+ return null;
+ }
+ else
+ {
+ return new URI( path );
+ }
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Internal error while attempting to construct a plugin uri."
+ + "\nPreferences: " + prefs
+ + "\nURI Specification: " + path;
+ throw new IllegalArgumentException( error );
+ }
}
+
}


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
Fri May 20 19:22:04 2005
@@ -26,55 +26,131 @@
import java.util.EventListener;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.NodeChangeListener;
import java.net.URI;

import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.HostModel;
import net.dpml.transit.model.PluginChangeEvent;
+import net.dpml.transit.model.PluginListener;
import net.dpml.transit.model.CacheListener;
import net.dpml.transit.model.FileChangeEvent;
import net.dpml.transit.model.HostEvent;
+import net.dpml.transit.model.ModelException;
+
+import net.dpml.transit.util.PropertyResolver;

/**
- * Default implementation of the cache director.
+ * Default implementation of the cache model.
*
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
* @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
*/
-public class CacheManager extends AbstractPluginManager implements CacheModel
+public class CacheManager extends AbstractPluginManager
+ implements CacheModel, NodeChangeListener , PluginListener
{
private final List m_list = new LinkedList();
private File m_cache;

- public CacheManager( Logger logger, File cache, HostModel boot )
+ public CacheManager( Logger logger, Preferences prefs ) throws
ModelException
{
- super( logger, null );
- m_cache = cache;
- m_list.add( boot );
- }
+ super( logger, prefs );

- public void setCacheModel( File dir )
- {
- synchronized( m_lock )
+ //
+ // setup the cache
+ //
+
+ File cache = resolveCacheDirectory( prefs );
+ setLocalCacheDirectory( cache );
+
+ //
+ // construct the hosts
+ //
+
+ Preferences hostsNode = prefs.node( "hosts" );
+ hostsNode.addNodeChangeListener( this );
+ try
{
- m_cache = dir;
- CacheModelyChangeEvent event = new CacheModelyChangeEvent( this,
dir );
- super.enqueueEvent( event );
+ String[] names = hostsNode.childrenNames();
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ Preferences p = hostsNode.node( name );
+ addHostModel( p, false );
+ }
}
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected exception while reading host preferences."
+ + "\nPreferences: " + prefs;
+ throw new ModelException( error, e );
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // PluginListener (listens to changes to plugin uris)
+ //
------------------------------------------------------------------------
+
+ public void pluginChanged( PluginChangeEvent event )
+ {
+ getLogger().info( "plugin changed: " + event.getPluginURI() );
}

- public void setPluginURI( URI uri )
+ //
------------------------------------------------------------------------
+ // PreferencesChangeListener (listens to cache prefs)
+ //
------------------------------------------------------------------------
+
+ public void preferenceChange( PreferenceChangeEvent event )
{
- synchronized( m_lock )
+ super.preferenceChange( event );
+
+ String key = event.getKey();
+ String value = event.getNewValue();
+ Preferences prefs = event.getNode();
+ if( "location".equals( key ) )
{
- CachePluginChangeEvent event = new CachePluginChangeEvent( this,
uri );
- notifyChange( event );
+ File cache = resolveCacheDirectory( prefs );
+ setLocalCacheDirectory( cache );
}
}

- public void addHostModel( HostModel director, int priority )
+ //
------------------------------------------------------------------------
+ // NodeChangeListener (listens to host prefs node addition and removal)
+ //
------------------------------------------------------------------------
+
+ /**
+ * Handle the addition of a host following a preferences node change to
the
+ * relative node hosts.
+ *
+ * @param event the node addition event
+ */
+ public void childAdded( NodeChangeEvent event )
{
- String id = director.getID();
+ Preferences prefs = event.getChild();
+ addHostModel( prefs, true );
+ }
+
+ public void childRemoved( NodeChangeEvent event )
+ {
+ Preferences prefs = event.getChild();
+ removeHostModel( prefs );
+ }
+
+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ private void addHostModel( Preferences prefs, boolean notify )
+ {
+ Logger logger = getLogger();
+ HostModel model = new HostManager( logger, prefs );
+ String id = model.getID();
+ int priority = model.getPriority();
synchronized( m_list )
{
Iterator iterator = m_list.iterator();
@@ -89,37 +165,58 @@
throw new IllegalArgumentException( error );
}
}
- m_list.add( director );
- HostAddedEvent event = new HostAddedEvent( this, director,
priority );
- super.enqueueEvent( event );
+ m_list.add( model );
+ model.addPluginListener( this );
+ if( notify )
+ {
+ HostAddedEvent event = new HostAddedEvent( this, model,
priority );
+ super.enqueueEvent( event );
+ }
}
}

- public void removeHostModel( HostModel director )
+ private void removeHostModel( Preferences prefs )
{
synchronized( m_list )
{
- boolean removed = m_list.remove( director );
- if( removed )
+ String id = prefs.name();
+ HostModel model = findHostModel( id );
+ if( null != model )
{
- HostRemovedEvent event = new HostRemovedEvent( this,
director );
+ m_list.remove( model );
+ model.removePluginListener( this );
+ HostRemovedEvent event = new HostRemovedEvent( this, model );
super.enqueueEvent( event );
}
}
}

+ private HostModel findHostModel( String id )
+ {
+ HostModel[] models = getHostModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ HostModel model = models[i];
+ if( id.equals( model.getID() ) )
+ {
+ return model;
+ }
+ }
+ return null;
+ }
+
/**
* Return the directory to be used by the cache handler as the cache
directory.
* @return the cache directory.
*/
- public File getCacheModely()
+ public File getCacheDirectory()
{
return m_cache;
}

/**
* Return an array of hosts currently assigned to the cache.
- * @return the host director array
+ * @return the host model array
*/
public HostModel[] getHostModels()
{
@@ -154,9 +251,9 @@
{
processHostEvent( (HostEvent) event );
}
- else if( event instanceof CacheModelyChangeEvent )
+ else if( event instanceof CacheDirectoryChangeEvent )
{
- processCacheModelyChangeEvent( (CacheModelyChangeEvent) event );
+ processCacheDirectoryChangeEvent( (CacheDirectoryChangeEvent)
event );
}
else
{
@@ -206,7 +303,7 @@
}
}

- private void processCacheModelyChangeEvent( CacheModelyChangeEvent event
)
+ private void processCacheDirectoryChangeEvent( CacheDirectoryChangeEvent
event )
{
EventListener[] listeners = super.listeners();
for( int i=0; i<listeners.length; i++ )
@@ -229,6 +326,69 @@
}
}

+ /**
+ * Resolve the cache directory using preferences.
+ * @param prefs the cache preferences
+ * @return the cache directory
+ */
+ private File resolveCacheDirectory( Preferences prefs )
+ {
+ String path = prefs.get( "location", "cache" );
+ String location = System.getProperty( CACHE_KEY, path );
+ String cache = PropertyResolver.resolve( System.getProperties(),
location );
+ return new File( cache );
+ }
+
+ /**
+ * Set the local cache directory.
+ * @param file the cache directory
+ */
+ protected synchronized void setLocalCacheDirectory( File file )
+ {
+ if( null == file )
+ {
+ throw new NullPointerException( "file" );
+ }
+ File cache = file;
+ if( false == cache.isAbsolute() )
+ {
+ File anchor = getAnchorDirectory();
+ cache = new File( anchor, file.toString() );
+ }
+ if( null == m_cache )
+ {
+ final String message =
+ "Setting cache directory."
+ + "\nDirectory: " + cache;
+ getLogger().fine( message );
+ }
+ else
+ {
+ final String message =
+ "Changing cache directory."
+ + "\nOld: " + m_cache
+ + "\nNew: " + cache;
+ getLogger().fine( message );
+ }
+ cache.mkdirs();
+ m_cache = cache;
+ }
+
+ private File getAnchorDirectory()
+ {
+ String path = System.getProperty( "dpml.data" );
+ if( null != path )
+ {
+ return new File( path );
+ }
+ else
+ {
+ final String error =
+ "Cannot resolve relative path as the DPML Data system property
'dpml.data' is undefined.";
+ throw new IllegalStateException( error );
+ }
+ }
+
static class HostAddedEvent extends HostEvent
{
private int m_priority;
@@ -266,9 +426,9 @@
}
}

- class CacheModelyChangeEvent extends FileChangeEvent
+ class CacheDirectoryChangeEvent extends FileChangeEvent
{
- public CacheModelyChangeEvent( Object source, File file )
+ public CacheDirectoryChangeEvent( Object source, File file )
{
super( source, file );
}

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ContentManager.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ContentManager.java
Fri May 20 19:22:04 2005
@@ -0,0 +1,185 @@
+/*
+ * 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.manager;
+
+import java.util.EventObject;
+import java.util.EventListener;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+
+import net.dpml.transit.model.ContentModel;
+import net.dpml.transit.model.PluginModel;
+import net.dpml.transit.model.PluginChangeEvent;
+import net.dpml.transit.model.ContentEvent;
+import net.dpml.transit.model.ContentListener;
+
+/**
+ * Default implementation of a content manager.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Id: HostManager.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
+ */
+public class ContentManager extends AbstractPluginManager implements
ContentModel
+{
+ //----------------------------------------------------------------------
+ // state
+ //----------------------------------------------------------------------
+
+ private final String m_type;
+ private String m_title;
+
+ //----------------------------------------------------------------------
+ // constructor
+ //----------------------------------------------------------------------
+
+ public ContentManager( Logger logger, Preferences prefs )
+ {
+ super( logger, prefs );
+ m_type = prefs.name();
+ m_title = prefs.get( "title", m_type );
+ }
+
+ //----------------------------------------------------------------------
+ // ContentModel
+ //----------------------------------------------------------------------
+
+ /**
+ * Return the immutable content type identifier.
+ * @return the content type
+ */
+ public String getContentType()
+ {
+ return m_type;
+ }
+
+ /**
+ * Returns the human readable name of the content type handler.
+ * @return the content type human readable name
+ */
+ public String getContentHandlerTitle()
+ {
+ return m_title;
+ }
+
+ /**
+ * Add a content listener to the director.
+ * @param the listener to add
+ */
+ public void addContentListener( ContentListener listener )
+ {
+ super.addListener( listener );
+ }
+
+ /**
+ * Remove a content listener from the director.
+ * @param the listener to remove
+ */
+ public void removeContentListener( ContentListener listener )
+ {
+ super.removeListener( listener );
+ }
+
+ //
------------------------------------------------------------------------
+ // 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 )
+ {
+ super.preferenceChange( event );
+
+ String key = event.getKey();
+ String value = event.getNewValue();
+ Preferences prefs = event.getNode();
+ if( "title".equals( key ) )
+ {
+ setTitle( value );
+ }
+ else if( false == "uri".equals( key ) )
+ {
+ final String warning =
+ "A content handler plugin preference node change event
references an unrecognized key."
+ + "\nPreference Node: " + prefs
+ + "\nKey: " + key;
+ getLogger().log( Level.SEVERE, warning );
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ private void setTitle( String title )
+ {
+ m_title = title;
+ ContentEvent event = new ContentEvent( this );
+ super.enqueueEvent( event );
+ }
+
+ public void processEvent( EventObject event )
+ {
+ if( event instanceof PluginChangeEvent )
+ {
+ super.processPluginChangeEvent( (PluginChangeEvent) event );
+ }
+ else if( event instanceof ContentEvent )
+ {
+ processContentEvent( (ContentEvent) event );
+ }
+ else
+ {
+ final String error =
+ "Event type not regognized."
+ + "\nEvent Class: " + event.getClass();
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ public void processContentEvent( ContentEvent event )
+ {
+ EventListener[] listeners = super.listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener eventListener = listeners[i];
+ if( eventListener instanceof ContentListener )
+ {
+ ContentListener listener = (ContentListener ) eventListener;
+ try
+ {
+ listener.titleChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "ContentListener title change notification error.";
+ getLogger().log( Level.SEVERE, error, e );
+ }
+ }
+ }
+ }
+}
+

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/HostManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/HostManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/HostManager.java
Fri May 20 19:22:04 2005
@@ -26,6 +26,10 @@
import java.net.URI;
import java.net.URL;
import java.net.Authenticator;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.logging.Logger;

import net.dpml.transit.model.HostModel;
import net.dpml.transit.model.PluginModel;
@@ -34,7 +38,11 @@
import net.dpml.transit.model.HostListener;

/**
- * Default implementation of a host manager.
+ * Default implementation of a host manager. The implementation establishes
+ * a preferences change listener on a supplied preferences instance
representing
+ * a named host. The immutable host id corresponds to the supplied
preference
+ * node name. Features of the host are resolved from preference node
attributes
+ * and consildated under the HostModel implementation.
*
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
* @version $Id: HostManager.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
@@ -51,38 +59,39 @@
private Authenticator m_authenticator;
private URI m_resolver;
private boolean m_available = false;
+ private int m_priority = 100;

- public HostManager( Logger logger, String id )
- {
- this( logger, null, id );
- }
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------

- public HostManager( Logger logger, URI plugin, String id )
+ public HostManager( Logger logger, Preferences prefs )
{
- this( logger, plugin, id, null );
+ super( logger, prefs );
+ m_id = prefs.name();
}

- public HostManager( Logger logger, URI plugin, String id, Map features )
+ //
------------------------------------------------------------------------
+ // PreferenceChangeListener
+ //
------------------------------------------------------------------------
+
+ public void preferenceChange( PreferenceChangeEvent event )
{
- super( logger, plugin );
- if( null == id )
+ String key = event.getKey();
+ if( "modified".equals( key ) )
{
- throw new NullPointerException( "id" );
- }
- m_id = id;
- if( null != features )
- {
- setFeatures( features, false );
+ fireChangeNotification();
}
}

- public void setPluginURI( URI uri )
+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ public void fireChangeNotification()
{
- synchronized( m_lock )
- {
- HostPluginChangeEvent event = new HostPluginChangeEvent( this,
uri );
- notifyChange( event );
- }
+ HostChangeEvent event = new HostChangeEvent( this, new String[0] );
+ enqueueEvent( event );
}

public void setFeatures( Map map )
@@ -179,6 +188,15 @@
}

/**
+ * Return the host priority.
+ * @return the host priority setting
+ */
+ public int getPriority()
+ {
+ return m_priority;
+ }
+
+ /**
* Return the available status.
* @return TRUE if available
*/

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
Fri May 20 19:22:04 2005
@@ -23,6 +23,9 @@
import java.util.Iterator;
import java.util.EventObject;
import java.util.EventListener;
+import java.util.prefs.Preferences;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.NodeChangeListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.net.URI;
@@ -32,6 +35,8 @@
import net.dpml.transit.model.PluginChangeEvent;
import net.dpml.transit.model.RegistryListener;
import net.dpml.transit.model.RegistryEvent;
+import net.dpml.transit.model.PluginListener;
+import net.dpml.transit.model.ModelException;

/**
* Default implementation of a content handler registry manager.
@@ -39,68 +44,90 @@
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
* @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
*/
-public class RegistryManager extends AbstractPluginManager implements
RegistryModel
+public class RegistryManager extends AbstractPluginManager
+ implements RegistryModel, NodeChangeListener, PluginListener
{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
private final List m_list = new LinkedList();

- public RegistryManager( Logger logger )
- {
- this( logger, null );
- }
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------

- public RegistryManager( Logger logger, URI uri )
+ public RegistryManager( Logger logger, Preferences prefs ) throws
ModelException
{
- super( logger, uri );
- }
+ super( logger, prefs );

- public void setPluginURI( URI uri )
- {
- synchronized( m_lock )
- {
- RegistryPluginChangeEvent event = new RegistryPluginChangeEvent(
this, uri );
- notifyChange( event );
- }
- }
+ //
+ // construct the content handler configurations
+ //

- public void addContentModel( ContentModel director )
- {
- String type = director.getContentType();
- synchronized( m_list )
+ try
{
- Iterator iterator = m_list.iterator();
- while( iterator.hasNext() )
+ String[] names = prefs.childrenNames();
+ for( int i=0; i<names.length; i++ )
{
- ContentModel d = (ContentModel) iterator.next();
- if( type.equals( d.getContentType() ) )
- {
- final String error =
- "Content type already registered."
- + "\nType: " + type;
- throw new IllegalArgumentException( error );
- }
+ String name = names[i];
+ Preferences p = prefs.node( name );
+ addContentModel( p, false );
}
- m_list.add( director );
- ContentAddedEvent event = new ContentAddedEvent( this, director
);
- super.enqueueEvent( event );
}
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected exception while reading content preferences."
+ + "\nPreferences: " + prefs;
+ throw new ModelException( error, e );
+ }
+
+ //
+ // add a listener to the preferences
+ //
+
+ prefs.addNodeChangeListener( this );
}

- public void removeContentModel( ContentModel director )
+ //
------------------------------------------------------------------------
+ // PluginListener (listens to changes to plugin uris)
+ //
------------------------------------------------------------------------
+
+ public void pluginChanged( PluginChangeEvent event )
{
- synchronized( m_list )
- {
- boolean removed = m_list.remove( director );
- if( removed )
- {
- ContentRemovedEvent event = new ContentRemovedEvent( this,
director );
- super.enqueueEvent( event );
- }
- }
+ getLogger().info( "plugin changed: " + event.getPluginURI() );
+ }
+
+ //
------------------------------------------------------------------------
+ // NodeChangeListener (listens to content prefs node addition and
removal)
+ //
------------------------------------------------------------------------
+
+ /**
+ * Handle the addition of a content handler configuration following a
+ * preferences node change.
+ *
+ * @param event the node addition event
+ */
+ public void childAdded( NodeChangeEvent event )
+ {
+ Preferences prefs = event.getChild();
+ addContentModel( prefs, true );
+ }
+
+ public void childRemoved( NodeChangeEvent event )
+ {
+ Preferences prefs = event.getChild();
+ removeContentModel( prefs );
}

+ //
------------------------------------------------------------------------
+ // RegistryManager
+ //
------------------------------------------------------------------------
+
/**
- * Return an array of content directors currently assigned to the
registry.
- * @return the content director array
+ * Return an array of content models currently assigned to the registry.
+ * @return the content model array
*/
public ContentModel[] getContentModels()
{
@@ -125,6 +152,69 @@
super.removeListener( listener );
}

+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ private ContentModel findContentModel( String type )
+ {
+ ContentModel[] models = getContentModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ ContentModel model = models[i];
+ if( type.equals( model.getContentType() ) )
+ {
+ return model;
+ }
+ }
+ return null;
+ }
+
+ private void addContentModel( Preferences prefs, boolean notify )
+ {
+ Logger logger = getLogger();
+ ContentModel model = new ContentManager( logger, prefs );
+ String type = model.getContentType();
+ synchronized( m_list )
+ {
+ Iterator iterator = m_list.iterator();
+ while( iterator.hasNext() )
+ {
+ ContentModel d = (ContentModel) iterator.next();
+ if( type.equals( d.getContentType() ) )
+ {
+ final String error =
+ "Content type already registered."
+ + "\nType: " + type;
+ throw new IllegalArgumentException( error );
+ }
+ }
+ m_list.add( model );
+ model.addPluginListener( this );
+ if( notify )
+ {
+ ContentAddedEvent event = new ContentAddedEvent( this, model
);
+ super.enqueueEvent( event );
+ }
+ }
+ }
+
+ private void removeContentModel( Preferences prefs )
+ {
+ synchronized( m_list )
+ {
+ String type = prefs.name();
+ ContentModel model = findContentModel( type );
+ if( null != model )
+ {
+ m_list.remove( model );
+ model.removePluginListener( this );
+ ContentRemovedEvent event = new ContentRemovedEvent( this,
model );
+ super.enqueueEvent( event );
+ }
+ }
+ }
+
public void processEvent( EventObject event )
{
if( event instanceof PluginChangeEvent )
@@ -144,7 +234,7 @@
}
}

- public void processRegistryEvent( RegistryEvent event )
+ private void processRegistryEvent( RegistryEvent event )
{
EventListener[] listeners = super.listeners();
for( int i=0; i<listeners.length; i++ )

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RepositoryManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RepositoryManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RepositoryManager.java
Fri May 20 19:22:04 2005
@@ -21,6 +21,7 @@
import java.util.EventObject;
import java.util.EventListener;
import java.util.logging.Logger;
+import java.util.prefs.Preferences;
import java.net.URI;

import net.dpml.transit.model.RepositoryModel;
@@ -35,27 +36,9 @@
*/
public class RepositoryManager extends AbstractPluginManager implements
RepositoryModel
{
- public RepositoryManager( Logger logger )
+ public RepositoryManager( Logger logger, Preferences prefs )
{
- super( logger, null );
- }
-
- public RepositoryManager( Logger logger, URI uri )
- {
- super( logger, uri );
- if( null == uri )
- {
- throw new NullPointerException( "uri" );
- }
- }
-
- public void setPluginURI( URI uri )
- {
- synchronized( m_lock )
- {
- RepositoryPluginChangeEvent event = new
RepositoryPluginChangeEvent( this, uri );
- notifyChange( event );
- }
+ super( logger, prefs );
}

public void processEvent( EventObject event )

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
Fri May 20 19:22:04 2005
@@ -18,33 +18,56 @@

package net.dpml.transit.manager;

-import java.net.URI;
+import java.io.File;
+import java.util.prefs.Preferences;
+import java.util.logging.Logger;

import net.dpml.transit.model.TransitModel;
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.RegistryModel;
import net.dpml.transit.model.RepositoryModel;
+import net.dpml.transit.model.ModelException;

/**
- * The TransitManager class is the default TransitDirector implementation.
+ * The TransitManager class is the default TransitModel implementation.
*
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
* @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
*/
public class TransitManager implements TransitModel
{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
private final CacheModel m_cache;
private final RegistryModel m_registry;
private final RepositoryModel m_repository;

- public TransitManager(
- final CacheModel cache, final RegistryModel registry, final
RepositoryModel repository )
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ public TransitManager( Logger logger, Preferences prefs )
+ throws NullPointerException, ModelException
{
- m_cache = cache;
- m_registry = registry;
- m_repository = repository;
+ if( null == prefs )
+ {
+ throw new NullPointerException( "prefs" );
+ }
+ if( null == logger )
+ {
+ throw new NullPointerException( "logger" );
+ }
+ m_cache = createCacheModel( logger, prefs );
+ m_registry = createRegistryModel( logger, prefs );
+ m_repository = createRepositoryModel( logger, prefs );
}

+ //
------------------------------------------------------------------------
+ // TransitModel
+ //
------------------------------------------------------------------------
+
/**
* Return the cache model.
* @return the cache model
@@ -76,5 +99,36 @@
return m_repository;
}

+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ private CacheModel createCacheModel( Logger logger, Preferences root )
throws ModelException
+ {
+ Preferences prefs = root.node( "cache" );
+ Logger log = getLogger( logger, "cache" );
+ return new CacheManager( log, prefs );
+ }
+
+ private RegistryModel createRegistryModel( Logger logger, Preferences
root ) throws ModelException
+ {
+ Preferences prefs = root.node( "content" );
+ Logger log = getLogger( logger, "content" );
+ return new RegistryManager( log, prefs );
+ }
+
+ private RepositoryModel createRepositoryModel( Logger logger,
Preferences root )
+ {
+ Preferences prefs = root.node( "repository" );
+ Logger log = getLogger( logger, "repository" );
+ return new RepositoryManager( log, prefs );
+ }
+
+ private Logger getLogger( Logger logger, String name )
+ {
+ String base = logger.getName();
+ String category = base = "." + name;
+ return Logger.getLogger( category );
+ }
}


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/CacheModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/CacheModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/CacheModel.java
Fri May 20 19:22:04 2005
@@ -29,10 +29,15 @@
public interface CacheModel extends PluginModel
{
/**
+ * Cache property key.
+ */
+ static final String CACHE_KEY = "dpml.transit.cache.location";
+
+ /**
* Return the directory to be used by the cache handler as the cache
directory.
* @return the cache directory.
*/
- File getCacheModely();
+ File getCacheDirectory();

/**
* Return the array of hosts configured for the cache.

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostModel.java
Fri May 20 19:22:04 2005
@@ -64,6 +64,12 @@
String getHostName();

/**
+ * Return the host priority.
+ * @return the host priority setting
+ */
+ int getPriority();
+
+ /**
* Return the host base url.
* @return the base url
*/

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ModelException.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ModelException.java
Fri May 20 19:22:04 2005
@@ -0,0 +1,51 @@
+/*
+ * 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.model;
+
+import java.net.ProtocolException;
+
+/**
+ * Exception to indicate that there was a configuration model related error.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ */
+public class ModelException extends Exception
+{
+ /**
+ * Construct a new <code>ModelException</code> instance.
+ *
+ * @param message The detail message for this exception.
+ */
+ public ModelException( final String message )
+ {
+ this( message, null );
+ }
+
+ /**
+ * Construct a new <code>ModelException</code> instance.
+ *
+ * @param message The detail message for this exception.
+ * @param cause the root cause of the exception
+ */
+ public ModelException( final String message, final Throwable cause )
+ {
+ super( message, cause );
+ }
+}
+

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/PluginChangeEvent.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/PluginChangeEvent.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/PluginChangeEvent.java
Fri May 20 19:22:04 2005
@@ -21,7 +21,7 @@
import java.net.URI;
import java.util.EventObject;

-public abstract class PluginChangeEvent extends EventObject
+public class PluginChangeEvent extends EventObject
{
private final URI m_plugin;


Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/package.html
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/package.html
Fri May 20 19:22:04 2005
@@ -0,0 +1,17 @@
+
+<body>
+<p>
+The model package contains a set of interfaces that define an active
+configuration model. The <a href="TransitModel.html">TransitModel</a> class
+defines the rot of the configuration model from which <a
href="CacheModel.html">CacheModel</a>,
+<a href="RegistryModel.html">RegistryModel</a> and <a
href="RepositoryModel.html">RepositoryModel</a>
+instances are accessible. The <a href="CacheModel.html">CacheModel</a>
provides information about
+the configured cache directory and hosts. Hosts are exposed as instances of
+<a href="CacheModel.html">HostModel</a>. The <a
href="RegistryModel.html">RegistryModel</a> provides
+information about registered content handler plugins via instances of
+<a href="ContentModel.html">ContentModel</a>. The <a
href="RepositoryModel.html">RepositoryModel</a>
+declares information about the repository service (plugin loading and
general classloader chain
+construction).
+</p>.
+</body>
+

Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
Fri May 20 19:22:04 2005
@@ -19,10 +19,13 @@
package net.dpml.transit.manager;

import java.io.File;
+import java.io.FileInputStream;
import java.util.logging.Logger;
+import java.util.prefs.Preferences;

import junit.framework.TestCase;

+import net.dpml.transit.Transit;
import net.dpml.transit.model.RepositoryModel;
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.RegistryModel;
@@ -33,33 +36,19 @@
*/
public class TransitManagerTestCase extends TestCase
{
- private RepositoryManager m_repository;
- private RegistryManager m_registry;
- private CacheManager m_cache;
private TransitManager m_manager;

public void setUp() throws Exception
{
- String testPath = System.getProperty( "basedir" );
-
- File cache = new File( "target/test/cache" );
+ System.setProperty( "dpml.data", "target/test/data" );
Logger logger = Logger.getLogger( "test" );
- m_repository = new RepositoryManager( logger );
- m_registry = new RegistryManager( logger );
- File localDir = new File( "target/test/local" );
- HostManager local = new HostManager( logger, "local" );
- m_cache = new CacheManager( logger, cache, local );
- m_manager = new TransitManager( m_cache, m_registry, m_repository );
+ Preferences prefs = Preferences.userNodeForPackage( Transit.class );
+ Preferences test = prefs.node( "test" );
+ m_manager = new TransitManager( logger, test );
}

public void testTransitManager()
{
- RepositoryModel repository = m_manager.getRepositoryModel();
- assertEquals( "repository", m_repository, repository );
- RegistryModel registry = m_manager.getContentRegistryModel();
- assertEquals( "registry", m_registry, registry );
- CacheModel cache = m_manager.getCacheModel();
- assertEquals( "cache", m_cache, cache );
}
}




  • svn commit: r2636 - in development/main/transit/core/handler: . src/main/net/dpml/transit/manager src/main/net/dpml/transit/model src/test/net/dpml/transit/manager, mcconnell, 05/20/2005

Archive powered by MHonArc 2.6.24.

Top of Page