Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2909 - in development/main/metro: central/src/main/net/dpml/metro/central composition/control composition/control/src/main/net/dpml/composition/control part/src/main/net/dpml/part/control

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: r2909 - in development/main/metro: central/src/main/net/dpml/metro/central composition/control composition/control/src/main/net/dpml/composition/control part/src/main/net/dpml/part/control
  • Date: Thu, 23 Jun 2005 09:01:25 -0400

Author: mcconnell AT dpml.net
Date: Thu Jun 23 09:01:25 2005
New Revision: 2909

Added:

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionControllerContext.java
Removed:

development/main/metro/central/src/main/net/dpml/metro/central/DefaultMetroModel.java
Modified:

development/main/metro/central/src/main/net/dpml/metro/central/MetroHelper.java

development/main/metro/central/src/main/net/dpml/metro/central/PartContentHandler.java

development/main/metro/central/src/main/net/dpml/metro/central/PartContentHandlerControlPanel.java
development/main/metro/composition/control/build.xml

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
development/main/metro/part/src/main/net/dpml/part/control/Controller.java

development/main/metro/part/src/main/net/dpml/part/control/ControllerContext.java
Log:
improve the relationship between a context model established by transit and
the context supplied to the metro controller

Modified:
development/main/metro/central/src/main/net/dpml/metro/central/MetroHelper.java
==============================================================================
---
development/main/metro/central/src/main/net/dpml/metro/central/MetroHelper.java
(original)
+++
development/main/metro/central/src/main/net/dpml/metro/central/MetroHelper.java
Thu Jun 23 09:01:25 2005
@@ -63,7 +63,6 @@
// state
//------------------------------------------------------------------

- private ControllerContext m_context;
private CompositionManager m_manager;

//------------------------------------------------------------------
@@ -83,8 +82,7 @@
Logger logger = new LoggingAdapter( "metro" );
DefaultContentModel model =
new DefaultContentModel( logger, null, type, title, properties );
- m_context = new DefaultMetroModel( model );
- m_manager = new CompositionManager( m_context );
+ m_manager = new CompositionManager( model );
}

public MetroHelper( ContentModel model ) throws Exception
@@ -93,9 +91,7 @@
{
throw new NullPointerException( "model" );
}
-
- m_context = new DefaultMetroModel( model );
- m_manager = new CompositionManager( m_context );
+ m_manager = new CompositionManager( model );
}

//------------------------------------------------------------------
@@ -111,7 +107,7 @@
{
try
{
- File base = m_context.getWorkingDirectory();
+ File base = m_manager.getWorkingDirectory();
File target = new File( base, path );
return target.toURI();
}

Modified:
development/main/metro/central/src/main/net/dpml/metro/central/PartContentHandler.java
==============================================================================
---
development/main/metro/central/src/main/net/dpml/metro/central/PartContentHandler.java
(original)
+++
development/main/metro/central/src/main/net/dpml/metro/central/PartContentHandler.java
Thu Jun 23 09:01:25 2005
@@ -71,9 +71,7 @@
{
throw new NullPointerException( "model" );
}
-
- ControllerContext context = new DefaultMetroModel( model );
- m_manager = new CompositionManager( context );
+ m_manager = new CompositionManager( model );
}

//------------------------------------------------------------------

Modified:
development/main/metro/central/src/main/net/dpml/metro/central/PartContentHandlerControlPanel.java
==============================================================================
---
development/main/metro/central/src/main/net/dpml/metro/central/PartContentHandlerControlPanel.java
(original)
+++
development/main/metro/central/src/main/net/dpml/metro/central/PartContentHandlerControlPanel.java
Thu Jun 23 09:01:25 2005
@@ -42,6 +42,11 @@
import javax.swing.ImageIcon;
import javax.swing.JTextField;

