Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2687 - in development/main: depot/prefs/src/main/net/dpml/depot/prefs transit/core/handler/src/main/net/dpml/transit/host transit/core/handler/src/main/net/dpml/transit/manager transit/core/handler/src/main/net/dpml/transit/model

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: r2687 - in development/main: depot/prefs/src/main/net/dpml/depot/prefs transit/core/handler/src/main/net/dpml/transit/host transit/core/handler/src/main/net/dpml/transit/manager transit/core/handler/src/main/net/dpml/transit/model
  • Date: Wed, 01 Jun 2005 15:11:34 -0400

Author: mcconnell AT dpml.net
Date: Wed Jun 1 15:11:32 2005
New Revision: 2687

Added:

development/main/transit/core/handler/src/main/net/dpml/transit/model/HostAvailabilityEvent.java
Modified:

development/main/depot/prefs/src/main/net/dpml/depot/prefs/HostManagerPanel.java

development/main/depot/prefs/src/main/net/dpml/depot/prefs/LayoutComboBoxModel.java

development/main/transit/core/handler/src/main/net/dpml/transit/host/ClassicResourceHost.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/model/HostListener.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/RegistryModel.java
Log:
Work-in-progress on host availability.

Modified:
development/main/depot/prefs/src/main/net/dpml/depot/prefs/HostManagerPanel.java
==============================================================================
---
development/main/depot/prefs/src/main/net/dpml/depot/prefs/HostManagerPanel.java
(original)
+++
development/main/depot/prefs/src/main/net/dpml/depot/prefs/HostManagerPanel.java
Wed Jun 1 15:11:32 2005
@@ -60,6 +60,7 @@
import net.dpml.transit.model.HostEnabledEvent;
import net.dpml.transit.model.HostTrustedEvent;
import net.dpml.transit.model.HostPriorityEvent;
+import net.dpml.transit.model.HostAvailabilityEvent;

/**
* A interactive panel that presents the preferences for a single host.
@@ -336,6 +337,14 @@
{
}

+ /**
+ * Notify a consumer of a change to the availability status.
+ * @param event the host event
+ */
+ public void availabilityChanged( HostAvailabilityEvent event )
+ {
+ }
+
//--------------------------------------------------------------
// PropertyChangeListener
//--------------------------------------------------------------

Modified:
development/main/depot/prefs/src/main/net/dpml/depot/prefs/LayoutComboBoxModel.java
==============================================================================
---
development/main/depot/prefs/src/main/net/dpml/depot/prefs/LayoutComboBoxModel.java
(original)
+++
development/main/depot/prefs/src/main/net/dpml/depot/prefs/LayoutComboBoxModel.java
Wed Jun 1 15:11:32 2005
@@ -29,6 +29,7 @@
import net.dpml.transit.model.HostTrustedEvent;
import net.dpml.transit.model.HostPriorityEvent;
import net.dpml.transit.model.HostLayoutEvent;
+import net.dpml.transit.model.HostAvailabilityEvent;
import net.dpml.transit.model.LayoutModel;
import net.dpml.transit.model.LayoutRegistryListener;
import net.dpml.transit.model.LayoutRegistryEvent;
@@ -149,5 +150,13 @@
}
}

+
+ /**
+ * Notify a consumer of a change to the availability status.
+ * @param event the host event
+ */
+ public void availabilityChanged( HostAvailabilityEvent event )
+ {
+ }
}


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/host/ClassicResourceHost.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/host/ClassicResourceHost.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/host/ClassicResourceHost.java
Wed Jun 1 15:11:32 2005
@@ -69,6 +69,7 @@
import net.dpml.transit.model.HostEnabledEvent;
import net.dpml.transit.model.HostTrustedEvent;
import net.dpml.transit.model.HostPriorityEvent;
+import net.dpml.transit.model.HostAvailabilityEvent;
import net.dpml.transit.model.HostLayoutEvent;
import net.dpml.transit.model.Logger;

