Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2543 - in development/main: depot depot/console depot/console/etc/bin depot/console/src/main/net/dpml/depot/console depot/console/src/main/net/dpml/depot/lang depot/station/src/main/net/dpml/depot/prefs transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/cache transit/core/handler/src/main/net/dpml/transit/host

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2543 - in development/main: depot depot/console depot/console/etc/bin depot/console/src/main/net/dpml/depot/console depot/console/src/main/net/dpml/depot/lang depot/station/src/main/net/dpml/depot/prefs transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/cache transit/core/handler/src/main/net/dpml/transit/host
  • Date: Fri, 13 May 2005 16:38:17 +0000

Author: mcconnell AT dpml.net
Date: Fri May 13 16:38:14 2005
New Revision: 2543

Added:
development/main/depot/console/src/main/net/dpml/depot/lang/
- copied from r2518,
development/main/depot/console/src/main/net/dpml/depot/console/
development/main/depot/console/src/main/net/dpml/depot/lang/DPML.java

development/main/depot/console/src/main/net/dpml/depot/lang/DepotClassLoader.java
- copied, changed from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/DepotClassLoader.java

development/main/depot/console/src/main/net/dpml/depot/lang/Environment.java
- copied, changed from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/Environment.java

development/main/depot/console/src/main/net/dpml/depot/lang/EnvironmentException.java
- copied, changed from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/EnvironmentException.java
development/main/depot/console/src/main/net/dpml/depot/lang/Main.java
- copied, changed from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/Main.java

development/main/depot/console/src/main/net/dpml/depot/lang/PropertyResolver.java
- copied, changed from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/PropertyResolver.java
development/main/depot/console/src/main/net/dpml/depot/lang/package.html
- copied unchanged from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/package.html

development/main/transit/core/handler/src/main/net/dpml/transit/TransitPreferences.java
Removed:
development/main/depot/console/src/main/net/dpml/depot/console/
Modified:
development/main/depot/console/build.xml
development/main/depot/console/etc/bin/depot-cygwin.sh
development/main/depot/console/etc/bin/depot-unix.sh
development/main/depot/console/etc/bin/depot.bat
development/main/depot/index.xml

development/main/depot/station/src/main/net/dpml/depot/prefs/CachePanel.java

development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerControllerPanel.java

development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerMainPanel.java
development/main/depot/station/src/main/net/dpml/depot/prefs/Main.java

development/main/depot/station/src/main/net/dpml/depot/prefs/TransitPanel.java

development/main/depot/station/src/main/net/dpml/depot/prefs/TransitResourceHostPanel.java

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

development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java

development/main/transit/core/handler/src/main/net/dpml/transit/host/PreferencesResourceManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/host/ResourceHostHelper.java

development/main/transit/core/handler/src/main/net/dpml/transit/host/StandardResourceManager.java
Log:
Updgrade Transit preferences usage such that a single preferences node is
used as the root and child nodes are supplied to sub-systems as required.
This update paves the way for following similar parttern for configuration
managers. Updates to depot have also been made to synchronize with the
Transit updates. Finally, changes have been made to the way in which factory
default settings are resolved which in principal should correct the build
failure under the Unix platform.

Modified: development/main/depot/console/build.xml
==============================================================================
--- development/main/depot/console/build.xml (original)
+++ development/main/depot/console/build.xml Fri May 13 16:38:14 2005
@@ -7,6 +7,7 @@
<transit:import uri="artifact:template:dpml/magic/standard"/>

<target name="init" depends="standard.init">
+ <filter token="BUILD-ID" value="${project.version}" />
<filter token="DEPOT-PATH"
value="dpml-depot-console-${project.version}.jar" />
<x:property name="transit.filename" key="dpml-transit-main"
feature="filename"/>
<x:property name="station.filename" key="dpml-depot-station"
feature="filename"/>

Modified: development/main/depot/console/etc/bin/depot-cygwin.sh
==============================================================================
--- development/main/depot/console/etc/bin/depot-cygwin.sh (original)
+++ development/main/depot/console/etc/bin/depot-cygwin.sh Fri May 13
16:38:14 2005
@@ -43,6 +43,6 @@
echo " Depot Arguments: $DEPOT_ARGS $@"
echo ""

-ARGS="$DEPOT_JVM_OPTS
-Djava.system.class.loader=net.dpml.depot.console.DepotClassLoader
\"-Djava.security.policy=$SECURITY_POLICY\" -classpath \"$DEPOT_CLASSPATH\"
net.dpml.depot.console.Main $DEPOT_ARGS $@"
+ARGS="$DEPOT_JVM_OPTS
-Djava.system.class.loader=net.dpml.depot.lang.DepotClassLoader
\"-Djava.security.policy=$SECURITY_POLICY\" -classpath \"$DEPOT_CLASSPATH\"
net.dpml.depot.lang.Main $DEPOT_ARGS $@"

echo $ARGS | xargs "$JAVA"

Modified: development/main/depot/console/etc/bin/depot-unix.sh
==============================================================================
--- development/main/depot/console/etc/bin/depot-unix.sh (original)
+++ development/main/depot/console/etc/bin/depot-unix.sh Fri May 13
16:38:14 2005
@@ -32,6 +32,6 @@

JAVA="$JAVA_HOME/bin/java"

-ARGS="$DEPOT_JVM_OPTS
-Djava.system.class.loader=net.dpml.depot.console.DepotClassLoader
\"-Djava.security.policy=$SECURITY_POLICY\" -classpath \"$DEPOT_CLASSPATH\"
net.dpml.depot.console.Main $DEPOT_ARGS $@"
+ARGS="$DEPOT_JVM_OPTS
-Djava.system.class.loader=net.dpml.depot.lang.DepotClassLoader
\"-Djava.security.policy=$SECURITY_POLICY\" -classpath \"$DEPOT_CLASSPATH\"
net.dpml.depot.lang.Main $DEPOT_ARGS $@"

echo $ARGS | xargs "$JAVA"

Modified: development/main/depot/console/etc/bin/depot.bat
==============================================================================
--- development/main/depot/console/etc/bin/depot.bat (original)
+++ development/main/depot/console/etc/bin/depot.bat Fri May 13 16:38:14
2005
@@ -18,14 +18,13 @@
if "%DPML_HOME%" == "" set DPML_HOME=%APPDATA%\DPML
if "%DPML_SYSTEM%" == "" set DPML_SYSTEM=%DPML_HOME%\Shared
if "%DPML_DEPOT_JAR%" == "" set DPML_DEPOT_JAR=@DEPOT-PATH@
-
+
set $DEPOT_CLASSPATH="%DPML_HOME%\Data\lib\%DPML_DEPOT_JAR%"
-if EXIST %$CACHED% ( set $CLASSPATH=%$CACHED% ) ELSE ( set
$CLASSPATH=%$LIBRARY% )
set $POLICY=-Djava.security.policy="%DPML_SYSTEM%\bin\security.policy"
set $ARGS=%*