+import net.dpml.transit.model.ContentModel;
+
+import net.dpml.composition.control.CompositionControllerContext;
+
+
/**
* A registry of descriptions of plugable content handlers. This
implementation
* maps user defined preferences to instance of ContentHandlerDescriptor.
@@ -65,10 +70,14 @@
private PropertyChangeSupport m_propertyChangeSupport;


- public PartContentHandlerControlPanel( Dialog parent )
+ private final CompositionControllerContext m_model;
+
+ public PartContentHandlerControlPanel( Dialog parent, ContentModel model
) throws Exception
{
super( parent );

+ m_model = new CompositionControllerContext( model );
+
m_propertyChangeSupport = new PropertyChangeSupport( this );

setTitle( "Metro FT Content Controller" );
@@ -131,7 +140,7 @@
return label;
}

- private JPanel createBodyContent( JDialog parent )
+ private JPanel createBodyContent( JDialog parent ) throws Exception
{
JPanel panel = new JPanel( new BorderLayout() );
panel.setBackground( Color.white );
@@ -140,7 +149,7 @@
return panel;
}

- private JPanel createStack()
+ private JPanel createStack() throws Exception
{
JPanel stack = new JPanel();
stack.setLayout( new BoxLayout( stack, BoxLayout.Y_AXIS ) );
@@ -191,7 +200,7 @@
return panel;
}

- private JPanel createDirectoryPanel()
+ private JPanel createDirectoryPanel() throws Exception
{
JPanel panel = new JPanel( new BorderLayout() );
panel.setBackground( Color.white );
@@ -205,15 +214,19 @@

JPanel stack = new JPanel();
stack.setLayout( new BoxLayout( stack, BoxLayout.Y_AXIS ) );
- JPanel working = createWorkingDirectoryPanel();
- JPanel temp = createTempDirectoryPanel();
+
+ String workPath = m_model.getWorkingDirectoryPath();
+ String tempPath = m_model.getTempDirectoryPath();
+
+ JPanel working = createWorkingDirectoryPanel( workPath );
+ JPanel temp = createTempDirectoryPanel( tempPath );
stack.add( working );
stack.add( temp );
panel.add( stack, BorderLayout.NORTH );
return panel;
}

- private JPanel createWorkingDirectoryPanel()
+ private JPanel createWorkingDirectoryPanel( String path )
{
JPanel panel = new JPanel( new BorderLayout() );
panel.setBackground( Color.white );
@@ -235,7 +248,7 @@
dirLabelHolder.add( dirLabel, BorderLayout.WEST );
dirLabelHolder.setBackground( Color.white );
dirLabelHolder.setBorder( new EmptyBorder( 0, 0, 3, 0 ) );
- JTextField dirValue = new JTextField( "${user.dir}" );
+ JTextField dirValue = new JTextField( path );
stack.add( dirLabelHolder );
stack.add( dirValue );

@@ -245,7 +258,7 @@
return panel;
}

- private JPanel createTempDirectoryPanel()
+ private JPanel createTempDirectoryPanel( String path )
{
JPanel panel = new JPanel( new BorderLayout() );
panel.setBackground( Color.white );
@@ -268,7 +281,7 @@
dirLabelHolder.add( dirLabel, BorderLayout.WEST );
dirLabelHolder.setBackground( Color.white );
dirLabelHolder.setBorder( new EmptyBorder( 0, 0, 3, 0 ) );
- JTextField dirValue = new JTextField( "${java.temp.dir}" );
+ JTextField dirValue = new JTextField( path );
stack.add( dirLabelHolder );
stack.add( dirValue );


Modified: development/main/metro/composition/control/build.xml
==============================================================================
--- development/main/metro/composition/control/build.xml (original)
+++ development/main/metro/composition/control/build.xml Thu Jun 23
09:01:25 2005
@@ -18,6 +18,7 @@
<rmic base="${basedir}/target/classes" classpathref="build.path">
<include name="**/DefaultControllerModel.class"/>
<include name="**/CompositionManager.class"/>
+ <include name="**/CompositionControllerContext.class"/>
<include name="**/CompositionController.class"/>
<include name="**/CompositionPartHandler.class"/>
<include name="**/CompositionModel.class"/>

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
Thu Jun 23 09:01:25 2005
@@ -18,6 +18,7 @@

package net.dpml.composition.control;

+import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
@@ -53,14 +54,14 @@
import net.dpml.part.control.Monitor;
import net.dpml.part.control.PartNotFoundException;
import net.dpml.part.control.Manager;
-
import net.dpml.part.model.Model;
import net.dpml.part.model.ModelException;
import net.dpml.part.model.Component;
import net.dpml.part.model.Provider;
-
import net.dpml.part.part.Part;