@@ -189,6 +190,14 @@
{
}

+ /**
+ * Notify a consumer of a change to the available status.
+ * @param event the availability change event
+ */
+ public void availabilityChanged( HostAvailabilityEvent event )
+ {
+ }
+
//
------------------------------------------------------------------------
// ResourceHost
//
------------------------------------------------------------------------

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
Wed Jun 1 15:11:32 2005
@@ -45,6 +45,13 @@
import net.dpml.transit.model.CacheListener;
import net.dpml.transit.model.FileChangeEvent;
import net.dpml.transit.model.HostNodeEvent;
+import net.dpml.transit.model.HostChangeEvent;
+import net.dpml.transit.model.HostEnabledEvent;
+import net.dpml.transit.model.HostTrustedEvent;
+import net.dpml.transit.model.HostPriorityEvent;
+import net.dpml.transit.model.HostLayoutEvent;
+import net.dpml.transit.model.HostAvailabilityEvent;
+import net.dpml.transit.model.HostListener;
import net.dpml.transit.model.ModelException;
import net.dpml.transit.model.Logger;

@@ -64,6 +71,7 @@
// state
//
------------------------------------------------------------------------

+ private final AvailabilityListener m_availabilityListener = new
AvailabilityListener();
private final LayoutRegistryManager m_layout;
private final List m_list = new LinkedList();

@@ -225,6 +233,14 @@
{
// ignore
}
+ try
+ {
+ model.removeHostListener( m_availabilityListener );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
}
}

@@ -350,6 +366,67 @@
}

//
------------------------------------------------------------------------
+ // HostListener
+ //
------------------------------------------------------------------------
+
+ private class AvailabilityListener implements HostListener
+ {
+ /**
+ * Notify a consumer of an aggregated set of changes.
+ * @param event the host change event
+ */
+ public void hostChanged( HostChangeEvent event )
+ {
+ }
+
+ /**
+ * Notify a consumer of a change to the enabled state.
+ * @param event the host event
+ */
+ public void enabledStateChanged( HostEnabledEvent event )
+ {
+ }
+
+ /**
+ * Notify a consumer of a change to the trusted state.
+ * @param event the host event
+ */
+ public void trustedStateChanged( HostTrustedEvent event )
+ {
+ }
+
+ /**
+ * Notify a consumer of a change to the host priority.
+ * @param event the host event
+ */
+ public void priorityChanged( HostPriorityEvent event )
+ {
+ }
+
+ /**
+ * Notify a consumer of a change to the host resolver.
+ * @param event the host resolver change event
+ */
+ public void layoutChanged( HostLayoutEvent event )
+ {
+ }
+
+ /**
+ * Notify a consumer of a change to availability status of a host.
+ * @param event the host availability event
+ */
+ public void availabilityChanged( HostAvailabilityEvent event )
+ {
+ System.out.println(
+ "# HOST AVAILABILITY CHANGE "
+ + event.getHostModel().getID()
+ + ", "
+ + event.getAvailability() );
+ }
+
+ }
+
+ //
------------------------------------------------------------------------
// internal
//
------------------------------------------------------------------------