:RUN_DEPOT
-%JAVA% -Djava.system.class.loader=net.dpml.depot.console.DepotClassLoader
%$POLICY% %DEPOT_JVM_OPTS% -classpath %$DEPOT_CLASSPATH%
net.dpml.depot.console.Main %DEPOT_ARGS% %$ARGS%
+%JAVA% -Djava.system.class.loader=net.dpml.depot.lang.DepotClassLoader
%$POLICY% %DEPOT_JVM_OPTS% -classpath %$DEPOT_CLASSPATH%
net.dpml.depot.lang.Main %DEPOT_ARGS% %$ARGS%
goto EndOfScript
:EndOfScript


Added: development/main/depot/console/src/main/net/dpml/depot/lang/DPML.java
==============================================================================
--- (empty file)
+++ development/main/depot/console/src/main/net/dpml/depot/lang/DPML.java
Fri May 13 16:38:14 2005
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.depot.lang;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.StringTokenizer;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.lang.reflect.Method;
+
+/**
+ * Utilitiy class that contains static references to DPML directories.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Id: Main.java 2480 2005-05-10 04:44:32Z mcconnell AT dpml.net $
+ */
+public final class DPML
+{
+ /**
+ * DPML build key.
+ */
+ public static final String BUILD_KEY = "dpml.build";
+
+ /**
+ * DPML home key.
+ */
+ public static final String HOME_KEY = "dpml.home";
+
+ /**
+ * DPML data key.
+ */
+ public static final String DATA_KEY = "dpml.data";
+
+ /**
+ * DPML preferences key.
+ */
+ public static final String PREFS_KEY = "dpml.prefs";
+
+ /**
+ * DPML system key.
+ */
+ public static final String SYSTEM_KEY = "dpml.system";
+
+ /**
+ * The DPML home directory established via assesment of the the
${dpml.home}
+ * system property and the DPML_HOME environment variable. If neither are
+ * defined the behaviour is platform specific. If the os is Windows,
+ * the value returned is equivalent to $APPDATA\DPML whereas Unix the
+ * environment will return ${user.home}/.dpml.
+ */
+ public static final File DPML_HOME;
+
+ /**
+ * If a system property named "dpml.system" is defined then the value
+ * is assigned otherwise the implementation will look for an environment
+ * variable named "DPML_SYSTEM". If neither case holds, the value assigned
+ * if platform dependent. If the os is Windows, the equivalent of
+ * $PROGRAMFILES\DPML is assigned otherwise the value defaults to
+ * "/usr/share/dpml".
+ */
+ public static final File DPML_SYSTEM;
+
+ /**
+ * The DPML personal data directory. The location of this diectory is
system
+ * dependent.
+ */
+ public static final File DPML_DATA;
+
+ /**
+ * The DPML personal preferences directory. The location of this diectory
is system
+ * dependent.
+ */
+ public static final File DPML_PREFS;
+
+ /**
+ * The Depot system version.
+ */
+ public static final String BUILD_ID = "@BUILD-ID@";
+
+ static
+ {
+ DPML_HOME = resolveHomeDirectory();
+ DPML_SYSTEM = resolveSystemDirectory( DPML_HOME );
+ DPML_DATA = resolveDataDirectory( DPML_HOME );
+ DPML_PREFS = resolvePreferencesDirectory( DPML_HOME );
+ }
+
+ /**
+ * Resolve the DPML home directory using assesment of the the ${dpml.home}
+ * system property, the DPML_HOME environment variable. If DPML_HOME is
+ * not declared, the behaviour is platform specific. If the os is
Windows,
+ * the value returned is equivalent to $APPDATA\DPML whereas Unix
environment
+ * will return ${user.home}/.dpml.
+ *
+ * @return the DPML home directory
+ */
+ private static File resolveHomeDirectory()
+ {
+ String home = System.getProperty( HOME_KEY );
+ if( null != home )
+ {
+ return new File( home );
+ }
+ home = Environment.getEnvVariable( HOME_SYMBOL );
+ if( null != home )
+ {
+ return new File( home );
+ }
+ String os = System.getProperty( "os.name" ).toLowerCase();
+ if( os.indexOf( "win" ) >= 0 )
+ {
+ home = Environment.getEnvVariable( "APPDATA" );
+ File data = new File( home );
+ return new File( data, "DPML" );
+ }
+ else
+ {
+ File user = new File( System.getProperty( "user.home" ) );
+ return new File( user, ".dpml" );
+ }
+ }
+
+ /**
+ * Resolve the DPML system home directory. If a system property
+ * named "dpml.system" is defined then the value as a file is
+ * returned otherwise the implementation will look for an environment
+ * variable named "DPML_SYSTEM" which if defined will be
+ * returned as a file. If neither case holds, the value assigned
+ * if platform dependent. If the os is Windows, the equivalent of
+ * $PROGRAMFILES\DPML is returned otherwise the default value
+ * of "/usr/share/dpml" is returned.
+ *
+ * @param dpmlHomeDir the default DPML_HOME value
+ * @return the transit system directory
+ */
+ private static File resolveSystemDirectory( File dpmlHomeDir )
+ {
+ String home = System.getProperty( SYSTEM_KEY );
+ if( null != home )
+ {
+ return new File( home );
+ }
+ home = Environment.getEnvVariable( SYSTEM_SYMBOL );
+ if( null != home )
+ {
+ return new File( home );
+ }
+
+ String os = System.getProperty( "os.name" ).toLowerCase();
+ if( os.indexOf( "win" ) >= 0 )
+ {
+ return new File( dpmlHomeDir, "Shared" );
+ }
+ else
+ {
+ return new File( dpmlHomeDir, "share" );
+ }
+ }
+
+ /**
+ * Resolve the DPML data directory. If the platform is Windows
+ * the returned value is equivalent to ${dpml.home}/Data
+ * whereas the Unix variant returns ${dpml.home}/data.
+ *
+ * @param dir the default DPML_HOME value
+ * @return the transit personal data directory
+ */
+ private static File resolveDataDirectory( File dir )
+ {
+ String os = System.getProperty( "os.name" ).toLowerCase();
+ if( os.indexOf( "win" ) >= 0 )
+ {
+ return new File( dir, "Data" );
+ }
+ else
+ {
+ return new File( dir, "data" );
+ }
+ }
+
+ /**
+ * Resolve the DPML prefs directory. If the platform is Windows
+ * the returned value is equivalent to ${dpml.home}/Preferences
+ * whereas the Unix variant returns ${dpml.home}/prefs.
+ *
+ * @param dir the default DPML_HOME value
+ * @return the transit personal data directory
+ */
+ private static File resolvePreferencesDirectory( File dir )
+ {
+ String os = System.getProperty( "os.name" ).toLowerCase();
+ if( os.indexOf( "win" ) >= 0 )
+ {
+ return new File( dir, "Preferences" );
+ }
+ else
+ {
+ return new File( dir, "prefs" );
+ }
+ }
+
+ /**
+ * DPML environment variable string.
+ */
+ private static final String HOME_SYMBOL = "DPML_HOME";
+
+ /**
+ * DPML environment variable string.
+ */
+ private static final String SYSTEM_SYMBOL = "DPML_SYSTEM";
+
+ /**
+ * Constructor (disabled).
+ */
+ private DPML()
+ {
+ // disabled
+ }
+}
+

