Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1271 - in development/main: central/site/src/docs/products/transit central/tutorials magic/bootstrap/src/main/net/dpml/magic/bootstrap magic/core/src/main/net/dpml/magic magic/core/src/main/net/dpml/magic/tasks metro/main/src/main/net/dpml/metro metro/system/impl/src/main/net/dpml/system/impl planet/facilities planet/facilities/http/impl/src/main/net/dpml/http/impl transit/handler/src/main/net/dpml/transit transit/handler/src/main/net/dpml/transit/artifact

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1271 - in development/main: central/site/src/docs/products/transit central/tutorials magic/bootstrap/src/main/net/dpml/magic/bootstrap magic/core/src/main/net/dpml/magic magic/core/src/main/net/dpml/magic/tasks metro/main/src/main/net/dpml/metro metro/system/impl/src/main/net/dpml/system/impl planet/facilities planet/facilities/http/impl/src/main/net/dpml/http/impl transit/handler/src/main/net/dpml/transit transit/handler/src/main/net/dpml/transit/artifact
  • Date: Thu, 23 Dec 2004 16:05:10 +0100

Author: niclas
Date: Thu Dec 23 16:05:10 2004
New Revision: 1271

Added:
development/main/central/tutorials/module.xml (contents, props changed)
Modified:
development/main/central/site/src/docs/products/transit/index.xml
development/main/central/tutorials/index.xml

development/main/magic/bootstrap/src/main/net/dpml/magic/bootstrap/MainTask.java

development/main/magic/bootstrap/src/main/net/dpml/magic/bootstrap/PluginManager.java
development/main/magic/core/src/main/net/dpml/magic/Index.java
development/main/magic/core/src/main/net/dpml/magic/tasks/JavacTask.java
development/main/metro/main/src/main/net/dpml/metro/Metro.java

development/main/metro/system/impl/src/main/net/dpml/system/impl/DefaultSystemContextFactory.java

development/main/metro/system/impl/src/main/net/dpml/system/impl/DefaultSystemCriteria.java

development/main/planet/facilities/http/impl/src/main/net/dpml/http/impl/JsseListener.java
development/main/planet/facilities/index.xml
development/main/transit/handler/src/main/net/dpml/transit/Main.java
development/main/transit/handler/src/main/net/dpml/transit/Transit.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/Util.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
Log:
Now there are too many ripples from Steve's changes, and I need to bolt down
a commit...

Modified: development/main/central/site/src/docs/products/transit/index.xml
==============================================================================
--- development/main/central/site/src/docs/products/transit/index.xml
(original)
+++ development/main/central/site/src/docs/products/transit/index.xml Thu
Dec 23 16:05:10 2004
@@ -30,10 +30,23 @@
<section name="Repository Enabled Solution">

<p>
-A repository enabled application is an application the leverages a local
cache of artifacts that are referenced by logical identifiers. Identifiers
typically reference content in the form of an artifact url such as
artifact:block:dpml/planet/http/dpml-planet-http-server#SNAPSHOT. These
identifiers disassociate the definition of an application from the source of
the resources needed to build and deploy the application.
+A repository enabled application is an application the leverages a local
+cache of artifacts that are referenced by logical identifiers. Identifiers
+typically reference content in the form of an artifact url such as
+artifact:block:dpml/planet/http/dpml-http-server#SNAPSHOT. These
+identifiers disassociate the definition of an application from the source
+of the resources needed to build and deploy the application.
</p>
<p>
-An application will normally make content requests to a local cache manager
which in turn interacts with one or more remote repositories to resolve
application requests. Varying levels of quality of service are provided by
repository systems, for example, a local cache manager can provide a level of
control over which repositories are accesses and provide content validation.
In addition, intelligent remote repositories can provide advanced solutions
including automated generation of artifacts relative to cache manager
requests, content filtering, referral management, and solutions customized
relative to client identity.
+An application will normally make content requests to a local cache manager
+which in turn interacts with one or more remote repositories to resolve
+application requests. Varying levels of quality of service are provided by
+repository systems, for example, a local cache manager can provide a level
+of control over which repositories are accesses and provide content
+validation. In addition, intelligent remote repositories can provide advanced
+solutions including automated generation of artifacts relative to cache
+manager requests, content filtering, referral management, and solutions
+customized relative to client identity.
</p>

<img src="../../images/transit/repositories.png"/>

Modified: development/main/central/tutorials/index.xml
==============================================================================
--- development/main/central/tutorials/index.xml (original)
+++ development/main/central/tutorials/index.xml Thu Dec 23 16:05:10
2004
@@ -6,6 +6,29 @@
uri="artifact:module:dpml/metro/dpml-metro#SNAPSHOT"/>

<!--
+ Tutorial Modules
+ -->
+
+ <project file="module.xml">
+ <info>
+ <group>dpml/metro</group>
+ <name>dpml-metro-tutorials</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ <type>module</type>
+ </info>
+ <plugins>
+ <include key="dpml-magic-checkstyle"/>
+ </plugins>
+ <dependencies>
+ <include key="dpml-magic"/>
+ <include key="dpml-transit"/>
+ <include key="dpml-util"/>
+ </dependencies>
+ </project>
+
+
+ <!--
Hello Tutorial.
-->


Added: development/main/central/tutorials/module.xml
==============================================================================
--- (empty file)
+++ development/main/central/tutorials/module.xml Thu Dec 23 16:05:10
2004
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Copyright 2004 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.
+-->
+
+<project name="dpml-metro-tutorials" default="docs" basedir="."
+ xmlns:magic="antlib:net.dpml.magic"
+ xmlns:x="plugin:dpml/magic/dpml-magic-core">
+
+ <magic:import uri="artifact:template:dpml/magic/standard"/>
+ <magic:import uri="artifact:template:dpml/magic/checkstyle"/>
+
+ <target name="build" depends="standard.build">
+ <x:module index="index.xml">
+ <header>
+ <svn href="http://paris.dpml.net/svn/development/main/metro"/>
+ <home href="http://www.dpml.net/central/products/tutorials/metro"/>
+ </header>
+ </x:module>
+ </target>
+
+ <target name="docs" depends="install"> <!-- checkstyle causes fail on full
build -->
+ <x:javadoc>
+ <link href="http://java.sun.com/j2se/1.4/docs/api"/>
+ <group title="Tutorials">
+ <package name="tutorial"/>
+ </group>
+ </x:javadoc>
+ </target>
+
+ <target name="junit-report">
+ <mkdir dir="target/reports/junit"/>
+ <junitreport todir="target/reports/junit">
+ <fileset dir=".">
+ <include name="**/target/test-reports/TEST-*.xml"/>
+ </fileset>
+ <report format="frames" todir="target/reports/junit"/>
+ </junitreport>
+ </target>
+
+</project>