@@ -371,6 +448,7 @@
}
m_list.add( model );
model.addPluginListener( this );
+ model.addHostListener( m_availabilityListener );
if( notify )
{
HostAddedEvent event = new HostAddedEvent( this, model,
priority );
@@ -389,6 +467,7 @@
{
m_list.remove( model );
model.removePluginListener( this );
+ model.removeHostListener( m_availabilityListener );
HostRemovedEvent event = new HostRemovedEvent( this, model );
super.enqueueEvent( event );
}

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
Wed Jun 1 15:11:32 2005
@@ -19,10 +19,12 @@
package net.dpml.transit.manager;

import java.io.IOException;
+import java.util.Date;
import java.util.Map;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.EventListener;
+import java.util.List;
import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
@@ -31,21 +33,22 @@
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;

+import net.dpml.transit.model.HostAvailabilityEvent;
import net.dpml.transit.model.HostEnabledEvent;
-import net.dpml.transit.model.HostModel;
-import net.dpml.transit.model.HostEvent;
import net.dpml.transit.model.HostChangeEvent;
+import net.dpml.transit.model.HostEvent;
import net.dpml.transit.model.HostLayoutEvent;
import net.dpml.transit.model.HostListener;
+import net.dpml.transit.model.HostModel;
+import net.dpml.transit.model.HostNameEvent;
+import net.dpml.transit.model.HostPriorityEvent;
+import net.dpml.transit.model.HostTrustedEvent;
import net.dpml.transit.model.LayoutModel;
import net.dpml.transit.model.LayoutRegistryModel;
import net.dpml.transit.model.Logger;
-import net.dpml.transit.model.HostNameEvent;
import net.dpml.transit.model.ModelException;
-import net.dpml.transit.model.HostPriorityEvent;
import net.dpml.transit.model.PluginModel;
import net.dpml.transit.model.PluginChangeEvent;
-import net.dpml.transit.model.HostTrustedEvent;

import net.dpml.transit.network.RequestIdentifier;

@@ -71,12 +74,13 @@
private boolean m_enabled = false;
private boolean m_trusted = false;
private LayoutModel m_layout;
- private boolean m_available = false;
private int m_priority = 600;
private RequestIdentifier m_identifier;
private PasswordAuthentication m_authentication;
private boolean m_bootstrap = false;

+ private Throwable m_error;
+
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
@@ -89,20 +93,57 @@
m_layoutRegistry = registry;
m_bootstrap = prefs.getBoolean( "bootstrap", false );
m_id = prefs.name();
+
m_name = prefs.get( "name", m_id );
m_trusted = prefs.getBoolean( "trusted", m_trusted );
m_enabled = prefs.getBoolean( "enabled", m_enabled );
m_priority = prefs.getInt( "priority", m_priority );
String layout = prefs.get( "layout", "classic" );
- m_layout = registry.getLayoutModel( layout );
-
- m_base = resolveBase( prefs );
- if( m_base != null )
+ m_layout = resolveLayoutModel( layout );
+
+ try
{
+ m_base = resolveBase( prefs );
m_index = resolveIndex( m_base, prefs );
m_identifier = resolveRequestIdentifier( m_base, prefs );
m_authentication = resolvePasswordAuthentication( prefs );
- m_available = true;
+ }
+ catch( Throwable e )
+ {
+ setError( e );
+ }
+ }
+
+ private void setError( Throwable e )
+ {
+ if( null == m_error )
+ {
+ if( null != e )
+ {
+ // raise a non-available event
+ m_error = e;
+ HostAvailabilityEvent event = new HostAvailabilityEvent(
this, false );
+ enqueueEvent( event );
+ }
+ else
+ {
+ // nothing changes
+ }
+ }
+ else
+ {
+ if( null == e )
+ {
+ // raise a available event
+ m_error = null;
+ HostAvailabilityEvent event = new HostAvailabilityEvent(
this, true );
+ enqueueEvent( event );
+ }
+ else
+ {
+ // update the error state
+ m_error = e;
+ }
}
}

@@ -112,68 +153,59 @@

public synchronized void update( URL base, URL index, boolean enabled,
boolean trusted, LayoutModel layout )
{
- m_base = base;
- m_enabled = enabled;
- m_trusted = trusted;
- m_layout = layout;
-
- updateBaseURL();
- updateTrusted();
- updateEnabled();
- updateLayoutModel();
+ storeBaseURL( base );
+ storeTrusted( trusted );
+ storeLayoutModel( layout );
+ storeEnabled( enabled );
+ storeModified();
}