Copied:
development/main/depot/console/src/main/net/dpml/depot/lang/DepotClassLoader.java
(from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/DepotClassLoader.java)
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/console/DepotClassLoader.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/lang/DepotClassLoader.java
Fri May 13 16:38:14 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.depot.console;
+package net.dpml.depot.lang;

import java.io.File;
import java.io.IOException;

Copied:
development/main/depot/console/src/main/net/dpml/depot/lang/Environment.java
(from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/Environment.java)
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/console/Environment.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/lang/Environment.java
Fri May 13 16:38:14 2005
@@ -17,7 +17,7 @@
* limitations under the License.
*/

-package net.dpml.depot.console;
+package net.dpml.depot.lang;

import java.io.File;
import java.io.IOException;

Copied:
development/main/depot/console/src/main/net/dpml/depot/lang/EnvironmentException.java
(from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/EnvironmentException.java)
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/console/EnvironmentException.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/lang/EnvironmentException.java
Fri May 13 16:38:14 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.depot.console;
+package net.dpml.depot.lang;

/**
* A simple wrapper exception around exceptions that could occur while
accessing

Copied: development/main/depot/console/src/main/net/dpml/depot/lang/Main.java
(from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/Main.java)
==============================================================================
--- development/main/depot/console/src/main/net/dpml/depot/console/Main.java
(original)
+++ development/main/depot/console/src/main/net/dpml/depot/lang/Main.java
Fri May 13 16:38:14 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.depot.console;
+package net.dpml.depot.lang;

import java.io.File;
import java.io.IOException;
@@ -55,69 +55,12 @@
System.setProperty( "java.util.logging.manager",
"net.dpml.depot.logging.LoggingManager" );
System.setProperty( "java.util.logging.manager.altclassloader",
"net.dpml.depot.logging.LoggingManager" );
System.setProperty( "java.util.logging.config.class",
"net.dpml.depot.logging.ConfigurationHandler" );
- }
-
- /**
- * DPML home key.
- */
- public static final String HOME_KEY = "dpml.home";
-
- /**
- * DPML home key.
- */
- public static final String DATA_KEY = "dpml.data";
-
- /**
- * DPML home key.
- */
- public static final String PREFS_KEY = "dpml.prefs";
-
- /**
- * DPML system key.
- */
- public static final String SYSTEM_KEY = "dpml.system";
-
- /**
- * The DPML home directory established via assesment of the the
${dpml.home}
- * system property and the DPML_HOME environment variable. If neither are
- * defined the behaviour is platform specific. If the os is Windows,
- * the value returned is equivalent to $APPDATA\DPML whereas Unix the
- * environment will return ${user.home}/.dpml.
- */
- public static final File DPML_HOME;
-
- /**
- * If a system property named "dpml.system" is defined then the value
- * is assigned otherwise the implementation will look for an environment
- * variable named "DPML_SYSTEM". If neither case holds, the value assigned
- * if platform dependent. If the os is Windows, the equivalent of
- * $PROGRAMFILES\DPML is assigned otherwise the value defaults to
- * "/usr/share/dpml".
- */
- public static final File DPML_SYSTEM;
-
- /**
- * The Transit personal data directory. The location of this diectory is
system
- * dependent.
- */
- public static final File DPML_DATA;

- /**
- * The Transit personal preferences directory. The location of this
diectory is system
- * dependent.
- */
- public static final File DPML_PREFS;
-
- static
- {
- DPML_HOME = resolveHomeDirectory();
- DPML_SYSTEM = resolveSystemDirectory( DPML_HOME );
- DPML_DATA = resolveDataDirectory( DPML_HOME );
- DPML_PREFS = resolvePreferencesDirectory( DPML_HOME );
- System.setProperty( SYSTEM_KEY, DPML_SYSTEM.getAbsolutePath() );
- System.setProperty( HOME_KEY, DPML_HOME.getAbsolutePath() );
- System.setProperty( DATA_KEY, DPML_DATA.getAbsolutePath() );
- System.setProperty( PREFS_KEY, DPML_PREFS.getAbsolutePath() );
+ System.setProperty( DPML.SYSTEM_KEY,
DPML.DPML_SYSTEM.getAbsolutePath() );
+ System.setProperty( DPML.HOME_KEY, DPML.DPML_HOME.getAbsolutePath()
);
+ System.setProperty( DPML.DATA_KEY, DPML.DPML_DATA.getAbsolutePath()
);
+ System.setProperty( DPML.PREFS_KEY,
DPML.DPML_PREFS.getAbsolutePath() );
+ System.setProperty( DPML.BUILD_KEY, DPML.BUILD_ID );
}

public static void main( final String[] args )
@@ -130,6 +73,8 @@
}

Logger logger = Logger.getLogger( "depot" );
+ logger.info( "Depot (Build ID " + DPML.BUILD_ID + ")." );
+
String name = profile.get( "title", profile.name() );
logger.info( "loading " + name );

@@ -159,10 +104,26 @@
}
else
{
-
- Class c = classloader.loadClass( classname );
- setup( profile.node( "properties" ) );
- deploy( c, args );
+ try
+ {
+ Class c = classloader.loadClass( classname );
+ setup( profile.node( "properties" ) );
+ deploy( c, args );
+ }
+ catch( ClassNotFoundException e )
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "Application class not found." );
+ buffer.append( "\nClassname: " + classname );
+ buffer.append( "\nSystem classpath:" );
+ URL[] urls = classloader.getURLs();
+ for( int i=0; i<urls.length; i++ )
+ {
+ buffer.append( "\n" + (i+1) + "\t" + urls[i] );
+ }
+ System.err.println( buffer.toString() );
+ return;
+ }
}
}
else
@@ -286,130 +247,6 @@
}