Modified:
development/main/magic/bootstrap/src/main/net/dpml/magic/bootstrap/MainTask.java
==============================================================================
---
development/main/magic/bootstrap/src/main/net/dpml/magic/bootstrap/MainTask.java
(original)
+++
development/main/magic/bootstrap/src/main/net/dpml/magic/bootstrap/MainTask.java
Thu Dec 23 16:05:10 2004
@@ -117,7 +117,7 @@
if( !init )
{
setupMonitors();
- File home = Transit.HOME;
+ File home = Transit.DPML_HOME;
log( "home: " + home.getAbsolutePath() );
TransitComponentHelper helper = new TransitComponentHelper(
project );
project.addBuildListener( helper );
@@ -138,7 +138,7 @@
*/
private void checkProperties( Project project ) throws BuildException
{
- File home = Transit.HOME;
+ File home = Transit.DPML_HOME;
File templates = new File( home, "templates" );
File docs = new File( home, "docs" );
File cache = new File( home, "main" );

Modified:
development/main/magic/bootstrap/src/main/net/dpml/magic/bootstrap/PluginManager.java
==============================================================================
---
development/main/magic/bootstrap/src/main/net/dpml/magic/bootstrap/PluginManager.java
(original)
+++
development/main/magic/bootstrap/src/main/net/dpml/magic/bootstrap/PluginManager.java
Thu Dec 23 16:05:10 2004
@@ -45,7 +45,7 @@

public PluginManager()
{
- m_MagicDir = new File( Transit.HOME, "processes" );
+ m_MagicDir = new File( Transit.DPML_HOME, "processes" );
}

public void buildStarted( BuildEvent event )

Modified: development/main/magic/core/src/main/net/dpml/magic/Index.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/Index.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/Index.java Thu
Dec 23 16:05:10 2004
@@ -161,7 +161,7 @@

public File getHomeDirectory()
{
- return Transit.HOME;
+ return Transit.DPML_HOME;
}

public File getCacheDirectory()

Modified:
development/main/magic/core/src/main/net/dpml/magic/tasks/JavacTask.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/tasks/JavacTask.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/tasks/JavacTask.java
Thu Dec 23 16:05:10 2004
@@ -50,7 +50,7 @@
public static final String FORK_KEY = "project.javac.fork";
public static final boolean FORK_VALUE = false;

- public static final String DEPRECATION_KEY = "projectjavac.deprecation";
+ public static final String DEPRECATION_KEY = "project.javac.deprecation";
public static final boolean DEPRECATION_VALUE = true;

public void init() throws BuildException

Modified: development/main/metro/main/src/main/net/dpml/metro/Metro.java
==============================================================================
--- development/main/metro/main/src/main/net/dpml/metro/Metro.java
(original)
+++ development/main/metro/main/src/main/net/dpml/metro/Metro.java Thu
Dec 23 16:05:10 2004
@@ -1,599 +1,599 @@
-/*
- * Copyright 2004 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.metro;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.Map;
-
-import net.dpml.activity.Startable;
-import net.dpml.cli.ArgumentHandler;
-import net.dpml.exception.ExceptionHelper;
-import net.dpml.i18n.ResourceManager;
-import net.dpml.i18n.Resources;
-import net.dpml.logging.Logger;
-import net.dpml.system.Factory;
-import net.dpml.system.SystemContext;
-import net.dpml.system.SystemContextFactory;
-import net.dpml.system.SystemException;
-import net.dpml.transit.artifact.Artifact;
-
-import net.dpml.transit.Transit;
-import net.dpml.transit.repository.Plugin;
-import net.dpml.transit.repository.Repository;
-import net.dpml.transit.monitors.Monitor;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.OptionGroup;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-
-
-/**
- * The metro system provides support for the establishment of a composition
- * model based on a root container defintion, a series of initial container
- * deployment targets, and configuration override management. This class
- * deals with the parameterization of a series of stacked plugins based on
- * supplied command line arguments.
- *
- * @author <a href="mailto:dev@dpmlnet";>Stephen J. McConnell</a>
- * @version $Id$
- */
-public class Metro implements Runnable
-{
- //
------------------------------------------------------------------------
- // static
- //
------------------------------------------------------------------------
-
- private static Resources REZ =
- ResourceManager.getPackageResources( Metro.class );
-
- private static String SYSTEM_IMPL_PLUGIN_DEFAULT =
- "@SYSTEM-PLUGIN-URI@";
-
- public static String SYSTEM_IMPL_SPEC_KEY =
- SystemContext.DOMAIN + ".metro.system.artifact";
-
- private static String TARGET_DEFAULT_URI =
- "@COMPOSITION-IMPL-ARTIFACT-URI@";
-
- public static String TARGET_URI_KEY =
- SystemContext.DOMAIN + ".metro.main.artifact";
-
- public static String DPML_PROPERTIES = "dpml.properties";
-
- //
------------------------------------------------------------------------
- // immutable state
- //
------------------------------------------------------------------------
-
- private final boolean m_server;
-
- //
------------------------------------------------------------------------
- // mutable state
- //
------------------------------------------------------------------------
-
- private SystemContext m_system;
- private Logger m_logger;
- private Object m_plugin;
- private boolean m_fail = false;
-
- //
------------------------------------------------------------------------
- // constructors
- //
------------------------------------------------------------------------
-
- /**
- * Creation of a new metro instance using a supplied bootstrap repository
- * plugin descriptor and commandline arguments.
- *
- * @param map transit deployment parameters
- * @param repository the bootstrap system repository
- * @param descriptor the descriptor of this plugin
- * @param args command line arguments
- */
- public Metro( Map map, Repository repository, Plugin descriptor,
String[] args )
- throws IOException, ParseException, Exception
- {
- Boolean debug = (Boolean) map.get( "urn:transit.debug.policy" );
-
- assertNotNull( "urn:transit.debug.policy", debug );
- assertNotNull( "repository", repository );
- assertNotNull( "descriptor", descriptor );
- assertNotNull( "args", args );
-
- //
- // create the inital context for the application
- //
-
- Options options = buildMetroOptions();
- ArgumentHandler handler = new ArgumentHandler( args );
- ArgumentHandler.Pair pair = handler.split( options );
- String[] metroArgs = pair.getSelection();
-
- CommandLineParser parser = new GnuParser();
- CommandLine line = parser.parse( options, metroArgs, false );
-
- if( line.hasOption( "help" ) )
- {
- m_server = false;
- handleHelpMessage();
- }
- else if( line.hasOption( "version" ) )
- {
- m_server = false;
- handleVersionMessage( descriptor );
- }
- else
- {
- m_server = getServerMode( line );
-
- //
- // load a full implementation of the transit system
- //
-
- Properties properties = getInitialProperties();
- URI system = getSystemContextURI( properties );
- m_system = loadSystemContext( map, repository, system,
pair.getRemainder() );
- m_logger = m_system.getLogger();
- getLogger().debug( "system context established" );
-
- //
- // we are loading the metro platform
- //
-
- try
- {
- URI target = getMainArtifact( properties );
- getLogger().debug( "loading plugin: [" + target + "]." );
-
- ClassLoader classloader = getRootClassLoader( line );
- m_plugin = loadPlugin( classloader, m_system, target );
-
- StringBuffer buffer = new StringBuffer( "Metro Context" );
- buffer.append( SystemContext.LINE );
- pack( buffer, SYSTEM_IMPL_SPEC_KEY, system.toString() );
- pack( buffer, TARGET_URI_KEY, target.toString() );
- buffer.append( SystemContext.LINE );
-
- if( m_system.getInfoMode() )
- {
- getLogger().info( buffer.toString() );
- }
- else if( m_system.getDebugMode() )
- {
- getLogger().debug( buffer.toString() );
- }
-
- if( m_plugin instanceof Startable )
- {
- ((Startable)m_plugin).start();
- getLogger().debug( "plugin startup completed" );
- if( !m_server )
- {
- ((Startable)m_plugin).stop();
- getLogger().debug( "plugin shutdown completed" );
- }
- }
- else
- {
- getLogger().debug( "plugin established" );
- }
- }
- catch( Throwable e )
- {
- final String message = "Unable to establish the metro
system.";
- final String error =
- ExceptionHelper.packException( message, e,
getLogger().isDebugEnabled() );
- getLogger().error( message + "\n" + error );
- m_fail = true;
- }
- }
- }
-
- private void pack( StringBuffer buffer, String key, Object value )
- {
- if( null == value )
- {
- pack( buffer, "${" + key + "} : " );
- }
- else
- {
- pack( buffer, "${" + key + "} : " + value );
- }
- }
-
- private void pack( StringBuffer buffer, String message )
- {
- buffer.append( "\n" + message );
- }
-
- private ClassLoader getRootClassLoader( CommandLine line ) throws
IOException
- {
- if( line.hasOption( "Xavalon" ) )
- {
- getLogger().debug( "including avalon apis" );
-
- URL[] urls = new URL[]
- {
- new URL(
"artifact:jar:avalon-framework/avalon-framework-api#4.2.0" ),
- new
URL("artifact:jar:avalon/util/avalon-util-lifecycle#1.1.1" )
- };
-
- return new URLClassLoader( urls,
SystemContext.class.getClassLoader() );
- }
- else
- {
- return SystemContext.class.getClassLoader();
- }
- }
-
- private boolean getServerMode( CommandLine line )
- {
- if( line.hasOption( "execute" ) )
- {
- return false;
- }
- else
- {
- return true;
- }
- }
-
- private Object loadPlugin(
- ClassLoader classloader, SystemContext system, URI uri )
- throws Exception
- {
- try
- {
- Object[] params = new Object[]{ system, system.getArgs(),
getLogger() };
- Object object = system.getRepository().getPlugin( classloader,
uri, params );
- if( object instanceof Factory )
- {
- return ((Factory)object).create();
- }
- else
- {
- return object;
- }
- }
- catch( Throwable e )
- {
- final String message =
- "Plugin deployment failure.";
- throw new SystemException( message, e );
- }
- }
-
- private URI getMainArtifact( Properties properties )
- throws URISyntaxException
- {
- String spec = properties.getProperty( TARGET_URI_KEY );
- if( null != spec )
- {
- return Artifact.createArtifact( spec ).toURI();
- }
- else
- {
- return Artifact.createArtifact( TARGET_DEFAULT_URI ).toURI();
- }
- }
-
- private SystemContext loadSystemContext(
- Map map, Repository repository, URI uri, String[] args )
- throws SystemException
- {
- try
- {
- ClassLoader classloader = SystemContext.class.getClassLoader();
- Object[] params = new Object[]{ map, args };
- Object object = repository.getPlugin( classloader, uri, params );
- if( object instanceof SystemContextFactory )
- {
- SystemContextFactory factory =
- (SystemContextFactory) object;
- return factory.createSystemContext();
- }
- else
- {
- final String error =
- "The declared system context factory ["
- + object.getClass().getName()
- + "] does not implement the "
- + SystemContextFactory.class.getName()
- + " interface.";
- throw new SystemException( error );
- }
- }
- catch( Throwable e )
- {
- final String error =
- "Unable to load the system context plugin using ["
- + uri
- + "].";
- throw new SystemException( error, e );
- }
- }
-
- private URI getSystemContextURI( Properties properties ) throws
URISyntaxException
- {
- String spec = properties.getProperty( SYSTEM_IMPL_SPEC_KEY );
- if( null != spec )
- {
- return Artifact.createArtifact( spec ).toURI();
- }
- else
- {
- return Artifact.createArtifact( SYSTEM_IMPL_PLUGIN_DEFAULT
).toURI();
- }
- }
-
- private void handleHelpMessage()
- {
- System.out.println("");
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp( "metro ", " ",
- buildMetroOptions(), "", true );
- System.out.println("");
- }
-
- private void handleVersionMessage( Plugin descriptor )
- {
- System.out.println(
- "\n Metro: "
- + descriptor.getURI()
- + "\n Build: " + descriptor.getBuild()
- + "\n" );
- }
-
- //
------------------------------------------------------------------------
- // Runnable
- //
------------------------------------------------------------------------
-
- /**
- * If the controller is established with server mode enabled then this
method
- * will continue a loop of checking for a thread interrupt signalling the
- * orderly termination of running plugins.
- */
- public void run()
- {
- boolean flag = m_server;
- while( flag && !m_fail )
- {
- try
- {
- Thread.sleep( 100 );
- }
- catch( InterruptedException ie )
- {
- flag = false;
- }
- }
-
- if( (null != m_plugin ) && m_plugin instanceof Startable )
- {
- getLogger().debug( "initiating shutdown" );
- try
- {
- ((Startable)m_plugin).stop();
- getLogger().debug( "shutdown complete" );
- }
- catch( Exception e )
- {
- final String error =
- "Target plugin raised an exception while attempting to
initiale the shutdown phase.";
- getLogger().error( error, e );
- }
- }
- }
-
- //
------------------------------------------------------------------------
- // internals
- //
------------------------------------------------------------------------
-
- private void assertNotNull( final String key, final Object object )
- {
- if( null == object )
- {
- throw new NullPointerException( key );
- }
- }
-
- private Logger getLogger()
- {
- return m_logger;
- }
-
- private Options buildMetroOptions()
- {
- Options options = new Options();
-
- //
- // language
- //
-
- OptionBuilder.hasArg();
- OptionBuilder.withArgName( "code" );
- OptionBuilder.withDescription( REZ.getString(
"cli-language-description" ) );
- Option option = OptionBuilder.create( "lang" );
- options.addOption( option );
-
- //
- // actions
- //
-
- OptionGroup group = new OptionGroup();
- option = new Option( "help", REZ.getString( "cli-help-description" )
);
- group.addOption( option );
- option = new Option( "version", REZ.getString(
"cli-version-description" ) );
- group.addOption( option );
- options.addOptionGroup( group );
-
- //
- // server/execute mode switch
- //
-
- OptionGroup server = new OptionGroup();
- server.addOption(
- new Option( "server", REZ.getString( "cli-server-description" ) )
);
- server.addOption(
- new Option( "execute", REZ.getString( "cli-execute-description" )
) );
- options.addOptionGroup( server );
-
- //
- // avalon switch
- //
-
- options.addOption(
- new Option( "Xavalon", REZ.getString( "cli-avalon-description" ) )
);
-
- //
- // other
- //
-
- options.addOption(
- new Option( "test", "metro test cycle" ) );
-
- return options;
- }
-
- private String[] getLoadArguments( String arg )
- {
- if( null == arg )
- return new String[0];
- if( arg.indexOf( "," ) == -1 )
- return new String[]{ arg };
- ArrayList list = new ArrayList();
- StringTokenizer tokenizer = new StringTokenizer( arg, "," );
- while( tokenizer.hasMoreTokens() )
- {
- list.add( tokenizer.nextToken() );
- }
- return (String[]) list.toArray( new String[0] );
- }
-
- /**
- * Load all properties file from the standard locations. Standard
- * locations in priority order include:
- * <ul>
- * <li>${user.dir}/dpml.properties</li>
- * <li>${user.home}/dpml.properties</li>
- * <li>${dpml.home}/dpml.properties</li>
- * </ul>
- * @return the aggregated properties
- */
- private static Properties getInitialProperties() throws SystemException
- {
- try
- {
- File home = Transit.HOME;
- Properties properties = getStaticProperties();
- File homePreferenceFile = new File( home, DPML_PROPERTIES );
- loadFile( properties, homePreferenceFile );
-
- //
- // get ${user.home}/[key].properties
- //
-
- File user = getUserDirectory();
- File userPreferenceFile = new File( user, DPML_PROPERTIES );
- loadFile( properties, userPreferenceFile );
-
- //
- // get ${user.dir}/[key].properties
- //
-
- File dir = getWorkingDirectory();
- File dirPreferenceFile = new File( dir, DPML_PROPERTIES );
- loadFile( properties, dirPreferenceFile );
-
- properties.setProperty( Transit.HOME_KEY, home.toString() );
- return properties;
- }
- catch( IOException ioe )
- {
- final String error =
- "Unexpected error while attempting to construct initial
context.";
- throw new SystemException( error, ioe );
- }
- }
-
- /**
- * Read in a static properties resource relative to a supplied class
- * and path.
- *
- * @param ref a class used to establish a classloader and anchors
- * relative path references
- * @param path the resource address
- * @return the static properties
- * @exception IllegalStateException if the path is unresolvable
- */
- private static Properties getStaticProperties()
- throws IOException
- {
- Properties bootstrap = new Properties();
- InputStream input =
- Metro.class.getClassLoader().getResourceAsStream( DPML_PROPERTIES
);
- if( input != null )
- {
- bootstrap.load( input );
- }
- return bootstrap;
- }
-
- private static File getUserDirectory()
- {
- return new File( System.getProperty( "user.home" ) );
- }
-
- private static File getWorkingDirectory()
- {
- return new File( System.getProperty( "user.dir" ) );
- }
-
- private static void loadFile( Properties properties, File file )
- throws IOException
- {
- if( file.exists() )
- {
- InputStream input = new FileInputStream( file );
- try
- {
- properties.load( input );
- } finally
- {
- input.close();
- }
- }
- }
-
-}
-
+/*
+ * Copyright 2004 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.metro;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Map;
+
+import net.dpml.activity.Startable;
+import net.dpml.cli.ArgumentHandler;
+import net.dpml.exception.ExceptionHelper;
+import net.dpml.i18n.ResourceManager;
+import net.dpml.i18n.Resources;
+import net.dpml.logging.Logger;
+import net.dpml.system.Factory;
+import net.dpml.system.SystemContext;
+import net.dpml.system.SystemContextFactory;
+import net.dpml.system.SystemException;
+import net.dpml.transit.artifact.Artifact;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.repository.Plugin;
+import net.dpml.transit.repository.Repository;
+import net.dpml.transit.monitors.Monitor;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
+
+/**
+ * The metro system provides support for the establishment of a composition
+ * model based on a root container defintion, a series of initial container
+ * deployment targets, and configuration override management. This class
+ * deals with the parameterization of a series of stacked plugins based on
+ * supplied command line arguments.
+ *
+ * @author <a href="mailto:dev@dpmlnet";>Stephen J. McConnell</a>
+ * @version $Id$
+ */
+public class Metro implements Runnable
+{
+ //
------------------------------------------------------------------------
+ // static
+ //
------------------------------------------------------------------------
+
+ private static Resources REZ =
+ ResourceManager.getPackageResources( Metro.class );
+
+ private static String SYSTEM_IMPL_PLUGIN_DEFAULT =
+ "@SYSTEM-PLUGIN-URI@";
+
+ public static String SYSTEM_IMPL_SPEC_KEY =
+ SystemContext.DOMAIN + ".metro.system.artifact";
+
+ private static String TARGET_DEFAULT_URI =
+ "@COMPOSITION-IMPL-ARTIFACT-URI@";
+
+ public static String TARGET_URI_KEY =
+ SystemContext.DOMAIN + ".metro.main.artifact";
+
+ public static String DPML_PROPERTIES = "dpml.properties";
+
+ //
------------------------------------------------------------------------
+ // immutable state
+ //
------------------------------------------------------------------------
+
+ private final boolean m_server;
+
+ //
------------------------------------------------------------------------
+ // mutable state
+ //
------------------------------------------------------------------------
+
+ private SystemContext m_system;
+ private Logger m_logger;
+ private Object m_plugin;
+ private boolean m_fail = false;
+
+ //
------------------------------------------------------------------------
+ // constructors
+ //
------------------------------------------------------------------------
+
+ /**
+ * Creation of a new metro instance using a supplied bootstrap repository
+ * plugin descriptor and commandline arguments.
+ *
+ * @param map transit deployment parameters
+ * @param repository the bootstrap system repository
+ * @param descriptor the descriptor of this plugin
+ * @param args command line arguments
+ */
+ public Metro( Map map, Repository repository, Plugin descriptor,
String[] args )
+ throws IOException, ParseException, Exception
+ {
+ Boolean debug = (Boolean) map.get( "urn:transit.debug.policy" );
+
+ assertNotNull( "urn:transit.debug.policy", debug );
+ assertNotNull( "repository", repository );
+ assertNotNull( "descriptor", descriptor );
+ assertNotNull( "args", args );
+
+ //
+ // create the inital context for the application
+ //
+
+ Options options = buildMetroOptions();
+ ArgumentHandler handler = new ArgumentHandler( args );
+ ArgumentHandler.Pair pair = handler.split( options );
+ String[] metroArgs = pair.getSelection();
+
+ CommandLineParser parser = new GnuParser();
+ CommandLine line = parser.parse( options, metroArgs, false );
+
+ if( line.hasOption( "help" ) )
+ {
+ m_server = false;
+ handleHelpMessage();
+ }
+ else if( line.hasOption( "version" ) )
+ {
+ m_server = false;
+ handleVersionMessage( descriptor );
+ }
+ else
+ {
+ m_server = getServerMode( line );
+
+ //
+ // load a full implementation of the transit system
+ //
+
+ Properties properties = getInitialProperties();
+ URI system = getSystemContextURI( properties );
+ m_system = loadSystemContext( map, repository, system,
pair.getRemainder() );
+ m_logger = m_system.getLogger();
+ getLogger().debug( "system context established" );
+
+ //
+ // we are loading the metro platform
+ //
+
+ try
+ {
+ URI target = getMainArtifact( properties );
+ getLogger().debug( "loading plugin: [" + target + "]." );
+
+ ClassLoader classloader = getRootClassLoader( line );
+ m_plugin = loadPlugin( classloader, m_system, target );
+
+ StringBuffer buffer = new StringBuffer( "Metro Context" );
+ buffer.append( SystemContext.LINE );
+ pack( buffer, SYSTEM_IMPL_SPEC_KEY, system.toString() );
+ pack( buffer, TARGET_URI_KEY, target.toString() );
+ buffer.append( SystemContext.LINE );
+
+ if( m_system.getInfoMode() )
+ {
+ getLogger().info( buffer.toString() );
+ }
+ else if( m_system.getDebugMode() )
+ {
+ getLogger().debug( buffer.toString() );
+ }
+
+ if( m_plugin instanceof Startable )
+ {
+ ((Startable)m_plugin).start();
+ getLogger().debug( "plugin startup completed" );
+ if( !m_server )
+ {
+ ((Startable)m_plugin).stop();
+ getLogger().debug( "plugin shutdown completed" );
+ }
+ }
+ else
+ {
+ getLogger().debug( "plugin established" );
+ }
+ }
+ catch( Throwable e )
+ {
+ final String message = "Unable to establish the metro
system.";
+ final String error =
+ ExceptionHelper.packException( message, e,
getLogger().isDebugEnabled() );
+ getLogger().error( message + "\n" + error );
+ m_fail = true;
+ }
+ }
+ }
+
+ private void pack( StringBuffer buffer, String key, Object value )
+ {
+ if( null == value )
+ {
+ pack( buffer, "${" + key + "} : " );
+ }
+ else
+ {
+ pack( buffer, "${" + key + "} : " + value );
+ }
+ }
+
+ private void pack( StringBuffer buffer, String message )
+ {
+ buffer.append( "\n" + message );
+ }
+
+ private ClassLoader getRootClassLoader( CommandLine line ) throws
IOException
+ {
+ if( line.hasOption( "Xavalon" ) )
+ {
+ getLogger().debug( "including avalon apis" );
+
+ URL[] urls = new URL[]
+ {
+ new URL(
"artifact:jar:avalon-framework/avalon-framework-api#4.2.0" ),
+ new
URL("artifact:jar:avalon/util/avalon-util-lifecycle#1.1.1" )
+ };
+
+ return new URLClassLoader( urls,
SystemContext.class.getClassLoader() );
+ }
+ else
+ {
+ return SystemContext.class.getClassLoader();
+ }
+ }
+
+ private boolean getServerMode( CommandLine line )
+ {
+ if( line.hasOption( "execute" ) )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ private Object loadPlugin(
+ ClassLoader classloader, SystemContext system, URI uri )
+ throws Exception
+ {
+ try
+ {
+ Object[] params = new Object[]{ system, system.getArgs(),
getLogger() };
+ Object object = system.getRepository().getPlugin( classloader,
uri, params );
+ if( object instanceof Factory )
+ {
+ return ((Factory)object).create();
+ }
+ else
+ {
+ return object;
+ }
+ }
+ catch( Throwable e )
+ {
+ final String message =
+ "Plugin deployment failure.";
+ throw new SystemException( message, e );
+ }
+ }
+
+ private URI getMainArtifact( Properties properties )
+ throws URISyntaxException
+ {
+ String spec = properties.getProperty( TARGET_URI_KEY );
+ if( null != spec )
+ {
+ return Artifact.createArtifact( spec ).toURI();
+ }
+ else
+ {
+ return Artifact.createArtifact( TARGET_DEFAULT_URI ).toURI();
+ }
+ }
+
+ private SystemContext loadSystemContext(
+ Map map, Repository repository, URI uri, String[] args )
+ throws SystemException
+ {
+ try
+ {
+ ClassLoader classloader = SystemContext.class.getClassLoader();
+ Object[] params = new Object[]{ map, args };
+ Object object = repository.getPlugin( classloader, uri, params );
+ if( object instanceof SystemContextFactory )
+ {
+ SystemContextFactory factory =
+ (SystemContextFactory) object;
+ return factory.createSystemContext();
+ }
+ else
+ {
+ final String error =
+ "The declared system context factory ["
+ + object.getClass().getName()
+ + "] does not implement the "
+ + SystemContextFactory.class.getName()
+ + " interface.";
+ throw new SystemException( error );
+ }
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to load the system context plugin using ["
+ + uri
+ + "].";
+ throw new SystemException( error, e );
+ }
+ }
+
+ private URI getSystemContextURI( Properties properties ) throws
URISyntaxException
+ {
+ String spec = properties.getProperty( SYSTEM_IMPL_SPEC_KEY );
+ if( null != spec )
+ {
+ return Artifact.createArtifact( spec ).toURI();
+ }
+ else
+ {
+ return Artifact.createArtifact( SYSTEM_IMPL_PLUGIN_DEFAULT
).toURI();
+ }
+ }
+
+ private void handleHelpMessage()
+ {
+ System.out.println("");
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "metro ", " ",
+ buildMetroOptions(), "", true );
+ System.out.println("");
+ }
+
+ private void handleVersionMessage( Plugin descriptor )
+ {
+ System.out.println(
+ "\n Metro: "
+ + descriptor.getURI()
+ + "\n Build: " + descriptor.getBuild()
+ + "\n" );
+ }
+
+ //
------------------------------------------------------------------------
+ // Runnable
+ //
------------------------------------------------------------------------
+
+ /**
+ * If the controller is established with server mode enabled then this
method
+ * will continue a loop of checking for a thread interrupt signalling the
+ * orderly termination of running plugins.
+ */
+ public void run()
+ {
+ boolean flag = m_server;
+ while( flag && !m_fail )
+ {
+ try
+ {
+ Thread.sleep( 100 );
+ }
+ catch( InterruptedException ie )
+ {
+ flag = false;
+ }
+ }
+
+ if( (null != m_plugin ) && m_plugin instanceof Startable )
+ {
+ getLogger().debug( "initiating shutdown" );
+ try
+ {
+ ((Startable)m_plugin).stop();
+ getLogger().debug( "shutdown complete" );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Target plugin raised an exception while attempting to
initiale the shutdown phase.";
+ getLogger().error( error, e );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // internals
+ //
------------------------------------------------------------------------
+
+ private void assertNotNull( final String key, final Object object )
+ {
+ if( null == object )
+ {
+ throw new NullPointerException( key );
+ }
+ }
+
+ private Logger getLogger()
+ {
+ return m_logger;
+ }
+
+ private Options buildMetroOptions()
+ {
+ Options options = new Options();
+
+ //
+ // language
+ //
+
+ OptionBuilder.hasArg();
+ OptionBuilder.withArgName( "code" );
+ OptionBuilder.withDescription( REZ.getString(
"cli-language-description" ) );
+ Option option = OptionBuilder.create( "lang" );
+ options.addOption( option );
+
+ //
+ // actions
+ //
+
+ OptionGroup group = new OptionGroup();
+ option = new Option( "help", REZ.getString( "cli-help-description" )
);
+ group.addOption( option );
+ option = new Option( "version", REZ.getString(
"cli-version-description" ) );
+ group.addOption( option );
+ options.addOptionGroup( group );
+
+ //
+ // server/execute mode switch
+ //
+
+ OptionGroup server = new OptionGroup();
+ server.addOption(
+ new Option( "server", REZ.getString( "cli-server-description" ) )
);
+ server.addOption(
+ new Option( "execute", REZ.getString( "cli-execute-description" )
) );
+ options.addOptionGroup( server );
+
+ //
+ // avalon switch
+ //
+
+ options.addOption(
+ new Option( "Xavalon", REZ.getString( "cli-avalon-description" ) )
);
+
+ //
+ // other
+ //
+
+ options.addOption(
+ new Option( "test", "metro test cycle" ) );
+
+ return options;
+ }
+
+ private String[] getLoadArguments( String arg )
+ {
+ if( null == arg )
+ return new String[0];
+ if( arg.indexOf( "," ) == -1 )
+ return new String[]{ arg };
+ ArrayList list = new ArrayList();
+ StringTokenizer tokenizer = new StringTokenizer( arg, "," );
+ while( tokenizer.hasMoreTokens() )
+ {
+ list.add( tokenizer.nextToken() );
+ }
+ return (String[]) list.toArray( new String[0] );
+ }
+
+ /**
+ * Load all properties file from the standard locations. Standard
+ * locations in priority order include:
+ * <ul>
+ * <li>${user.dir}/dpml.properties</li>
+ * <li>${user.home}/dpml.properties</li>
+ * <li>${dpml.home}/dpml.properties</li>
+ * </ul>
+ * @return the aggregated properties
+ */
+ private static Properties getInitialProperties() throws SystemException
+ {
+ try
+ {
+ File home = Transit.DPML_HOME;
+ Properties properties = getStaticProperties();
+ File homePreferenceFile = new File( home, DPML_PROPERTIES );
+ loadFile( properties, homePreferenceFile );
+
+ //
+ // get ${user.home}/[key].properties
+ //
+
+ File user = getUserDirectory();
+ File userPreferenceFile = new File( user, DPML_PROPERTIES );
+ loadFile( properties, userPreferenceFile );
+
+ //
+ // get ${user.dir}/[key].properties
+ //
+
+ File dir = getWorkingDirectory();
+ File dirPreferenceFile = new File( dir, DPML_PROPERTIES );
+ loadFile( properties, dirPreferenceFile );
+
+ properties.setProperty( Transit.HOME_KEY, home.toString() );
+ return properties;
+ }
+ catch( IOException ioe )
+ {
+ final String error =
+ "Unexpected error while attempting to construct initial
context.";
+ throw new SystemException( error, ioe );
+ }
+ }
+
+ /**
+ * Read in a static properties resource relative to a supplied class
+ * and path.
+ *
+ * @param ref a class used to establish a classloader and anchors
+ * relative path references
+ * @param path the resource address
+ * @return the static properties
+ * @exception IllegalStateException if the path is unresolvable
+ */
+ private static Properties getStaticProperties()
+ throws IOException
+ {
+ Properties bootstrap = new Properties();
+ InputStream input =
+ Metro.class.getClassLoader().getResourceAsStream( DPML_PROPERTIES
);
+ if( input != null )
+ {
+ bootstrap.load( input );
+ }
+ return bootstrap;
+ }
+
+ private static File getUserDirectory()
+ {
+ return new File( System.getProperty( "user.home" ) );
+ }
+
+ private static File getWorkingDirectory()
+ {
+ return new File( System.getProperty( "user.dir" ) );
+ }
+
+ private static void loadFile( Properties properties, File file )
+ throws IOException
+ {
+ if( file.exists() )
+ {
+ InputStream input = new FileInputStream( file );
+ try
+ {
+ properties.load( input );
+ } finally
+ {
+ input.close();
+ }
+ }
+ }
+
+}
+

Modified:
development/main/metro/system/impl/src/main/net/dpml/system/impl/DefaultSystemContextFactory.java
==============================================================================
---
development/main/metro/system/impl/src/main/net/dpml/system/impl/DefaultSystemContextFactory.java
(original)
+++
development/main/metro/system/impl/src/main/net/dpml/system/impl/DefaultSystemContextFactory.java
Thu Dec 23 16:05:10 2004
@@ -1,678 +1,678 @@
-/*
- * Copyright 2004 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.system.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.net.URI;
-import java.net.URL;
-import java.util.Map;
-import java.util.Properties;
-
-import net.dpml.cli.ArgumentHandler;
-import net.dpml.defaults.Defaults;
-import net.dpml.defaults.DefaultsBuilder;
-import net.dpml.i18n.ResourceManager;
-import net.dpml.i18n.Resources;
-import net.dpml.logging.Logger;
-import net.dpml.logging.provider.LoggingCriteria;
-import net.dpml.logging.provider.LoggingFactory;
-import net.dpml.logging.provider.LoggingManager;
-import net.dpml.system.Factory;
-import net.dpml.system.SystemContext;
-import net.dpml.system.SystemContextFactory;
-import net.dpml.system.SystemCriteria;
-import net.dpml.system.SystemException;
-import net.dpml.system.SystemRuntimeException;
-import net.dpml.system.monitors.CacheMonitorLoggerAdapter;
-import net.dpml.system.monitors.RepositoryMonitorLoggerAdapter;
-import net.dpml.system.monitors.NetworkMonitorLoggerAdapter;
-
-import net.dpml.transit.Transit;
-import net.dpml.transit.TransitException;
-import net.dpml.transit.artifact.Artifact;
-import net.dpml.transit.repository.Repository;
-import net.dpml.transit.repository.StandardLoader;
-import net.dpml.transit.monitors.Monitor;
-import net.dpml.transit.monitors.CacheMonitor;
-import net.dpml.transit.monitors.NetworkMonitor;
-import net.dpml.transit.monitors.RepositoryMonitor;
-
-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.OptionBuilder;
-import org.apache.commons.cli.OptionGroup;
-import org.apache.commons.cli.Options;
-
-/**
- * The factory class provides services supporting the establishment of
- * a system context. The system context provides access to a logging manager,
- * repository, working and temporary directories, and system level flags and
- * services supporting the deployment of plugins.
- *
- * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
- * @version $Id$
- */
-public class DefaultSystemContextFactory implements Factory,
SystemContextFactory
-{
- //
------------------------------------------------------------------------
- // static
- //
------------------------------------------------------------------------
-
- private static Resources REZ =
- ResourceManager.getPackageResources(
DefaultSystemContextFactory.class );
-
- //
------------------------------------------------------------------------
- // immutable state
- //
------------------------------------------------------------------------
-
- private final Repository m_repository;
- private CommandLine m_line;
- private String[] m_remainder;
- private final Properties m_properties;
- private final File m_home;
- private boolean m_DebugMode;
- private boolean m_InfoMode;
- private Map m_params;
-
- //
------------------------------------------------------------------------
- // constructors
- //
------------------------------------------------------------------------
-
- public DefaultSystemContextFactory(
- Map map, Repository repository, String[] args )
- throws Exception
- {
- assertNotNull( "map", map );
- assertNotNull( "repository", repository );
- assertNotNull( "args", args );
-
- m_params = map;
-
- Boolean debug = (Boolean) map.get( "urn:transit.debug.policy" );
- assertNotNull( "urn:transit.debug.policy", debug );
- m_DebugMode = debug.booleanValue();
-
- Options options = buildCommandLineOptions();
- ArgumentHandler handler = new ArgumentHandler( args );
- ArgumentHandler.Pair pair = handler.split( options );
- String[] arguments = pair.getSelection();
- CommandLineParser parser = new GnuParser();
- m_line = parser.parse( options, arguments, false );
- m_InfoMode = m_line.hasOption( "info" );
-
- m_remainder = pair.getRemainder();
- m_repository = createRepository();
-
- try
- {
- Properties props = new Properties();
- m_home = Transit.HOME;
- props.put( Transit.HOME_KEY, m_home.toString() );
- m_properties = getStaticProperties( m_home, SystemContext.DOMAIN,
- DefaultSystemContextFactory.class.getClassLoader(),
- "/system.properties" );
-
- // TODO: the expansion below seems to be very basic, and should
be replaced by the
- // net.dpml.transit.artifact.PropertyResolver class.
- Defaults.macroExpand( m_properties, new Properties[0] );
- Defaults.macroExpand( m_properties, new Properties[0] );
- Defaults.macroExpand( m_properties, new Properties[0] );
- }
- catch ( IOException e )
- {
- throw new SystemException(
- "Failed to load system properties.", e );
- }
- }
-
- //
------------------------------------------------------------------------
- // Factory
- //
------------------------------------------------------------------------
-
- public Map createDefaultCriteria()
- {
- return createDefaultSystemCriteria();
- }
-
- public Object create() throws Exception
- {
- return create( createDefaultCriteria() );
- }
-
- public Object create( Map map ) throws Exception
- {
- assertNotNull( "map", map );
- SystemCriteria criteria = getSystemCriteria( map );
- return createSystemContext( criteria );
- }
-
- //
------------------------------------------------------------------------
- // SystemContextFactory
- //
------------------------------------------------------------------------
-
- /**
- * Return the default system critera.
- *
- * @return the system factory criteria
- */
- public SystemCriteria createDefaultSystemCriteria()
- {
- SystemCriteria criteria = newDefaultSystemCriteria();
-
- //
- // apply command line args to criteria
- //
-
- try
- {
- if( m_line.hasOption( "noproxy" ) )
- {
- criteria.setIsolationMode( false );
- }
-
- else if( m_line.hasOption( "proxy" ) )
- {
- criteria.setIsolationMode( true );
- }
-
- if( m_line.hasOption( "dir" ) )
- {
- String path = m_line.getOptionValue( "dir" );
- criteria.put( SystemContext.DIR_KEY, path );
- }
-
- if( m_line.hasOption( "temp" ) )
- {
- String path = m_line.getOptionValue( "temp" );
- criteria.put( SystemContext.TEMP_KEY, path );
- }
-
- if( m_line.hasOption( "logging" ) )
- {
- String path = m_line.getOptionValue( "logging" );
- criteria.put( SystemContext.LOGGING_CONFIGURATION_KEY, path
);
- }
- }
- catch( Throwable e )
- {
- final String error =
- "Error during the creation of the default system criteria.";
- throw new SystemRuntimeException( error, e );
- }
-
- return criteria;
- }
-
- /**
- * Create a new system context.
- */
- public SystemContext createSystemContext()
- throws SystemException
- {
- try
- {
- SystemCriteria criteria = createDefaultSystemCriteria();
- return createSystemContext( criteria );
- }
- catch( Throwable e )
- {
- final String error =
- "Cannot create system context.";
- throw new SystemException( error, e );
- }
- }
-
- /**
- * Create a new system context.
- */
- public SystemContext createSystemContext( SystemCriteria criteria )
- throws SystemException
- {
- assertNotNull( "criteria", criteria );
-
- boolean isolate = criteria.getIsolationMode();
-
- File dir = normalize( criteria.getWorkingDirectory() );
- File temp = normalize( criteria.getTempDirectory() );
- File anchor = normalize( criteria.getAnchorDirectory() );
-
- URL url = criteria.getLoggingConfiguration();
- URI uri = criteria.getLoggingURI();
- LoggingManager logging =
- createLoggingManager( m_repository, uri, dir, url, m_DebugMode );
- Logger logger = logging.getLoggerForCategory( SystemContext.DOMAIN );
- Repository repository = createRepository();
-
- setupMonitors( logger );
-
- StringBuffer buffer =
- new StringBuffer(
- "info"
- + SystemContext.LINE
- + "\nInitial Context" );
-
- buffer.append( SystemContext.LINE );
-
- if( m_InfoMode )
- {
- logger.info( buffer.toString() );
- }
- else if( m_DebugMode )
- {
- logger.debug( buffer.toString() );
- }
-
- buffer =
- new StringBuffer( "System Context" );
- buffer.append( SystemContext.LINE );
-
- pack( buffer, SystemContext.LOGGING_IMPLEMENTATION_KEY, uri );
- pack( buffer, SystemContext.LOGGING_CONFIGURATION_KEY, url );
- pack( buffer, SystemContext.HOME_KEY, Transit.HOME );
- pack( buffer, SystemContext.ANCHOR_KEY, anchor );
- pack( buffer, SystemContext.TEMP_KEY, temp );
- pack( buffer, SystemContext.DIR_KEY, dir );
- buffer.append( SystemContext.LINE );
-
- if( m_InfoMode )
- {
- logger.info( buffer.toString() );
- }
- else if( m_DebugMode )
- {
- logger.debug( buffer.toString() );
- }
-
- return new DefaultSystemContext(
- repository, logging, logger, Transit.HOME, dir, anchor, temp,
- m_InfoMode, m_DebugMode, isolate, m_remainder, m_properties );
- }
-
- private void setupMonitors( Logger logger ) throws SystemException
- {
- try
- {
- Transit transit = Transit.getInstance();
-
- Logger repository = logger.getChildLogger( "repository" );
-
- transit.getRepositoryMonitorRouter().addMonitor(
- new RepositoryMonitorLoggerAdapter( repository ) );
-
- Monitor repositoryMonitor = (Monitor) m_params.get(
"urn:transit.repository.monitor" );
- if( null != repositoryMonitor )
- {
- transit.getRepositoryMonitorRouter().removeMonitor(
repositoryMonitor );
- }
-
- Logger cache = logger.getChildLogger( "cache" );
- transit.getCacheMonitorRouter().addMonitor(
- new CacheMonitorLoggerAdapter( cache ) );
- Monitor cacheMonitor = (Monitor) m_params.get(
"urn:transit.cache.monitor" );
- if( null != cacheMonitor )
- {
- transit.getCacheMonitorRouter().removeMonitor( cacheMonitor
);
- }
-
- Logger network = logger.getChildLogger( "network" );
- transit.getNetworkMonitorRouter().addMonitor(
- new NetworkMonitorLoggerAdapter( cache ) );
- Monitor netMonitor = (Monitor) m_params.get(
"urn:transit.network.monitor" );
- if( null != netMonitor )
- {
- transit.getNetworkMonitorRouter().removeMonitor( netMonitor
);
- }
- }
- catch( TransitException e )
- {
- final String error =
- "Internal error while attempt to setup transit monitors.";
- throw new SystemException( error, e );
- }
- }
-
- private File normalize( File file )
- {
- if( null == file )
- {
- return null;
- }
- else
- {
- try
- {
- return file.getCanonicalFile();
- }
- catch( IOException ioe )
- {
- final String error =
- "Unexpected exception while attempting to normaliize the
file ["
- + file.toString()
- + "].";
- throw new SystemRuntimeException( error, ioe );
- }
- }
- }
-
- private void pack( StringBuffer buffer, String key, Object value )
- {
- if( null == value )
- {
- pack( buffer, "${" + key + "} : " );
- }
- else
- {
- pack( buffer, "${" + key + "} : " + value );
- }
- }
-
- private void pack( StringBuffer buffer, String message )
- {
- buffer.append( "\n" + message );
- }
-
- //
------------------------------------------------------------------------
- // internal
- //
------------------------------------------------------------------------
-
- public SystemCriteria newDefaultSystemCriteria()
- {
- try
- {
- return new DefaultSystemCriteria( m_properties, m_home );
- }
- catch( Throwable e )
- {
- final String error =
- "Error during the creation of the default system criteria.";
- throw new SystemRuntimeException( error, e );
- }
- }
-
- private Repository createRepository() throws SystemException
- {
- try
- {
- return new StandardLoader();
- }
- catch( Throwable e )
- {
- final String error =
- "Error in repository subsystem establishment.";
- throw new SystemException( error, e );
- }
- }
-
-
- /**
- * Utility method to create the LoggingManager.
- * @param uri the logging implementation factory artifact
- * @param dir the logging system base directory
- * @param path the logging system configuration path
- * @param debug the debug flag
- * @return the logging manager
- * @exception NullPointerException if the supplied context is null
- */
- private LoggingManager createLoggingManager(
- final Repository repository, final URI uri, final File dir,
- final URL path, boolean debug ) throws SystemException
- {
- try
- {
- ClassLoader classloader = SystemContext.class.getClassLoader();
- Object[] args = new Object[0];
- Object object = repository.getPlugin( classloader, uri, args );
- if( object instanceof LoggingFactory )
- {
- LoggingFactory factory = (LoggingFactory) object;
- LoggingCriteria params =
factory.createDefaultLoggingCriteria();
- params.setBaseDirectory( dir );
- params.setLoggingConfiguration( path );
- params.setDebugEnabled( debug );
- return factory.createLoggingManager( params );
- }
- else
- {
- final String error =
- "Logging manager provider referenced by ["
- + uri
- + "] does not implement the service interface ["
- + LoggingFactory.class.getName()
- + "].";
- throw new SystemException( error );
- }
- }
- catch( Exception e )
- {
- final String error =
- "Error in logging subsystem establishment.";
- throw new SystemException( error, e );
- }
- }
-
- private SystemCriteria getSystemCriteria( Map map ) throws
SystemException
- {
- if( null == map )
- {
- throw new NullPointerException( "map" );
- }
- if( map instanceof SystemCriteria )
- {
- return (SystemCriteria) map;
- }
- else
- {
- SystemCriteria criteria = (SystemCriteria)
createDefaultCriteria();
- try
- {
- String[] keys = (String[]) map.keySet().toArray( new
String[0] );
- for( int i=0; i<keys.length; i++ )
- {
- String key = keys[i];
- Object value = map.get( key );
- criteria.put( key, value );
- }
- return criteria;
- }
- catch( Throwable e )
- {
- final String error =
- "Could not map supplied keys to the system context.";
- throw new SystemException( error, e );
- }
- }
- }
-
- private void assertNotNull( String key, Object object )
- throws NullPointerException
- {
- if( null == object )
- throw new NullPointerException( key );
- }
-
- private Options buildCommandLineOptions()
- {
- Options options = new Options();
-
- //
- // on-line/offline switches
- //
-
- OptionGroup onlineMode = new OptionGroup();
- onlineMode.addOption(
- new Option( "offline", REZ.getString( "cli-offline-description" )
) );
- onlineMode.addOption(
- new Option( "online", REZ.getString( "cli-online-description" ) )
);
- options.addOptionGroup( onlineMode );
-
- //
- // proxy/noproxy switch
- //
-
- OptionGroup proxyMode = new OptionGroup();
- proxyMode.addOption(
- new Option( "proxy", REZ.getString( "cli-proxy-description" ) ) );
- proxyMode.addOption(
- new Option( "noproxy", REZ.getString( "cli-noproxy-description" )
) );
- options.addOptionGroup( onlineMode );
-
- //
- // timestamp switches
- //
-
- // timestamp options no longer relevant because they have been moved
- // to per host
- //
- //OptionGroup timestamp = new OptionGroup();
- //timestamp.addOption(
- // new Option( "fast", REZ.getString( "cli-fast-description" ) ) );
- //timestamp.addOption(
- // new Option( "snapshot", REZ.getString(
"cli-snapshot-description" ) ) );
- //timestamp.addOption(
- // new Option( "timestamp", REZ.getString(
"cli-timestamp-description" ) ) );
- //timestamp.addOption(
- // new Option( "overwrite", REZ.getString(
"cli-overwrite-description" ) ) );
- //options.addOptionGroup( timestamp );
-
- //
- // parameters
- //
-
- options.addOption(
- new Option( "debug", REZ.getString( "cli-debug-description" ) ) );
- options.addOption(
- new Option( "info", REZ.getString( "cli-info-description" ) ) );
-
- options.addOption(
- OptionBuilder.hasArg().withArgName( REZ.getString( "directory" ) )
- .withDescription( REZ.getString( "cli-dir-description" ) )
- .create( "dir" ) );
- options.addOption(
- OptionBuilder.hasArg().withArgName( REZ.getString( "directory" ) )
- .withDescription( REZ.getString( "cli-temp-description" ) )
- .create( "temp" ) );
-
- options.addOption(
- OptionBuilder.hasArg().withArgName( REZ.getString( "uri" ) )
- .withDescription( REZ.getString( "cli-logging-description" ) )
- .create( "logging" ) );
- options.addOption(
- OptionBuilder.hasArg().withArgName( REZ.getString( "directory" ) )
- .withDescription( REZ.getString( "cli-cache-description" ) )
- .create( "cache" ) );
- options.addOption(
- OptionBuilder.hasArgs().withArgName( REZ.getString( "host" ) )
- .withDescription( REZ.getString( "cli-hosts-description" ) )
- .withValueSeparator( ',' )
- .create( "hosts" ) );
-
- return options;
- }
-
- private static Properties getStaticProperties( File home, String key,
- ClassLoader cl, String
bootstrap )
- throws IOException
- {
- String filename = key + ".properties";
-
- //
- // get [home]/[key].properties
- //
-
- Properties properties = getStaticProperties( cl, bootstrap );
- File homePreferenceFile = new File( home, filename );
- loadFile( properties, homePreferenceFile );
-
- //
- // get ${user.home}/[key].properties
- //
-
- File user = getUserDirectory();
- File userPreferenceFile = new File( user, filename );
- loadFile( properties, userPreferenceFile );
-
- //
- // get ${user.dir}/[key].properties
- //
-
- File dir = getWorkingDirectory();
- File dirPreferenceFile = new File( dir, filename );
- loadFile( properties, dirPreferenceFile );
-
- String homeKey = key + ".home";
- properties.setProperty( homeKey, home.toString() );
-
- return properties;
- }
-
- private static File getUserDirectory()
- {
- return new File( System.getProperty( "user.home" ) );
- }
-
- private static File getWorkingDirectory()
- {
- return new File( System.getProperty( "user.dir" ) );
- }
-
- /**
- * Read in a static properties resource relative to a supplied class
- * and path.
- *
- * @param ref a class used to establish a classloader and anchors
- * relative path references
- * @param path the resource address
- * @return the static properties
- * @exception IllegalStateException if the path is unresolvable
- */
- public static Properties getStaticProperties( ClassLoader ref, String
path )
- throws IOException
- {
- Properties bootstrap = new Properties();
- InputStream input = ref.getResourceAsStream( path );
- if( input != null )
- {
- bootstrap.load( input );
- }
- return bootstrap;
- }
-
- private static void loadFile( Properties properties, File file )
- throws IOException
- {
- if( file.exists() )
- {
- InputStream input = new FileInputStream( file );
- try
- {
- properties.load( input );
- } finally
- {
- input.close();
- }
- }
- }
-
-}
-
+/*
+ * Copyright 2004 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.system.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+import net.dpml.cli.ArgumentHandler;
+import net.dpml.defaults.Defaults;
+import net.dpml.defaults.DefaultsBuilder;
+import net.dpml.i18n.ResourceManager;
+import net.dpml.i18n.Resources;
+import net.dpml.logging.Logger;
+import net.dpml.logging.provider.LoggingCriteria;
+import net.dpml.logging.provider.LoggingFactory;
+import net.dpml.logging.provider.LoggingManager;
+import net.dpml.system.Factory;
+import net.dpml.system.SystemContext;
+import net.dpml.system.SystemContextFactory;
+import net.dpml.system.SystemCriteria;
+import net.dpml.system.SystemException;
+import net.dpml.system.SystemRuntimeException;
+import net.dpml.system.monitors.CacheMonitorLoggerAdapter;
+import net.dpml.system.monitors.RepositoryMonitorLoggerAdapter;
+import net.dpml.system.monitors.NetworkMonitorLoggerAdapter;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitException;
+import net.dpml.transit.artifact.Artifact;
+import net.dpml.transit.repository.Repository;
+import net.dpml.transit.repository.StandardLoader;
+import net.dpml.transit.monitors.Monitor;
+import net.dpml.transit.monitors.CacheMonitor;
+import net.dpml.transit.monitors.NetworkMonitor;
+import net.dpml.transit.monitors.RepositoryMonitor;
+
+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.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+
+/**
+ * The factory class provides services supporting the establishment of
+ * a system context. The system context provides access to a logging manager,
+ * repository, working and temporary directories, and system level flags and
+ * services supporting the deployment of plugins.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id$
+ */
+public class DefaultSystemContextFactory implements Factory,
SystemContextFactory
+{
+ //
------------------------------------------------------------------------
+ // static
+ //
------------------------------------------------------------------------
+
+ private static Resources REZ =
+ ResourceManager.getPackageResources(
DefaultSystemContextFactory.class );
+
+ //
------------------------------------------------------------------------
+ // immutable state
+ //
------------------------------------------------------------------------
+
+ private final Repository m_repository;
+ private CommandLine m_line;
+ private String[] m_remainder;
+ private final Properties m_properties;
+ private final File m_home;
+ private boolean m_DebugMode;
+ private boolean m_InfoMode;
+ private Map m_params;
+
+ //
------------------------------------------------------------------------
+ // constructors
+ //
------------------------------------------------------------------------
+
+ public DefaultSystemContextFactory(
+ Map map, Repository repository, String[] args )
+ throws Exception
+ {
+ assertNotNull( "map", map );
+ assertNotNull( "repository", repository );
+ assertNotNull( "args", args );
+
+ m_params = map;
+
+ Boolean debug = (Boolean) map.get( "urn:transit.debug.policy" );
+ assertNotNull( "urn:transit.debug.policy", debug );
+ m_DebugMode = debug.booleanValue();
+
+ Options options = buildCommandLineOptions();
+ ArgumentHandler handler = new ArgumentHandler( args );
+ ArgumentHandler.Pair pair = handler.split( options );
+ String[] arguments = pair.getSelection();
+ CommandLineParser parser = new GnuParser();
+ m_line = parser.parse( options, arguments, false );
+ m_InfoMode = m_line.hasOption( "info" );
+
+ m_remainder = pair.getRemainder();
+ m_repository = createRepository();
+
+ try
+ {
+ Properties props = new Properties();
+ m_home = Transit.DPML_HOME;
+ props.put( Transit.HOME_KEY, m_home.toString() );
+ m_properties = getStaticProperties( m_home, SystemContext.DOMAIN,
+ DefaultSystemContextFactory.class.getClassLoader(),
+ "/system.properties" );
+
+ // TODO: the expansion below seems to be very basic, and should
be replaced by the
+ // net.dpml.transit.artifact.PropertyResolver class.
+ Defaults.macroExpand( m_properties, new Properties[0] );
+ Defaults.macroExpand( m_properties, new Properties[0] );
+ Defaults.macroExpand( m_properties, new Properties[0] );
+ }
+ catch ( IOException e )
+ {
+ throw new SystemException(
+ "Failed to load system properties.", e );
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // Factory
+ //
------------------------------------------------------------------------
+
+ public Map createDefaultCriteria()
+ {
+ return createDefaultSystemCriteria();
+ }
+
+ public Object create() throws Exception
+ {
+ return create( createDefaultCriteria() );
+ }
+
+ public Object create( Map map ) throws Exception
+ {
+ assertNotNull( "map", map );
+ SystemCriteria criteria = getSystemCriteria( map );
+ return createSystemContext( criteria );
+ }
+
+ //
------------------------------------------------------------------------
+ // SystemContextFactory
+ //
------------------------------------------------------------------------
+
+ /**
+ * Return the default system critera.
+ *
+ * @return the system factory criteria
+ */
+ public SystemCriteria createDefaultSystemCriteria()
+ {
+ SystemCriteria criteria = newDefaultSystemCriteria();
+
+ //
+ // apply command line args to criteria
+ //
+
+ try
+ {
+ if( m_line.hasOption( "noproxy" ) )
+ {
+ criteria.setIsolationMode( false );
+ }
+
+ else if( m_line.hasOption( "proxy" ) )
+ {
+ criteria.setIsolationMode( true );
+ }
+
+ if( m_line.hasOption( "dir" ) )
+ {
+ String path = m_line.getOptionValue( "dir" );
+ criteria.put( SystemContext.DIR_KEY, path );
+ }
+
+ if( m_line.hasOption( "temp" ) )
+ {
+ String path = m_line.getOptionValue( "temp" );
+ criteria.put( SystemContext.TEMP_KEY, path );
+ }
+
+ if( m_line.hasOption( "logging" ) )
+ {
+ String path = m_line.getOptionValue( "logging" );
+ criteria.put( SystemContext.LOGGING_CONFIGURATION_KEY, path
);
+ }
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Error during the creation of the default system criteria.";
+ throw new SystemRuntimeException( error, e );
+ }
+
+ return criteria;
+ }
+
+ /**
+ * Create a new system context.
+ */
+ public SystemContext createSystemContext()
+ throws SystemException
+ {
+ try
+ {
+ SystemCriteria criteria = createDefaultSystemCriteria();
+ return createSystemContext( criteria );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Cannot create system context.";
+ throw new SystemException( error, e );
+ }
+ }
+
+ /**
+ * Create a new system context.
+ */
+ public SystemContext createSystemContext( SystemCriteria criteria )
+ throws SystemException
+ {
+ assertNotNull( "criteria", criteria );
+
+ boolean isolate = criteria.getIsolationMode();
+
+ File dir = normalize( criteria.getWorkingDirectory() );
+ File temp = normalize( criteria.getTempDirectory() );
+ File anchor = normalize( criteria.getAnchorDirectory() );
+
+ URL url = criteria.getLoggingConfiguration();
+ URI uri = criteria.getLoggingURI();
+ LoggingManager logging =
+ createLoggingManager( m_repository, uri, dir, url, m_DebugMode );
+ Logger logger = logging.getLoggerForCategory( SystemContext.DOMAIN );
+ Repository repository = createRepository();
+
+ setupMonitors( logger );
+
+ StringBuffer buffer =
+ new StringBuffer(
+ "info"
+ + SystemContext.LINE
+ + "\nInitial Context" );
+
+ buffer.append( SystemContext.LINE );
+
+ if( m_InfoMode )
+ {
+ logger.info( buffer.toString() );
+ }
+ else if( m_DebugMode )
+ {
+ logger.debug( buffer.toString() );
+ }
+
+ buffer =
+ new StringBuffer( "System Context" );
+ buffer.append( SystemContext.LINE );
+
+ pack( buffer, SystemContext.LOGGING_IMPLEMENTATION_KEY, uri );
+ pack( buffer, SystemContext.LOGGING_CONFIGURATION_KEY, url );
+ pack( buffer, SystemContext.HOME_KEY, Transit.DPML_HOME );
+ pack( buffer, SystemContext.ANCHOR_KEY, anchor );
+ pack( buffer, SystemContext.TEMP_KEY, temp );
+ pack( buffer, SystemContext.DIR_KEY, dir );
+ buffer.append( SystemContext.LINE );
+
+ if( m_InfoMode )
+ {
+ logger.info( buffer.toString() );
+ }
+ else if( m_DebugMode )
+ {
+ logger.debug( buffer.toString() );
+ }
+
+ return new DefaultSystemContext(
+ repository, logging, logger, Transit.DPML_HOME, dir, anchor,
temp,
+ m_InfoMode, m_DebugMode, isolate, m_remainder, m_properties );
+ }
+
+ private void setupMonitors( Logger logger ) throws SystemException
+ {
+ try
+ {
+ Transit transit = Transit.getInstance();
+
+ Logger repository = logger.getChildLogger( "repository" );
+
+ transit.getRepositoryMonitorRouter().addMonitor(
+ new RepositoryMonitorLoggerAdapter( repository ) );
+
+ Monitor repositoryMonitor = (Monitor) m_params.get(
"urn:transit.repository.monitor" );
+ if( null != repositoryMonitor )
+ {
+ transit.getRepositoryMonitorRouter().removeMonitor(
repositoryMonitor );
+ }
+
+ Logger cache = logger.getChildLogger( "cache" );
+ transit.getCacheMonitorRouter().addMonitor(
+ new CacheMonitorLoggerAdapter( cache ) );
+ Monitor cacheMonitor = (Monitor) m_params.get(
"urn:transit.cache.monitor" );
+ if( null != cacheMonitor )
+ {
+ transit.getCacheMonitorRouter().removeMonitor( cacheMonitor
);
+ }
+
+ Logger network = logger.getChildLogger( "network" );
+ transit.getNetworkMonitorRouter().addMonitor(
+ new NetworkMonitorLoggerAdapter( cache ) );
+ Monitor netMonitor = (Monitor) m_params.get(
"urn:transit.network.monitor" );
+ if( null != netMonitor )
+ {
+ transit.getNetworkMonitorRouter().removeMonitor( netMonitor
);
+ }
+ }
+ catch( TransitException e )
+ {
+ final String error =
+ "Internal error while attempt to setup transit monitors.";
+ throw new SystemException( error, e );
+ }
+ }
+
+ private File normalize( File file )
+ {
+ if( null == file )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return file.getCanonicalFile();
+ }
+ catch( IOException ioe )
+ {
+ final String error =
+ "Unexpected exception while attempting to normaliize the
file ["
+ + file.toString()
+ + "].";
+ throw new SystemRuntimeException( error, ioe );
+ }
+ }
+ }
+
+ private void pack( StringBuffer buffer, String key, Object value )
+ {
+ if( null == value )
+ {
+ pack( buffer, "${" + key + "} : " );
+ }
+ else
+ {
+ pack( buffer, "${" + key + "} : " + value );
+ }
+ }
+
+ private void pack( StringBuffer buffer, String message )
+ {
+ buffer.append( "\n" + message );
+ }
+
+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ public SystemCriteria newDefaultSystemCriteria()
+ {
+ try
+ {
+ return new DefaultSystemCriteria( m_properties, m_home );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Error during the creation of the default system criteria.";
+ throw new SystemRuntimeException( error, e );
+ }
+ }
+
+ private Repository createRepository() throws SystemException
+ {
+ try
+ {
+ return new StandardLoader();
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Error in repository subsystem establishment.";
+ throw new SystemException( error, e );
+ }
+ }
+
+
+ /**
+ * Utility method to create the LoggingManager.
+ * @param uri the logging implementation factory artifact
+ * @param dir the logging system base directory
+ * @param path the logging system configuration path
+ * @param debug the debug flag
+ * @return the logging manager
+ * @exception NullPointerException if the supplied context is null
+ */
+ private LoggingManager createLoggingManager(
+ final Repository repository, final URI uri, final File dir,
+ final URL path, boolean debug ) throws SystemException
+ {
+ try
+ {
+ ClassLoader classloader = SystemContext.class.getClassLoader();
+ Object[] args = new Object[0];
+ Object object = repository.getPlugin( classloader, uri, args );
+ if( object instanceof LoggingFactory )
+ {
+ LoggingFactory factory = (LoggingFactory) object;
+ LoggingCriteria params =
factory.createDefaultLoggingCriteria();
+ params.setBaseDirectory( dir );
+ params.setLoggingConfiguration( path );
+ params.setDebugEnabled( debug );
+ return factory.createLoggingManager( params );
+ }
+ else
+ {
+ final String error =
+ "Logging manager provider referenced by ["
+ + uri
+ + "] does not implement the service interface ["
+ + LoggingFactory.class.getName()
+ + "].";
+ throw new SystemException( error );
+ }
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Error in logging subsystem establishment.";
+ throw new SystemException( error, e );
+ }
+ }
+
+ private SystemCriteria getSystemCriteria( Map map ) throws
SystemException
+ {
+ if( null == map )
+ {
+ throw new NullPointerException( "map" );
+ }
+ if( map instanceof SystemCriteria )
+ {
+ return (SystemCriteria) map;
+ }
+ else
+ {
+ SystemCriteria criteria = (SystemCriteria)
createDefaultCriteria();
+ try
+ {
+ String[] keys = (String[]) map.keySet().toArray( new
String[0] );
+ for( int i=0; i<keys.length; i++ )
+ {
+ String key = keys[i];
+ Object value = map.get( key );
+ criteria.put( key, value );
+ }
+ return criteria;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Could not map supplied keys to the system context.";
+ throw new SystemException( error, e );
+ }
+ }
+ }
+
+ private void assertNotNull( String key, Object object )
+ throws NullPointerException
+ {
+ if( null == object )
+ throw new NullPointerException( key );
+ }
+
+ private Options buildCommandLineOptions()
+ {
+ Options options = new Options();
+
+ //
+ // on-line/offline switches
+ //
+
+ OptionGroup onlineMode = new OptionGroup();
+ onlineMode.addOption(
+ new Option( "offline", REZ.getString( "cli-offline-description" )
) );
+ onlineMode.addOption(
+ new Option( "online", REZ.getString( "cli-online-description" ) )
);
+ options.addOptionGroup( onlineMode );
+
+ //
+ // proxy/noproxy switch
+ //
+
+ OptionGroup proxyMode = new OptionGroup();
+ proxyMode.addOption(
+ new Option( "proxy", REZ.getString( "cli-proxy-description" ) ) );
+ proxyMode.addOption(
+ new Option( "noproxy", REZ.getString( "cli-noproxy-description" )
) );
+ options.addOptionGroup( onlineMode );
+
+ //
+ // timestamp switches
+ //
+
+ // timestamp options no longer relevant because they have been moved
+ // to per host
+ //
+ //OptionGroup timestamp = new OptionGroup();
+ //timestamp.addOption(
+ // new Option( "fast", REZ.getString( "cli-fast-description" ) ) );
+ //timestamp.addOption(
+ // new Option( "snapshot", REZ.getString(
"cli-snapshot-description" ) ) );
+ //timestamp.addOption(
+ // new Option( "timestamp", REZ.getString(
"cli-timestamp-description" ) ) );
+ //timestamp.addOption(
+ // new Option( "overwrite", REZ.getString(
"cli-overwrite-description" ) ) );
+ //options.addOptionGroup( timestamp );
+
+ //
+ // parameters
+ //
+
+ options.addOption(
+ new Option( "debug", REZ.getString( "cli-debug-description" ) ) );
+ options.addOption(
+ new Option( "info", REZ.getString( "cli-info-description" ) ) );
+
+ options.addOption(
+ OptionBuilder.hasArg().withArgName( REZ.getString( "directory" ) )
+ .withDescription( REZ.getString( "cli-dir-description" ) )
+ .create( "dir" ) );
+ options.addOption(
+ OptionBuilder.hasArg().withArgName( REZ.getString( "directory" ) )
+ .withDescription( REZ.getString( "cli-temp-description" ) )
+ .create( "temp" ) );
+
+ options.addOption(
+ OptionBuilder.hasArg().withArgName( REZ.getString( "uri" ) )
+ .withDescription( REZ.getString( "cli-logging-description" ) )
+ .create( "logging" ) );
+ options.addOption(
+ OptionBuilder.hasArg().withArgName( REZ.getString( "directory" ) )
+ .withDescription( REZ.getString( "cli-cache-description" ) )
+ .create( "cache" ) );
+ options.addOption(
+ OptionBuilder.hasArgs().withArgName( REZ.getString( "host" ) )
+ .withDescription( REZ.getString( "cli-hosts-description" ) )
+ .withValueSeparator( ',' )
+ .create( "hosts" ) );
+
+ return options;
+ }
+
+ private static Properties getStaticProperties( File home, String key,
+ ClassLoader cl, String
bootstrap )
+ throws IOException
+ {
+ String filename = key + ".properties";
+
+ //
+ // get [home]/[key].properties
+ //
+
+ Properties properties = getStaticProperties( cl, bootstrap );
+ File homePreferenceFile = new File( home, filename );
+ loadFile( properties, homePreferenceFile );
+
+ //
+ // get ${user.home}/[key].properties
+ //
+
+ File user = getUserDirectory();
+ File userPreferenceFile = new File( user, filename );
+ loadFile( properties, userPreferenceFile );
+
+ //
+ // get ${user.dir}/[key].properties
+ //
+
+ File dir = getWorkingDirectory();
+ File dirPreferenceFile = new File( dir, filename );
+ loadFile( properties, dirPreferenceFile );
+
+ String homeKey = key + ".home";
+ properties.setProperty( homeKey, home.toString() );
+
+ return properties;
+ }
+
+ private static File getUserDirectory()
+ {
+ return new File( System.getProperty( "user.home" ) );
+ }
+
+ private static File getWorkingDirectory()
+ {
+ return new File( System.getProperty( "user.dir" ) );
+ }
+
+ /**
+ * Read in a static properties resource relative to a supplied class
+ * and path.
+ *
+ * @param ref a class used to establish a classloader and anchors
+ * relative path references
+ * @param path the resource address
+ * @return the static properties
+ * @exception IllegalStateException if the path is unresolvable
+ */
+ public static Properties getStaticProperties( ClassLoader ref, String
path )
+ throws IOException
+ {
+ Properties bootstrap = new Properties();
+ InputStream input = ref.getResourceAsStream( path );
+ if( input != null )
+ {
+ bootstrap.load( input );
+ }
+ return bootstrap;
+ }
+
+ private static void loadFile( Properties properties, File file )
+ throws IOException
+ {
+ if( file.exists() )
+ {
+ InputStream input = new FileInputStream( file );
+ try
+ {
+ properties.load( input );
+ } finally
+ {
+ input.close();
+ }
+ }
+ }
+
+}
+