- private void updateBaseURL()
+ private void storeBaseURL( URL base )
{
Preferences prefs = getPreferences();
- if( null == m_base )
+ if( null == base )
{
prefs.remove( "base" );
}
else
{
- prefs.put( "base", m_base.toExternalForm() );
+ prefs.put( "base", base.toExternalForm() );
}
}

- private void updateTrusted()
+ private void storeTrusted( boolean trusted )
{
Preferences prefs = getPreferences();
- prefs.putBoolean( "trusted", m_trusted );
+ prefs.putBoolean( "trusted", trusted );
}

- public void updateEnabled()
+ private void storeEnabled( boolean enabled )
{
Preferences prefs = getPreferences();
- prefs.putBoolean( "enabled", m_enabled );
+ prefs.putBoolean( "enabled", enabled );
}

- public void updateLayoutModel()
+ private void storeLayoutModel( LayoutModel layout )
{
- String id = m_layout.getID();
Preferences prefs = getPreferences();
- prefs.put( "layout", id );
- }
-
- /**
- * Set the host authentication.
- * @param auth the password authentication to use for host sign-on
- */
- public void setAuthentication( PasswordAuthentication auth ) throws
IOException
- {
- m_authentication = auth;
- Preferences prefs = getPreferences();
- if( null == auth )
+ if( null == layout )
{
- prefs.putByteArray( "authentication", new byte[0] );
+ prefs.put( "layout", "classic" );
}
else
{
- byte[] bytes = CredentialsHelper.exportCredentials(
m_authentication );
- prefs.putByteArray( "authentication", bytes );
+ String id = layout.getID();
+ prefs.put( "layout", id );
}
}

+ private void storeModified()
+ {
+ Preferences prefs = getPreferences();
+ long timestamp = new Date().getTime();
+ prefs.putLong( "modified", timestamp );
+ }
+
//----------------------------------------------------------------------
// Comparable
//----------------------------------------------------------------------
@@ -226,10 +258,7 @@
*/
public int getPriority()
{
- synchronized( this )
- {
- return m_priority;
- }
+ return m_priority;
}

/**
@@ -238,10 +267,7 @@
*/
public boolean getAvailable()
{
- synchronized( this )
- {
- return m_base != null;
- }
+ return ( null == m_error );
}

/**
@@ -250,10 +276,7 @@
*/
public String getHostName()
{
- synchronized( this )
- {
- return m_name;
- }
+ return m_name;
}

/**
@@ -262,10 +285,7 @@
*/
public URL getBaseURL()
{
- synchronized( this )
- {
- return m_base;
- }
+ return m_base;
}

/**
@@ -274,10 +294,7 @@
*/
public URL getIndexURL()
{
- synchronized( this )
- {
- return m_index;
- }
+ return m_index;
}

/**
@@ -286,10 +303,7 @@
*/
public boolean getEnabled()
{
- synchronized( this )
- {
- return m_enabled;
- }
+ return m_enabled;
}

/**
@@ -298,10 +312,7 @@
*/
public boolean getTrusted()
{
- synchronized( this )
- {
- return m_trusted;
- }
+ return m_trusted;
}

/**
@@ -310,10 +321,7 @@
*/
public PasswordAuthentication getAuthentication()
{
- synchronized( this )
- {
- return m_authentication;
- }
+ return m_authentication;
}

/**
@@ -322,10 +330,7 @@
*/
public RequestIdentifier getRequestIdentifier()
{
- synchronized( this )
- {
- return m_identifier;
- }
+ return m_identifier;
}

/**
@@ -334,10 +339,7 @@
*/
public LayoutModel getLayoutModel()
{
- synchronized( this )
- {
- return m_layout;
- }
+ return m_layout;
}

