notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2867 - development/main/metro/composition/part/src/main/net/dpml/composition/part
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2867 - development/main/metro/composition/part/src/main/net/dpml/composition/part
- Date: Fri, 17 Jun 2005 08:43:01 -0400
Author: mcconnell AT dpml.net
Date: Fri Jun 17 08:43:01 2005
New Revision: 2867
Added:
development/main/metro/composition/part/src/main/net/dpml/composition/part/CompositionContentHandlerModel.java
development/main/metro/composition/part/src/main/net/dpml/composition/part/CompositionContentHandlerStorageUnit.java
Log:
add content handler model and home
Added:
development/main/metro/composition/part/src/main/net/dpml/composition/part/CompositionContentHandlerModel.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/part/src/main/net/dpml/composition/part/CompositionContentHandlerModel.java
Fri Jun 17 08:43:01 2005
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 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.composition.part;
+
+import java.io.File;
+import java.net.URI;
+import java.rmi.RemoteException;
+import java.util.Date;
+import java.util.Map;
+import java.util.EventObject;
+import java.util.EventListener;
+import java.util.WeakHashMap;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+
+import net.dpml.composition.event.WeakEventProducer;
+
+import net.dpml.parts.control.ControllerContext;
+import net.dpml.parts.control.ControllerContextListener;
+import net.dpml.parts.control.ControllerContextEvent;
+
+import net.dpml.transit.home.ContentHome;
+import net.dpml.transit.model.ContentRegistryModel;
+import net.dpml.transit.model.DefaultContentModel;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.util.PropertyResolver;
+
+
+/**
+ * The ControllerContext is a management service supplied to a controller
instance. It
+ * provides support for operations though which the context state may be
updated and
+ * a provision for default values based on underlying preferences.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class CompositionContentHandlerModel extends DefaultContentModel
implements ControllerContext
+{
+
//----------------------------------------------------------------------------
+ // state
+
//----------------------------------------------------------------------------
+
+ private Preferences m_preferences;
+
+ private File m_work;
+
+ private File m_temp;
+
+ private Map m_listeners = new WeakHashMap();
+
+ /**
+ * Internal synchronization lock.
+ */
+ protected final Object m_lock = new Object();
+
+
//----------------------------------------------------------------------------
+ // constructor
+
//----------------------------------------------------------------------------
+
+ public CompositionContentHandlerModel(
+ Logger logger, Date creation, ContentHome home,
+ URI uri, String type, String title, String work, String temp ) throws
RemoteException
+ {
+ super( logger, creation, home, uri, type, title );
+ m_work = getWorkingDirectory( work );
+ m_temp = getTempDirectory( temp );
+ }
+
+
//----------------------------------------------------------------------------
+ // ControllerContext
+
//----------------------------------------------------------------------------
+
+ /**
+ * Return the context uri.
+ *
+ * @return the uri for this context.
+ */
+ public URI getURI() throws RemoteException
+ {
+ return CONTEXT_URI;
+ }
+
+ /**
+ * Return the root working directory.
+ *
+ * @return directory representing the root of the working directory
hierachy
+ */
+ public File getWorkingDirectory() throws RemoteException
+ {
+ synchronized( m_work )
+ {
+ return m_work;
+ }
+ }
+
+ /**
+ * Return the root temporary directory.
+ *
+ * @return directory representing the root of the temporary directory
hierachy.
+ */
+ public File getTempDirectory() throws RemoteException
+ {
+ synchronized( m_temp )
+ {
+ return m_temp;
+ }
+ }
+
+ /**
+ * Add the supplied controller context listener to the controller
context. A
+ * controller implementation should not maintain strong references to
supplied
+ * listeners.
+ *
+ * @param listener the controller context listener to add
+ */
+ public void addControllerContextlistener( ControllerContextListener
listener )
+ throws RemoteException
+ {
+ addListener( listener );
+ }
+
+ /**
+ * Remove the supplied controller context listener from the controller
context.
+ *
+ * @param listener the controller context listener to remove
+ */
+ public void removeControllerContextlistener( ControllerContextListener
listener )
+ throws RemoteException
+ {
+ removeListener( listener );
+ }
+
+
//----------------------------------------------------------------------------
+ // private
+
//----------------------------------------------------------------------------
+
+ protected void processEvent( EventObject event )
+ {
+ if( event instanceof WorkingDirectoryChangeEvent )
+ {
+ processWorkingDirectoryChangeEvent(
(WorkingDirectoryChangeEvent) event );
+ }
+ else if( event instanceof TempDirectoryChangeEvent )
+ {
+ processTempDirectoryChangeEvent( (TempDirectoryChangeEvent)
event );
+ }
+ else
+ {
+ super.processEvent( event );
+ }
+ }
+
+ public void processWorkingDirectoryChangeEvent(
WorkingDirectoryChangeEvent event )
+ {
+ EventListener[] listeners = super.listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener eventListener = listeners[i];
+ if( eventListener instanceof ControllerContextListener )
+ {
+ ControllerContextListener listener =
(ControllerContextListener) eventListener;
+ try
+ {
+ listener.workingDirectoryChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "ControllerContextListener working dir change
notification error.";
+ getLogger().error( error, e );
+ }
+ }
+ }
+ }
+
+ public void processTempDirectoryChangeEvent( TempDirectoryChangeEvent
event )
+ {
+ EventListener[] listeners = super.listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener eventListener = listeners[i];
+ if( eventListener instanceof ControllerContextListener )
+ {
+ ControllerContextListener listener =
(ControllerContextListener) eventListener;
+ try
+ {
+ listener.tempDirectoryChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "ControllerContextListener temp dir change
notification error.";
+ getLogger().error( error, e );
+ }
+ }
+ }
+ }
+
+ private File getWorkingDirectory( String value )
+ {
+ Properties properties = System.getProperties();
+ String path = PropertyResolver.resolve( properties, value );
+ return new File( path );
+ }
+
+ private File getTempDirectory( String value )
+ {
+ Properties properties = System.getProperties();
+ String path = PropertyResolver.resolve( properties, value );
+ return new File( path );
+ }
+
+
//----------------------------------------------------------------------------
+ // static (private)
+
//----------------------------------------------------------------------------
+
+ private static URI CONTEXT_URI = setupContextURI();
+
+ private static URI setupContextURI()
+ {
+ try
+ {
+ return new URI( "metro:local" );
+ }
+ catch( Throwable e )
+ {
+ return null;
+ }
+ }
+
+ static class WorkingDirectoryChangeEvent extends ControllerContextEvent
+ {
+ public WorkingDirectoryChangeEvent(
+ CompositionContentHandlerModel source, File oldDir, File newDir )
+ {
+ super( source, oldDir, newDir );
+ }
+ }
+
+ static class TempDirectoryChangeEvent extends ControllerContextEvent
+ {
+ public TempDirectoryChangeEvent(
+ CompositionContentHandlerModel source, File oldDir, File newDir )
+ {
+ super( source, oldDir, newDir );
+ }
+ }
+}
Added:
development/main/metro/composition/part/src/main/net/dpml/composition/part/CompositionContentHandlerStorageUnit.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/part/src/main/net/dpml/composition/part/CompositionContentHandlerStorageUnit.java
Fri Jun 17 08:43:01 2005
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 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.composition.part;
+
+import java.io.File;
+import java.net.URI;
+import java.rmi.RemoteException;
+import java.util.Date;
+import java.util.prefs.Preferences;
+
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.ContentModel;
+import net.dpml.transit.unit.ContentStorageUnit;
+import net.dpml.transit.unit.BuilderException;
+
+/**
+ * The ControllerContext is a management service supplied to a controller
instance. It
+ * provides support for operations though which the context state may be
updated and
+ * a provision for default values based on underlying preferences.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public class CompositionContentHandlerStorageUnit extends ContentStorageUnit
+{
+
//----------------------------------------------------------------------------
+ // state
+
//----------------------------------------------------------------------------
+
+ private final ContentModel m_model;
+
+ private String m_work;
+
+ private String m_temp;
+
+
//----------------------------------------------------------------------------
+ // constructor
+
//----------------------------------------------------------------------------
+
+ /**
+ * Creation of a new CompositionContentHandlerStorageUnit using a
supplied
+ * preferences node.
+ *
+ * @param prefs the preferences node assigned to the storage unit from
which default
+ * values may be resolved
+ */
+ public CompositionContentHandlerStorageUnit(
+ Preferences prefs, Logger logger, Date creation, Boolean policy )
+ {
+ super( prefs, logger, creation, policy.booleanValue() );
+ m_model = createContentModel();
+ }
+
+
//----------------------------------------------------------------------------
+ // ContentStorageUnit
+
//----------------------------------------------------------------------------
+
+ protected ContentModel createContentModel()
+ {
+ Preferences prefs = getPreferences();
+ Logger logger = getLogger();
+ Date creation = getCreationDate();
+ URI uri = getCodeBaseURI();
+ String type = getType();
+ String title = getTitle();
+ String work = getWorkingDirectory();
+ String temp = getTempDirectory();
+ try
+ {
+ return new CompositionContentHandlerModel(
+ logger, creation, this, uri, type, title, work, temp );
+ }
+ catch( RemoteException e )
+ {
+ final String error =
+ "Unable to construct part content model due to a remote
exception.";
+ throw new BuilderException( error, e );
+ }
+ }
+
+
//----------------------------------------------------------------------------
+ // impl
+
//----------------------------------------------------------------------------
+
+
+ private String getWorkingDirectory()
+ {
+ Preferences prefs = getPreferences();
+ return prefs.get( "working-directory", "${user.dir}" );
+ }
+
+ private String getTempDirectory()
+ {
+ Preferences prefs = getPreferences();
+ return prefs.get( "temp-directory", "${java.temp.dir}" );
+ }
+}
- svn commit: r2867 - development/main/metro/composition/part/src/main/net/dpml/composition/part, mcconnell, 06/17/2005
Archive powered by MHonArc 2.6.24.