Modified:
development/main/metro/system/impl/src/main/net/dpml/system/impl/DefaultSystemCriteria.java
==============================================================================
---
development/main/metro/system/impl/src/main/net/dpml/system/impl/DefaultSystemCriteria.java
(original)
+++
development/main/metro/system/impl/src/main/net/dpml/system/impl/DefaultSystemCriteria.java
Thu Dec 23 16:05:10 2004
@@ -1,497 +1,497 @@
-/*
- * Copyright 2004 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.system.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-import java.util.Properties;
-
-import net.dpml.criteria.Criteria;
-import net.dpml.criteria.CriteriaRuntimeException;
-import net.dpml.criteria.Parameter;
-import net.dpml.system.SystemContext;
-import net.dpml.system.SystemCriteria;
-
-import net.dpml.transit.Transit;
-
-/**
- * DefaultLoggingCriteria is a class holding the values supplied by a user
- * for application to a LoggingManager factory.
- *
- * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
- * @version $Id$
- */
-public class DefaultSystemCriteria extends Criteria implements SystemCriteria
-{
- //--------------------------------------------------------------
- // static
- //--------------------------------------------------------------
-
- public static final String[] KEYS =
- new String[]{
- SystemContext.LOGGING_IMPLEMENTATION_KEY,
- SystemContext.LOGGING_CONFIGURATION_KEY,
- SystemContext.HOME_KEY,
- SystemContext.TEMP_KEY,
- SystemContext.DIR_KEY,
- SystemContext.ANCHOR_KEY,
- SystemContext.ISOLATE_KEY
- };
-
- /**
- * The factory parameters template.
- * @return the set of parameters constraining the criteria
- */
- private static Parameter[] buildParameters( Properties properties, File
home )
- {
- return new Parameter[] {
- new Parameter(
- SystemContext.LOGGING_IMPLEMENTATION_KEY,
- URI.class,
- getDefaultURI(
- properties.getProperty(
SystemContext.LOGGING_IMPLEMENTATION_KEY ) )
- ),
- new Parameter(
- SystemContext.LOGGING_CONFIGURATION_KEY,
- String.class,
- properties.getProperty(
SystemContext.LOGGING_CONFIGURATION_KEY )
- ),
- new Parameter(
- SystemContext.TEMP_KEY,
- File.class,
- getDefaultFile(
- properties.getProperty( SystemContext.TEMP_KEY ),
- new File( System.getProperty( "java.io.tmpdir" ) ) )
- ),
- new Parameter(
- SystemContext.DIR_KEY,
- File.class,
- getDefaultFile(
- properties.getProperty( SystemContext.DIR_KEY ),
- new File( System.getProperty( "user.dir" ) ) )
- ),
- new Parameter(
- SystemContext.ANCHOR_KEY,
- File.class,
- getDefaultFile(
- properties.getProperty( SystemContext.ANCHOR_KEY ), null )
- ),
- new Parameter(
- SystemContext.ISOLATE_KEY,
- Boolean.class,
- getDefaultBoolean(
- properties.getProperty( SystemContext.ISOLATE_KEY ), true )
- )
- };
- }
-
- private static File getDefaultFile( String value, File fallback )
- {
- if( null == value )
- {
- return fallback;
- }
- else
- {
- return new File( value );
- }
- }
-
- private static URI getDefaultURI( String spec )
- {
- if( null == spec )
- {
- return null;
- }
- else
- {
- try
- {
- return new URI( spec );
- }
- catch( Throwable e )
- {
- final String error =
- "Bad default artifact uri: [" + spec + "] due to "
- + e.toString();
- throw new IllegalArgumentException( error );
- }
- }
- }
-
- private static Boolean getDefaultBoolean( String value, boolean fallback
)
- {
- if( null == value )
- {
- return new Boolean( fallback );
- }
- else
- {
- return new Boolean( value );
- }
- }
-
- //--------------------------------------------------------------
- // constructor
- //--------------------------------------------------------------
-
- /**
- * Creation of a new default logging criteria.
- */
- public DefaultSystemCriteria( Properties properties, File home )
- {
- super( buildParameters( properties, home ) );
- }
-
- //--------------------------------------------------------------
- // SystemCriteria
- //--------------------------------------------------------------
-
- /**
- * Set the isolation enabled.
- * @param mode TRUE to enable isolation mode else FALSE
- */
- public void setIsolationMode( boolean mode )
- {
- put( SystemContext.ISOLATE_KEY, new Boolean( mode ) );
- }
-
- /**
- * Set the working directory.
- * @param dir the working directory
- */
- public void setWorkingDirectory( File dir )
- {
- if( null == dir )
- {
- throw new NullPointerException( SystemContext.DIR_KEY );
- }
- put( SystemContext.DIR_KEY, dir );
- }
-
- /**
- * Set the temp directory.
- * @param dir the temp directory
- */
- public void setTempDirectory( File dir )
- {
- if( null == dir )
- {
- throw new NullPointerException( SystemContext.TEMP_KEY );
- }
- put( SystemContext.TEMP_KEY, dir );
- }
-
- /**
- * Set the anchor directory.
- * @param dir the anchor directory
- */
- public void setAnchorDirectory( File dir )
- {
- if( null == dir )
- {
- throw new NullPointerException( SystemContext.ANCHOR_KEY );
- }
- put( SystemContext.ANCHOR_KEY, dir );
- }
-
- /**
- * Set the logging system configuration URI.
- * @param uri the configuration URI
- */
- public void setLoggingConfiguration( String uri )
- {
- if( null == uri )
- {
- throw new NullPointerException(
SystemContext.LOGGING_CONFIGURATION_KEY );
- }
- put( SystemContext.LOGGING_CONFIGURATION_KEY, uri );
- }
-
- /**
- * Set the logging system artifact specification.
- * @param uri the URI of the logging system artifact spec
- */
- public void setLoggingURI( URI uri )
- {
- if( null == uri )
- {
- throw new NullPointerException(
SystemContext.LOGGING_IMPLEMENTATION_KEY );
- }
- put( SystemContext.LOGGING_IMPLEMENTATION_KEY, uri );
- }
-
- //----------------------------------------------------------------
- // accessors
- //----------------------------------------------------------------
-
- /**
- * Get the isolation enabled policy
- * @return mode TRUE if isolation mode enabled else FALSE
- */
- public boolean getIsolationMode()
- {
- return getBooleanValue( SystemContext.ISOLATE_KEY );
- }
-
- /**
- * Get the working directory.
- * @return the working directory.
- */
- public File getWorkingDirectory()
- {
- return getFileValue( SystemContext.DIR_KEY );
- }
-
- /**
- * Get the temporary directory.
- * @return the temporary directory.
- */
- public File getTempDirectory()
- {
- return getFileValue( SystemContext.TEMP_KEY );
- }
-
- /**
- * Get the library anchor directory.
- * @return the anchor directory.
- */
- public File getAnchorDirectory()
- {
- File anchor = getFileValue( SystemContext.ANCHOR_KEY );
- if( null == anchor )
- {
- return new File( Transit.HOME, "lib" );
- }
- else
- {
- return anchor;
- }
- }
-
- /**
- * Get the logging configuration url.
- * @return the logging configuration url (possibly null)
- */
- public URL getLoggingConfiguration()
- {
- Object object = get( SystemContext.LOGGING_CONFIGURATION_KEY );
- if( null == object )
- {
- return null;
- }
- else if( object instanceof File )
- {
- return convertToURL( (File) object );
- }
- else if( object instanceof String )
- {
- String path = (String) object;
- File file = new File( path );
- if( file.isAbsolute() )
- {
- return convertToURL( file );
- }
- else
- {
- File base = getWorkingDirectory();
- File target = new File( base, path );
- return convertToURL( target );
- }
- }
- else
- {
- final String error =
- "Cannot convert value of the class ["
- + object.getClass().getName()
- + "] to a url.";
- throw new CriteriaRuntimeException( error );
- }
- }
-
- private URL convertToURL( File file )
- {
- try
- {
- return file.toURL();
- }
- catch( IOException e )
- {
- final String error =
- "Error while attempting to convert the file ["
- + file.toString()
- + "] to a url.";
- throw new CriteriaRuntimeException( error, e );
- }
- }
-
- private URI convertToURI( String path )
- {
- try
- {
- return new URI( path );
- }
- catch( Throwable e )
- {
- final String error =
- "Error while attempting to convert the path ["
- + path
- + "] to a uri.";
- throw new CriteriaRuntimeException( error, e );
- }
- }
-
- /**
- * Get the logging configuration url.
- * @return the logging configuration artifact (possibly null)
- */
- public URI getLoggingURI()
- {
- Object object = get( SystemContext.LOGGING_IMPLEMENTATION_KEY );
- if( null == object )
- {
- return null;
- }
- else if( object instanceof URI )
- {
- return (URI) object;
- }
- else if( object instanceof String )
- {
- String path = (String) object;
- return convertToURI( path );
- }
- else
- {
- final String error =
- "Cannot convert value of the class ["
- + object.getClass().getName()
- + "] to a uri.";
- throw new CriteriaRuntimeException( error );
- }
- }
-
- //----------------------------------------------------------------
- // internals
- //----------------------------------------------------------------
-
- private boolean getBooleanValue( String key )
- {
- Object object = get( key );
- if( null == object )
- {
- throw new NullPointerException( key );
- }
- if( object instanceof Boolean )
- {
- Boolean value = (Boolean) object;
- return value.booleanValue();
- }
- else
- {
- final String error =
- "Criteria parameter for key [" + key
- + "] returned an unexpected type ["
- + object.getClass().getName()
- + "] (expecting Boolean).";
- throw new IllegalStateException( error );
- }
- }
-
- private File getFileValue( String key )
- {
- return getFileValue( key, null );
- }
-
- private File getFileValue( String key, File defaultValue )
- {
- Object object = get( key );
- if( null == object )
- {
- return defaultValue;
- }
- if( object instanceof File )
- {
- return (File) object;
- }
- else
- {
- final String error =
- "Criteria parameter for key [" + key
- + "] returned an unexpected type ["
- + object.getClass().getName()
- + "] (expecting java.io.File).";
- throw new IllegalStateException( error );
- }
- }
-/* Never used. TODO: Remove
- private URL getURLValue( String key, boolean flag )
- {
- Object object = get( key );
- if( null == object )
- {
- if( flag )
- {
- return null;
- }
- else
- {
- throw new NullPointerException( key );
- }
- }
- if( object instanceof URL )
- {
- return (URL) object;
- }
- else
- {
- final String error =
- "Criteria parameter for key [" + key
- + "] returned an unexpected type ["
- + object.getClass().getName()
- + "] (expecting java.net.URL).";
- throw new IllegalStateException( error );
- }
- }
-
- private Artifact getArtifactValue( String key )
- {
- Object object = get( key );
- if( null == object )
- {
- throw new NullPointerException( key );
- }
- if( object instanceof Artifact )
- {
- return (Artifact) object;
- }
- else
- {
- final String error =
- "Criteria parameter for key [" + key
- + "] returned an unexpected type ["
- + object.getClass().getName()
- + "] (expecting net.dpml.transit.artifact.Artifact).";
- throw new IllegalStateException( error );
- }
- }
-*/
-}
+/*
+ * Copyright 2004 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.system.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Properties;
+
+import net.dpml.criteria.Criteria;
+import net.dpml.criteria.CriteriaRuntimeException;
+import net.dpml.criteria.Parameter;
+import net.dpml.system.SystemContext;
+import net.dpml.system.SystemCriteria;
+
+import net.dpml.transit.Transit;
+
+/**
+ * DefaultLoggingCriteria is a class holding the values supplied by a user
+ * for application to a LoggingManager factory.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id$
+ */
+public class DefaultSystemCriteria extends Criteria implements SystemCriteria
+{
+ //--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ public static final String[] KEYS =
+ new String[]{
+ SystemContext.LOGGING_IMPLEMENTATION_KEY,
+ SystemContext.LOGGING_CONFIGURATION_KEY,
+ SystemContext.HOME_KEY,
+ SystemContext.TEMP_KEY,
+ SystemContext.DIR_KEY,
+ SystemContext.ANCHOR_KEY,
+ SystemContext.ISOLATE_KEY
+ };
+
+ /**
+ * The factory parameters template.
+ * @return the set of parameters constraining the criteria
+ */
+ private static Parameter[] buildParameters( Properties properties, File
home )
+ {
+ return new Parameter[] {
+ new Parameter(
+ SystemContext.LOGGING_IMPLEMENTATION_KEY,
+ URI.class,
+ getDefaultURI(
+ properties.getProperty(
SystemContext.LOGGING_IMPLEMENTATION_KEY ) )
+ ),
+ new Parameter(
+ SystemContext.LOGGING_CONFIGURATION_KEY,
+ String.class,
+ properties.getProperty(
SystemContext.LOGGING_CONFIGURATION_KEY )
+ ),
+ new Parameter(
+ SystemContext.TEMP_KEY,
+ File.class,
+ getDefaultFile(
+ properties.getProperty( SystemContext.TEMP_KEY ),
+ new File( System.getProperty( "java.io.tmpdir" ) ) )
+ ),
+ new Parameter(
+ SystemContext.DIR_KEY,
+ File.class,
+ getDefaultFile(
+ properties.getProperty( SystemContext.DIR_KEY ),
+ new File( System.getProperty( "user.dir" ) ) )
+ ),
+ new Parameter(
+ SystemContext.ANCHOR_KEY,
+ File.class,
+ getDefaultFile(
+ properties.getProperty( SystemContext.ANCHOR_KEY ), null )
+ ),
+ new Parameter(
+ SystemContext.ISOLATE_KEY,
+ Boolean.class,
+ getDefaultBoolean(
+ properties.getProperty( SystemContext.ISOLATE_KEY ), true )
+ )
+ };
+ }
+
+ private static File getDefaultFile( String value, File fallback )
+ {
+ if( null == value )
+ {
+ return fallback;
+ }
+ else
+ {
+ return new File( value );
+ }
+ }
+
+ private static URI getDefaultURI( String spec )
+ {
+ if( null == spec )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return new URI( spec );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Bad default artifact uri: [" + spec + "] due to "
+ + e.toString();
+ throw new IllegalArgumentException( error );
+ }
+ }
+ }
+
+ private static Boolean getDefaultBoolean( String value, boolean fallback
)
+ {
+ if( null == value )
+ {
+ return new Boolean( fallback );
+ }
+ else
+ {
+ return new Boolean( value );
+ }
+ }
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ /**
+ * Creation of a new default logging criteria.
+ */
+ public DefaultSystemCriteria( Properties properties, File home )
+ {
+ super( buildParameters( properties, home ) );
+ }
+
+ //--------------------------------------------------------------
+ // SystemCriteria
+ //--------------------------------------------------------------
+
+ /**
+ * Set the isolation enabled.
+ * @param mode TRUE to enable isolation mode else FALSE
+ */
+ public void setIsolationMode( boolean mode )
+ {
+ put( SystemContext.ISOLATE_KEY, new Boolean( mode ) );
+ }
+
+ /**
+ * Set the working directory.
+ * @param dir the working directory
+ */
+ public void setWorkingDirectory( File dir )
+ {
+ if( null == dir )
+ {
+ throw new NullPointerException( SystemContext.DIR_KEY );
+ }
+ put( SystemContext.DIR_KEY, dir );
+ }
+
+ /**
+ * Set the temp directory.
+ * @param dir the temp directory
+ */
+ public void setTempDirectory( File dir )
+ {
+ if( null == dir )
+ {
+ throw new NullPointerException( SystemContext.TEMP_KEY );
+ }
+ put( SystemContext.TEMP_KEY, dir );
+ }
+
+ /**
+ * Set the anchor directory.
+ * @param dir the anchor directory
+ */
+ public void setAnchorDirectory( File dir )
+ {
+ if( null == dir )
+ {
+ throw new NullPointerException( SystemContext.ANCHOR_KEY );
+ }
+ put( SystemContext.ANCHOR_KEY, dir );
+ }
+
+ /**
+ * Set the logging system configuration URI.
+ * @param uri the configuration URI
+ */
+ public void setLoggingConfiguration( String uri )
+ {
+ if( null == uri )
+ {
+ throw new NullPointerException(
SystemContext.LOGGING_CONFIGURATION_KEY );
+ }
+ put( SystemContext.LOGGING_CONFIGURATION_KEY, uri );
+ }
+
+ /**
+ * Set the logging system artifact specification.
+ * @param uri the URI of the logging system artifact spec
+ */
+ public void setLoggingURI( URI uri )
+ {
+ if( null == uri )
+ {
+ throw new NullPointerException(
SystemContext.LOGGING_IMPLEMENTATION_KEY );
+ }
+ put( SystemContext.LOGGING_IMPLEMENTATION_KEY, uri );
+ }
+
+ //----------------------------------------------------------------
+ // accessors
+ //----------------------------------------------------------------
+
+ /**
+ * Get the isolation enabled policy
+ * @return mode TRUE if isolation mode enabled else FALSE
+ */
+ public boolean getIsolationMode()
+ {
+ return getBooleanValue( SystemContext.ISOLATE_KEY );
+ }
+
+ /**
+ * Get the working directory.
+ * @return the working directory.
+ */
+ public File getWorkingDirectory()
+ {
+ return getFileValue( SystemContext.DIR_KEY );
+ }
+
+ /**
+ * Get the temporary directory.
+ * @return the temporary directory.
+ */
+ public File getTempDirectory()
+ {
+ return getFileValue( SystemContext.TEMP_KEY );
+ }
+
+ /**
+ * Get the library anchor directory.
+ * @return the anchor directory.
+ */
+ public File getAnchorDirectory()
+ {
+ File anchor = getFileValue( SystemContext.ANCHOR_KEY );
+ if( null == anchor )
+ {
+ return new File( Transit.DPML_HOME, "lib" );
+ }
+ else
+ {
+ return anchor;
+ }
+ }
+
+ /**
+ * Get the logging configuration url.
+ * @return the logging configuration url (possibly null)
+ */
+ public URL getLoggingConfiguration()
+ {
+ Object object = get( SystemContext.LOGGING_CONFIGURATION_KEY );
+ if( null == object )
+ {
+ return null;
+ }
+ else if( object instanceof File )
+ {
+ return convertToURL( (File) object );
+ }
+ else if( object instanceof String )
+ {
+ String path = (String) object;
+ File file = new File( path );
+ if( file.isAbsolute() )
+ {
+ return convertToURL( file );
+ }
+ else
+ {
+ File base = getWorkingDirectory();
+ File target = new File( base, path );
+ return convertToURL( target );
+ }
+ }
+ else
+ {
+ final String error =
+ "Cannot convert value of the class ["
+ + object.getClass().getName()
+ + "] to a url.";
+ throw new CriteriaRuntimeException( error );
+ }
+ }
+
+ private URL convertToURL( File file )
+ {
+ try
+ {
+ return file.toURL();
+ }
+ catch( IOException e )
+ {
+ final String error =
+ "Error while attempting to convert the file ["
+ + file.toString()
+ + "] to a url.";
+ throw new CriteriaRuntimeException( error, e );
+ }
+ }
+
+ private URI convertToURI( String path )
+ {
+ try
+ {
+ return new URI( path );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Error while attempting to convert the path ["
+ + path
+ + "] to a uri.";
+ throw new CriteriaRuntimeException( error, e );
+ }
+ }
+
+ /**
+ * Get the logging configuration url.
+ * @return the logging configuration artifact (possibly null)
+ */
+ public URI getLoggingURI()
+ {
+ Object object = get( SystemContext.LOGGING_IMPLEMENTATION_KEY );
+ if( null == object )
+ {
+ return null;
+ }
+ else if( object instanceof URI )
+ {
+ return (URI) object;
+ }
+ else if( object instanceof String )
+ {
+ String path = (String) object;
+ return convertToURI( path );
+ }
+ else
+ {
+ final String error =
+ "Cannot convert value of the class ["
+ + object.getClass().getName()
+ + "] to a uri.";
+ throw new CriteriaRuntimeException( error );
+ }
+ }
+
+ //----------------------------------------------------------------
+ // internals
+ //----------------------------------------------------------------
+
+ private boolean getBooleanValue( String key )
+ {
+ Object object = get( key );
+ if( null == object )
+ {
+ throw new NullPointerException( key );
+ }
+ if( object instanceof Boolean )
+ {
+ Boolean value = (Boolean) object;
+ return value.booleanValue();
+ }
+ else
+ {
+ final String error =
+ "Criteria parameter for key [" + key
+ + "] returned an unexpected type ["
+ + object.getClass().getName()
+ + "] (expecting Boolean).";
+ throw new IllegalStateException( error );
+ }
+ }
+
+ private File getFileValue( String key )
+ {
+ return getFileValue( key, null );
+ }
+
+ private File getFileValue( String key, File defaultValue )
+ {
+ Object object = get( key );
+ if( null == object )
+ {
+ return defaultValue;
+ }
+ if( object instanceof File )
+ {
+ return (File) object;
+ }
+ else
+ {
+ final String error =
+ "Criteria parameter for key [" + key
+ + "] returned an unexpected type ["
+ + object.getClass().getName()
+ + "] (expecting java.io.File).";
+ throw new IllegalStateException( error );
+ }
+ }
+/* Never used. TODO: Remove
+ private URL getURLValue( String key, boolean flag )
+ {
+ Object object = get( key );
+ if( null == object )
+ {
+ if( flag )
+ {
+ return null;
+ }
+ else
+ {
+ throw new NullPointerException( key );
+ }
+ }
+ if( object instanceof URL )
+ {
+ return (URL) object;
+ }
+ else
+ {
+ final String error =
+ "Criteria parameter for key [" + key
+ + "] returned an unexpected type ["
+ + object.getClass().getName()
+ + "] (expecting java.net.URL).";
+ throw new IllegalStateException( error );
+ }
+ }
+
+ private Artifact getArtifactValue( String key )
+ {
+ Object object = get( key );
+ if( null == object )
+ {
+ throw new NullPointerException( key );
+ }
+ if( object instanceof Artifact )
+ {
+ return (Artifact) object;
+ }
+ else
+ {
+ final String error =
+ "Criteria parameter for key [" + key
+ + "] returned an unexpected type ["
+ + object.getClass().getName()
+ + "] (expecting net.dpml.transit.artifact.Artifact).";
+ throw new IllegalStateException( error );
+ }
+ }
+*/
+}