+import net.dpml.transit.model.ContentModel;
+
/**
* A initial test controller.
*
@@ -90,14 +91,14 @@
// constructor
//--------------------------------------------------------------------

- CompositionController( ControllerContext context ) throws RemoteException
+ CompositionController( ContentModel context ) throws RemoteException
{
super();

- m_logger = getLoggerForURI( context.getURI() );
+ m_context = new CompositionControllerContext( context );
+ m_logger = getLoggerForURI( m_context.getURI() );
m_logger.info( "metro controller established" );
m_monitor = new DefaultMonitor( m_logger );
- m_context = context;
m_valueController = new ValueController( this );
ComponentController manager = new ComponentController( m_monitor,
this );
m_lifestyleHandler = new LifestyleHandler( m_monitor, manager );
@@ -144,6 +145,16 @@
// Controller
//--------------------------------------------------------------------

+ public File getWorkingDirectory() throws RemoteException
+ {
+ return m_context.getWorkingDirectory();
+ }
+
+ public File getTempDirectory() throws RemoteException
+ {
+ return m_context.getTempDirectory();
+ }
+
/**
* Return a system resource relative to the supplied urn. Standard
* urn values are listed in the following table.

Added:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionControllerContext.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionControllerContext.java
Thu Jun 23 09:01:25 2005
@@ -0,0 +1,304 @@
+/*
+ * 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.control;
+
+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.part.control.ControllerContext;
+import net.dpml.part.control.ControllerContextListener;
+import net.dpml.part.control.ControllerContextEvent;
+
+import net.dpml.transit.model.DefaultModel;
+import net.dpml.transit.model.ContentModel;
+import net.dpml.transit.model.DefaultContentModel;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.util.PropertyResolver;
+
+/**
+ * The CompositionControllerContext class wraps a ContentModel and supplies
convinience
+ * operations that translate ContentModel properties and events to type-safe
values used
+ * in the conposition controller.
+ *
+ * @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 CompositionControllerContext extends DefaultModel implements
ControllerContext
+{
+
//----------------------------------------------------------------------------
+ // state
+
//----------------------------------------------------------------------------
+
+ /**
+ * Working directory.
+ */
+ private File m_work;
+
+ /**
+ * Temp directory.
+ */
+ private File m_temp;
+
+ private final ContentModel m_model;
+
+ private URI m_uri;
+
+
//----------------------------------------------------------------------------
+ // constructor
+
//----------------------------------------------------------------------------
+
+ public CompositionControllerContext( ContentModel model ) throws
RemoteException
+ {
+ super( "metro" );
+
+ m_model = model;
+
+ // TODO: add listeners to changes to the content model properties
+
+ String work = getWorkingDirectoryPath();
+ String temp = getTempDirectoryPath();
+
+ String domain = model.getProperty( "domain.name", "local" );
+
+ m_uri = setupContextURI( domain );
+ m_work = getWorkingDirectory( work );
+ m_temp = getTempDirectory( temp );
+ }
+
+
//----------------------------------------------------------------------------
+ // ControllerContext
+
//----------------------------------------------------------------------------
+
+ /**
+ * Return the root working directory path.
+ *
+ * @return directory path representing the root of the working directory
hierachy
+ */
+ public String getWorkingDirectoryPath() throws RemoteException
+ {
+ return m_model.getProperty( "work.dir", "${dpml.data}/work" );
+ }
+
+ /**
+ * Return the root temporary directory path.
+ *
+ * @return directory path representing the root of the temporary
directory hierachy.
+ */
+ public String getTempDirectoryPath() throws RemoteException
+ {
+ return m_model.getProperty( "temp.dir", "${java.io.tmpdir}" );
+ }
+
+ /**
+ * Return the context uri.
+ *
+ * @return the uri for this context.
+ */
+ public URI getURI() throws RemoteException
+ {
+ return m_uri;
+ }
+
+ /**
+ * Return the root working directory.
+ *
+ * @return directory representing the root of the working directory
hierachy
+ */
+ public File getWorkingDirectory() throws RemoteException
+ {
+ synchronized( m_lock )
+ {
+ return m_work;
+ }
+ }
+
+ /**
+ * Set the root working directory.
+ *
+ * @param dir the root of the working directory hierachy
+ */
+ public void setWorkingDirectory( File dir ) throws RemoteException
+ {
+ synchronized( m_lock )
+ {
+ m_work = dir;
+ }
+ }
+
+ /**
+ * Return the root temporary directory.
+ *
+ * @return directory representing the root of the temporary directory
hierachy.
+ */
+ public File getTempDirectory() throws RemoteException
+ {
+ synchronized( m_lock )
+ {
+ 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 setupContextURI( String domain )
+ {
+ try
+ {
+ return new URI( "metro:" + domain );
+ }
+ catch( Throwable e )
+ {
+ return null;
+ }
+ }
+
+ static class WorkingDirectoryChangeEvent extends ControllerContextEvent
+ {
+ public WorkingDirectoryChangeEvent(
+ ControllerContext source, File oldDir, File newDir )
+ {
+ super( source, oldDir, newDir );
+ }
+ }
+
+ static class TempDirectoryChangeEvent extends ControllerContextEvent
+ {
+ public TempDirectoryChangeEvent(
+ ControllerContext source, File oldDir, File newDir )
+ {
+ super( source, oldDir, newDir );
+ }
+ }
+}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
Thu Jun 23 09:01:25 2005
@@ -46,12 +46,7 @@
import net.dpml.part.model.ModelException;
import net.dpml.part.part.Part;

-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-
+import net.dpml.transit.model.ContentModel;

/**
* The CompositionManager is a top-level manager responsible for the
management
@@ -66,7 +61,6 @@
// state
//--------------------------------------------------------------------

- private final ControllerContext m_context;
private final ClassLoader m_classloader;
private final Set m_components = Collections.synchronizedSet( new
HashSet() );
private final Map m_instances = new Hashtable();
@@ -75,22 +69,12 @@
// constructor
//--------------------------------------------------------------------

- public CompositionManager( ControllerContext context ) throws Exception
+ public CompositionManager( ContentModel context ) throws Exception
{
super( context );

- m_context = context;
m_classloader =
net.dpml.composition.info.Type.class.getClassLoader();
-
setShutdownHook( this );
- String[] args = context.getArgs();
- CommandLine line = getCommandLine( args );
- String[] arguments = line.getArgs();
- URI uri = getLauchTargetURI( arguments );
- if( null != uri )
- {
- addRootPart( uri );
- }
}

//--------------------------------------------------------------------
@@ -213,42 +197,6 @@
//
}

- private URI getLauchTargetURI( String[] arguments ) throws
RemoteException
- {
- if( arguments.length == 0 )
- {
- return null;
- }
- else if( arguments.length == 1 )
- {
- String spec = arguments[0];
- return createURI( spec );
- }
- else
- {
- final String error =
- "Multi-part loading not supported at this time.";
- throw new UnsupportedOperationException( error );
- }
- }
-
- private CommandLine getCommandLine( String[] args ) throws
RemoteException
- {
- try
- {
- Options options = buildCommandLineOptions();
- CommandLineParser parser = new GnuParser();
- return parser.parse( options, args, false );
- }
- catch( Throwable e )
- {
- URI uri = getURI();
- final String error =
- "Commandline parsing error.";
- throw new ControlRuntimeException( uri, error, e );
- }
- }
-
private void addRootPart( URI uri ) throws RemoteException
{
getLogger().info( "adding root part: " + uri );
@@ -296,44 +244,4 @@
}
);
}
-
- //--------------------------------------------------------------------
- // static utilities
- //--------------------------------------------------------------------
-
- /*
- private static URI createPartition( SystemContext system )
- {
- URI uri = system.getDomain();
- String path = uri.getSchemeSpecificPart();
- try
- {
- if( path.endsWith( "/" ) )
- {
- return new URI( "metro", path, null );
- }
- else
- {
- return new URI( "metro", path + "/", null );
- }
- }
- catch( URISyntaxException e )
- {
- final String error =
- "Internal exception while attempting to construct a part uri
relative to the system context uri ["
- + uri.toString()
- + "].";
- throw new RuntimeException( error, e );
- }
- }
- */
-
- private static Options buildCommandLineOptions()
- {
- Options options = new Options();
- options.addOption(
- new Option( "audit", "Enable audit mode." ) );
- return options;
- }
-
}