/**
@@ -410,24 +412,35 @@
String id = event.getNewValue();
try
{
- setLayoutModel( id );
+ m_layout = resolveLayoutModel( id );
+ HostLayoutEvent e = new HostLayoutEvent( this, m_layout );
+ enqueueEvent( e );
}
catch( ModelException e )
{
+ setError( e );
final String error =
"Host layout not set due to an unexpected error.";
getLogger().error( error, e );
return;
}
- LayoutModel layout = getLayoutModel();
- HostLayoutEvent e = new HostLayoutEvent( this, layout );
- enqueueEvent( e );
}
else if( "modified".equals( key ) )
{
- // this is a trigger marking modification to any of the
- // attributes "base", "username", "password", "prompt" or
"scheme"
- // in which case we notify a host controller of the change via
+ // This is a trigger marking modification to any of the
+ // attributes "base", "index", "username", "password", "prompt"
+ // or "scheme".
+ //
+ // If the value of the modified attribute is greater than zero
+ // this signals that the preceeding attributes are in a state
+ // ready for propergation into the model. If propergation
+ // raises an error the modified attribute will be reset.
+ //
+
+
+ // If the value of the modified attribute is greater than zero
this
+ // signals a valid set of information that we can use in a host
change
+ // event. we notify a host controller of the change via
// a single HostChangeEvent

synchronized( this )
@@ -436,8 +449,8 @@
try
{
URL base = resolveBase( prefs );
- URL index = resolveIndex( m_base, prefs );
- RequestIdentifier identifier = resolveRequestIdentifier(
m_base, prefs );
+ URL index = resolveIndex( base, prefs );
+ RequestIdentifier identifier = resolveRequestIdentifier(
base, prefs );
PasswordAuthentication authentication =
resolvePasswordAuthentication( prefs );

m_base = base;
@@ -448,9 +461,11 @@
HostChangeEvent e =
new HostChangeEvent( this, base, index, identifier,
authentication );
enqueueEvent( e );
+ setError( null );
}
catch( UnknownHostException uhe )
{
+ setError( uhe );
final String error =
"Unable to propergate change event due to an
unresolved host."
+ "\nPreferences Node: " + prefs
@@ -459,6 +474,7 @@
}
catch( IOException ioe )
{
+ setError( ioe );
final String error =
"Unable to propergate change event due to an
unexpected IO error."
+ "\nPreferences Node: " + prefs;
@@ -472,11 +488,30 @@
// internal
//----------------------------------------------------------------------

- public void setLayoutModel( String id ) throws ModelException
+ /**
+ * Set the host authentication.
+ * @param auth the password authentication to use for host sign-on
+ */
+ public void setAuthentication( PasswordAuthentication auth ) throws
IOException
+ {
+ m_authentication = auth;
+ Preferences prefs = getPreferences();
+ if( null == auth )
+ {
+ prefs.putByteArray( "authentication", new byte[0] );
+ }
+ else
+ {
+ byte[] bytes = CredentialsHelper.exportCredentials(
m_authentication );
+ prefs.putByteArray( "authentication", bytes );
+ }
+ }
+
+ public LayoutModel resolveLayoutModel( String id ) throws ModelException
{
if( ( null != m_layout ) && m_layout.getID().equals( id ) )
{
- return;
+ return m_layout;
}
else
{
@@ -507,12 +542,16 @@
}
}

- m_layout = layout;
+ return layout;
}
}