Modified:
development/main/planet/facilities/http/impl/src/main/net/dpml/http/impl/JsseListener.java
==============================================================================
---
development/main/planet/facilities/http/impl/src/main/net/dpml/http/impl/JsseListener.java
(original)
+++
development/main/planet/facilities/http/impl/src/main/net/dpml/http/impl/JsseListener.java
Thu Dec 23 16:05:10 2004
@@ -154,7 +154,15 @@
if( m_Logger.isDebugEnabled() )
m_Logger.debug( "Starting SSL socket: " + this );
m_HttpServer.addListener( this );
- super.start();
+ try
+ {
+ super.start();
+ } catch( NullPointerException e )
+ {
+ // Seems to be thrown if the password can not be properly
+ // resolved. Let's log, but ignore it.
+ m_Logger.warn( "SSL failed to start. Probably invalid KeyStore
or incorrect password to the KeyStore." );
+ }
}

public void stop()

Modified: development/main/planet/facilities/index.xml
==============================================================================
--- development/main/planet/facilities/index.xml (original)
+++ development/main/planet/facilities/index.xml Thu Dec 23 16:05:10
2004
@@ -71,7 +71,7 @@
<info>
<group>jetty</group>
<name>org.mortbay.jetty</name>
- <version>5.0.0</version>
+ <version>5.1.2pre0</version>
<type>jar</type>
</info>
<gump>