Modified:
development/main/metro/part/src/main/net/dpml/part/control/Controller.java
==============================================================================
---
development/main/metro/part/src/main/net/dpml/part/control/Controller.java
(original)
+++
development/main/metro/part/src/main/net/dpml/part/control/Controller.java
Thu Jun 23 09:01:25 2005
@@ -18,6 +18,7 @@

package net.dpml.part.control;

+import java.io.File;
import java.net.URI;
import java.rmi.RemoteException;

@@ -37,6 +38,10 @@
*/
public interface Controller extends Control
{
+ File getWorkingDirectory() throws RemoteException;
+
+ File getTempDirectory() throws RemoteException;
+
/**
* Return a resource relative to the supplied urn. Standard
* urn values are listed in the following table.

Modified:
development/main/metro/part/src/main/net/dpml/part/control/ControllerContext.java
==============================================================================
---
development/main/metro/part/src/main/net/dpml/part/control/ControllerContext.java
(original)
+++
development/main/metro/part/src/main/net/dpml/part/control/ControllerContext.java
Thu Jun 23 09:01:25 2005
@@ -38,10 +38,18 @@
URI getURI() throws RemoteException;

/**
- * Return any command line arguments.
- * @return the possibly empty set of command line arguments.
+ * Return the root working directory path.
+ *
+ * @return directory path representing the root of the working directory
hierachy
+ */
+ String getWorkingDirectoryPath() throws RemoteException;
+
+ /**
+ * Return the root temporary directory path.
+ *
+ * @return directory path representing the root of the temporary
directory hierachy.
*/
- String[] getArgs() throws RemoteException;
+ String getTempDirectoryPath() throws RemoteException;

/**
* Return the root working directory.



  • svn commit: r2909 - in development/main/metro: central/src/main/net/dpml/metro/central composition/control composition/control/src/main/net/dpml/composition/control part/src/main/net/dpml/part/control, mcconnell, 06/23/2005

Archive powered by MHonArc 2.6.24.

Top of Page