/**
- * Resolve the DPML home directory using assesment of the the ${dpml.home}
- * system property, the DPML_HOME environment variable. If DPML_HOME is
- * not declared, the behaviour is platform specific. If the os is
Windows,
- * the value returned is equivalent to $APPDATA\DPML whereas Unix
environment
- * will return ${user.home}/.dpml.
- *
- * @return the DPML home directory
- */
- private static File resolveHomeDirectory()
- {
- String home = System.getProperty( HOME_KEY );
- if( null != home )
- {
- return new File( home );
- }
- home = Environment.getEnvVariable( HOME_SYMBOL );
- if( null != home )
- {
- return new File( home );
- }
- String os = System.getProperty( "os.name" ).toLowerCase();
- if( os.indexOf( "win" ) >= 0 )
- {
- home = Environment.getEnvVariable( "APPDATA" );
- File data = new File( home );
- return new File( data, "DPML" );
- }
- else
- {
- File user = new File( System.getProperty( "user.home" ) );
- return new File( user, ".dpml" );
- }
- }
-
- /**
- * Resolve the DPML system home directory. If a system property
- * named "dpml.system" is defined then the value as a file is
- * returned otherwise the implementation will look for an environment
- * variable named "DPML_SYSTEM" which if defined will be
- * returned as a file. If neither case holds, the value assigned
- * if platform dependent. If the os is Windows, the equivalent of
- * $PROGRAMFILES\DPML is returned otherwise the default value
- * of "/usr/share/dpml" is returned.
- *
- * @param dpmlHomeDir the default DPML_HOME value
- * @return the transit system directory
- */
- private static File resolveSystemDirectory( File dpmlHomeDir )
- {
- String home = System.getProperty( SYSTEM_KEY );
- if( null != home )
- {
- return new File( home );
- }
- home = Environment.getEnvVariable( SYSTEM_SYMBOL );
- if( null != home )
- {
- return new File( home );
- }
-
- String os = System.getProperty( "os.name" ).toLowerCase();
- if( os.indexOf( "win" ) >= 0 )
- {
- return new File( dpmlHomeDir, "Shared" );
- }
- else
- {
- return new File( dpmlHomeDir, "share" );
- }
- }
-
- /**
- * Resolve the DPML data directory. If the platform is Windows
- * the returned value is equivalent to ${dpml.home}/Data
- * whereas the Unix variant returns ${dpml.home}/data.
- *
- * @param dir the default DPML_HOME value
- * @return the transit personal data directory
- */
- private static File resolveDataDirectory( File dir )
- {
- String os = System.getProperty( "os.name" ).toLowerCase();
- if( os.indexOf( "win" ) >= 0 )
- {
- return new File( dir, "Data" );
- }
- else
- {
- return new File( dir, "data" );
- }
- }
-
- /**
- * Resolve the DPML prefs directory. If the platform is Windows
- * the returned value is equivalent to ${dpml.home}/Preferences
- * whereas the Unix variant returns ${dpml.home}/prefs.
- *
- * @param dir the default DPML_HOME value
- * @return the transit personal data directory
- */
- private static File resolvePreferencesDirectory( File dir )
- {
- String os = System.getProperty( "os.name" ).toLowerCase();
- if( os.indexOf( "win" ) >= 0 )
- {
- return new File( dir, "Preferences" );
- }
- else
- {
- return new File( dir, "prefs" );
- }
- }
-
- /**
- * DPML environment variable string.
- */
- private static final String HOME_SYMBOL = "DPML_HOME";
-
- /**
- * DPML environment variable string.
- */
- private static final String SYSTEM_SYMBOL = "DPML_SYSTEM";
-
- /**
* Constructor (disabled).
*/
private Main()

Copied:
development/main/depot/console/src/main/net/dpml/depot/lang/PropertyResolver.java
(from r2542,
development/main/depot/console/src/main/net/dpml/depot/console/PropertyResolver.java)
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/console/PropertyResolver.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/lang/PropertyResolver.java
Fri May 13 16:38:14 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.depot.console;
+package net.dpml.depot.lang;

import java.util.Properties;
import java.util.Stack;

Modified: development/main/depot/index.xml
==============================================================================
--- development/main/depot/index.xml (original)
+++ development/main/depot/index.xml Fri May 13 16:38:14 2005
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

-<index key="dpml-metro">
+<index key="dpml-depot">

<import uri="${dpml.transit.uri}"/>
<import uri="${dpml.magic.uri}"/>
@@ -56,6 +56,7 @@
</types>
</info>
<dependencies>
+ <include key="dpml-depot-console" tag="api"/>
<include key="dpml-transit-main" tag="api"/>
</dependencies>
</project>

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/CachePanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/CachePanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/CachePanel.java
Fri May 13 16:38:14 2005
@@ -63,6 +63,8 @@
import net.dpml.transit.host.ResourceManager;
import net.dpml.transit.util.Util;

+import net.dpml.depot.lang.DPML;
+