Modified: development/main/transit/handler/src/main/net/dpml/transit/Main.java
==============================================================================
--- development/main/transit/handler/src/main/net/dpml/transit/Main.java
(original)
+++ development/main/transit/handler/src/main/net/dpml/transit/Main.java
Thu Dec 23 16:05:10 2004
@@ -18,6 +18,9 @@

package net.dpml.transit;

+import java.io.File;
+import java.io.FileInputStream;
+
import java.net.URI;
import java.util.ArrayList;
import java.util.Map;
@@ -69,7 +72,23 @@
//
// Setup transit protocol handler
//
-
+
+ File propsFile = new File( Transit.DPML_HOME,
"transit/system.properties" );
+ if( propsFile.exists() )
+ {
+ FileInputStream fis = null;
+ try
+ {
+ fis = new FileInputStream( propsFile );
+ System.getProperties().load( fis );
+ } catch( Exception e )
+ {
+ System.out.println( "Can't read: " + propsFile );
+ } finally
+ {
+ fis.close();
+ }
+ }
System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);

//

Modified:
development/main/transit/handler/src/main/net/dpml/transit/Transit.java
==============================================================================
--- development/main/transit/handler/src/main/net/dpml/transit/Transit.java
(original)
+++ development/main/transit/handler/src/main/net/dpml/transit/Transit.java
Thu Dec 23 16:05:10 2004
@@ -87,7 +87,7 @@
* is defined, then the assigned value will be returned, otherwise the
* DPML home directory shall default to ${user.home}/.dpml.
*/
- public static final File HOME = resolveHomeDirectory();
+ public static final File DPML_HOME = resolveHomeDirectory();

