notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2805 - in development/main/depot: console/src/main/net/dpml/depot/profile station/src/main/net/dpml/depot/station
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2805 - in development/main/depot: console/src/main/net/dpml/depot/profile station/src/main/net/dpml/depot/station
- Date: Wed, 08 Jun 2005 22:04:41 -0400
Author: mcconnell AT dpml.net
Date: Wed Jun 8 22:04:39 2005
New Revision: 2805
Added:
development/main/depot/station/src/main/net/dpml/depot/station/ActivationStorage.java
Modified:
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileStorage.java
Log:
Modified:
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
Wed Jun 8 22:04:39 2005
@@ -126,7 +126,16 @@
Logger logger = getLogger().getChildLogger( id );
boolean policy = getStoragePolicy();
Date creation = getCreationDate();
- ProfileStorage store = new ProfileStorage( prefs, logger, creation,
policy );
+ String path = prefs.get( "plugin", null );
+ ProfileStorage store = null;
+ if( null != path )
+ {
+ store = new PluginProfileStorage( prefs, logger, creation,
policy );
+ }
+ else
+ {
+ store = new BootstrapProfileStorage( prefs, logger, creation,
policy );
+ }
return store.getProfile();
}
@@ -154,7 +163,7 @@
prefs.put( "title", "Depot Preferences" );
prefs.node( "classpath" ).put( "dpml-depot-prefs",
"${dpml.data}/lib/@DEPOT-PREFS-LIB@" );
prefs.putBoolean( "command", false );
- ProfileStorage store = new ProfileStorage( prefs, logger, creation,
policy );
+ ProfileStorage store = new BootstrapProfileStorage( prefs, logger,
creation, policy );
return store.getProfile();
}
@@ -169,7 +178,7 @@
prefs.put( "title", "Depot Station" );
prefs.putBoolean( "command", false );
prefs.node( "connection" );
- ProfileStorage store = new ProfileStorage( prefs, logger, creation,
policy );
+ ProfileStorage store = new PluginProfileStorage( prefs, logger,
creation, policy );
return store.getProfile();
}
@@ -183,7 +192,7 @@
prefs.put( "plugin", "@TEST-PLUGIN-URI@" );
prefs.put( "title", "Depot Station Test" );
prefs.putBoolean( "command", true );
- ProfileStorage store = new ProfileStorage( prefs, logger, creation,
policy );
+ ProfileStorage store = new PluginProfileStorage( prefs, logger,
creation, policy );
return store.getProfile();
}
Modified:
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileStorage.java
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileStorage.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileStorage.java
Wed Jun 8 22:04:39 2005
@@ -35,15 +35,9 @@
/**
* A ProfileHome maintains a persistent application profile.
*/
-public class ProfileStorage extends AbstractStorageUnit implements Home
+public abstract class ProfileStorage extends AbstractStorageUnit implements
Home
{
//
------------------------------------------------------------------------
- // state
- //
------------------------------------------------------------------------
-
- private final Profile m_profile;
-
- //
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
@@ -52,50 +46,6 @@
throws ProfileException
{
super( prefs, logger, creation, policy );
-
- String id = prefs.name();
- String title = prefs.get( "title", id );
- Properties properties = getProperties();
- Connection connection = getConnection();
- String path = prefs.get( "plugin", null );
- boolean command = prefs.getBoolean( "command", false );
- if( null != path )
- {
- try
- {
- URI uri = new URI( path );
- m_profile =
- new PluginProfile(
- logger, creation, this, id, title, properties, command,
- connection, uri );
- }
- catch( URISyntaxException e )
- {
- final String error =
- "Plugin application profile contains an invalid uri value."
- + "\nURI: " + path;
- throw new ProfileException( error, e );
- }
- }
- else
- {
- String classname = prefs.get( "classname", null );
- if( null != classname )
- {
- String[] classpath = getClasspath();
- m_profile =
- new BootstrapProfile(
- logger, creation, this, id, title, properties, command,
- connection, classname, classpath );
- }
- else
- {
- final String error =
- "Requested profile '" + prefs
- + "' does not declare either a classname or a plugin
attribute.";
- throw new ProfileException( error );
- }
- }
}
//
------------------------------------------------------------------------
@@ -128,44 +78,63 @@
// utils
//
------------------------------------------------------------------------
- Profile getProfile()
+ protected abstract Profile getProfile();
+
+ protected String getID()
{
- return m_profile;
+ return getPreferences().name();
}
- private String[] getClasspath() throws ProfileException
+ protected String getTitle()
{
- Preferences prefs = getPreferences().node( "classpath" );
+ String id = getID();
+ return getPreferences().get( "title", id );
+ }
+
+ protected boolean getCommandPolicy()
+ {
+ Preferences prefs = getPreferences();
+ return prefs.getBoolean( "command", false );
+ }
+
+ protected Properties getProperties() throws ProfileException
+ {
+ Properties properties = new Properties();
+ Preferences prefs = getPreferences().node( "properties" );
try
{
String[] keys = prefs.keys();
- String[] values = new String[ keys.length ];
for( int i=0; i<keys.length; i++ )
{
String key = keys[i];
- values[i] = prefs.get( key, null );
+ String value = prefs.get( key, null );
+ if( null != value )
+ {
+ properties.setProperty( key, value );
+ }
}
- return values;
+ return properties;
}
catch( BackingStoreException e )
{
final String error =
- "Cannot construct a classpath due to non-availability of the
preferences store.";
+ "Internal error while resolving persistent application
properties.";
throw new ProfileException( error, e );
}
}
- private Connection getConnection() throws ProfileException
+ protected Connection getConnection() throws ProfileException
{
+ Preferences root = getPreferences();
try
{
- if( false == getPreferences().nodeExists( "connection" ) )
+ if( false == root.nodeExists( "connection" ) )
{
return null;
}
else
{
- Preferences prefs = getPreferences().node( "connection" );
+ Preferences prefs = root.node( "connection" );
String host = prefs.get( "host", null );
int port = prefs.getInt( "port", 1099 );
return new Connection( host, port );
@@ -179,53 +148,32 @@
}
}
- private Properties getProperties() throws ProfileException
+ /*
+ private String[] getClasspath() throws ProfileException
{
- Properties properties = new Properties();
- Preferences prefs = getPreferences().node( "properties" );
+ Preferences prefs = getPreferences().node( "classpath" );
try
{
String[] keys = prefs.keys();
+ String[] values = new String[ keys.length ];
for( int i=0; i<keys.length; i++ )
{
String key = keys[i];
- String value = prefs.get( key, null );
- if( null != value )
- {
- properties.setProperty( key, value );
- }
+ values[i] = prefs.get( key, null );
}
- return properties;
+ return values;
}
catch( BackingStoreException e )
{
final String error =
- "Internal error while resolving persistent application
properties.";
+ "Cannot construct a classpath due to non-availability of the
preferences store.";
throw new ProfileException( error, e );
}
}
+ */
- private void store( Profile profile )
- {
- if( profile instanceof BootstrapProfile )
- {
- BootstrapProfile p = (BootstrapProfile) profile;
- saveBootstrapProfile( p );
- }
- else if( profile instanceof PluginProfile )
- {
- PluginProfile p = (PluginProfile) profile;
- savePluginProfile( p );
- }
- }
-
- private void saveBootstrapProfile( BootstrapProfile profile )
- {
- throw new UnsupportedOperationException( "saveBootstrapProfile/1" );
- }
-
- private void savePluginProfile( PluginProfile profile )
+ protected void store( Profile profile )
{
- throw new UnsupportedOperationException( "savePluginProfile/1" );
+ throw new UnsupportedOperationException( "store/1" );
}
}
Added:
development/main/depot/station/src/main/net/dpml/depot/station/ActivationStorage.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/ActivationStorage.java
Wed Jun 8 22:04:39 2005
@@ -0,0 +1,133 @@
+/*
+ * 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.depot.station;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Date;
+import java.util.Properties;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
+import java.rmi.activation.ActivationGroupID;
+
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.management.Home;
+import net.dpml.transit.management.ModificationEvent;
+import net.dpml.transit.builder.AbstractStorageUnit;
+
+import net.dpml.depot.profile.Profile.Connection;
+import net.dpml.depot.profile.PluginProfile;
+import net.dpml.depot.profile.ProfileException;
+import net.dpml.depot.profile.PluginProfileStorage;
+
+/**
+ * A ProfileHome maintains a persistent application profile.
+ */
+public class ActivationStorage extends PluginProfileStorage
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private final ActivationProfile m_profile;
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ public ActivationStorage(
+ Preferences prefs, Logger logger, Date creation, boolean policy,
+ ActivationGroupID group ) throws ProfileException
+ {
+ super( prefs, logger, creation, policy );
+
+ String id = prefs.name();
+ String title = prefs.get( "title", id );
+ Properties properties = getProperties();
+ Connection connection = getConnection();
+ boolean command = prefs.getBoolean( "command", false );
+
+ String classname = getActivationClassname();
+ boolean restart = getRestartPolicy();
+ URI uri = getPluginURI();
+
+ m_profile =
+ new ActivationProfile(
+ logger, creation, this, id, title, properties, command,
+ connection, uri, group, classname, restart );
+ }
+
+ //
------------------------------------------------------------------------
+ // ModificationListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
+ public void modified( ModificationEvent event )
+ {
+ if( getStoragePolicy() )
+ {
+ try
+ {
+ ActivationProfile manager = (ActivationProfile)
event.getManager();
+ Date date = new Date();
+ store( manager );
+ manager.setCreationDate( date );
+ }
+ catch( Throwable e )
+ {
+ getLogger().error( "storage failure", e );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // utils
+ //
------------------------------------------------------------------------
+
+ protected boolean getRestartPolicy()
+ {
+ Preferences prefs = getPreferences();
+ return prefs.getBoolean( "restart", true );
+ }
+
+ protected String getActivationClassname() throws ProfileException
+ {
+ Preferences prefs = getPreferences();
+ String classname = prefs.get( "classname", null );
+ if( null == classname )
+ {
+ final String error =
+ "Activation profile does not declare the target classname.";
+ throw new ProfileException( error );
+ }
+ else
+ {
+ return classname;
+ }
+ }
+
+ private void store( ActivationProfile profile )
+ {
+ super.store( profile );
+ throw new UnsupportedOperationException( "store/1" );
+ }
+}
- svn commit: r2805 - in development/main/depot: console/src/main/net/dpml/depot/profile station/src/main/net/dpml/depot/station, mcconnell, 06/08/2005
Archive powered by MHonArc 2.6.24.