/**
* Control panel for editing the cache preferences.
@@ -297,7 +299,7 @@
String filename = m_cachePrefs.get( "location", null );
if( null == filename )
{
- return null;
+ return new File( DPML.DPML_DATA, "cache" );
}
else
{

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerControllerPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerControllerPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerControllerPanel.java
Fri May 13 16:38:14 2005
@@ -112,7 +112,7 @@
m_parent = parent;
m_propertyChangeSupport = new PropertyChangeSupport( this );

- m_preferences = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
+ m_preferences = Preferences.userNodeForPackage( Transit.class
).node( "content" );

setLayout( new BorderLayout() );
setBackground( Color.white );

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerMainPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerMainPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerMainPanel.java
Fri May 13 16:38:14 2005
@@ -117,7 +117,7 @@
new EmptyBorder( 0,0,0,0 ), "Content Handlers",
TitledBorder.LEFT, TitledBorder.TOP );
ContentHandlerMainPanel.setBorder( new CompoundBorder( tb, border5 )
);

- Preferences prefs = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
+ Preferences prefs = Preferences.userNodeForPackage( Transit.class
).node( "content" );
m_preferences = prefs;
TableColumnModel columns = createContentHandlerColumnModel();
GenericTableModel model = new GenericTableModel( prefs );

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/Main.java
==============================================================================
--- development/main/depot/station/src/main/net/dpml/depot/prefs/Main.java
(original)
+++ development/main/depot/station/src/main/net/dpml/depot/prefs/Main.java
Fri May 13 16:38:14 2005
@@ -38,11 +38,6 @@
public static void main( final String[] args )
throws Exception
{
- //
- // Setup transit protocol handler
- //
-
- System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);

Logger logger = Logger.getLogger( "depot.prefs" );

@@ -68,12 +63,18 @@
}
catch( Throwable e )
{
- logger.log( Level.SEVERE, "preference rest failed", e );
+ logger.log( Level.SEVERE, "preference reset failed", e );
}
}
}

//
+ // Setup transit protocol handler
+ //
+
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+
+ //
// check if a prefs are enabled (default is true)
//

@@ -97,7 +98,7 @@
try
{
new DepotPreferencesDialog();
- }
+ }
catch( Exception e )
{
e.printStackTrace();

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitPanel.java
Fri May 13 16:38:14 2005
@@ -63,8 +63,6 @@
import net.dpml.transit.host.ResourceHost;
import net.dpml.transit.util.Util;

-
-
/**
* Runnable plugin that handles DPML environment setup.
*
@@ -89,7 +87,7 @@
private JButton m_edit;
private JButton m_delete;

- private String m_hostName; // selected hostname
+ private String m_selection; // selected hostname

//--------------------------------------------------------------
// constructor
@@ -97,6 +95,8 @@

public TransitPanel( JDialog parent ) throws Exception
{
+ Transit.getInstance();
+
m_parent = parent;

m_editAction = new EditAction( "Edit" );
@@ -116,7 +116,7 @@
new EmptyBorder( 0,0,0,0 ), "Resource Hosts", TitledBorder.LEFT,
TitledBorder.TOP );
hostPanel.setBorder( new CompoundBorder( tb, border5 ) );

- Preferences hosts = Preferences.userNodeForPackage(
ResourceHost.class );
+ Preferences hosts = Preferences.userNodeForPackage( Transit.class
).node( "hosts" );
TableColumnModel columns = createHostsColumnModel();
GenericTableModel model = new GenericTableModel( hosts );
m_table = new GenericTable( model, columns );
@@ -148,8 +148,8 @@
{
if( "selection".equals( event.getPropertyName() ) )
{
- m_hostName = (String) event.getNewValue();
- if( null != m_hostName )
+ m_selection = (String) event.getNewValue();
+ if( null != m_selection )
{
m_edit.setEnabled( true );
m_delete.setEnabled( true );
@@ -367,8 +367,8 @@
try
{
JDialog dialog = new JDialog( m_parent, true );
- dialog.setTitle( "Resource Host: " + m_hostName );
- JPanel panel = new TransitResourceHostPanel( dialog,
m_hostName );
+ dialog.setTitle( "Resource Host: " + m_selection );
+ JPanel panel = new TransitResourceHostPanel( dialog,
m_selection );
dialog.setContentPane( panel );
Dimension size = new Dimension( 400, 360 );
dialog.setSize( size );
@@ -398,12 +398,12 @@

public void actionPerformed( ActionEvent event )
{
- if( null == m_hostName )
+ if( null == m_selection )
{
return;
}
- Preferences hosts = Preferences.userNodeForPackage(
ResourceHost.class );
- Preferences target = hosts.node( m_hostName );
+ Preferences hosts = Preferences.userNodeForPackage(
Transit.class ).node( "hosts" );
+ Preferences target = hosts.node( m_selection );
try
{
target.removeNode();

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitResourceHostPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitResourceHostPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitResourceHostPanel.java
Fri May 13 16:38:14 2005
@@ -118,8 +118,8 @@
setBackground( Color.white );
setBorder( new EmptyBorder( 10, 6, 0, 6 ) );

- m_hostsPrefs = Preferences.userNodeForPackage( ResourceHost.class );
- m_hostPrefs = m_hostsPrefs.node( name ); // TODO: host could have
been removed
+ m_hostsPrefs = Preferences.userNodeForPackage( Transit.class ).node(
"hosts" );
+ m_hostPrefs = m_hostsPrefs.node( name );
m_hostPrefs.addPreferenceChangeListener( this );

HostDescriptor descriptor = new HostDescriptor( m_hostPrefs );

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
Fri May 13 16:38:14 2005
@@ -265,19 +265,39 @@

Properties props = getTransitProperties( authorative );
String classname = null;
+
+ //
+ // for now we are using preferences from the user node
net/dpml/transit
+ // however we should move to using a supplied preferences
instance, or
+ // preferably a transit management object that we can listen
to
+ //
+
+ Preferences prefs = Preferences.userNodeForPackage(
Transit.class );
boolean flag = isPreferencesEnabled( props );
if( flag )
{
- classname = getResourceManagerClassname(); // using
preferences
+ if( prefs.getLong( "installation", -1 ) < 0 )
+ {
+ TransitPreferences.setupFactoryPreferences( prefs );
+ }
+ classname = getResourceManagerClassname( prefs ); //
using preferences
}
else
{
classname = getResourceManagerClassname( props ); //
using properties
}

- Preferences prefs = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
- ContentHandlerRegistry registry = new
DefaultContentHandlerRegistry( logger, prefs );
- ResourceManager manager = createResourceManager( classname,
authorative );
+ //
+ // irrespective of the 'prefs enabled' status we are
constructing the
+ // DefaultContentHandlerRegistry using a supplied prefs
instance because
+ // content handling is a relativly new addition - even so,
this should
+ // replaced by a content manager that the registry can use
to establish
+ // initial state and listed to for subsequent configuration
changes
+ //
+
+ Preferences contentPrefs = prefs.node( "content" );
+ ContentHandlerRegistry registry = new
DefaultContentHandlerRegistry( logger, contentPrefs );
+ ResourceManager manager = createResourceManager( classname,
authorative, prefs );
CacheHandler ch = manager.createCacheHandler();
if( logger.isLoggable( Level.FINE ) )
{
@@ -459,20 +479,20 @@
*
* @param classname the classname of the ResourceManager to be created.
* @param authorative the URL to the authorative host.
- * @param monitor the SystemMonitor to receive notifications.
+ * @param prefs the transit preferences
*
* @return the resource manager
*/
private static ResourceManager createResourceManager(
- String classname, URL authorative ) throws TransitException
+ String classname, URL authorative, Preferences prefs ) throws
TransitException
{
try
{
Class cls = ResourceManager.class.getClassLoader().loadClass(
classname );
Class[] params = new Class[]{
- URL.class};
+ URL.class, Preferences.class };
Object[] args = new Object[]{
- authorative};
+ authorative, prefs };
Constructor cons = cls.getConstructor( params );
return (ResourceManager) cons.newInstance( args );
}
@@ -503,20 +523,18 @@
/**
* Return the classname of the class implementating the resource manager.
* Resolved relative to the system property
'dpml.transit.authority.resourcemanager.classname'.
- * with fallback to preferencees defained under the Transit class package
group.
- * If undefined the default classname is returned.
+ * with fallback to preferencees defined under the supplied preferences
instance.
+ * If undefined the default classname declared by the ResourceManager
interface is returned.
*
* @return the resource manager classname
*/
- private static String getResourceManagerClassname()
+ private static String getResourceManagerClassname( Preferences prefs )
{
final String key = "resource-manager-classname";
final String fallback =
ResourceManager.TRANSIT_PREFS_RESOURCE_MANAGER_CLASSNAME;
- Preferences systemPrefs = Preferences.systemNodeForPackage(
Transit.class );
- Preferences userPrefs = Preferences.userNodeForPackage(
Transit.class );
return System.getProperty(
ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME_KEY,
- userPrefs.get( key, systemPrefs.get( key, fallback ) ) );
+ prefs.get( key, fallback ) );
}