/**
* Returns the singleton instance of the transit system.

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
Thu Dec 23 16:05:10 2004
@@ -241,7 +241,7 @@
File cachedir = new File( cache );
if( !cachedir.isAbsolute() )
{
- cachedir = new File( Transit.HOME, cache );
+ cachedir = new File( Transit.DPML_HOME, cache );
}
cachedir.mkdirs();
return cachedir;

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
Thu Dec 23 16:05:10 2004
@@ -330,7 +330,7 @@
File f = new File( base );
if( !f.isAbsolute() )
{
- f = new File( Transit.HOME, base );
+ f = new File( Transit.DPML_HOME, base );
}
base = f.toURL().toExternalForm();
}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
Thu Dec 23 16:05:10 2004
@@ -283,7 +283,7 @@
//

File artifactAuthFile;
- File transitDir = new File( Transit.HOME, "transit" );
+ File transitDir = new File( Transit.DPML_HOME, "transit" );
artifactAuthFile = new File( transitDir, AUTHORITY_FILENAME );
if( artifactAuthFile.exists() )
{
@@ -333,7 +333,7 @@
monitor.trace( message );
}

- return new File( Transit.HOME, "transit" ).toURL();
+ return new File( Transit.DPML_HOME, "transit" ).toURL();

}
catch( Exception e )
@@ -381,7 +381,7 @@
try
{
Properties p = new Properties();
- p.setProperty( Transit.HOME_KEY, Transit.HOME.toString() );
+ p.setProperty( Transit.HOME_KEY, Transit.DPML_HOME.toString() );
p.load( stream );
String authority = Util.getProperty( p, AUTHORITY_KEY, null );
if( authority == null )
@@ -391,7 +391,7 @@
File f = new File( authority );
if( !f.isAbsolute() )
{
- f = new File( Transit.HOME, "transit/" + authority );
+ f = new File( Transit.DPML_HOME, "transit/" + authority );
}
if( f.exists() )
{

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/Util.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/Util.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/Util.java
Thu Dec 23 16:05:10 2004
@@ -51,7 +51,7 @@
try
{
Properties p = new Properties();
- p.setProperty( Transit.HOME_KEY, Transit.HOME.toString() );
+ p.setProperty( Transit.HOME_KEY, Transit.DPML_HOME.toString() );
p.load( stream );
Iterator list = p.entrySet().iterator();
while ( list.hasNext() )

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
Thu Dec 23 16:05:10 2004
@@ -152,7 +152,7 @@
}
else
{
- File dir = new File( Transit.HOME, path );
+ File dir = new File( Transit.DPML_HOME, path );
dir.mkdirs();
return dir.toURL();
}



  • svn commit: r1271 - in development/main: central/site/src/docs/products/transit central/tutorials magic/bootstrap/src/main/net/dpml/magic/bootstrap magic/core/src/main/net/dpml/magic magic/core/src/main/net/dpml/magic/tasks metro/main/src/main/net/dpml/metro metro/system/impl/src/main/net/dpml/system/impl planet/facilities planet/facilities/http/impl/src/main/net/dpml/http/impl transit/handler/src/main/net/dpml/transit transit/handler/src/main/net/dpml/transit/artifact, niclas, 12/23/2004

Archive powered by MHonArc 2.6.24.

Top of Page