private RequestIdentifier resolveRequestIdentifier( URL base,
Preferences prefs )
{
+ if( null == base )
+ {
+ throw new NullPointerException( "base" );
+ }
String scheme = prefs.get( "scheme", "" );
String prompt = prefs.get( "prompt", "" );
String protocol = base.getProtocol();
@@ -548,7 +587,10 @@
String baseSpec = prefs.get( "base", null );
if( null == baseSpec )
{
- return null;
+ final String error =
+ "Undefined host base url"
+ + "\nHost ID: " + prefs.name();
+ throw new ModelException( error );
}

//
@@ -568,7 +610,7 @@
{
if( null == base )
{
- return null;
+ throw new NullPointerException( "base" );
}
String indexSpec = prefs.get( "index", null );
if( null != indexSpec )
@@ -587,6 +629,10 @@
{
super.processPluginChangeEvent( (PluginChangeEvent) event );
}
+ else if( event instanceof HostAvailabilityEvent )
+ {
+ processHostAvailabilityEvent( (HostAvailabilityEvent) event );
+ }
else if( event instanceof HostChangeEvent )
{
processHostChangeEvent( (HostChangeEvent) event );
@@ -630,7 +676,26 @@
{
final String error =
"HostListener enabled status change notification error.";
- getLogger().error( error, e );
+ getLogger().warn( error, e );
+ }
+ }
+ }
+
+ private void processHostAvailabilityEvent( HostAvailabilityEvent event )
+ {
+ HostListener[] listeners = getHostListeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ HostListener listener = listeners[i];
+ try
+ {
+ listener.availabilityChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "HostListener availability change notification error.";
+ getLogger().warn( error, e );
}
}
}
@@ -649,7 +714,7 @@
{
final String error =
"HostListener trusted status change notification error.";
- getLogger().error( error, e );
+ getLogger().warn( error, e );
}
}
}
@@ -668,7 +733,7 @@
{
final String error =
"HostListener resolver change notification error.";
- getLogger().error( error, e );
+ getLogger().warn( error, e );
}
}
}
@@ -687,7 +752,7 @@
{
final String error =
"HostListener priority change notification error.";
- getLogger().error( error, e );
+ getLogger().warn( error, e );
}
}
}
@@ -706,7 +771,7 @@
{
final String error =
"HostListener change notification error.";
- getLogger().error( error, e );
+ getLogger().warn( error, e );
}
}
}

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
Wed Jun 1 15:11:32 2005
@@ -73,9 +73,13 @@
{
String name = names[i];
Preferences p = prefs.node( name );
- addContentModel( p, false );
+ addContentManager( p, false );
}
}
+ catch( ModelException e )
+ {
+ throw e;
+ }
catch( Exception e )
{
final String error =
@@ -115,9 +119,62 @@
return manager;
}
}
+
+ //
+ // check for a system property that defines the plugin uri
+ //
+
+ String spec = "dpml.transit.content.plugin." + type;
+ String value = System.getProperty( spec );
+ if( null != value )
+ {
+ try
+ {
+ URI uri = new URI( value );
+ return addContentManager( type, type, uri );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Cannot construct content handler for system property
specification."
+ + "\nContent Type ID: " + type
+ + "\nSystem Defined URI: " + value;
+ IllegalArgumentException exception =
+ new IllegalArgumentException( error );
+ exception.initCause( e );
+ throw exception;
+ }
+ }
+
return null;
}

+ /**
+ * Register a new content manager.
+ *
+ * @return the content manager
+ */
+ public ContentManager addContentManager( String type, String title, URI
uri ) throws ModelException
+ {
+ if( null == type )
+ {
+ throw new NullPointerException( "type" );
+ }
+ if( null == title )
+ {
+ throw new NullPointerException( "title" );
+ }
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+
+ Preferences prefs = getPreferences().node( type );
+ prefs.put( "title", title );
+ prefs.put( "uri", uri.toString() );
+ return addContentManager( prefs, true );
+ }
+
public void removeContentModel( String type ) throws ModelException
{
try
@@ -173,47 +230,25 @@
}

//
------------------------------------------------------------------------
- // RegistryManager
+ // RegistryModel
//
------------------------------------------------------------------------

/**
* Register a new content model.
*
+ * @param type the content type identifier
+ * @param title the title of the content model
+ * @param plugin the content plugin uri
* @return the content model
*/
- public ContentModel addContentModel( String type, String title, URI uri )
+ public ContentModel addContentModel( String type, String title, URI
plugin ) throws ModelException
{
- if( null == type )
- {
- throw new NullPointerException( "type" );
- }
- if( null == title )
- {
- throw new NullPointerException( "title" );
- }
- if( null == uri )
- {
- throw new NullPointerException( "uri" );
- }
-
- Preferences prefs = getPreferences().node( type );
- prefs.put( "title", title );
- prefs.put( "uri", uri.toString() );
- return addContentModel( prefs, true );
+ return addContentManager( type, title, plugin );
}