/**

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/TransitPreferences.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/TransitPreferences.java
Fri May 13 16:38:14 2005
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2005 Stephen McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.transit;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.net.URL;
+import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.Date;
+import java.lang.reflect.Constructor;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.Date;
+
+import net.dpml.lang.NullArgumentException;
+
+import net.dpml.io.CascadingIOException;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.cache.CacheHandler;
+import net.dpml.transit.TransitException;
+import net.dpml.transit.util.Util;
+import net.dpml.transit.layout.LocationResolver;
+import net.dpml.transit.layout.ClassicResolver;
+
+/**
+ * The TransitInstaller class is responsible for the setup of initial factory
+ * default preference settings.
+ */
+class TransitPreferences
+{
+
//--------------------------------------------------------------------------
+ // static
+
//--------------------------------------------------------------------------
+
+ /**
+ * Default priority string.
+ */
+ private static final String DEFAULT_PRIORITY_STRING = "10";
+
+ /**
+ * Setup the default factory preferences for the Transit system using
+ * user preferences tree /net/dpml/transit.
+ * @exception TransitException if a error occcurs during preferences
initialization
+ */
+ public static void setupFactoryPreferences() throws TransitException
+ {
+ Preferences prefs = Preferences.userNodeForPackage( Transit.class );
+ setupFactoryPreferences( prefs );
+ }
+
+ /**
+ * Setup the default factory preferences for the Transit system.
+ * @param root the preferences node to use for the population of transit
preferences
+ * @exception TransitException if a error occcurs during preferences
initialization
+ */
+ public static void setupFactoryPreferences( Preferences root ) throws
TransitException
+ {
+ try
+ {
+ Preferences cache = root.node( "cache" );
+ setupCachePreferences( cache );
+ Preferences hosts = root.node( "hosts" );
+ setupHostsPreferences( hosts );
+ root.putLong( "installation", new Date().getTime() );
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "Unable to resolve transit preferences due to a backing store
error.";
+ throw new TransitException( error, e );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to resolve transit preferences due to an unexpected
error.";
+ throw new TransitException( error, e );
+ }
+ }
+
+ private static void setupCachePreferences( Preferences prefs ) throws
IOException, BackingStoreException
+ {
+ ClassLoader classloader = Transit.class.getClassLoader();
+ URL resource = classloader.getResource(
"transit/authority/cache.properties" );
+ Properties properties = Util.readProps( resource );
+ String location = properties.getProperty( CacheHandler.CACHE_KEY );
+ if( null != location )
+ {
+ prefs.put( "location", location );
+ }
+ String classname = properties.getProperty(
CacheHandler.CACHE_CLASS_KEY );
+ if( null != classname )
+ {
+ prefs.put( "classname", classname );
+ }
+ String resolver = properties.getProperty(
CacheHandler.RESOLVER_CLASS_KEY );
+ if( null != resolver )
+ {
+ prefs.put( "resolver", resolver );
+ }
+ }
+
+ private static void setupHostsPreferences( Preferences prefs ) throws
IOException, BackingStoreException
+ {
+ setupNamedHost( prefs, "www.ibiblio.org",
"transit/authority/hosts/www.ibiblio.org.host" );
+ setupNamedHost( prefs, "www.apache.org",
"transit/authority/hosts/www.apache.org.host" );
+ setupNamedHost( prefs, "repository.dpml.net",
"transit/authority/hosts/repository.dpml.net.host" );
+ setupNamedHost( prefs, "local", "transit/authority/hosts/local.host"
);
+ }
+
+ private static void setupNamedHost( Preferences prefs, String name,
String resource ) throws IOException
+ {
+ URL url = Transit.class.getClassLoader().getResource( resource );
+ Preferences host = prefs.node( name );
+ setupHost( host, url );
+ }
+
+ private static void setupHost( Preferences prefs, URL hostDef ) throws
TransitException
+ {
+ if( null == hostDef )
+ {
+ throw new NullArgumentException( "hostDef" );
+ }
+ if( null == prefs )
+ {
+ throw new NullArgumentException( "prefs" );
+ }
+
+ String name = prefs.name();
+ try
+ {
+ Properties props = Util.readProps( hostDef );
+ String base = Util.getProperty( props,
"dpml.transit.resourcehost.base", null );
+ if( base == null )
+ {
+ final String error =
+ "Invalid host defintion (no base url declaration)."
+ + "\nHost Definition Resource: " + hostDef;
+ throw new IllegalArgumentException( error );
+ }
+ String key = "dpml.transit.resourcehost.class";
+ String def = "net.dpml.transit.host.ClassicResourceHost";
+ String classname = Util.getProperty( props, key, def );
+ String index = Util.getProperty( props,
"dpml.transit.resourcehost.knowngroups", null );
+
+ String priorityText =
+ Util.getProperty( props, "dpml.transit.resourcehost.priority",
DEFAULT_PRIORITY_STRING );
+ if( "".equals( priorityText ) )
+ {
+ priorityText = DEFAULT_PRIORITY_STRING;
+ }
+ int priority = Integer.parseInt( priorityText );
+ String username = Util.getProperty( props,
"dpml.transit.resourcehost.username", "" );
+ String password = Util.getProperty( props,
"dpml.transit.resourcehost.password", "" );
+ String prompt = Util.getProperty( props,
"dpml.transit.resourcehost.prompt", "" );
+ String scheme = Util.getProperty( props,
"dpml.transit.resourcehost.scheme", "" );
+ String resolverclass =
+ Util.getProperty( props, "dpml.transit.resourcehost.resolver",
"net.dpml.transit.layout.ClassicResolver" );
+ boolean enabled =
+ Util.getProperty(
+ props, "dpml.transit.resourcehost.enabled", "true"
).equalsIgnoreCase( "true" );
+ boolean trusted =
+ Util.getProperty(
+ props, "dpml.transit.resourcehost.trusted", "false"
).equalsIgnoreCase( "true" );
+
+ prefs.put( "classname", classname );
+ prefs.put( "base", base );
+
+ if( null != index )
+ {
+ prefs.put( "index", index );
+ }
+ prefs.putInt( "priority", priority );
+ prefs.putBoolean( "enabled", enabled );
+ prefs.putBoolean( "trusted", trusted );
+ prefs.put( "username", username );
+ prefs.put( "password", password ); // TODO: needs to be encoded
+ prefs.put( "scheme", scheme );
+ prefs.put( "resolver", resolverclass );
+ prefs.putBoolean( "available", true );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error occured while attempting to construct a
default host preferences."
+ + "\nHost Name: " + name
+ + "\nResource URL: " + hostDef;
+ throw new TransitException( error, e );
+ }
+ }
+
+ private static File convertToFile( URL url ) throws IOException
+ {
+ String protocol = url.getProtocol();
+ if( "file".equals( protocol ) )
+ {
+ String spec = url.toExternalForm();
+ String s = spec.substring( 6 );
+ return new File( s );
+ }
+ else
+ {
+ final String error =
+ "Don't know how to convert the '" + protocol + "' protocol to
a file.";
+ throw new IOException( error );
+ }
+ }
+
+ /**
+ * Disabled.
+ */
+ private TransitPreferences()
+ {
+ }
+}
+

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
Fri May 13 16:38:14 2005
@@ -55,6 +55,7 @@
import net.dpml.transit.layout.LocationResolver;
import net.dpml.transit.monitors.CacheMonitorRouter;
import net.dpml.transit.monitors.Monitor;
+import net.dpml.transit.util.PropertyResolver;
import net.dpml.transit.util.Util;

/**
@@ -94,10 +95,10 @@

/**
* Creation of a new file based cache handler using system preferences.
- * @param monitor the assigned monitor
+ * @param prefs the root transit preferences
* @param resolver the location resolver
*/
- public FileCacheHandler( LocationResolver resolver ) throws
TransitException
+ public FileCacheHandler( LocationResolver resolver, Preferences prefs )
throws TransitException
{
m_zipCache = new ZipCache();
m_resourceHosts = new TreeMap();
@@ -110,14 +111,14 @@
// construct the hosts using the system preferences
//

- Preferences prefs = Preferences.userNodeForPackage(
ResourceHost.class );
+ Preferences hostsNode = getHostsPreferences( prefs );
try
{
- String[] names = getHostNodeNames();
+ String[] names = getHostNodeNames( hostsNode );
for( int i=0; i<names.length; i++ )
{
String name = names[i];
- Preferences p = prefs.node( name );
+ Preferences p = getNamedHostPreferences( hostsNode, name );
handleHostAddition( p );
}
}
@@ -133,9 +134,11 @@
// add a listener to the user preferences
//

- prefs.addPreferenceChangeListener( this );
- prefs.addNodeChangeListener( this );
- File cache = resolveCacheDirectory();
+ Preferences cachePrefs = getCachePreferences( prefs );
+ cachePrefs.addPreferenceChangeListener( this );
+
+ hostsNode.addNodeChangeListener( this );
+ File cache = resolveCacheDirectory( cachePrefs );
setLocalCacheDirectory( cache );
}

@@ -438,19 +441,15 @@
}

