notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2799 - development/main/depot/console/src/main/net/dpml/depot/profile
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2799 - development/main/depot/console/src/main/net/dpml/depot/profile
- Date: Wed, 08 Jun 2005 12:42:02 -0400
Author: mcconnell AT dpml.net
Date: Wed Jun 8 12:42:02 2005
New Revision: 2799
Added:
development/main/depot/console/src/main/net/dpml/depot/profile/
development/main/depot/console/src/main/net/dpml/depot/profile/BootstrapProfile.java
development/main/depot/console/src/main/net/dpml/depot/profile/DepotManager.java
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
development/main/depot/console/src/main/net/dpml/depot/profile/PluginProfile.java
development/main/depot/console/src/main/net/dpml/depot/profile/Profile.java
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileException.java
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileStorage.java
Log:
Add deata models for application profiles.
Added:
development/main/depot/console/src/main/net/dpml/depot/profile/BootstrapProfile.java
==============================================================================
--- (empty file)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/BootstrapProfile.java
Wed Jun 8 12:42:02 2005
@@ -0,0 +1,69 @@
+/*
+ * 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.profile;
+
+import java.net.URL;
+import java.util.Date;
+import java.util.Properties;
+
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.manager.DefaultManager;
+import net.dpml.transit.management.Home;
+
+/**
+ * A ProfileModel maintains information about the configuration
+ * of an application profile.
+ */
+public class BootstrapProfile extends Profile
+{
+ private String m_classname;
+ private String[] m_classpath;
+
+ public BootstrapProfile(
+ Logger logger, Date creation, Home home, String title,
+ Properties properties, Connection connection,
+ String classname, String[] classpath )
+ throws NullPointerException
+ {
+ super( logger, creation, home, title, properties, connection );
+
+ m_classname = classname;
+ m_classpath = classpath;
+ }
+
+ public String getClassname()
+ {
+ return m_classname;
+ }
+
+ public void setClassname( String classname )
+ {
+ m_classname = classname;
+ }
+
+ public String[] getClasspath()
+ {
+ return m_classpath;
+ }
+
+ public void setClasspath( String[] classpath )
+ {
+ m_classpath = classpath;
+ }
+}
Added:
development/main/depot/console/src/main/net/dpml/depot/profile/DepotManager.java
==============================================================================
--- (empty file)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/DepotManager.java
Wed Jun 8 12:42:02 2005
@@ -0,0 +1,50 @@
+/*
+ * 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.profile;
+
+import java.net.URI;
+import java.util.Properties;
+import java.util.Date;
+
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.manager.DefaultManager;
+import net.dpml.transit.management.Home;
+
+/**
+ * A ProfileModel maintains information about the configuration
+ * of an application profile.
+ */
+public class DepotManager extends DefaultManager
+{
+ private Profile[] m_profiles;
+
+ public DepotManager( Logger logger, Date creation, Home home, Profile[]
profiles )
+ throws NullPointerException
+ {
+ super( logger, creation, home );
+
+ m_profiles = profiles;
+ }
+
+ public Profile[] getProfiles()
+ {
+ return m_profiles;
+ }
+
+}
Added:
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
==============================================================================
--- (empty file)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
Wed Jun 8 12:42:02 2005
@@ -0,0 +1,119 @@
+/*
+ * 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.profile;
+
+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 net.dpml.transit.model.Logger;
+import net.dpml.transit.management.Home;
+import net.dpml.transit.management.ModificationEvent;
+import net.dpml.transit.builder.AbstractStorageUnit;
+
+/**
+ * A DepotStorage maintains persistent records of application profiles.
+ */
+public class DepotStorage extends AbstractStorageUnit implements Home
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private DepotManager m_depot;
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ public DepotStorage(
+ Preferences prefs, Logger logger, Date creation, boolean policy )
+ throws ProfileException
+ {
+ super( prefs, logger, creation, policy );
+
+ Profile[] profiles = getProfiles();
+ m_depot = new DepotManager( logger, creation, this, profiles );
+ }
+
+ //
------------------------------------------------------------------------
+ // 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
+ {
+ DepotManager manager = (DepotManager) event.getManager();
+ Date date = new Date();
+ store( manager );
+ manager.setCreationDate( date );
+ }
+ catch( Throwable e )
+ {
+ getLogger().error( "storage failure", e );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // utils
+ //
------------------------------------------------------------------------
+
+ private Profile[] getProfiles() throws ProfileException
+ {
+ Preferences prefs = getPreferences().node( "profiles" );
+ try
+ {
+ String[] names = prefs.childrenNames();
+ Profile[] profiles = new Profile[ names.length ];
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ Preferences p = prefs.node( name );
+ Logger logger = getLogger().getChildLogger( name );
+ boolean policy = getStoragePolicy();
+ Date creation = getCreationDate();
+ ProfileStorage store = new ProfileStorage( p, logger,
creation, policy );
+ profiles[i] = store.getProfile();
+ }
+ return profiles;
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "internal error while resolving porofiles due to
non-availability of the preferences store.";
+ throw new ProfileException( error, e );
+ }
+ }
+
+ private void store( DepotManager manager )
+ {
+ throw new UnsupportedOperationException( "store/1" );
+ }
+}
Added:
development/main/depot/console/src/main/net/dpml/depot/profile/PluginProfile.java
==============================================================================
--- (empty file)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/PluginProfile.java
Wed Jun 8 12:42:02 2005
@@ -0,0 +1,54 @@
+/*
+ * 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.profile;
+
+import java.net.URI;
+import java.util.Date;
+import java.util.Properties;
+
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.management.Home;
+
+/**
+ * A ProfileModel maintains information about the configuration
+ * of an application profile.
+ */
+public class PluginProfile extends Profile
+{
+ private URI m_uri;
+
+ public PluginProfile(
+ Logger logger, Date creation, Home home, String title,
+ Properties properties, Connection connection, URI uri )
+ {
+ super( logger, creation, home, title, properties, connection );
+
+ m_uri = uri;
+ }
+
+ public URI getURI()
+ {
+ return m_uri;
+ }
+
+ public void setURI( URI uri )
+ {
+ m_uri = uri;
+ }
+}
Added:
development/main/depot/console/src/main/net/dpml/depot/profile/Profile.java
==============================================================================
--- (empty file)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/Profile.java
Wed Jun 8 12:42:02 2005
@@ -0,0 +1,110 @@
+/*
+ * 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.profile;
+
+import java.net.URI;
+import java.util.Properties;
+import java.util.Date;
+
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.manager.DefaultManager;
+import net.dpml.transit.management.Home;
+
+/**
+ * A ProfileModel maintains information about the configuration
+ * of an application profile.
+ */
+public class Profile extends DefaultManager
+{
+ private String m_title;
+ private Properties m_properties;
+ private Connection m_connection;
+
+ public Profile( Logger logger, Date creation, Home home, String title,
Properties properties, Connection connection )
+ throws NullPointerException
+ {
+ super( logger, creation, home );
+
+ m_title = title;
+ m_properties = properties;
+ m_connection = connection;
+ }
+
+ public String getTitle()
+ {
+ return m_title;
+ }
+
+ public void setTitle( String title )
+ {
+ m_title = title;
+ }
+
+ public Properties getSystemProperties()
+ {
+ return m_properties;
+ }
+
+ public void setSystemProperties( Properties properties )
+ {
+ m_properties = properties;
+ }
+
+ public Connection getConnection()
+ {
+ return m_connection;
+ }
+
+ public void setConnection( Connection connection )
+ {
+ m_connection = connection;
+ }
+
+ public static class Connection
+ {
+ private String m_host;
+ private int m_port;
+
+ public Connection( String host, int port )
+ {
+ m_host = host;
+ m_port = port;
+ }
+
+ public String getHost()
+ {
+ return m_host;
+ }
+
+ public void setHost( String host )
+ {
+ m_host = host;
+ }
+
+ public int getPort()
+ {
+ return m_port;
+ }
+
+ public void setPort( int port )
+ {
+ m_port = port;
+ }
+ }
+}
Added:
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileException.java
==============================================================================
--- (empty file)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileException.java
Wed Jun 8 12:42:02 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 2004-2005 Niclas Hedhman.
+ *
+ * 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.profile;
+
+/**
+ * Exception to indicate that there was a profile related error.
+ *
+ * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
+ * @version $Id: TransitException.java 2786 2005-06-08 03:02:29Z
mcconnell AT dpml.net $
+ */
+public class ProfileException extends Exception
+{
+ /**
+ * Construct a new <code>ProfileException</code> instance.
+ *
+ * @param message The detail message for this exception.
+ */
+ public ProfileException( final String message )
+ {
+ this( message, null );
+ }
+
+ /**
+ * Construct a new <code>ProfileException</code> instance.
+ *
+ * @param message The detail message for this exception.
+ * @param cause the root cause of the exception
+ */
+ public ProfileException( final String message, final Throwable cause )
+ {
+ super( message, cause );
+ }
+}
+
Added:
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileStorage.java
==============================================================================
--- (empty file)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/ProfileStorage.java
Wed Jun 8 12:42:02 2005
@@ -0,0 +1,218 @@
+/*
+ * 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.profile;
+
+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 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;
+
+/**
+ * A ProfileHome maintains a persistent application profile.
+ */
+public class ProfileStorage extends AbstractStorageUnit implements Home
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private final Profile m_profile;
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ public ProfileStorage(
+ Preferences prefs, Logger logger, Date creation, boolean policy )
+ throws ProfileException
+ {
+ super( prefs, logger, creation, policy );
+
+ String title = prefs.get( "title", prefs.name() );
+ Properties properties = getProperties();
+ Connection connection = getConnection();
+ String path = prefs.get( "plugin", null );
+ if( null != path )
+ {
+ try
+ {
+ URI uri = new URI( path );
+ m_profile = new PluginProfile( logger, creation, this,
title, properties, 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, title, properties, connection,
classname, classpath );
+ }
+ else
+ {
+ final String error =
+ "Requested profile '" + prefs
+ + "' does not declare either a classname or a plugin
attribute.";
+ throw new ProfileException( error );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // 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
+ {
+ Profile manager = (Profile) event.getManager();
+ Date date = new Date();
+ store( manager );
+ manager.setCreationDate( date );
+ }
+ catch( Throwable e )
+ {
+ getLogger().error( "storage failure", e );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // utils
+ //
------------------------------------------------------------------------
+
+ Profile getProfile()
+ {
+ return m_profile;
+ }
+
+ private String[] getClasspath() throws ProfileException
+ {
+ Preferences prefs = getPreferences().node( "classpath" );
+ try
+ {
+ return prefs.keys();
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "Cannot construct a classpath due to non-availability of the
preferences store.";
+ throw new ProfileException( error, e );
+ }
+ }
+
+ private Connection getConnection() throws ProfileException
+ {
+ try
+ {
+ if( false == getPreferences().nodeExists( "connection" ) )
+ {
+ return null;
+ }
+ else
+ {
+ Preferences prefs = getPreferences().node( "connection" );
+ String host = prefs.get( "host", null );
+ int port = prefs.getInt( "port", 1099 );
+ return new Connection( host, port );
+ }
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "Cannot construct a connection due to non-availability of the
preferences store.";
+ throw new ProfileException( error, e );
+ }
+ }
+
+ private Properties getProperties() throws ProfileException
+ {
+ Properties properties = new Properties();
+ Preferences prefs = getPreferences().node( "properties" );
+ try
+ {
+ String[] keys = prefs.keys();
+ 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 );
+ }
+ }
+ return properties;
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "Internal error while resolving persistent application
properties.";
+ 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 )
+ {
+ throw new UnsupportedOperationException( "savePluginProfile/1" );
+ }
+}
- svn commit: r2799 - development/main/depot/console/src/main/net/dpml/depot/profile, mcconnell, 06/08/2005
Archive powered by MHonArc 2.6.24.