public ContentModel getContentModel( 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;
+ return getContentManager( type );
}

/**
@@ -265,7 +300,16 @@
public void childAdded( NodeChangeEvent event )
{
Preferences prefs = event.getChild();
- addContentModel( prefs, true );
+ try
+ {
+ addContentManager( prefs, true );
+ }
+ catch( ModelException e )
+ {
+ String message = e.getMessage();
+ Throwable cause = e.getCause();
+ getLogger().error( message, cause );
+ }
}

public void childRemoved( NodeChangeEvent event )
@@ -278,24 +322,20 @@
// internal
//
------------------------------------------------------------------------

- private ContentModel addContentModel( Preferences prefs, boolean notify )
+ private ContentManager addContentManager( Preferences prefs, boolean
notify ) throws ModelException
{
Logger logger = getLogger();
- ContentModel model = new ContentManager( logger, prefs );
+ ContentManager model = new ContentManager( logger, prefs );
String type = model.getContentType();
synchronized( m_list )
{
- Iterator iterator = m_list.iterator();
- while( iterator.hasNext() )
+ ContentModel m = getContentModel( type );
+ if( null != m )
{
- ContentModel d = (ContentModel) iterator.next();
- if( type.equals( d.getContentType() ) )
- {
- final String error =
- "Content type already registered."
- + "\nType: " + type;
- throw new IllegalArgumentException( error );
- }
+ final String error =
+ "Content type already registered."
+ + "\nType: " + type;
+ throw new ModelException( error );
}
m_list.add( model );
model.addPluginListener( this );

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostAvailabilityEvent.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostAvailabilityEvent.java
Wed Jun 1 15:11:32 2005
@@ -0,0 +1,50 @@
+/*
+ * 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.util.EventObject;
+
+/**
+ * An event signalling the change in the availability of a host.
+ */
+public class HostAvailabilityEvent extends EventObject
+{
+ private final boolean m_availability;
+
+ /**
+ * Creation of a new host availability event.
+ * @param host the host whos availability status has changed
+ * @param availability the avalability status
+ */
+ public HostAvailabilityEvent( HostModel host, boolean availability )
+ {
+ super( host );
+ m_availability = availability;
+ }
+
+ public HostModel getHostModel()
+ {
+ return (HostModel) getSource();
+ }
+
+ public boolean getAvailability()
+ {
+ return m_availability;
+ }
+}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostListener.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostListener.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostListener.java
Wed Jun 1 15:11:32 2005
@@ -58,5 +58,11 @@
*/
void layoutChanged( HostLayoutEvent event );

+ /**
+ * Notify a consumer of a change to availability status of a host.
+ * @param event the host availability event
+ */
+ void availabilityChanged( HostAvailabilityEvent event );
+
}


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/RegistryModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/RegistryModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/RegistryModel.java
Wed Jun 1 15:11:32 2005
@@ -35,7 +35,7 @@
* @param plugin the content plugin uri
* @return the content model
*/
- ContentModel addContentModel( String type, String title, URI plugin );
+ ContentModel addContentModel( String type, String title, URI plugin )
throws ModelException;

/**
* Return a content model matching the supplied type. If the type is
unknown



  • svn commit: r2687 - in development/main: depot/prefs/src/main/net/dpml/depot/prefs transit/core/handler/src/main/net/dpml/transit/host transit/core/handler/src/main/net/dpml/transit/manager transit/core/handler/src/main/net/dpml/transit/model, mcconnell, 06/01/2005

Archive powered by MHonArc 2.6.24.

Top of Page