/**
- * Resolve the cache directory using the preferences assigned under the
- * net.dpml.transit.cache package group using the "location" key.
+ * Resolve the cache directory using the preferences.
*
* @return the cache directory
*/
- private File resolveCacheDirectory()
+ private File resolveCacheDirectory( Preferences cachePrefs )
{
- String defaultCache = "cache";
- Preferences system = Preferences.systemNodeForPackage(
FileCacheHandler.class );
- String systemPreference = system.get( "location", defaultCache );
- Preferences user = Preferences.userNodeForPackage(
FileCacheHandler.class );
- String userPreference = user.get( "location", systemPreference );
- String cache = System.getProperty( CACHE_KEY, userPreference );
+ String path = cachePrefs.get( "location", "cache" );
+ String location = System.getProperty( CACHE_KEY, path );
+ String cache = PropertyResolver.resolve( System.getProperties(),
location );
return new File( cache );
}

@@ -535,13 +534,16 @@
// PreferencesChangeListener (listens to cache prefs)
//
------------------------------------------------------------------------

+ // TODO: change this to a CacheConfigurationListener
+
public void preferenceChange( PreferenceChangeEvent event )
{
String key = event.getKey();
String value = event.getNewValue();
+ Preferences prefs = event.getNode();
if( "location".equals( key ) )
{
- File cache = resolveCacheDirectory();
+ File cache = resolveCacheDirectory( prefs );
setLocalCacheDirectory( cache );
}
}
@@ -550,8 +552,11 @@
// NodeChangeListener (listens to host prefs addition and removal)
//
------------------------------------------------------------------------

+ // TODO: change this to a HostsRegistryListener
+
/**
- * Handle the addition of a host following a preferences node change.
+ * Handle the addition of a host following a preferences node change to
the
+ * relative node hosts.
*
* @param event the node addition event
*/
@@ -598,17 +603,37 @@
// prefs utilities
//
------------------------------------------------------------------------

- private Preferences getUserHostNode()
+ private Preferences getCachePreferences( Preferences root ) throws
TransitException
{
- return Preferences.userNodeForPackage( ResourceHost.class );
+ return root.node( "cache" );
}

- private String[] getHostNodeNames() throws BackingStoreException
+ private Preferences getHostsPreferences( Preferences root ) throws
TransitException
{
- return getUserHostNode().childrenNames();
+ return root.node( "hosts" );
+ }
+
+ private Preferences getNamedHostPreferences( Preferences hostsPrefs,
String name )
+ {
+ return hostsPrefs.node( name );
+ }
+
+ private String[] getHostNodeNames( Preferences hostsPrefs ) throws
TransitException
+ {
+ try
+ {
+ return hostsPrefs.childrenNames();
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "Unexpected error occured while attempting to access a named
named hosts."
+ + "\nTransit hosts root preferences: " + hostsPrefs;
+ throw new TransitException( error, e );
+ }
}

- private void handleHostAddition( Preferences prefs )
+ private void handleHostAddition( Preferences prefs )
{
HostDescriptor descriptor = new HostDescriptor( prefs );
if( descriptor.getLastModified() > 0 )

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/host/PreferencesResourceManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/host/PreferencesResourceManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/host/PreferencesResourceManager.java
Fri May 13 16:38:14 2005
@@ -82,8 +82,7 @@
// state

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

- private final Preferences m_system;
- private final Preferences m_user;
+ private final Preferences m_preferences;

private final LocationResolver m_resolver;

@@ -94,25 +93,18 @@

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

/**
- * Creation of a new resource manager.
- * @param authorative the authorative base url
+ * Creation of a new resource manager based on a suppllied preferences
node.
+ *
+ * @param authorative not used (passed to supertype)
* @exception IOException if an io error occurs
* @exception TransitException if a transit system error occurs
*/
- public PreferencesResourceManager( URL authorative )
+ public PreferencesResourceManager( URL authorative, Preferences prefs )
throws TransitException, IOException
{
- super( authorative );
+ super( authorative, prefs );

- m_system = Preferences.systemNodeForPackage( ResourceManager.class );
- m_user = Preferences.userNodeForPackage( ResourceManager.class );
- String version = m_system.get( "install", null );
- if( null == version )
- {
- setupInitialPreferences();
- String date = new Date().toString();
- m_system.put( "install", date ); // used as a flag
- }
+ m_preferences = prefs;
m_resolver = createResolver();
}

@@ -129,17 +121,11 @@
public CacheHandler createCacheHandler()
throws TransitException, IOException
{
- Preferences cacheSystemPrefs = getSystemCacheNode();
- Preferences cacheUserPrefs = getUserCacheNode();
-
+ Preferences prefs = getCachePreferences();
String classname =
System.getProperty(
CacheHandler.CACHE_CLASS_KEY,
- cacheUserPrefs.get(
- "classname",
- cacheSystemPrefs.get(
- "classname",
- TRANSIT_CACHE_DEFAULT_HANDLER_CLASSNAME ) ) );
+ prefs.get( "classname", TRANSIT_CACHE_DEFAULT_HANDLER_CLASSNAME
) );
return createCacheHandler( classname );
}

@@ -153,13 +139,14 @@
protected CacheHandler createCacheHandler( String classname )
throws TransitException, IOException
{
+ Preferences prefs = getCachePreferences();
try
{
Class cls = getClass().getClassLoader().loadClass( classname );
Class[] params = new Class[]{
- LocationResolver.class};
+ LocationResolver.class, Preferences.class};
Object[] args = new Object[]{
- m_resolver};
+ m_resolver, m_preferences};
Constructor cons = cls.getConstructor( params );
return (CacheHandler) cons.newInstance( args );
}
@@ -175,17 +162,11 @@

private LocationResolver createResolver()
{
- Preferences cacheSystemPrefs = getSystemCacheNode();
- Preferences cacheUserPrefs = getUserCacheNode();
-
+ Preferences prefs = getCachePreferences();
String classname =
System.getProperty(
CacheHandler.CACHE_CLASS_KEY,
- cacheUserPrefs.get(
- "resolver",
- cacheSystemPrefs.get(
- "resolver",
- TRANSIT_CACHE_DEFAULT_RESOLVER_CLASSNAME ) ) );
+ prefs.get( "resolver", TRANSIT_CACHE_DEFAULT_RESOLVER_CLASSNAME
) );
try
{
Class cls = getClass().getClassLoader().loadClass( classname );
@@ -197,203 +178,9 @@
}
}

- //
- // preferences setup
- //
-
- private Preferences getUserHostNode( String key )
- {
- return getUserHostNode().node( key );
- }
-
- private Preferences getUserHostNode()
- {
- return Preferences.userNodeForPackage( ResourceHost.class );
- }
-
- private Preferences getSystemCacheNode()
- {
- return Preferences.systemNodeForPackage( CacheHandler.class );
- }
-
- private Preferences getUserCacheNode()
- {
- return Preferences.userNodeForPackage( CacheHandler.class );
- }
-
- private void setupInitialPreferences() throws TransitException
- {
- try
- {
- createDefaultCachePreferences();
- createDefaultResourceHostPreferences();
- }
- catch( BackingStoreException e )
- {
- final String error =
- "Unable to resolve transit preferences due to a backing store
error.";
- throw new TransitException( error, e );
- }
- catch( Exception e )
- {
- final String error =
- "Unable to resolve transit preferences due to an unexpected
error.";
- throw new TransitException( error, e );
- }
- }
-
- private void createDefaultCachePreferences() throws IOException,
BackingStoreException
- {
- Preferences systemCachePrefs = getSystemCacheNode();
- ClassLoader classloader = Transit.class.getClassLoader();
- URL resource = classloader.getResource(
"transit/authority/cache.properties" );
- Properties properties = Util.readProps( resource );
- String location = properties.getProperty( CacheHandler.CACHE_KEY );
- if( null != location )
- {
- systemCachePrefs.put( "location", location );
- }
- String classname = properties.getProperty(
CacheHandler.CACHE_CLASS_KEY );
- if( null != classname )
- {
- systemCachePrefs.put( "classname", classname );
- }
- String resolver = properties.getProperty(
CacheHandler.RESOLVER_CLASS_KEY );
- if( null != resolver )
- {
- systemCachePrefs.put( "resolver", resolver );
- }
- }
-
- private void createDefaultResourceHostPreferences() throws IOException,
BackingStoreException
- {
- ClassLoader classloader = Transit.class.getClassLoader();
- JarFile jar = getTransitJarFile();
- Enumeration entries = jar.entries();
- while( entries.hasMoreElements() )
- {
- ZipEntry entry = (ZipEntry) entries.nextElement();
- String name = entry.getName();
- if( name.endsWith( ".host" ) )
- {
- int n = name.lastIndexOf( "/" );
- int m = name.lastIndexOf( "." );
- String shortname = name.substring( n+1, m );
- URL resource = classloader.getResource( name );
- createResourceHostPreferences( shortname, resource );
- }
- }
- }
-
- private JarFile getTransitJarFile() throws IOException
+ private Preferences getCachePreferences()
{
- URL url =
Transit.class.getProtectionDomain().getCodeSource().getLocation();
- File file = convertToFile( url );
- try
- {
- return new JarFile( file );
- }
- catch( Throwable e )
- {
- Logger logger = Logger.getLogger( "transit" );
- final String error =
- "Unexpected error occured while resolving Transit jar file."
- + "\nCode-source URL: " + url
- + "\nFile: " + file;
- logger.log( Level.SEVERE, error, e );
- throw new CascadingIOException( error, e );
- }
- }
-
- private void createResourceHostPreferences( String name, URL hostDef )
throws TransitException
- {
- if( null == hostDef )
- {
- throw new NullArgumentException( "hostDef" );
- }
- if( null == name )
- {
- throw new NullArgumentException( "name" );
- }
-
- try
- {
- Properties props = Util.readProps( hostDef );
- String base = Util.getProperty( props,
"dpml.transit.resourcehost.base", null );
- if( base == null )
- {
- final String error =
- "Invalid host defintion (no base url declaration)."
- + "\nHost Definition Resource: " + hostDef;
- throw new IllegalArgumentException( error );
- }
- String key = "dpml.transit.resourcehost.class";
- String def = "net.dpml.transit.host.ClassicResourceHost";
- String classname = Util.getProperty( props, key, def );
- String index = Util.getProperty( props,
"dpml.transit.resourcehost.knowngroups", null );
-
- String priorityText =
- Util.getProperty( props, "dpml.transit.resourcehost.priority",
DEFAULT_PRIORITY_STRING );
- if( "".equals( priorityText ) )
- {
- priorityText = DEFAULT_PRIORITY_STRING;
- }
- int priority = Integer.parseInt( priorityText );
- String username = Util.getProperty( props,
"dpml.transit.resourcehost.username", "" );
- String password = Util.getProperty( props,
"dpml.transit.resourcehost.password", "" );
- String prompt = Util.getProperty( props,
"dpml.transit.resourcehost.prompt", "" );
- String scheme = Util.getProperty( props,
"dpml.transit.resourcehost.scheme", "" );
- String resolverclass =
- Util.getProperty( props, "dpml.transit.resourcehost.resolver",
"net.dpml.transit.layout.ClassicResolver" );
- boolean enabled =
- Util.getProperty(
- props, "dpml.transit.resourcehost.enabled", TRUE_VALUE
).equalsIgnoreCase( TRUE_VALUE );
- boolean trusted =
- Util.getProperty(
- props, "dpml.transit.resourcehost.trusted", "false"
).equalsIgnoreCase( TRUE_VALUE );
-
- Preferences prefs = getUserHostNode( name );
- prefs.put( "classname", classname );
- prefs.put( "base", base );
-
- if( null != index )
- {
- prefs.put( "index", index );
- }
- prefs.putInt( "priority", priority );
- prefs.putBoolean( "enabled", enabled );
- prefs.putBoolean( "trusted", trusted );
- prefs.put( "username", username );
- prefs.put( "password", password ); // TODO: needs to be encoded
- prefs.put( "scheme", scheme );
- prefs.put( "resolver", resolverclass );
- prefs.putBoolean( "available", true );
- }
- catch( Throwable e )
- {
- final String error =
- "Unexpected error occured while attempting to construct a
default host preferences."
- + "\nHost Name: " + name
- + "\nResource URL: " + hostDef;
- throw new TransitException( error, e );
- }
- }
-
- private File convertToFile( URL url ) throws IOException
- {
- String protocol = url.getProtocol();
- if( "file".equals( protocol ) )
- {
- String spec = url.toExternalForm();
- String s = spec.substring( 6 );
- return new File( s );
- }
- else
- {
- final String error =
- "Don't know how to convert the '" + protocol + "' protocol to
a file.";
- throw new IOException( error );
- }
+ return m_preferences.node( "cache" );
}
}


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/host/ResourceHostHelper.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/host/ResourceHostHelper.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/host/ResourceHostHelper.java
Fri May 13 16:38:14 2005
@@ -99,7 +99,7 @@

/**
* Utility method used to construct a new resource host instance.
- * @param preferences the preferences instance
+ * @param descriptor the host descriptor
* @exception TransitException if a construction error occurs
*/
public static ResourceHost createResourceHost( HostDescriptor descriptor
)

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/host/StandardResourceManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/host/StandardResourceManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/host/StandardResourceManager.java
Fri May 13 16:38:14 2005
@@ -30,6 +30,7 @@
import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.Properties;
+import java.util.prefs.Preferences;

/**
* Internal resource manager that establishes a CacheHandler implementation
using
@@ -79,10 +80,11 @@
/**
* Creation of a new resource manager.
* @param authorative the authorative base url
+ * @param prefs not used
* @exception IOException if an io error occurs
* @exception TransitException if a transit system error occurs
*/
- public StandardResourceManager( URL authorative )
+ public StandardResourceManager( URL authorative, Preferences prefs )
throws TransitException, IOException
{
m_authorative = authorative;



  • svn commit: r2543 - in development/main: depot depot/console depot/console/etc/bin depot/console/src/main/net/dpml/depot/console depot/console/src/main/net/dpml/depot/lang depot/station/src/main/net/dpml/depot/prefs transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/cache transit/core/handler/src/main/net/dpml/transit/host, mcconnell, 05/13/2005

Archive powered by MHonArc 2.6.24.

Top of Page