notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2674 - in development/main/transit/core: handler handler/etc/setup/authority handler/etc/setup/authority/hosts handler/etc/test/hosts handler/src/main/net/dpml/io handler/src/main/net/dpml/transit handler/src/main/net/dpml/transit/adapter handler/src/main/net/dpml/transit/artifact handler/src/main/net/dpml/transit/cache handler/src/main/net/dpml/transit/content handler/src/main/net/dpml/transit/event handler/src/main/net/dpml/transit/host handler/src/main/net/dpml/transit/layout handler/src/main/net/dpml/transit/link handler/src/main/net/dpml/transit/logging handler/src/main/net/dpml/transit/manager handler/src/main/net/dpml/transit/model handler/src/test/net/dpml/transit/manager handler/src/test/net/dpml/transit/test handler/src/test/net/dpml/transit/util tools/src/main/net/dpml/transit/tools
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2674 - in development/main/transit/core: handler handler/etc/setup/authority handler/etc/setup/authority/hosts handler/etc/test/hosts handler/src/main/net/dpml/io handler/src/main/net/dpml/transit handler/src/main/net/dpml/transit/adapter handler/src/main/net/dpml/transit/artifact handler/src/main/net/dpml/transit/cache handler/src/main/net/dpml/transit/content handler/src/main/net/dpml/transit/event handler/src/main/net/dpml/transit/host handler/src/main/net/dpml/transit/layout handler/src/main/net/dpml/transit/link handler/src/main/net/dpml/transit/logging handler/src/main/net/dpml/transit/manager handler/src/main/net/dpml/transit/model handler/src/test/net/dpml/transit/manager handler/src/test/net/dpml/transit/test handler/src/test/net/dpml/transit/util tools/src/main/net/dpml/transit/tools
- Date: Mon, 30 May 2005 09:59:29 -0400
Author: mcconnell AT dpml.net
Date: Mon May 30 09:59:27 2005
New Revision: 2674
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/TransitRuntimeException.java
development/main/transit/core/handler/src/main/net/dpml/transit/cache/DefaultCacheHandler.java
- copied, changed from r2662,
development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentRegistry.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerRegistry.java
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentRegistry.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerRegistry.java
development/main/transit/core/handler/src/main/net/dpml/transit/layout/ClassicLayout.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/layout/ClassicResolver.java
development/main/transit/core/handler/src/main/net/dpml/transit/layout/DefaultLayoutRegistry.java
development/main/transit/core/handler/src/main/net/dpml/transit/layout/EclipseLayout.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/layout/EclipseResolver.java
development/main/transit/core/handler/src/main/net/dpml/transit/layout/Layout.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/layout/LocationResolver.java
development/main/transit/core/handler/src/main/net/dpml/transit/layout/LayoutRegistry.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/EventProducer.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/event/EventProducer.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/LayoutManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/LayoutRegistryManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitPreferences.java
- copied, changed from r2659,
development/main/transit/core/handler/src/main/net/dpml/transit/TransitPreferences.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostEnabledEvent.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/model/EnabledEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostLayoutEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostNameEvent.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/model/NameChangeEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostPriorityEvent.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/model/PriorityEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostTrustedEvent.java
- copied, changed from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/model/TrustedEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutListener.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutModel.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryListener.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryModel.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/Logger.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/Model.java
development/main/transit/core/handler/src/test/net/dpml/transit/util/
development/main/transit/core/handler/src/test/net/dpml/transit/util/ConfigurationHandler.java
development/main/transit/core/handler/src/test/net/dpml/transit/util/StandardFormatter.java
Removed:
development/main/transit/core/handler/etc/setup/authority/hosts.xml.example
development/main/transit/core/handler/src/main/net/dpml/io/
development/main/transit/core/handler/src/main/net/dpml/transit/TransitPreferences.java
development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerDescriptor.java
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerRegistry.java
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerDescriptor.java
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerRegistry.java
development/main/transit/core/handler/src/main/net/dpml/transit/event/
development/main/transit/core/handler/src/main/net/dpml/transit/host/HostDescriptor.java
development/main/transit/core/handler/src/main/net/dpml/transit/host/HostDescriptorChangeEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/host/HostDescriptorChangeListener.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/ResourceHostFactory.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/ResourceManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/host/StandardResourceManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/host/XMLHostsBuilder.java
development/main/transit/core/handler/src/main/net/dpml/transit/layout/ClassicResolver.java
development/main/transit/core/handler/src/main/net/dpml/transit/layout/EclipseResolver.java
development/main/transit/core/handler/src/main/net/dpml/transit/layout/LocationResolver.java
development/main/transit/core/handler/src/main/net/dpml/transit/logging/
development/main/transit/core/handler/src/main/net/dpml/transit/model/EnabledEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/NameChangeEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/PriorityEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/TrustedEvent.java
Modified:
development/main/transit/core/handler/build.xml
development/main/transit/core/handler/etc/setup/authority/cache.properties
development/main/transit/core/handler/etc/setup/authority/hosts/local.host
development/main/transit/core/handler/etc/setup/authority/hosts/repository.dpml.net.host
development/main/transit/core/handler/etc/setup/authority/hosts/www.apache.org.host
development/main/transit/core/handler/etc/setup/authority/hosts/www.ibiblio.org.host
development/main/transit/core/handler/etc/setup/authority/transit.properties
development/main/transit/core/handler/etc/test/hosts/test.repo
development/main/transit/core/handler/src/main/net/dpml/transit/Main.java
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/Adapter.java
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/LoggingAdapter.java
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ArtifactURLConnection.java
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Handler.java
development/main/transit/core/handler/src/main/net/dpml/transit/cache/CacheHandler.java
development/main/transit/core/handler/src/main/net/dpml/transit/host/ClassicResourceHost.java
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ContentManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CredentialsHelper.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/HostManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/PluginManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RepositoryManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/CacheModel.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostListener.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostModel.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/ModelException.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/PluginModel.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/RegistryModel.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitModel.java
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
development/main/transit/core/handler/src/test/net/dpml/transit/test/ArtifactTestCase.java
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
development/main/transit/core/handler/src/test/net/dpml/transit/test/OfflineTestCase.java
development/main/transit/core/handler/src/test/net/dpml/transit/test/OnlineTestCase.java
development/main/transit/core/tools/src/main/net/dpml/transit/tools/AntAdapter.java
development/main/transit/core/tools/src/main/net/dpml/transit/tools/ImportArtifactTask.java
development/main/transit/core/tools/src/main/net/dpml/transit/tools/MainTask.java
Log:
Bringing Transit up-to-date.
Modified: development/main/transit/core/handler/build.xml
==============================================================================
--- development/main/transit/core/handler/build.xml (original)
+++ development/main/transit/core/handler/build.xml Mon May 30 09:59:27
2005
@@ -24,12 +24,6 @@
<import file="${home}/standard.xml"/>
- <target name="patch">
- <replace token="Modely" value="Directory" dir=".">
- <include name="**/*.java"/>
- </replace>
- </target>
-
<target name="setup-path" depends="init">
<path id="project.test.path">
<pathelement
location="${target.deliverables.jars.dir}/${project.filename}"/>
Modified:
development/main/transit/core/handler/etc/setup/authority/cache.properties
==============================================================================
---
development/main/transit/core/handler/etc/setup/authority/cache.properties
(original)
+++
development/main/transit/core/handler/etc/setup/authority/cache.properties
Mon May 30 09:59:27 2005
@@ -2,6 +2,7 @@
dpml.transit.cache.location=${dpml.data}/cache
# The class that implements the cache handler
-dpml.transit.cache.class=net.dpml.transit.cache.FileCacheHandler
+dpml.transit.cache.class=net.dpml.transit.cache.DefaultCacheHandler
-dpml.transit.cache.locationresolver.class=net.dpml.transit.layout.ClassicResolver
+# The cache layout strategy identifier
+dpml.transit.cache.layout=classic
Modified:
development/main/transit/core/handler/etc/setup/authority/hosts/local.host
==============================================================================
---
development/main/transit/core/handler/etc/setup/authority/hosts/local.host
(original)
+++
development/main/transit/core/handler/etc/setup/authority/hosts/local.host
Mon May 30 09:59:27 2005
@@ -1,7 +1,7 @@
-dpml.transit.resourcehost.enabled=true
-dpml.transit.resourcehost.class=net.dpml.transit.host.ClassicResourceHost
-dpml.transit.resourcehost.base=file:${dpml.system}/local
-dpml.transit.resourcehost.priority=10
-dpml.transit.resourcehost.trusted=true
-dpml.transit.resourcehost.policy=timestamp
-
+dpml.transit.host.enabled=true
+dpml.transit.host.class=net.dpml.transit.host.ClassicResourceHost
+dpml.transit.host.base=file:${dpml.system}/local
+dpml.transit.host.priority=10
+dpml.transit.host.trusted=true
+dpml.transit.host.policy=timestamp
+dpml.transit.host.bootstrap=true
\ No newline at end of file
Modified:
development/main/transit/core/handler/etc/setup/authority/hosts/repository.dpml.net.host
==============================================================================
---
development/main/transit/core/handler/etc/setup/authority/hosts/repository.dpml.net.host
(original)
+++
development/main/transit/core/handler/etc/setup/authority/hosts/repository.dpml.net.host
Mon May 30 09:59:27 2005
@@ -1,10 +1,7 @@
-dpml.transit.resourcehost.enabled=true
-dpml.transit.resourcehost.class=net.dpml.transit.host.ClassicResourceHost
-dpml.transit.resourcehost.base=http://repository.dpml.net/classic
-dpml.transit.resourcehost.priority=40
-dpml.transit.resourcehost.trusted=false
-dpml.transit.resourcehost.policy=fast
-#dpml.transit.resourcehost.knowngroups=
-#dpml.transit.resourcehost.username=
-#dpml.transit.resourcehost.password=
+dpml.transit.host.enabled=true
+dpml.transit.host.class=net.dpml.transit.host.ClassicResourceHost
+dpml.transit.host.base=http://repository.dpml.net/classic
+dpml.transit.host.priority=40
+dpml.transit.host.trusted=false
+dpml.transit.host.policy=fast
Modified:
development/main/transit/core/handler/etc/setup/authority/hosts/www.apache.org.host
==============================================================================
---
development/main/transit/core/handler/etc/setup/authority/hosts/www.apache.org.host
(original)
+++
development/main/transit/core/handler/etc/setup/authority/hosts/www.apache.org.host
Mon May 30 09:59:27 2005
@@ -1,7 +1,7 @@
-dpml.transit.resourcehost.enabled=true
-dpml.transit.resourcehost.class=net.dpml.transit.host.ClassicResourceHost
-dpml.transit.resourcehost.base=http://www.apache.org/dist/java-repository
-dpml.transit.resourcehost.priority=100
-dpml.transit.resourcehost.trusted=false
-dpml.transit.resourcehost.policy=fast
+dpml.transit.host.enabled=true
+dpml.transit.host.class=net.dpml.transit.host.ClassicResourceHost
+dpml.transit.host.base=http://www.apache.org/dist/java-repository
+dpml.transit.host.priority=100
+dpml.transit.host.trusted=false
+dpml.transit.host.policy=fast
Modified:
development/main/transit/core/handler/etc/setup/authority/hosts/www.ibiblio.org.host
==============================================================================
---
development/main/transit/core/handler/etc/setup/authority/hosts/www.ibiblio.org.host
(original)
+++
development/main/transit/core/handler/etc/setup/authority/hosts/www.ibiblio.org.host
Mon May 30 09:59:27 2005
@@ -1,7 +1,7 @@
-dpml.transit.resourcehost.enabled=true
-dpml.transit.resourcehost.class=net.dpml.transit.host.ClassicResourceHost
-dpml.transit.resourcehost.base=http://www.ibiblio.org/maven
-dpml.transit.resourcehost.priority=70
-dpml.transit.resourcehost.trusted=false
-dpml.transit.resourcehost.policy=fast
+dpml.transit.host.enabled=true
+dpml.transit.host.class=net.dpml.transit.host.ClassicResourceHost
+dpml.transit.host.base=http://www.ibiblio.org/maven
+dpml.transit.host.priority=70
+dpml.transit.host.trusted=false
+dpml.transit.host.policy=fast
Modified:
development/main/transit/core/handler/etc/setup/authority/transit.properties
==============================================================================
---
development/main/transit/core/handler/etc/setup/authority/transit.properties
(original)
+++
development/main/transit/core/handler/etc/setup/authority/transit.properties
Mon May 30 09:59:27 2005
@@ -10,14 +10,12 @@
# If true, checksums will only be downloaded from the trusted repository
hosts.
# Not yet implemented.
-dpml.authority.checksum.from.trusted=true
-
+dpml.transit.authority.checksum.from.trusted=true
# If true, artifacts must be signed. If not, the artifact will not be loaded.
# Not yet implemented.
dpml.transit.authority.signature.required=false
-
# If true, anonymous signatures will be allowed. I.e. signatures that are
made
# with self-signed certificates, or with a certificate chain that does not
lead
# to a known Certificate Authority (CA).
Modified: development/main/transit/core/handler/etc/test/hosts/test.repo
==============================================================================
--- development/main/transit/core/handler/etc/test/hosts/test.repo
(original)
+++ development/main/transit/core/handler/etc/test/hosts/test.repo Mon
May 30 09:59:27 2005
@@ -1,11 +1,8 @@
-dpml.transit.resourcehost.enabled=true
-dpml.transit.resourcehost.class=net.dpml.transit.host.ClassicResourceHost
-dpml.transit.resourcehost.base=file:${user.dir}/target/test/trusted
-dpml.transit.resourcehost.knowngroups=
-dpml.transit.resourcehost.priority=10
-dpml.transit.resourcehost.trusted=true
-dpml.transit.resourcehost.policy=fast
-dpml.transit.resourcehost.username=
-dpml.transit.resourcehost.password=
+dpml.transit.host.enabled=true
+dpml.transit.host.class=net.dpml.transit.host.ClassicResourceHost
+dpml.transit.host.base=file:${user.dir}/target/test/trusted
+dpml.transit.host.priority=10
+dpml.transit.host.trusted=true
+dpml.transit.host.policy=fast
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/Main.java
==============================================================================
--- development/main/transit/core/handler/src/main/net/dpml/transit/Main.java
(original)
+++ development/main/transit/core/handler/src/main/net/dpml/transit/Main.java
Mon May 30 09:59:27 2005
@@ -55,38 +55,12 @@
// static utilities for setup of logging manager
//--------------------------------------------------------------------------
- // The following keys and static operations are needed to trigger the
loading
- // of a custom LogManager. The log manager is loader by requesting the
loading
- // of a class named under the LOG_MANAGER_KEY key. This will fail with
a
- // ClassNotFound but the LogManager impl checks for the class in the
context
- // classloader if and only if the first property request fails (which is
really
- // strange). We also include a custom logging configuration handler
declaration
- // for the setup and maintenance of the logging configuration.
-
- /**
- * Java Logging Manager impl key that is used to trigger a ClassNotFound
- * exception which in turn triggers evaluation of LOG_MANAGER_ALT_KEY.
- */
- private static final String LOG_MANAGER_KEY =
"java.util.logging.manager";
-
- /**
- * The key used to resolve the logging manager class from the context
classloader.
- */
- private static final String LOG_MANAGER_ALT_KEY =
"java.util.logging.manager.altclassloader";
-
/**
* The key used to declare the custom logging configuration handler class.
*/
private static final String LOG_CONFIG_CLASS_KEY =
"java.util.logging.config.class";
-
static
{
- System.setProperty( LOG_MANAGER_KEY,
- System.getProperty( LOG_MANAGER_KEY,
- "net.dpml.transit.logging.LoggingManager" ) );
- System.setProperty( LOG_MANAGER_ALT_KEY,
- System.getProperty( LOG_MANAGER_ALT_KEY,
- "net.dpml.transit.logging.LoggingManager" ) );
System.setProperty( LOG_CONFIG_CLASS_KEY,
System.getProperty( LOG_CONFIG_CLASS_KEY,
"net.dpml.transit.logging.ConfigurationHandler" ) );
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
Mon May 30 09:59:27 2005
@@ -18,14 +18,27 @@
package net.dpml.transit;
-import net.dpml.io.ResourceHelper;
import net.dpml.lang.NullArgumentException;
+
import net.dpml.transit.cache.CacheHandler;
-import net.dpml.transit.content.ContentHandlerRegistry;
-import net.dpml.transit.content.DefaultContentHandlerRegistry;
-import net.dpml.transit.host.ResourceManager;
+import net.dpml.transit.cache.DefaultCacheHandler;
+import net.dpml.transit.content.ContentRegistry;
+import net.dpml.transit.content.DefaultContentRegistry;
import net.dpml.transit.link.FileLinkManager;
import net.dpml.transit.link.LinkManager;
+import net.dpml.transit.layout.Layout;
+import net.dpml.transit.layout.LayoutRegistry;
+import net.dpml.transit.layout.DefaultLayoutRegistry;
+import net.dpml.transit.layout.ClassicLayout;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.TransitModel;
+import net.dpml.transit.model.RegistryModel;
+import net.dpml.transit.model.CacheModel;
+import net.dpml.transit.model.LayoutRegistryModel;
+import net.dpml.transit.model.ProxyModel;
+import net.dpml.transit.model.ProxyListener;
+import net.dpml.transit.model.ProxyChangeEvent;
+import net.dpml.transit.model.ProxyExcludesEvent;
import net.dpml.transit.network.DelegatingAuthenticator;
import net.dpml.transit.network.RequestIdentifier;
import net.dpml.transit.network.TransitAuthenticator;
@@ -40,11 +53,10 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
+import java.net.PasswordAuthentication;
import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
-import java.util.logging.Logger;
-import java.util.logging.Level;
import java.util.prefs.Preferences;
import java.util.Properties;
@@ -61,79 +73,50 @@
//------------------------------------------------------------------
/**
- * The namespace string for transit related properties.
- */
- static public final String DOMAIN = "dpml.transit";
-
- /**
- * The authority file filename.
- */
- static public final String AUTHORITY_FILENAME = DOMAIN +
".authority";
-
- /**
- * The authority key.
- */
- static public final String AUTHORITY_KEY = DOMAIN +
".authority";
-
- /**
- * The proxy host name key.
- */
- static public final String PROXY_HOST_KEY = DOMAIN +
".proxy.host";
-
- /**
- * The proxy host port key.
- */
- static public final String PROXY_PORT_KEY = DOMAIN +
".proxy.port";
-
- /**
- * The exluded proxy host names.
- */
- static public final String PROXY_EXCLUDES_KEY = DOMAIN +
".proxy.excludes";
-
- /**
- * The proxy username key.
- */
- static public final String PROXY_USERNAME_KEY = DOMAIN +
".proxy.username";
-
- /**
- * The proxy password key.
- */
- static public final String PROXY_PASSWORD_KEY = DOMAIN +
".proxy.password";
-
- /**
- * The proxy protocol key.
- */
- static public final String PROXY_PROTOCOL_KEY = DOMAIN +
".proxy.protocol";
-
- /**
- * The proxy scheme key.
- */
- static public final String PROXY_SCHEME_KEY = DOMAIN +
".proxy.scheme";
-
- /**
- * The proxy prompt/realm key.
+ * Creation of the transit context. If the transit context has already
+ * been established the method returns the singeton context otherwise a
new
+ * context is created relative to the authoritve url and returned.
+ *
+ * @return the secured transit context
+ * @exception TransitException if an error occurs during context creation
+ * @exception NullArgumentException if the supplied configration model is
null
+ * and an instance of this class has not been created already.
*/
- static public final String PROXY_PROMPT_KEY = DOMAIN +
".proxy.prompt";
+ public static SecuredTransitContext create( TransitModel model )
+ throws TransitException, NullArgumentException
+ {
+ synchronized( SecuredTransitContext.class )
+ {
+ if( m_CONTEXT != null )
+ {
+ return m_CONTEXT;
+ }
- /**
- * The transit properties filename.
- */
- static public final String TRANSIT_PROPERTIES_FILENAME =
"transit.properties";
+ if( null == model )
+ {
+ throw new NullArgumentException( "model" );
+ }
- /**
- * The proxy prompt/realm key.
- */
- static public final String PREFERENCES_ENABLED_KEY = DOMAIN +
".preferences.enabled";
+ Logger logger = model.getLogger();
+ if( logger.isDebugEnabled() )
+ {
+ logger.debug( "creating secure transit context" );
+ }
- /**
- * The singleton transit context.
- */
- private static SecuredTransitContext m_CONTEXT;
+ try
+ {
+ m_CONTEXT = new SecuredTransitContext( model );
+ }
+ catch( Exception e )
+ {
+ String error = "Unable to establish the
SecuredTransitContext.";
+ logger.error( error, e );
+ throw new TransitException( error, e );
+ }
- /**
- * The fallback remote authority.
- */
- private static final String DEFAULT_REMOTE_AUTHORITY =
"http://repository.dpml.net";
+ return m_CONTEXT;
+ }
+ }
/**
* Return the singleton context.
@@ -143,7 +126,14 @@
{
synchronized( SecuredTransitContext.class )
{
- return m_CONTEXT;
+ if( null == m_CONTEXT )
+ {
+ throw new IllegalStateException( "context" );
+ }
+ else
+ {
+ return m_CONTEXT;
+ }
}
}
@@ -152,6 +142,11 @@
//------------------------------------------------------------------
/**
+ * The configuration model.
+ */
+ private TransitModel m_model;
+
+ /**
* The cache handler.
*/
private CacheHandler m_cacheHandler;
@@ -162,14 +157,14 @@
private LinkManager m_linkManager;
/**
- * The ContentHandler plugin registry.
+ * The registry.
*/
- private ContentHandlerRegistry m_contentHandlerRegistry;
+ private ContentRegistry m_registry;
/**
- * The authoritive anchor url.
+ * The registry.
*/
- private URL m_authorativeHost;
+ private LayoutRegistry m_layout;
/**
* Logging channel.
@@ -177,11 +172,6 @@
private Logger m_logger;
/**
- * Prefs enabled flag.
- */
- private boolean m_prefsEnabled = false;
-
- /**
* The repository service provider.
*/
private Repository m_repository;
@@ -189,46 +179,43 @@
//------------------------------------------------------------------
// constructors
//------------------------------------------------------------------
-
/**
* Creation of a new secured transit context.
- * @param authorative the authorative url.
- * @param props the properties for the secured transit context.
- * @param handler the cache handler.
- * @exception TransitException if a context creation error occurs.
- */
- private SecuredTransitContext(
- boolean flag, URL authorative, ContentHandlerRegistry registry,
CacheHandler handler, Properties props )
- throws TransitException
- {
- this( flag, handler, registry );
- try
- {
- setupAuthenticator( props );
- }
- catch( IOException e )
- {
- throw new TransitException( "Unable to read Transit
configuration at " + authorative, e );
- }
- }
-
- /**
- * Creation of a new secured transit context using a remote service.
+ * @param model the transit configuration model
* @param handler the cache handler
+ * @param registry the content handler registry
*/
- private SecuredTransitContext( boolean flag, CacheHandler handler,
ContentHandlerRegistry registry )
+ private SecuredTransitContext( TransitModel model ) throws
TransitException
{
- m_prefsEnabled = flag;
- m_authorativeHost = null;
- m_cacheHandler = handler;
- m_contentHandlerRegistry = registry;
-
- m_logger = Logger.getLogger( "transit" );
-
- // Niclas; Hardcoding the LinkManager for now. When/If pluggable
- // LinkManagers becomes a reality, we'll worry about how
- // to install them.
- m_linkManager = new FileLinkManager();
+ m_model = model;
+
+ //
+ // During boostrap there is only the DefaultCacheHandler,
ClassicLayout
+ // and DefaultContentRegistry. After bootstrap is complete we can
evaluate
+ // alternative cache handlers, resolvers and registries via plugins
+ // (see SecuredTransitContext.initialize() )
+ //
+
+ LayoutRegistryModel layoutModel = model.getLayoutRegistryModel();
+ LayoutRegistry layout = new DefaultLayoutRegistry( layoutModel );
+ ClassicLayout resolver = new ClassicLayout();
+ CacheModel cacheModel = model.getCacheModel();
+ DefaultCacheHandler cache = new DefaultCacheHandler( cacheModel,
resolver );
+ RegistryModel registryModel = model.getRegistryModel();
+ ContentRegistry registry = new DefaultContentRegistry( registryModel
);
+
+ m_cacheHandler = cache;
+ m_registry = registry;
+ m_layout = layout;
+ m_logger = model.getLogger();
+
+ ProxyModel proxy = m_model.getProxyModel();
+ synchronized( proxy )
+ {
+ setupProxy();
+ ProxyController controller = new ProxyController();
+ proxy.addProxyListener( controller );
+ }
}
//------------------------------------------------------------------
@@ -236,95 +223,8 @@
//------------------------------------------------------------------
/**
- * Creation of the transit context. If the transit context has already
- * been established the method returns the singeton context otherwise a
new context
- * is created relative to the authoritve url and returned.
- *
- * @return the secured transit context
- * @exception TransitException if an error occurs during context creation
- * @exception NullArgumentException if the supplied monitor is null and
an instance
- * of this class has not been created already.
- */
- public static SecuredTransitContext create()
- throws TransitException, NullArgumentException
- {
- synchronized( SecuredTransitContext.class )
- {
- if( m_CONTEXT != null )
- {
- return m_CONTEXT;
- }
-
- Logger logger = Logger.getLogger( "transit" );
- if( logger.isLoggable( Level.FINE ) )
- {
- logger.fine( "creating secure transit context" );
- }
-
- try
- {
- URL authorative = establishAuthority( logger );
- if( logger.isLoggable( Level.FINE ) )
- {
- logger.fine( "using authority: " + authorative );
- }
-
- 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 )
- {
- if( prefs.getLong( "installation", -1 ) < 0 )
- {
- TransitPreferences.setupFactoryPreferences( prefs );
- }
- classname = getResourceManagerClassname( prefs ); //
using preferences
- }
- else
- {
- classname = getResourceManagerClassname( props ); //
using properties
- }
-
- //
- // 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 ) )
- {
- logger.fine( "establish cache: " +
ch.getClass().getName() );
- }
- m_CONTEXT = new SecuredTransitContext( flag, authorative,
registry, ch, props );
- }
- catch( Exception e )
- {
- String error = "Unable to establish the
SecuredTransitContext.";
- logger.log( Level.SEVERE, error, e );
- throw new TransitException( error, e );
- }
- return m_CONTEXT;
- }
- }
-
- /**
* Return the Transit repository service.
* @return the repository service
- * @exception IllegalStateException if Transit has not been initialized
*/
public Repository getRepository()
{
@@ -332,7 +232,7 @@
}
/**
- * Return cache handler directory.
+ * Return the cache handler.
* @return the cache handler
*/
public CacheHandler getCacheHandler()
@@ -340,6 +240,10 @@
return m_cacheHandler;
}
+ /**
+ * Return the link manager.
+ * @return the cache handler
+ */
public LinkManager getLinkManager()
{
return m_linkManager;
@@ -349,18 +253,44 @@
* Return the registry of pluggable content handlers.
* @return the content handler registry
*/
- public ContentHandlerRegistry getContentHandlerRegistry()
+ public ContentRegistry getContentHandlerRegistry()
{
- return m_contentHandlerRegistry;
+ return m_registry;
}
- /**
- * Return the authorative host URL.
- * @return the authorative host url
- */
- public URL getAuthorativeHost()
+ //------------------------------------------------------------------
+ // internals
+ //------------------------------------------------------------------
+
+ /**
+ * General setup.
+ * @exception UnknownHostException if a proxy host is declared but is
unknown
+ */
+ protected synchronized void setupProxy()
{
- return m_authorativeHost;
+ ProxyModel model = m_model.getProxyModel();
+ if( model.isProxyEnabled() )
+ {
+ PasswordAuthentication auth = model.getProxyAuthentication();
+ if( null != auth )
+ {
+ TransitAuthenticator ta = new TransitAuthenticatorImpl( auth
);
+ RequestIdentifier id = model.getProxyRequestIdentifier();
+ DelegatingAuthenticator da =
DelegatingAuthenticator.getInstance();
+ da.addTransitAuthenticator( ta, id );
+ }
+
+ String proxy = model.getProxyHost();
+ int port = model.getProxyPort();
+ Properties system = System.getProperties();
+ system.put( "http.proxyHost", proxy );
+ system.put( "http.proxyPort", "" + port );
+ String excludes = model.getProxyExcludes();
+ if( null != excludes )
+ {
+ system.put( "http.nonProxyHosts", excludes );
+ }
+ }
}
/**
@@ -374,439 +304,111 @@
*/
protected void initialize() throws TransitException
{
+ m_linkManager = new FileLinkManager();
m_repository = new StandardLoader();
- if( false == m_prefsEnabled )
+ initializeCache();
+ initializeRegistry();
+ }
+
+ /**
+ * Cache initialization. If the cache model delcares a plugin uri
+ * then we load a replacement cache handler. Otherwise we initialize
+ * the default cache handler during which any custom hosts are loaded.
+ *
+ * @exception TransitException if an initialization error occurs
+ */
+ private void initializeCache() throws TransitException
+ {
+ CacheModel model = m_model.getCacheModel();
+ URI uri = model.getPluginURI();
+ if( null == uri )
{
- return;
+ ((DefaultCacheHandler)m_cacheHandler).initialize();
}
-
- Preferences prefs = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
- String defaultPath = prefs.get( "uri", null );
- String path =
- System.getProperty(
ContentHandlerRegistry.CONTENT_HANDLER_PLUGIN_KEY, defaultPath );
- if( null != path )
+ else
{
- m_logger.info( "assigning custom content handler registry" );
+ m_logger.debug( "loading custom cache handler" );
try
{
- URI uri = new URI( path );
- Object[] args = new Object[]{ prefs, m_logger };
+ Object[] args = new Object[]{ model };
ClassLoader classloader = Transit.class.getClassLoader();
- ContentHandlerRegistry registry =
- (ContentHandlerRegistry) getRepository().getPlugin(
classloader, uri, args );
- m_contentHandlerRegistry = registry;
- m_logger.info( "registry uri: " + path );
+ CacheHandler handler = (CacheHandler)
getRepository().getPlugin( classloader, uri, args );
+ m_cacheHandler = handler;
}
catch( Throwable e )
{
final String error =
- "Bypassing custom content hander registry assignment due
to internal error.";
- m_logger.log( Level.WARNING, error, e );
+ "Bypassing custom cache hander assignment due to internal
error.";
+ m_logger.error( error, e );
}
}
}
- //------------------------------------------------------------------
- // internals
- //------------------------------------------------------------------
-
/**
- * Setup the transit authenticator.
- * @param properties the transit properties
- * @exception UnknownHostException if a proxy host is declared but is
unknown
+ * ContentRegistry initialization.
+ *
+ * @exception TransitException if an initialization error occurs
*/
- private void setupAuthenticator( Properties properties )
- throws UnknownHostException
+ private void initializeRegistry() throws TransitException
{
- TransitAuthenticator ta = createProxyAuthenticator( properties );
- if( ta != null )
- {
- RequestIdentifier id = createProxyRequestIdentifier( properties
);
- DelegatingAuthenticator da =
DelegatingAuthenticator.getInstance();
- da.addTransitAuthenticator( ta, id );
- }
- }
-
- /**
- * Creation of a new transit authenticator.
- * @param properties the transit properties
- * @return the transit authenticator
- */
- private TransitAuthenticator createProxyAuthenticator( Properties
properties )
- {
- String username = Util.getProperty( properties, PROXY_USERNAME_KEY,
null );
- String password = Util.getProperty( properties, PROXY_PASSWORD_KEY,
null );
- if( null == username )
+ RegistryModel model = m_model.getRegistryModel();
+ URI uri = model.getPluginURI();
+ if( null != uri )
{
- return null;
+ m_logger.debug( "loading custom content handler registry" );
+ try
+ {
+ Object[] args = new Object[]{ model };
+ ClassLoader classloader = Transit.class.getClassLoader();
+ ContentRegistry registry = (ContentRegistry)
getRepository().getPlugin( classloader, uri, args );
+ m_registry = registry;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Bypassing custom content hander registry assignment due
to internal error.";
+ m_logger.error( error, e );
+ }
}
- return new TransitAuthenticatorImpl( username, password );
}
- /**
- * Creation of a new request identifier.
- * @param properties the transit properties
- * @return the request identifier
- * @exception UnknownHostException if a proxy host is declared but is
unknown
- * @exception IllegalArgumentException if a proxy host is declared and
- * either the proxy scheme or proxy prompt property values are undefined
- */
- private RequestIdentifier createProxyRequestIdentifier( Properties
properties )
- throws UnknownHostException, IllegalArgumentException
+ private class ProxyController implements ProxyListener
{
- String proxy = Util.getProperty( properties, PROXY_HOST_KEY, null );
- if( null == proxy )
- {
- return null;
- }
-
- String protocol = Util.getProperty( properties, PROXY_PROTOCOL_KEY,
"http" );
- String scheme = Util.getProperty( properties, PROXY_SCHEME_KEY, null
);
- if( scheme == null )
- {
- throw new IllegalArgumentException( "Missing " +
PROXY_SCHEME_KEY + " in properties." );
- }
- String prompt = Util.getProperty( properties, PROXY_PROMPT_KEY, null
);
- if( prompt == null )
+ /**
+ * Notify a listener of the change to Transit proxy settings.
+ * @param event the proxy change event
+ */
+ public void proxySettingsChanged( ProxyChangeEvent event )
{
- throw new IllegalArgumentException( "Missing " +
PROXY_PROMPT_KEY + " in properties." );
+ setupProxy();
}
- String portText = Util.getProperty( properties, PROXY_PORT_KEY, "0"
);
- int port = Integer.parseInt( portText );
- Properties system = System.getProperties();
- system.put( "http.proxyHost", proxy );
- system.put( "http.proxyPort", "" + port );
- String excludes = Util.getProperty( properties, PROXY_EXCLUDES_KEY,
null );
- if( null != excludes )
+ /**
+ * Notify a listener of the change to the set of excluded hosts.
+ * @param event the proxy excludes change event
+ */
+ public void proxyExcludesChanged( ProxyExcludesEvent event )
{
- system.put( "http.nonProxyHosts", excludes );
+ String excludes = event.getProxyModel().getProxyExcludes();
+ if( null != excludes )
+ {
+ Properties system = System.getProperties();
+ system.put( "http.nonProxyHosts", excludes );
+ }
}
- RequestIdentifier id = new RequestIdentifier( proxy, port, protocol,
scheme, prompt );
- return id;
}
//------------------------------------------------------------------
- // internal static utilities
+ // static (utils)
//------------------------------------------------------------------
/**
- * Create the resource manager that will be responsible for the
establishment
- * of the transit cache handler. The class implementating the resource
manager
- * is resolved relative to the transit property
- * 'dpml.transit.authority.resourcemanager.classname'. If undefined the
- * default implementation used in the StandardResourceManager class.
- *
- * @param classname the classname of the ResourceManager to be created.
- * @param authorative the URL to the authorative host.
- * @param prefs the transit preferences
- *
- * @return the resource manager
- */
- private static ResourceManager createResourceManager(
- String classname, URL authorative, Preferences prefs ) throws
TransitException
- {
- try
- {
- Class cls = ResourceManager.class.getClassLoader().loadClass(
classname );
- Class[] params = new Class[]{
- URL.class, Preferences.class };
- Object[] args = new Object[]{
- authorative, prefs };
- Constructor cons = cls.getConstructor( params );
- return (ResourceManager) cons.newInstance( args );
- }
- catch( Throwable e )
- {
- String error =
- "Unable to establish the ResourceManager using the class ["
- + classname
- + "].";
- throw new TransitException( error, e );
- }
- }
-
- /**
- * Return TRUE if preference managment is enabled.
- *
- * @param props the transit properties
- * @return the preferences enabled status
- */
- private static boolean isPreferencesEnabled( Properties props )
- {
- String value = System.getProperty(
- PREFERENCES_ENABLED_KEY,
- props.getProperty( PREFERENCES_ENABLED_KEY, "false" ) );
- return "true".equals( value );
- }
-
- /**
- * 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 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( Preferences prefs )
- {
- final String key = "resource-manager-classname";
- final String fallback =
ResourceManager.TRANSIT_PREFS_RESOURCE_MANAGER_CLASSNAME;
- return System.getProperty(
- ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME_KEY,
- prefs.get( key, fallback ) );
- }
-
- /**
- * Return the classname of the class implementating the resource manager.
- * Resolved relative to the transit property
'dpml.transit.authority.resourcemanager.classname'.
- * If undefined the default classname is returned.
- *
- * @param props the transit properties
- * @return the resource manager classname
- */
- private static String getResourceManagerClassname( Properties props )
- {
- return System.getProperty(
- ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME_KEY,
- props.getProperty(
- ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME_KEY,
- ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME ) );
- }
-
- private static Properties getTransitProperties( URL authorative ) throws
IOException
- {
- try
- {
- URL conf = new URL( authorative, TRANSIT_PROPERTIES_FILENAME );
- return Util.readProps( conf );
- }
- catch( FileNotFoundException fnfe )
- {
- URL url =
SecuredTransitContext.class.getClassLoader().getResource(
- "transit/authority/" + TRANSIT_PROPERTIES_FILENAME );
- return Util.readProps( url );
- }
- }
-
- /**
- * Resolve the authorative url. The implementation will check for a
- * system property named "dpml.transit.authority.file". If the value
- * refers to a file then the file will be used to resolve the authority
- * url by reading the property "dpml.transit.authority". If no system
- * property is defined then a attempt will be made to locate the file
- * ${dpml.prefs}/transit/dpml.transit.authority. If this file does not
exist the
- * implementation will attempt to locate an authority file in the
directory
- * referenced by the system property "java.ext.dirs". If no file is found
- * the implementation will be establised using a bundled default.
- *
- * @param monitor the bootstrap monitor
- * @return the authorative url
- * @exception TransitException if an error occurs during authority url
creation
+ * The namespace string for transit related properties.
*/
- private static URL establishAuthority( final Logger logger )
- throws TransitException
- {
- try
- {
- //
- // System property declaration of an authority file takes
precedence.
- //
-
- String path = System.getProperty( "dpml.transit.authority.file"
);
- if( null != path )
- {
- File authorativeFile = getCanonicalFile( new File( path ) );
- if( !authorativeFile.exists() )
- {
- final String error =
- "The System property 'dpml.transit.authority.file'
referes to the path: ["
- + authorativeFile
- + "] which does not exist.";
- throw new TransitException( error );
- }
- else
- {
- if( logger.isLoggable( Level.FINE ) )
- {
- final String message =
- "using system property
'dpml.transit.authority.file' ["
- + path
- + "]";
- logger.fine( message );
- }
- return useForAuthority( authorativeFile );
- }
- }
-
- //
- // Otherwise check for a authoritive file in the
${dpml.prefs}/transit
- // directory.
- //
-
- File transitDir = new File( Transit.DPML_PREFS, "transit" );
- File artifactAuthFile = new File( transitDir, AUTHORITY_FILENAME
);
- if( artifactAuthFile.exists() )
- {
- if( logger.isLoggable( Level.FINE ) )
- {
- final String message =
- "using authority file ["
- + artifactAuthFile
- + "]";
- logger.fine( message );
- }
- return useForAuthority( artifactAuthFile );
- }
-
- //
- // Otherwise fallback to checking for the authority file in the
- // java extensions directory.
- //
-
- File extlib = new File( System.getProperty( "java.ext.dirs" ) );
- File javaAuthFile = new File( extlib, AUTHORITY_FILENAME );
- if( javaAuthFile .exists() )
- {
- if( logger.isLoggable( Level.FINE ) )
- {
- final String message =
- "using extension authority file ["
- + javaAuthFile
- + "]";
- logger.fine( message );
- }
- return useForAuthority( javaAuthFile );
- }
-
- //
- // create it based on packaged defaults
- //
-
- File authority = new File( transitDir, "authority" );
- File hosts = new File( authority, "hosts" );
-
- try
- {
- authority.mkdirs();
- ClassLoader classloader = Transit.class.getClassLoader();
- ResourceHelper.unpack( classloader, "transit/" +
AUTHORITY_FILENAME, artifactAuthFile );
- ResourceHelper.unpack( classloader,
"transit/authority/cache.properties", new File( authority, "cache.properties"
) );
- ResourceHelper.unpack( classloader,
"transit/authority/hosts.xml.example", new File( authority,
"hosts.xml.example" ) );
- ResourceHelper.unpack( classloader,
"transit/authority/transit.properties", new File( authority,
"transit.properties" ) );
- ResourceHelper.unpack(
- classloader, "transit/authority/hosts/local.host", new
File( hosts, "local.host" ) );
- ResourceHelper.unpack(
- classloader,
"transit/authority/hosts/repository.dpml.net.host", new File( hosts,
"repository.dpml.net.host" ) );
- ResourceHelper.unpack(
- classloader,
"transit/authority/hosts/www.ibiblio.org.host", new File( hosts,
"www.ibiblio.org.host" ) );
- ResourceHelper.unpack(
- classloader,
"transit/authority/hosts/www.apache.org.host", new File( hosts,
"www.apache.org.host" ) );
-
- if( logger.isLoggable( Level.FINE ) )
- {
- final String message =
- "using bundled defaults ["
- + artifactAuthFile
- + "]";
- logger.fine( message );
- }
-
- return useForAuthority( artifactAuthFile );
-
- }
- catch( SecurityException se )
- {
- if( logger.isLoggable( Level.FINE ) )
- {
- final String message =
- "using http://repository.dpml.net/ as authorative
source";
- logger.fine( message );
- }
- return new URL( DEFAULT_REMOTE_AUTHORITY );
- }
- }
- catch( Exception e )
- {
- throw new TransitException( "Artifact AUTHORITY cannot be
established.", e );
- }
- }
+ static public final String DOMAIN = "dpml.transit";
/**
- * Return the cononical form of a file.
- * @param file the file to convert to its cononical form
- * @return the converted file
- * @exception TransitException if the file could not be converted
- */
- private static File getCanonicalFile( final File file ) throws
TransitException
- {
- try
- {
- return file.getCanonicalFile();
- }
- catch( IOException e )
- {
- final String error =
- "Internal error while attempting to convert the supplied file
["
- + file.toString()
- + "] to its canonical form.";
- throw new TransitException( error );
- }
- }
-
- /**
- * Parse an authorative file for the "dpml.transit.authority" property
- * value and resolve from this value the authorative url.
- * @param authFile the authorative file
- * @return the authorative url
- * @exception IOException if a file read error occurs
- * @exception MalformedURLException if the value assigned to the property
- * dpml.transit.authority could not be resolved to a url.
- * @exception TransitException if the dpml.transit.authority property is
undefined
+ * The singleton transit context.
*/
- private static URL useForAuthority( File authFile )
- throws IOException, MalformedURLException, TransitException
- {
- FileInputStream stream = new FileInputStream( authFile );
- try
- {
- Properties p = new Properties();
- p.setProperty( Transit.HOME_KEY, Transit.DPML_HOME.toString() );
- p.setProperty( Transit.PREFS_KEY, Transit.DPML_PREFS.toString()
);
- p.setProperty( Transit.DATA_KEY, Transit.DPML_DATA.toString() );
- p.setProperty( Transit.SYSTEM_KEY,
Transit.DPML_SYSTEM.toString() );
- p.load( stream );
-
- String authority = Util.getProperty( p, AUTHORITY_KEY, null );
- if( authority == null )
- {
- throw new TransitException( "No " + AUTHORITY_KEY + " could
be found in " + authFile );
- }
- if( ! authority.endsWith( "/" ) )
- {
- authority = authority + "/";
- }
-
- File f = new File( authority );
- if( !f.isAbsolute() )
- {
- f = new File( Transit.DPML_PREFS, "transit/" + authority );
- }
- if( f.exists() )
- {
- URL url = f.toURL();
- return url;
- }
- else
- {
- URL url = new URL( authority );
- return url;
- }
- }
- finally
- {
- stream.close();
- }
- }
-
+ private static SecuredTransitContext m_CONTEXT;
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
Mon May 30 09:59:27 2005
@@ -28,6 +28,8 @@
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.util.prefs.Preferences;
+
import net.dpml.lang.NullArgumentException;
import net.dpml.transit.monitors.Monitor;
@@ -38,6 +40,13 @@
import net.dpml.transit.repository.Repository;
import net.dpml.transit.repository.StandardLoader;
+import net.dpml.transit.link.LinkManager;
+
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.TransitModel;
+import net.dpml.transit.manager.TransitManager;
+import net.dpml.transit.adapter.LoggingAdapter;
+
/**
* The Transit class manages the establishment of a singleton transit
instance
* together with a service supporting the deployment of a application plugin
and
@@ -140,7 +149,32 @@
{
if( m_INSTANCE == null )
{
- m_INSTANCE = new Transit();
+ Logger logger = new LoggingAdapter();
+ Preferences prefs = Preferences.userNodeForPackage(
Transit.class );
+ TransitModel model = new TransitManager( logger, prefs );
+ return getInstance( model );
+ }
+ else
+ {
+ return m_INSTANCE;
+ }
+ }
+ }
+
+ /**
+ * Returns the singleton instance of the transit system. If this method
+ * has already been invoked the server and monitor argument will be
ignored.
+ * @return the singleton transit instance
+ * @exception TransitException if an error occurs during establishment
+ */
+ public static Transit getInstance( TransitModel model )
+ throws TransitException, NullArgumentException
+ {
+ synchronized( Transit.class )
+ {
+ if( m_INSTANCE == null )
+ {
+ m_INSTANCE = new Transit( model );
// before returning from this method we need to give the
transit
// subsystems a chance to complete initialization actions
that
@@ -157,6 +191,11 @@
//------------------------------------------------------------------
/**
+ * Logging channel.
+ */
+ private Logger m_logger;
+
+ /**
* Singleton repository monitor router.
*/
private RepositoryMonitorRouter m_repositoryMonitor;
@@ -188,16 +227,43 @@
* Private constructor of a transit instance.
* @exception TransitException if an establishment error occurs
*/
- private Transit()
- throws TransitException
+ private Transit( TransitModel model ) throws TransitException
{
+ m_logger = model.getLogger();
+
+ if( m_logger.isDebugEnabled() )
+ {
+ m_logger.debug( "transit initialization" );
+ }
+
+ //
+ // create the transit context
+ //
+
try
{
- m_context = SecuredTransitContext.create(); // Ensure secured
environment.
- m_repositoryMonitor = new RepositoryMonitorRouter();
- m_cacheMonitor = new CacheMonitorRouter();
- m_networkMonitor = new NetworkMonitorRouter();
+ m_context = SecuredTransitContext.create( model );
+ }
+ catch( TransitException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ final String error = "Unable to construct transit context.";
+ throw new TransitException( error, e );
+ }
+ //
+ // setup the monitors
+ //
+
+ m_repositoryMonitor = new RepositoryMonitorRouter();
+ m_cacheMonitor = new CacheMonitorRouter();
+ m_networkMonitor = new NetworkMonitorRouter();
+
+ try
+ {
// Setting up a temporary directory for Transit.
File temp = new File( DPML_DATA, "temp" );
@@ -339,7 +405,6 @@
catch( Throwable e )
{
// ignore it
- final boolean reality = true;
}
finally
{
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/TransitRuntimeException.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/TransitRuntimeException.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 2004-2005 Niclas Hedhman.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.transit;
+
+/**
+ * Runtime exception to indicate that there was a transit system error.
+ *
+ * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
+ * @version $Id: TransitException.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
+ */
+public class TransitRuntimeException extends RuntimeException
+{
+ /**
+ * Construct a new <code>TransitRuntimeException </code> instance.
+ *
+ * @param message The detail message for this exception.
+ */
+ public TransitRuntimeException( final String message )
+ {
+ this( message, null );
+ }
+
+ /**
+ * Construct a new <code>TransitRuntimeException</code> instance.
+ *
+ * @param message The detail message for this exception.
+ * @param cause the root cause of the exception
+ */
+ public TransitRuntimeException( final String message, final Throwable
cause )
+ {
+ super( message, cause );
+ }
+}
+
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/Adapter.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/Adapter.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/Adapter.java
Mon May 30 09:59:27 2005
@@ -20,6 +20,7 @@
import java.net.URL;
+import net.dpml.transit.model.Logger;
/**
* Utility interface defining a monitor adapter. The contract defines a set
of operations
@@ -30,57 +31,8 @@
* @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
* @version $Id$
*/
-public interface Adapter
+public interface Adapter extends Logger
{
- /**
- * Return TRUE is debug level logging is enabled.
- * @return the enabled state of debug logging
- */
- boolean isDebugEnabled();
-
- /**
- * Return TRUE is info level logging is enabled.
- * @return the enabled state of info logging
- */
- boolean isInfoEnabled();
-
- /**
- * Return TRUE is error level logging is enabled.
- * @return the enabled state of error logging
- */
- boolean isErrorEnabled();
-
- /**
- * Record a debug level message.
- * @param message the debug message to record
- */
- void debug( String message );
-
- /**
- * Record a informative message.
- * @param message the info message to record
- */
- void info( String message );
-
- /**
- * Record a warning message.
- * @param message the warning message to record
- */
- void warn( String message );
-
- /**
- * Record a error level message.
- * @param message the error message to record
- */
- void error( String message );
-
- /**
- * Record a error level message.
- * @param message the error message to record
- * @param e the error
- */
- void error( String message, Throwable e );
-
/**
* Hnadle download notification.
* @param resource the resource under attention
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/LoggingAdapter.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/LoggingAdapter.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/adapter/LoggingAdapter.java
Mon May 30 09:59:27 2005
@@ -62,7 +62,16 @@
*/
public LoggingAdapter()
{
- m_logger = Logger.getLogger( CATEGORY );
+ this( Logger.getLogger( CATEGORY ) );
+ }
+
+ /**
+ * Creation of a new console adapter that is used to redirect transit
events
+ * the system output stream.
+ */
+ public LoggingAdapter( Logger logger )
+ {
+ m_logger = logger;
}
//
------------------------------------------------------------------------
@@ -167,6 +176,13 @@
}
}
+ public net.dpml.transit.model.Logger getChildLogger( String category )
+ {
+ String name = m_logger.getName();
+ String path = name + "." + category;
+ return new LoggingAdapter( Logger.getLogger( path ) );
+ }
+
/**
* Handle download notification.
* @param resource the resource under attention
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ArtifactURLConnection.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ArtifactURLConnection.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ArtifactURLConnection.java
Mon May 30 09:59:27 2005
@@ -33,13 +33,13 @@
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
import net.dpml.transit.SecuredTransitContext;
-import net.dpml.transit.content.ContentHandlerRegistry;
+import net.dpml.transit.content.ContentRegistry;
import net.dpml.transit.cache.CacheHandler;
-import net.dpml.transit.layout.ClassicResolver;
-import net.dpml.transit.layout.LocationResolver;
+import net.dpml.transit.layout.ClassicLayout;
+import net.dpml.transit.layout.Layout;
import net.dpml.transit.util.MimeTypeHandler;
import net.dpml.transit.util.StreamUtils;
-import net.dpml.transit.repository.StandardLoader;
+import net.dpml.transit.repository.Repository;
import net.dpml.transit.repository.Plugin;
/**
@@ -198,7 +198,7 @@
//
String type = m_artifact.getType();
- ContentHandlerRegistry registry =
m_context.getContentHandlerRegistry();
+ ContentRegistry registry = m_context.getContentHandlerRegistry();
ContentHandler handler = registry.getContentHandler( type );
if( null != handler )
{
@@ -206,12 +206,12 @@
}
//
- // if the type is a plugin then hande this directly
+ // if the type is a plugin then handle this directly
//
if( "plugin".equals( type ) )
{
- StandardLoader loader = new StandardLoader();
+ Repository loader = Transit.getInstance().getRepository();
ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
URI uri = m_artifact.toURI();
if( classes.length == 0 )
@@ -267,7 +267,7 @@
if( c.equals( File.class ) )
{
InputStream content = getInputStream();
- LocationResolver resolver = new ClassicResolver();
+ Layout resolver = new ClassicLayout();
String name = resolver.resolvePath( m_artifact );
File cache = new File( Transit.DPML_DATA, "cache" );
return new File( cache, name );
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Handler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Handler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Handler.java
Mon May 30 09:59:27 2005
@@ -66,7 +66,8 @@
{
try
{
- m_context = SecuredTransitContext.create();
+ Transit.getInstance();
+ m_context = SecuredTransitContext.getInstance();
}
catch( TransitException e )
{
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/cache/CacheHandler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/cache/CacheHandler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/cache/CacheHandler.java
Mon May 30 09:59:27 2005
@@ -39,26 +39,6 @@
*/
public interface CacheHandler
{
- /**
- * The domain identifier.
- */
- static final String DOMAIN = SecuredTransitContext.DOMAIN;
-
- /**
- * Cache property key.
- */
- static final String CACHE_KEY = DOMAIN + ".cache.location";
-
- /**
- * Cache handler classname key.
- */
- static final String CACHE_CLASS_KEY = DOMAIN + ".cache.class";
-
- /**
- * Cache location resolver classname key.
- */
- static final String RESOLVER_CLASS_KEY = DOMAIN +
".cache.locationresolver.class";
-
/**
* Attempts to download and cache a remote artifact using a set of remote
* repositories.
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/cache/DefaultCacheHandler.java
(from r2662,
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/DefaultCacheHandler.java
Mon May 30 09:59:27 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 Stephen J. McConnell.
+ * Copyright 2004-2005 Stephen J. McConnell.
* Copyright 2004 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,12 +26,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URI;
+import java.net.UnknownHostException;
import java.util.Date;
import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
-import java.util.logging.Logger;
-import java.util.logging.Level;
+import java.util.WeakHashMap;
import java.util.prefs.Preferences;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.PreferenceChangeEvent;
@@ -42,19 +44,24 @@
import java.util.zip.ZipFile;
import net.dpml.lang.NullArgumentException;
+
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
import net.dpml.transit.artifact.Artifact;
import net.dpml.transit.artifact.ArtifactAlreadyExistsException;
import net.dpml.transit.artifact.ArtifactNotFoundException;
import net.dpml.transit.host.ResourceHost;
-import net.dpml.transit.host.ResourceHostHelper;
-import net.dpml.transit.host.HostDescriptor;
-import net.dpml.transit.host.HostDescriptorChangeEvent;
-import net.dpml.transit.host.HostDescriptorChangeListener;
-import net.dpml.transit.layout.LocationResolver;
+import net.dpml.transit.host.ClassicResourceHost;
+import net.dpml.transit.layout.Layout;
+import net.dpml.transit.model.CacheModel;
+import net.dpml.transit.model.CacheListener;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.FileChangeEvent;
+import net.dpml.transit.model.HostModel;
+import net.dpml.transit.model.HostNodeEvent;
import net.dpml.transit.monitors.CacheMonitorRouter;
import net.dpml.transit.monitors.Monitor;
+import net.dpml.transit.repository.Repository;
import net.dpml.transit.util.PropertyResolver;
import net.dpml.transit.util.Util;
@@ -64,8 +71,7 @@
* cache configuration, and another listener for changes to subsidiary node
changes
* reflecting the addition, modification and removal of hosts.
*/
-public class FileCacheHandler
- implements CacheHandler, PreferenceChangeListener, NodeChangeListener,
HostDescriptorChangeListener
+public class DefaultCacheHandler implements CacheHandler, CacheListener
{
//
------------------------------------------------------------------------
// state
@@ -81,113 +87,132 @@
*/
private TreeMap m_resourceHosts;
- private LocationResolver m_resolver;
+ private Layout m_resolver;
private ZipCache m_zipCache;
- private boolean m_flag = false;
-
private Logger m_logger;
+ private CacheModel m_model;
+
+ private final Map m_plugins = new WeakHashMap(); // plugin uris as keys
to plugin classes
+
//
------------------------------------------------------------------------
- // constructor (preferences based)
+ // constructor
//
------------------------------------------------------------------------
/**
- * Creation of a new file based cache handler using system preferences.
- * @param prefs the file subsystem preferences
- * @param resolver the location resolver
+ * Creation of a new file based cache controller using a supplied
+ * configuration model and cache layout resolver.
+ *
+ * @param model the cache system confiuguration model
+ * @param resolver the local cache layout resolver
*/
- public FileCacheHandler( LocationResolver resolver, Preferences prefs )
throws TransitException
+ public DefaultCacheHandler( CacheModel model, Layout resolver ) throws
TransitException
{
+ m_model = model;
m_zipCache = new ZipCache();
m_resourceHosts = new TreeMap();
m_resolver = resolver;
- m_flag = true;
- m_logger = Logger.getLogger( "transit" );
+ m_logger = model.getLogger();
+
+ if( m_logger.isDebugEnabled() )
+ {
+ m_logger.debug( "cache controller initialization" );
+ }
//
- // construct the hosts using the system preferences
+ // For all of the declared host models we check for hosts that do
not
+ // declare a plugin uri. If no plugin uri is declared we are
dealing with
+ // a classic resource host that serves as a bootstrap host. Leter
on the
+ // SecuredTransitContext will initialize this instance and we will
continue
+ // with host loading for plugin based resource hosts.
//
- Preferences hostsNode = getHostsPreferences( prefs );
- try
+ HostModel[] hosts = model.getHostModels();
+ if( m_logger.isDebugEnabled() )
{
- String[] names = getHostNodeNames( hostsNode );
- for( int i=0; i<names.length; i++ )
- {
- String name = names[i];
- Preferences p = getNamedHostPreferences( hostsNode, name );
- handleHostAddition( p );
- }
+ m_logger.debug( "cache configuration host count: " +
hosts.length );
}
- catch( Exception e )
+ for( int i=0; i<hosts.length; i++ )
{
- final String error =
- "Unexpected exception while reading host preferences."
- + "\nPreferences: " + prefs;
- throw new TransitException( error, e );
+ HostModel host = hosts[i];
+ if( null == host.getPluginURI() )
+ {
+ String id = host.getID();
+ if( m_logger.isDebugEnabled() )
+ {
+ final String message =
+ "Creating new classic resource host: " + id
+ + "\nBase URL: " + host.getBaseURL();
+ m_logger.debug( message );
+ }
+ ResourceHost handler = createClassicResourceHost( host );
+ m_resourceHosts.put( id, handler );
+ }
}
//
- // add a listener to the user preferences
+ // setup the cache directory
//
- prefs.addPreferenceChangeListener( this );
- hostsNode.addNodeChangeListener( this );
- File cache = resolveCacheDirectory( prefs );
+ File cache = model.getCacheDirectory();
setLocalCacheDirectory( cache );
+
+ if( m_logger.isDebugEnabled() )
+ {
+ m_logger.debug( "cache controller initialization complete" );
+ }
}
//
------------------------------------------------------------------------
- // constructor (properties based)
+ // impl
//
------------------------------------------------------------------------
/**
- * Creation of a new file based cache handler using supplied hosts and
properties.
- * @param hosts the assigned hosts
- * @param props the properties against which this instance will be
configured
- * @param resolver the location resolver
+ * Initialization of the cache controller. This operation is invoked by
+ * the secure transit context following the establishment of bootstrap
+ * services. During initialization the implementation loads any custom
+ * resource hosts.
+ *
+ * @exception TransitException if a custom host deployment error occurs
*/
- public FileCacheHandler( ResourceHost[] hosts, Properties props,
LocationResolver resolver )
+ public void initialize() throws TransitException
{
- m_zipCache = new ZipCache();
-
- m_resolver = resolver;
- m_resourceHosts = new TreeMap();
-
- m_logger = Logger.getLogger( "transit" );
+ m_model.addCacheListener( this );
- for( int i=0; i < hosts.length; i++ )
+ HostModel[] hosts = m_model.getHostModels();
+ for( int i=0; i<hosts.length; i++ )
{
- // We need to ensure that no other host already have the same
- // priority, in which case we increase the priority until we find
- // an available spot.
-
- int priority = hosts[i].getPriority();
- Integer key;
- while ( true )
+ HostModel host = hosts[i];
+ if( null != host.getPluginURI() )
{
- key = new Integer( priority );
- if( !m_resourceHosts.containsKey( key ) )
+ try
+ {
+ handleHostAddition( host );
+ }
+ catch( Throwable e )
{
- break;
+ //
+ // TODO: mark the host model as invalid by apply
+ // the exception to the model
+ //
+
+ final String error =
+ "Dropping custom resource host due to a deployment
failure."
+ + "\nHost ID: " + host.getID();
+ m_logger.error( error, e );
}
- priority = priority + 1;
}
- m_resourceHosts.put( key, hosts[i] );
}
-
- File cache = resolveCacheDirectory( props );
- setLocalCacheDirectory( cache );
}
/**
* Set the local cache directory.
- *
+ * @param file the cache directory
*/
- protected synchronized void setLocalCacheDirectory( File file )
+ private synchronized void setLocalCacheDirectory( File file )
{
if( null == file )
{
@@ -197,9 +222,9 @@
if( null == m_cacheDir )
{
final String message =
- "Setting cache directory."
+ "Setting local cache directory."
+ "\nDirectory: " + cache;
- m_logger.fine( message );
+ m_logger.debug( message );
}
else
{
@@ -207,7 +232,7 @@
"Changing cache directory."
+ "\nOld: " + m_cacheDir
+ "\nNew: " + cache;
- m_logger.fine( message );
+ m_logger.debug( message );
}
if( false == cache.isAbsolute() )
{
@@ -220,7 +245,7 @@
/**
* Return a directory established to provide the local cache.
*
- * @return the feature collection
+ * @return the local cache directory
*/
protected File getLocalCacheDirectory()
{
@@ -295,7 +320,6 @@
InputStream stream = zip.getInputStream( entry );
return new BufferedInputStream( stream );
}
-
}
/** Creates an output stream to where the artifact content can be written
@@ -340,19 +364,22 @@
*/
private ResourceHost findKnownGroupHost( Artifact artifact )
{
- Iterator list = m_resourceHosts.values().iterator();
- while ( list.hasNext() )
+ synchronized( m_resourceHosts )
{
- ResourceHost host = (ResourceHost) list.next();
- if( host.isEnabled() )
+ Iterator list = m_resourceHosts.values().iterator();
+ while ( list.hasNext() )
{
- if( host.checkPresence( artifact, true ) )
+ ResourceHost host = (ResourceHost) list.next();
+ if( host.isEnabled() )
{
- return host;
+ if( host.checkPresence( artifact, true ) )
+ {
+ return host;
+ }
}
}
+ return null;
}
- return null;
}
/**
@@ -362,19 +389,22 @@
*/
private ResourceHost findAnyPresence( Artifact artifact )
{
- Iterator list = m_resourceHosts.values().iterator();
- while ( list.hasNext() )
+ synchronized( m_resourceHosts )
{
- ResourceHost host = (ResourceHost) list.next();
- if( host.isEnabled() )
- {
- if( host.checkPresence( artifact, false ) )
+ Iterator list = m_resourceHosts.values().iterator();
+ while ( list.hasNext() )
+ {
+ ResourceHost host = (ResourceHost) list.next();
+ if( host.isEnabled() )
{
- return host;
+ if( host.checkPresence( artifact, false ) )
+ {
+ return host;
+ }
}
}
+ return null;
}
- return null;
}
/**
@@ -420,37 +450,6 @@
}
}
- /**
- * Create the file to the root of the cache directory. If the cache key is
- * declared as a system property, the value will take precidence over the
- * cache configuration properties. If the cache key is declared as a
system
- * property, the system prioperty value will take precidence over the
- * cache preferences.
- *
- * @param props the configuration properties
- * @return the cache root directory
- */
- private File resolveCacheDirectory( Properties props )
- {
- String defaultCache = "cache";
- String fallback = Util.getProperty( props, CACHE_KEY, defaultCache );
- String cache = System.getProperty( CACHE_KEY, fallback );
- return new File( cache );
- }
-
- /**
- * Resolve the cache directory using the preferences.
- *
- * @return the cache directory
- */
- private File resolveCacheDirectory( Preferences cachePrefs )
- {
- String path = cachePrefs.get( "location", "cache" );
- String location = System.getProperty( CACHE_KEY, path );
- String cache = PropertyResolver.resolve( System.getProperties(),
location );
- return new File( cache );
- }
-
private void endNotifyMonitor( CacheMonitorRouter monitor, boolean
existed,
Artifact artifact, File destination )
{
@@ -529,132 +528,161 @@
}
//
------------------------------------------------------------------------
- // PreferencesChangeListener (listens to cache prefs)
+ // CacheListener
//
------------------------------------------------------------------------
- // TODO: change this to a CacheConfigurationListener
-
- public void preferenceChange( PreferenceChangeEvent event )
+ /**
+ * Notify the listener of a change to the cache directory.
+ * @param event the cache directory change event
+ */
+ public void cacheDirectoryChanged( FileChangeEvent event )
{
- String key = event.getKey();
- String value = event.getNewValue();
- Preferences prefs = event.getNode();
- if( "location".equals( key ) )
+ File cache = event.getFile();
+ synchronized( this )
{
- File cache = resolveCacheDirectory( prefs );
setLocalCacheDirectory( cache );
}
}
- //
------------------------------------------------------------------------
- // 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 to
the
- * relative node hosts.
- *
- * @param event the node addition event
+ * Notify the listener of the addition of a new host.
+ * @param event the host added event
*/
- public void childAdded( NodeChangeEvent event )
+ public void hostAdded( HostNodeEvent event )
{
- Preferences prefs = event.getChild();
- handleHostAddition( prefs );
+ HostModel host = event.getHostModel();
+ try
+ {
+ handleHostAddition( host );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "An internal error occured while attempting to handle host
addition.";
+ m_model.getLogger().error( error, e );
+ }
}
- public void childRemoved( NodeChangeEvent event )
+ /**
+ * Notify the listener of the removal of a host.
+ * @param event the host removed event
+ */
+ public void hostRemoved( HostNodeEvent event )
{
- Preferences prefs = event.getChild();
- String name = prefs.name();
- m_resourceHosts.remove( name );
+ HostModel host = event.getHostModel();
+ String id = host.getID();
+ synchronized( m_resourceHosts )
+ {
+ m_resourceHosts.remove( id );
+ }
}
//
------------------------------------------------------------------------
- // HostChangedListener (listens to changes in a host descriptor)
+ // internals
//
------------------------------------------------------------------------
- // TODO: update all of this once we switch to prefs - we should be
creating
- // a ResourceHost without any concern for exceptions and leave it up to
the
- // ResourceHost implementation to maintain its own availability based on
the
- // underlying prefs and it's own state - so for example, if it has a bad
base
- // url it would automatically declare itself as unavailable and expose
- // somewhere the reason for non-availability
-
- public void hostChanged( HostDescriptorChangeEvent event )
+ private void handleHostAddition( HostModel model )
+ throws UnknownHostException, TransitException, IOException
{
- HostDescriptor descriptor = event.getDescriptor();
- String name = descriptor.getHostName();
- if( false == m_resourceHosts.containsKey( name ) )
+ synchronized( m_resourceHosts )
{
- if( descriptor.getLastModified() > 0 )
+ String id = model.getID();
+ if( null == m_resourceHosts.get( id ) )
+ {
+ ResourceHost host = createResourceHost( model );
+ m_resourceHosts.put( id, host );
+ }
+ else
{
- descriptor.removeHostDescriptorChangeListener( this );
- ResourceHost host = createResourceHost( descriptor );
- m_resourceHosts.put( name, host );
+ final String error =
+ "Illegal attempt to override existing host handler: " + id;
+ throw new TransitException( error );
}
}
}
- //
------------------------------------------------------------------------
- // prefs utilities
- //
------------------------------------------------------------------------
-
- private Preferences getHostsPreferences( Preferences root ) throws
TransitException
- {
- return root.node( "hosts" );
- }
-
- private Preferences getNamedHostPreferences( Preferences hostsPrefs,
String name )
- {
- return hostsPrefs.node( name );
- }
-
- private String[] getHostNodeNames( Preferences hostsPrefs ) throws
TransitException
+ private ResourceHost createResourceHost( HostModel model )
+ throws UnknownHostException, TransitException, IOException
{
- try
+ URI uri = model.getPluginURI();
+ if( null == uri )
{
- return hostsPrefs.childrenNames();
+ return createClassicResourceHost( model );
}
- catch( BackingStoreException e )
+ else
{
- final String error =
- "Unexpected error occured while attempting to access a named
named hosts."
- + "\nTransit hosts root preferences: " + hostsPrefs;
- throw new TransitException( error, e );
+ return loadResourceHost( model );
}
}
- private void handleHostAddition( Preferences prefs )
+ protected ResourceHost loadResourceHost( HostModel model ) throws
IOException
{
- HostDescriptor descriptor = new HostDescriptor( prefs );
- if( descriptor.getLastModified() > 0 )
+ Class clazz = loadResourceHostClass( model );
+ Repository loader = Transit.getInstance().getRepository();
+ return (ResourceHost) loader.instantiate( clazz, new Object[]{ model
} );
+ }
+
+ protected Class loadResourceHostClass( HostModel model ) throws
IOException
+ {
+ URI uri = model.getPluginURI();
+ Class clazz = (Class) m_plugins.get( uri );
+ if( null != clazz )
{
- String name = descriptor.getHostName();
- ResourceHost host = createResourceHost( descriptor );
- m_resourceHosts.put( name, host );
+ return clazz;
}
else
{
- descriptor.addHostDescriptorChangeListener( this );
+ try
+ {
+ m_logger.debug( "loading host plugin: " + uri );
+ Repository loader = Transit.getInstance().getRepository();
+ ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
+ clazz = loader.getPluginClass( classloader, uri );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to load a content handler plugin due to an
unexpected exception.";
+ throw new TransitException( error, e );
+ }
+
+ if( ResourceHost.class.isAssignableFrom( clazz ) )
+ {
+ m_plugins.put( uri, clazz );
+ return clazz;
+ }
+ else
+ {
+ final String error =
+ "Host plugin is not assignable to a
net.dpml.transit.host.ResourceHost."
+ + "\nPlugin URI: " + uri
+ + "\nPlugin Class: " + clazz.getName();
+ throw new TransitException( error );
+ }
}
}
- private ResourceHost createResourceHost( HostDescriptor descriptor )
+ private ResourceHost createClassicResourceHost( HostModel model ) throws
TransitException
{
+ if( m_logger.isDebugEnabled() )
+ {
+ final String message =
+ "Creating new classic resource host."
+ + "\nHost ID: " + model.getID()
+ + "\nBase URL: " + model.getBaseURL();
+ m_logger.debug( message );
+ }
try
{
- return ResourceHostHelper.createResourceHost( descriptor );
+ return new ClassicResourceHost( model, m_resolver );
}
catch( Throwable e )
{
final String error =
- "Unexpected error while attempting to add a resource host."
- + "\nHost: " + descriptor;
- RuntimeException exception = new RuntimeException( error );
- exception.initCause( e );
- throw exception;
+ "Unexpected exception while attempting to load standard host:
" + model.getID()
+ + "\nBase URL: " + model.getBaseURL();
+ throw new TransitException( error, e );
}
}
}
+
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentRegistry.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerRegistry.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentHandlerRegistry.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/content/ContentRegistry.java
Mon May 30 09:59:27 2005
@@ -22,13 +22,10 @@
import java.net.ContentHandler;
/**
- * A interface supporting access to pluggable content handlers. An
implementation
- * may request a Logger and Preferences node as optional constructor
arguments.
+ * A interface supporting access to pluggable content handlers.
*/
-public interface ContentHandlerRegistry
+public interface ContentRegistry
{
- public static final String CONTENT_HANDLER_PLUGIN_KEY =
"dpml.transit.content.plugin";
-
/**
* Return a content handler capable for supporting the supplied type. If
* the a handler is available the handler is returned otherwise the
returned
@@ -39,3 +36,4 @@
*/
ContentHandler getContentHandler( final String type ) throws IOException;
}
+
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentRegistry.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerRegistry.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentHandlerRegistry.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/content/DefaultContentRegistry.java
Mon May 30 09:59:27 2005
@@ -30,32 +30,32 @@
import java.util.prefs.NodeChangeListener;
import java.util.prefs.NodeChangeEvent;
import java.util.prefs.BackingStoreException;
-import java.util.logging.Logger;
-
-import net.dpml.io.CascadingIOException;
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
import net.dpml.transit.repository.Repository;
+import net.dpml.transit.model.RegistryModel;
+import net.dpml.transit.model.RegistryListener;
+import net.dpml.transit.model.RegistryEvent;
+import net.dpml.transit.model.ContentModel;
+import net.dpml.transit.model.Logger;
/**
* A registry of descriptions of plugable content handlers. This
implementation
* maps user defined preferences to instance of ContentHandlerDescriptor.
*/
-public class DefaultContentHandlerRegistry implements
ContentHandlerRegistry, NodeChangeListener
+public class DefaultContentRegistry implements ContentRegistry,
RegistryListener
{
//
------------------------------------------------------------------------
// state
//
------------------------------------------------------------------------
- private final Map m_descriptors = new Hashtable();
-
- private final Preferences m_preferences;
-
- private Logger m_logger;
+ private final Logger m_logger;
private final Map m_links = new WeakHashMap();
+ private final RegistryModel m_model;
+
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
@@ -65,44 +65,62 @@
* artifact types, and values that correspond to the description of a
* content type handler plugins.
*/
- public DefaultContentHandlerRegistry( Logger logger, Preferences prefs )
throws BackingStoreException
+ public DefaultContentRegistry( RegistryModel model )
{
- m_logger = logger;
- m_preferences = prefs;
- synchronized( m_descriptors )
- {
- prefs.addNodeChangeListener( this );
- String[] names = prefs.childrenNames();
- for( int i=0; i<names.length; i++ )
- {
- String name = names[i];
- Preferences p = prefs.node( name );
- addContentHandlerDescriptor( p );
- }
- }
+ m_model = model;
+ m_logger = model.getLogger();
+ model.addRegistryListener( this );
}
//
------------------------------------------------------------------------
- // ContentHandlerRegistry
+ // ContentRegistry
//
------------------------------------------------------------------------
public ContentHandler getContentHandler( final String type ) throws
IOException
{
- ContentHandlerDescriptor descriptor = getContentHandlerDescriptor(
type );
- if( null == descriptor )
+ ContentModel model = m_model.getContentModel( type );
+ if( null == model )
{
return null;
}
else
{
- return getContentHandler( descriptor );
+ return getContentHandler( model );
}
}
- protected ContentHandler getContentHandler( ContentHandlerDescriptor
descriptor ) throws IOException
+ //
------------------------------------------------------------------------
+ // RegistryListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify all listeners of the addition of a content model.
+ * @param event the registry event
+ */
+ public void contentAdded( RegistryEvent event )
+ {
+ // TODO: load and validate
+ }
+
+ /**
+ * Notify all listeners of the removal of a content model.
+ * @param event the registry event
+ */
+ public void contentRemoved( RegistryEvent event )
{
- String type = descriptor.getContentType();
- URI uri = descriptor.getPluginURI();
+ ContentModel model = event.getContentModel();
+ URI uri = model.getPluginURI();
+ m_links.remove( uri );
+ }
+
+ //
------------------------------------------------------------------------
+ // impl
+ //
------------------------------------------------------------------------
+
+ protected ContentHandler getContentHandler( ContentModel model ) throws
IOException
+ {
+ String type = model.getContentType();
+ URI uri = model.getPluginURI();
ContentHandler handler = (ContentHandler) m_links.get( uri );
if( null != handler )
{
@@ -112,10 +130,10 @@
{
try
{
- m_logger.info( "loading content handler for: " + type );
+ m_logger.debug( "loading content handler for: " + type );
Repository loader = Transit.getInstance().getRepository();
ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
- Object plugin = loader.getPlugin( classloader, uri, new
Object[0] );
+ Object plugin = loader.getPlugin( classloader, uri, new
Object[]{ model } );
if( plugin instanceof ContentHandler )
{
handler = (ContentHandler) plugin;
@@ -134,133 +152,10 @@
catch( Exception e )
{
final String error =
- "Unable to load a content handler plugin.";
- throw new CascadingIOException( error, e );
+ "Unable to load a content handler plugin due to an
unexpected exception.";
+ throw new TransitException( error, e );
}
}
}
-
- //
------------------------------------------------------------------------
- // NodeChangeListener (listens to host prefs addition and removal)
- //
------------------------------------------------------------------------
-
- /**
- * Handle the addition of a content handler mapping.
- *
- * @param event the node addition event
- */
- public void childAdded( NodeChangeEvent event )
- {
- Preferences prefs = event.getChild();
- addContentHandlerDescriptor( prefs );
- }
-
- public void childRemoved( NodeChangeEvent event )
- {
- Preferences prefs = event.getChild();
- removeContentHandlerDescriptor( prefs );
- }
-
- //
------------------------------------------------------------------------
- // internals
- //
------------------------------------------------------------------------
-
- private URI getContentHandlerDescriptorURI( final String type )
- {
- ContentHandlerDescriptor descriptor = getContentHandlerDescriptor(
type );
- if( null == descriptor )
- {
- return null;
- }
- else
- {
- return descriptor.getPluginURI();
- }
- }
-
- public ContentHandlerDescriptor getContentHandlerDescriptor( final
String type )
- {
- if( null == type )
- {
- throw new NullPointerException( "type" );
- }
- synchronized( m_descriptors )
- {
- ContentHandlerDescriptor descriptor = (ContentHandlerDescriptor)
m_descriptors.get( type );
- if( null == descriptor )
- {
- return null;
- }
- else if( null == descriptor.getPluginURI() )
- {
- return null;
- }
- else
- {
- return descriptor;
- }
- }
- }
-
- /**
- * Add a description of a content handler based on a supplied
- * prefernces object. The name of the preferences object
- * corresponds to an artifact type. Request for the resolution
- * of URL content may be resolved by locating a content handler
- * plugin for the type exposed by the URL.
- */
- protected void addContentHandlerDescriptor( ContentHandlerDescriptor
descriptor )
- {
- String type = descriptor.getContentType();
- if( m_descriptors.containsKey( type ) )
- {
- final String error =
- "Duplicate content handler descriptor type."
- + "\nContentHandlerDescriptor: " + descriptor
- + "\nContent Type: " + type;
- throw new IllegalStateException( error );
- }
- else
- {
- m_logger.fine( "registering '" + type + "' content handler" );
- m_descriptors.put( type, descriptor );
- }
- }
-
- /**
- * Add a description of a content handler based on a supplied
- * prefernces object. The name of the preferences object
- * corresponds to an artifact type. Request for the resolution
- * of URL content may be resolved by locating a content handler
- * plugin for the type exposed by the URL.
- */
- protected void addContentHandlerDescriptor( Preferences prefs )
- {
- ContentHandlerDescriptor descriptor = new
DefaultContentHandlerDescriptor( m_logger, prefs );
- addContentHandlerDescriptor( descriptor );
- }
-
- /**
- * Remove a content handler descriptor.
- * @param prefs the preferences node
- * @return the content handler descriptor that was removed (possibly null)
- */
- protected ContentHandlerDescriptor removeContentHandlerDescriptor(
Preferences prefs )
- {
- synchronized( m_descriptors )
- {
- String type = prefs.name();
- ContentHandlerDescriptor descriptor =
getContentHandlerDescriptor( type );
- if( descriptor != null )
- {
- m_descriptors.remove( type );
- if( descriptor instanceof DefaultContentHandlerDescriptor )
- {
- DefaultContentHandlerDescriptor d =
(DefaultContentHandlerDescriptor) descriptor;
- d.dispose();
- }
- }
- return descriptor;
- }
- }
}
+
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/host/ClassicResourceHost.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/host/ClassicResourceHost.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/host/ClassicResourceHost.java
Mon May 30 09:59:27 2005
@@ -37,6 +37,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
+import java.net.PasswordAuthentication;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -47,17 +48,13 @@
import java.util.HashMap;
import java.util.HashSet;
-import java.util.prefs.Preferences;
-import java.util.prefs.PreferenceChangeListener;
-import java.util.prefs.PreferenceChangeEvent;
-
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
import net.dpml.transit.artifact.Artifact;
-import net.dpml.transit.layout.ClassicResolver;
-import net.dpml.transit.layout.LocationResolver;
+import net.dpml.transit.layout.ClassicLayout;
+import net.dpml.transit.layout.Layout;
import net.dpml.transit.network.ConnectionCache;
import net.dpml.transit.network.DelegatingAuthenticator;
@@ -66,44 +63,31 @@
import net.dpml.transit.network.TransitAuthenticator;
import net.dpml.transit.network.TransitAuthenticatorImpl;
+import net.dpml.transit.model.HostModel;
+import net.dpml.transit.model.HostListener;
+import net.dpml.transit.model.HostChangeEvent;
+import net.dpml.transit.model.HostEnabledEvent;
+import net.dpml.transit.model.HostTrustedEvent;
+import net.dpml.transit.model.HostPriorityEvent;
+import net.dpml.transit.model.HostLayoutEvent;
+import net.dpml.transit.model.Logger;
+
+import net.dpml.transit.util.Util;
+
+
/** This class represents a single host where resources are stored at.
* <p>
* <strong>NOTE:</strong> This ResourceHost does NOT currently support
* realm/domain authentication. It may be introduced in the future.
* </p>
*/
-public class ClassicResourceHost
- implements ResourceHost, HostDescriptorChangeListener
+public class ClassicResourceHost implements ResourceHost, HostListener
{
//
------------------------------------------------------------------------
- // static
- //
------------------------------------------------------------------------
-
- /**
- * HTTP port number.
- */
- private static final int HTTP_PORT = 80;
-
- /**
- * FTP port number.
- */
- private static final int FTP_PORT = 21;
-
- /**
- * HTTPS port number.
- */
- private static final int HTTPS_PORT = 443;
-
- //
------------------------------------------------------------------------
// state
//
------------------------------------------------------------------------
/**
- * Host base url.
- */
- private URL m_baseUrl;
-
- /**
* Known groups.
*/
private HashSet m_knownGroups = new HashSet();
@@ -116,259 +100,93 @@
private HashMap m_locks = new HashMap();
/**
- * Host priority.
- */
- private int m_priority;
-
- /**
- * Enabled state.
- */
- private boolean m_enabled;
-
- /**
- * Trusted state.
- */
- private boolean m_trusted;
-
- /**
* Connections.
*/
private ConnectionCache m_connections;
- private LocationResolver m_resolver;
+ private Layout m_layout;
+
+ private HostModel m_model;
//
------------------------------------------------------------------------
- // constructor (preference based)
+ // constructor
//
------------------------------------------------------------------------
/**
- * Constructor for a resource host using a supplied Perferences
instance. The
- * implementation registeres itdself as a preferences change listener
and maintains
- * the synchronization of this instance with the supplied preferences
instance.
+ * Constructor for a resource host using a supplied host configuration.
*
- * @param descriptor the host descriptor object
+ * @param model the host model
+ * @param layout the host layout strategy
* @exception UnknownHostException if the supplied base url references
an unknown host
*/
- public ClassicResourceHost( HostDescriptor descriptor )
- throws UnknownHostException, TransitException, UnknownHostException,
IOException
+ public ClassicResourceHost( HostModel model, Layout layout )
+ throws UnknownHostException, IOException
{
- descriptor.addHostDescriptorChangeListener( this );
- if( descriptor.getLastModified() > 0 )
- {
- m_enabled = descriptor.getEnabled();
- }
- else
- {
- m_enabled = false;
- }
+ m_model = model;
+ m_layout = layout;
+
+ model.addHostListener( this );
m_connections = ConnectionCache.getInstance();
- m_resolver = setupResolver( descriptor );
- m_priority = descriptor.getPriority();
- m_trusted = descriptor.getTrusted();
- m_baseUrl = setupBase( descriptor );
- String[] groups = setupGroups( descriptor );
+ String[] groups = setupGroups();
resetGroups( groups );
- setupAuthenticator( m_baseUrl, descriptor );
-
- // TODO: add a node change listener on the parent node so we can
- // destroy ourselves and release the listener if the node is dropped
-
- }
-
- private void resetGroups( String[] groups )
- {
- synchronized( m_knownGroups )
- {
- m_knownGroups.clear();
- for( int i = 0; i < groups.length; i++ )
- {
- String group = groups[i];
- m_knownGroups.add( group );
- }
- }
+ setupAuthenticator();
}
//
------------------------------------------------------------------------
- // constructor (long list of parameters based)
+ // HostListener
//
------------------------------------------------------------------------
- /** Constructor for a resource host.
- *
- * The <i>base</i> argument is the location of the root level of the
- * group hierarchy.
- *
- * @param base the host base url
- * @param knownGroups known groups within the host
- * @param priority host priority
- * @param enabled the enabled state
- * @param trusted the trusted state
- * @param username an authentication username
- * @param password the authentication password
- * @param scheme the authentication scheme
- * @param prompt the authentication prompt/realm
- * @param resolver the LocationResolver to use.
- * @exception UnknownHostException if the supplied base url references
an unknown host
- */
- public ClassicResourceHost(
- URL base, String[] knownGroups, int priority, boolean enabled,
- boolean trusted, String username, String password, String scheme,
- String prompt, LocationResolver resolver )
- throws UnknownHostException
+ /**
+ * Notify a consumer of an aggregated set of changes.
+ * @param event the host change event
+ */
+ public void hostChanged( HostChangeEvent event )
{
- if( resolver != null )
- m_resolver = resolver;
- else
- m_resolver = new ClassicResolver();
- m_connections = ConnectionCache.getInstance();
- m_baseUrl = base;
- m_priority = priority;
- m_trusted = trusted;
- m_enabled = enabled;
-
- for( int i = 0; i < knownGroups.length; i++ )
- {
- String group = knownGroups[ i ];
- m_knownGroups.add( group );
- }
-
- String protocol = base.getProtocol();
- String host = base.getHost();
- int port = base.getPort();
- if( port == 0 )
+ synchronized( this )
{
- if( protocol.equals( "http" ) )
- {
- port = HTTP_PORT;
- }
- else if( protocol.equals( "ftp" ) )
+ try
{
- port = FTP_PORT;
+ setupAuthenticator();
+ String[] groups = setupGroups();
+ resetGroups( groups );
}
- else if( protocol.equals( "https" ) )
+ catch( Exception e )
{
- port = HTTPS_PORT;
- }
- }
- RequestIdentifier id = new RequestIdentifier( host, port, protocol,
scheme, prompt );
- TransitAuthenticator ta = new TransitAuthenticatorImpl( username,
password );
- DelegatingAuthenticator da = DelegatingAuthenticator.getInstance();
- da.addTransitAuthenticator( ta, id );
- }
-
- //
------------------------------------------------------------------------
- // PreferenceChangeListener
- //
------------------------------------------------------------------------
-
- // ### This should be dumped as soon as we decide to switch over to
prefs based
- // ### management. We should be reading directory of the HostDescriptor
instead of
- // ### holding state locally.
-
- public void hostChanged( HostDescriptorChangeEvent event )
- {
- HostDescriptor descriptor = event.getDescriptor();
- if( descriptor.getLastModified() > 0 )
- {
- m_enabled = descriptor.getEnabled();
- }
- else
- {
- m_enabled = false;
- }
- if( m_trusted != descriptor.getTrusted() )
- {
- m_trusted = descriptor.getTrusted();
- }
- if( false == m_baseUrl.toExternalForm().equals(
descriptor.getBasePath() ) )
- {
- synchronized( this )
- {
- try
- {
- m_baseUrl = setupBase( descriptor );
- setupAuthenticator( m_baseUrl, descriptor );
- String[] groups = setupGroups( descriptor );
- resetGroups( groups );
- }
- catch( Exception e )
- {
- // TODO: interesting scenario ..
- // the preferences are already updated - in principal
- // we should disable or reset the host and issue a
high-level transit event
- // that can be captured by a management system, but
beyond this, we should
- // probably reach down and flag the preferences as
invalid
-
- m_enabled = false;
-
- System.out.println( "# ERROR IN HOST CHANGE" );
- e.printStackTrace();
- }
+ e.printStackTrace();
}
}
}
- private LocationResolver setupResolver( HostDescriptor descriptor )
throws TransitException
+ /**
+ * Notify a consumer of a change to the enabled state.
+ * @param event the host event
+ */
+ public void enabledStateChanged( HostEnabledEvent event )
{
- String resolverClassname = descriptor.getResolverClassname();
- return ResourceHostHelper.createResolver( resolverClassname );
}
- private URL setupBase( HostDescriptor descriptor ) throws
UnknownHostException, IOException
+ /**
+ * Notify a consumer of a change to the trusted state.
+ * @param event the host event
+ */
+ public void trustedStateChanged( HostTrustedEvent event )
{
- String baseSpec = descriptor.getBasePath();
- if( null == baseSpec )
- {
- final String error =
- "Undefined base url.";
- throw new UnknownHostException( error );
- }
- return new URL( baseSpec );
}
- private String[] setupGroups( HostDescriptor descriptor ) throws
IOException
+ /**
+ * Notify a consumer of a change to the host priority.
+ * @param event the host event
+ */
+ public void priorityChanged( HostPriorityEvent event )
{
- String indexSpec = descriptor.getIndexPath();
- if( null != indexSpec )
- {
- // TODO: fix this so that the url is resolved relative to the
base
- URL index = new URL( indexSpec );
- return ResourceHostHelper.getKnownGroups( index );
- }
- else
- {
- return new String[0];
- }
}
- private void setupAuthenticator( URL base, HostDescriptor descriptor )
+ /**
+ * Notify a consumer of a change to the assigned resolver.
+ * @param event the resolver id change event
+ */
+ public void layoutChanged( HostLayoutEvent event )
{
- String protocol = base.getProtocol();
- String host = base.getHost();
- int port = base.getPort();
- if( port == 0 )
- {
- if( protocol.equals( "http" ) )
- {
- port = HTTP_PORT;
- }
- else if( protocol.equals( "ftp" ) )
- {
- port = FTP_PORT;
- }
- else if( protocol.equals( "https" ) )
- {
- port = HTTPS_PORT;
- }
- }
-
- String username = descriptor.getUsername();
- String password = descriptor.getPassword();
- String scheme = descriptor.getScheme();
- String prompt = descriptor.getPrompt();
-
- RequestIdentifier id = new RequestIdentifier( host, port, protocol,
scheme, prompt );
- TransitAuthenticator ta = new TransitAuthenticatorImpl( username,
password );
- DelegatingAuthenticator da = DelegatingAuthenticator.getInstance();
- da.addTransitAuthenticator( ta, id );
}
//
------------------------------------------------------------------------
@@ -381,7 +199,7 @@
*/
public String getHostName()
{
- return m_baseUrl.getHost();
+ return m_model.getBaseURL().getHost();
}
/**
@@ -391,7 +209,7 @@
*/
public URL getURL()
{
- return m_baseUrl;
+ return m_model.getBaseURL();
}
/**
@@ -400,7 +218,7 @@
*/
public int getPriority()
{
- return m_priority;
+ return m_model.getPriority();
}
/** Downloads the given artifact to the directory indicated.
@@ -476,7 +294,7 @@
*/
public boolean checkPresence( Artifact artifact, boolean knownOnly )
{
- if( "file".equals( m_baseUrl.getProtocol() ) )
+ if( "file".equals( getURL().getProtocol() ) )
{
return checkAtServer( artifact );
}
@@ -497,7 +315,7 @@
*/
public boolean isEnabled()
{
- return m_enabled;
+ return m_model.getEnabled();
}
/** Returns true if the ResourceHost is considered trusted.
@@ -506,13 +324,57 @@
*/
public boolean isTrusted()
{
- return m_trusted;
+ return m_model.getTrusted();
+ }
+
+ /** Returns the layout assigned to the host.
+ *
+ * @return the layout model
+ */
+ public Layout getLayout()
+ {
+ return m_layout;
}
//
------------------------------------------------------------------------
// implementation
//
------------------------------------------------------------------------
+ private String[] setupGroups() throws IOException
+ {
+ URL index = m_model.getIndexURL();
+ if( null != index )
+ {
+ return getKnownGroups( index );
+ }
+ else
+ {
+ return new String[0];
+ }
+ }
+
+ private void resetGroups( String[] groups )
+ {
+ synchronized( m_knownGroups )
+ {
+ m_knownGroups.clear();
+ for( int i = 0; i < groups.length; i++ )
+ {
+ String group = groups[i];
+ m_knownGroups.add( group );
+ }
+ }
+ }
+
+ private void setupAuthenticator()
+ {
+ RequestIdentifier id = m_model.getRequestIdentifier();
+ PasswordAuthentication auth = m_model.getAuthentication();
+ TransitAuthenticator ta = new TransitAuthenticatorImpl( auth );
+ DelegatingAuthenticator da = DelegatingAuthenticator.getInstance();
+ da.addTransitAuthenticator( ta, id );
+ }
+
/**
* Check if the supplied artifact group is known.
* @param artifact the subject artifact to check
@@ -602,7 +464,7 @@
if( conn instanceof HttpsURLConnection )
{
log.println( this + " - HTTPS connection opened." );
- if( m_trusted )
+ if( isTrusted() )
{
log.println( this + " - Using NullTrustManager." );
HttpsURLConnection ssl = (HttpsURLConnection) conn;
@@ -650,8 +512,9 @@
private URL createRemoteUrl( Artifact artifact )
throws MalformedURLException
{
- String path = m_resolver.resolvePath( artifact );
- URL url = new URL( m_baseUrl, path );
+ String path = m_layout.resolvePath( artifact );
+ URL base = getURL();
+ URL url = new URL( base, path );
return url;
}
@@ -661,9 +524,13 @@
*/
public String toString()
{
- return "[HOST: " + m_baseUrl + "]";
+ return "[HOST: " + getURL() + "]";
}
+ //
------------------------------------------------------------------------
+ // static (utils)
+ //
------------------------------------------------------------------------
+
/**
* A null trust manager that will accept any certificate. I.e. this
* class performs NO TRUST MANAGEMENT and simply serves as a mechanism
@@ -705,4 +572,49 @@
return EMPTY_CERTS;
}
}
+
+ /**
+ * Return a set of known groups froma host.
+ * @param href the host against which the request is to be made
+ * @return the set of known group names
+ * @exception TransitException if an error occurs while attempting to
read the
+ * remote address
+ */
+ private static String[] getKnownGroups( URL href ) throws
TransitException
+ {
+ if( href != null )
+ {
+ try
+ {
+ return Util.readListFile( href );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to extract the groups from "
+ + href;
+ throw new TransitException( error, e );
+ }
+ }
+ else
+ {
+ return new String[0];
+ }
+ }
+
+ /**
+ * HTTP port number.
+ */
+ private static final int HTTP_PORT = 80;
+
+ /**
+ * FTP port number.
+ */
+ private static final int FTP_PORT = 21;
+
+ /**
+ * HTTPS port number.
+ */
+ private static final int HTTPS_PORT = 443;
+
}
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/layout/ClassicLayout.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/layout/ClassicResolver.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/layout/ClassicResolver.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/layout/ClassicLayout.java
Mon May 30 09:59:27 2005
@@ -21,7 +21,7 @@
import net.dpml.transit.artifact.Artifact;
-/** The ClassicResolver decodes artifacts into the Classic/Maven layout
+/** The ClassicLayout decodes artifacts into the Classic/Maven layout
* of artifacts on a file system or http server.
* This format says that for an artifact
<code>artifact:[type]:[group]/[name]#[version]</code>
* the location of such artifact would be;
@@ -29,8 +29,8 @@
* Example; <code>artifact:jar:metro/cache/dpml-cache-main#1.0.0</code>
* would return the path
<code>metro/cache/jars/dpml-cache-main-1.0.0.jar</code>.
*/
-public class ClassicResolver
- implements LocationResolver
+public class ClassicLayout
+ implements Layout
{
/**
* Return the base path for an artifact. The base path is derived from
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/layout/DefaultLayoutRegistry.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/layout/DefaultLayoutRegistry.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,196 @@
+/*
+ * 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.layout;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.net.ContentHandler;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.prefs.Preferences;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.BackingStoreException;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitException;
+import net.dpml.transit.repository.Repository;
+import net.dpml.transit.model.LayoutRegistryModel;
+import net.dpml.transit.model.LayoutRegistryListener;
+import net.dpml.transit.model.LayoutRegistryEvent;
+import net.dpml.transit.model.LayoutModel;
+import net.dpml.transit.model.Logger;
+
+/**
+ * A registry of descriptions of plugable content handlers. This
implementation
+ * maps user defined preferences to instance of ContentHandlerDescriptor.
+ */
+public class DefaultLayoutRegistry implements LayoutRegistry,
LayoutRegistryListener
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private final Logger m_logger;
+
+ private final Map m_plugins = new WeakHashMap();
+
+ private final LayoutRegistryModel m_model;
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ /**
+ * Provides support for the resolution of location resolver instances.
+ */
+ public DefaultLayoutRegistry( LayoutRegistryModel model )
+ {
+ m_model = model;
+ m_logger = model.getLogger();
+ model.addLayoutRegistryListener( this );
+ }
+
+ //
------------------------------------------------------------------------
+ // LayoutRegistry
+ //
------------------------------------------------------------------------
+
+ public Layout getLayout( final String id ) throws IOException
+ {
+ LayoutModel model = m_model.getLayoutModel( id );
+ return getLayout( model );
+ }
+
+ /**
+ * Locate and return a location resolver.
+ * @param model the location resolver model
+ * @return the resolver
+ */
+ protected Layout getLayout( LayoutModel model ) throws IOException
+ {
+ String id = model.getID();
+ String classname = model.getClassname();
+ if( null != classname )
+ {
+ return loadLayout( classname );
+ }
+ else
+ {
+ return loadLayout( model );
+ }
+ }
+
+ protected Layout loadLayout( final String classname ) throws IOException
+ {
+ if( ClassicLayout.class.getName().equals( classname ) )
+ {
+ return CLASSIC_RESOLVER;
+ }
+ else if( EclipseLayout.class.getName().equals( classname ) )
+ {
+ return ECLIPSE_RESOLVER;
+ }
+ else
+ {
+ final String error =
+ "Bootstrap location resolver classname not recognized."
+ + "\nClassname: " + classname;
+ throw new TransitException( error );
+ }
+ }
+
+ protected Layout loadLayout( LayoutModel model ) throws IOException
+ {
+ Class clazz = loadLayoutClass( model );
+ Repository loader = Transit.getInstance().getRepository();
+ return (Layout) loader.instantiate( clazz, new Object[]{ model } );
+ }
+
+ protected Class loadLayoutClass( LayoutModel model ) throws IOException
+ {
+ URI uri = model.getPluginURI();
+ Class clazz = (Class) m_plugins.get( uri );
+ if( null != clazz )
+ {
+ return clazz;
+ }
+ else
+ {
+ try
+ {
+ m_logger.debug( "loading resolver plugin: " + uri );
+ Repository loader = Transit.getInstance().getRepository();
+ ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
+ clazz = loader.getPluginClass( classloader, uri );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to load a content handler plugin due to an
unexpected exception.";
+ throw new TransitException( error, e );
+ }
+
+ if( Layout.class.isAssignableFrom( clazz ) )
+ {
+ m_plugins.put( uri, clazz );
+ return clazz;
+ }
+ else
+ {
+ final String error =
+ "Plugin is not assignable to a
net.dpml.transit.location.Layout."
+ + "\nPlugin URI: " + uri
+ + "\nPlugin Class: " + clazz.getName();
+ throw new TransitException( error );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // LayoutRegistryListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify all listeners of the addition of a content model.
+ * @param event the registry event
+ */
+ public void layoutAdded( LayoutRegistryEvent event )
+ {
+ // TODO: cache the plugin class
+ }
+
+ /**
+ * Notify all listeners of the removal of a content model.
+ * @param event the registry event
+ */
+ public void layoutRemoved( LayoutRegistryEvent event )
+ {
+ }
+
+ //
------------------------------------------------------------------------
+ // static
+ //
------------------------------------------------------------------------
+
+ private static final Layout CLASSIC_RESOLVER = new ClassicLayout();
+ private static final Layout ECLIPSE_RESOLVER = new EclipseLayout();
+}
+
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/layout/EclipseLayout.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/layout/EclipseResolver.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/layout/EclipseResolver.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/layout/EclipseLayout.java
Mon May 30 09:59:27 2005
@@ -21,7 +21,7 @@
import net.dpml.transit.artifact.Artifact;
-/** The EclipseResolver decodes artifacts into the Eclipse specified layout
+/** The EclipseLayout decodes artifacts into the Eclipse specified layout
* of artifacts on a file system or http server.
* This format says that for an artifact
<code>artifact:[type]:[group]/[name]#[version]</code>
* the location of such artifact would be;
@@ -29,8 +29,8 @@
* Example;
<code>artifact:jar:eclipse/plugins/eclipse-osgi-runtime/core#3.1.0</code>
* would return the path
<code>eclipse/plugins/eclipse-osgi-runtime-3.1.0/core.jar</code>.
*/
-public class EclipseResolver
- implements LocationResolver
+public class EclipseLayout
+ implements Layout
{
/**
* Return the base path for an artifact. The base path is derived from
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/layout/Layout.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/layout/LocationResolver.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/layout/LocationResolver.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/layout/Layout.java
Mon May 30 09:59:27 2005
@@ -23,7 +23,7 @@
/** The LocationResolver abstracts the decoding process of the location
* of artifacts in various filesystems.
*/
-public interface LocationResolver
+public interface Layout
{
/**
* Return the base path for an artifact. The base path is the location
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/layout/LayoutRegistry.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/layout/LayoutRegistry.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,39 @@
+/*
+ * 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.layout;
+
+import java.io.IOException;
+
+/**
+ * A interface supporting access to pluggable content handlers.
+ */
+public interface LayoutRegistry
+{
+ public static final String LAYOUT_HANDLER_PLUGIN_KEY =
"dpml.transit.layout.plugin";
+
+ /**
+ * Return a location resolver capable for supporting the supplied id. If
+ * a handler is available the handler is returned otherwise the returned
+ * value is null.
+ *
+ * @param id the layout identifier
+ * @return the location resolver or null if not available
+ */
+ Layout getLayout( final String id ) throws IOException;
+}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
Mon May 30 09:59:27 2005
@@ -37,6 +37,8 @@
*/
public class LinkURLConnection extends URLConnection
{
+ private LinkManager m_linkManager;
+
private boolean m_connected;
private URL m_targetURL;
@@ -64,8 +66,9 @@
if( m_connected )
return;
m_connected = true;
- final SecuredTransitContext securedTransitContext =
SecuredTransitContext.create();
- final LinkManager linkManager =
securedTransitContext.getLinkManager();
+
+ m_linkManager = SecuredTransitContext.getInstance().getLinkManager();
+
try
{
AccessController.doPrivileged( new PrivilegedExceptionAction()
@@ -75,7 +78,7 @@
throws IOException
{
URI linkUri = URI.create( url.toExternalForm() );
- URI targetUri = linkManager.getTargetURI( linkUri );
+ URI targetUri = m_linkManager.getTargetURI( linkUri );
if( targetUri != null )
m_targetURL = new URL( targetUri.toString() );
else
@@ -159,7 +162,6 @@
Object result = AccessController.doPrivileged( new PrivilegedAction()
{
-
public Object run()
{
for( int i=0; i < classes.length; i++ )
@@ -167,10 +169,9 @@
Class c = classes[i];
if( c.equals( Link.class ) )
{
- LinkManager linkManager =
SecuredTransitContext.getInstance().getLinkManager();
String extUri = getURL().toString();
URI uri = URI.create( extUri );
- Link link = new Link( uri, linkManager );
+ Link link = new Link( uri, m_linkManager );
return link;
}
if( c.equals( URI.class ) )
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
Mon May 30 09:59:27 2005
@@ -25,8 +25,6 @@
import java.util.Iterator;
import java.util.EventObject;
import java.util.EventListener;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.util.prefs.Preferences;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
@@ -46,6 +44,7 @@
import net.dpml.transit.model.FileChangeEvent;
import net.dpml.transit.model.HostNodeEvent;
import net.dpml.transit.model.ModelException;
+import net.dpml.transit.model.Logger;
import net.dpml.transit.util.PropertyResolver;
@@ -63,17 +62,21 @@
// state
//
------------------------------------------------------------------------
+ private final LayoutRegistryManager m_layout;
private final List m_list = new LinkedList();
+
private File m_cache;
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
- public CacheManager( Logger logger, Preferences prefs ) throws
ModelException
+ public CacheManager( Logger logger, Preferences prefs,
LayoutRegistryManager layout ) throws ModelException
{
super( logger, prefs );
+ m_layout = layout;
+
//
// setup the cache
//
@@ -121,11 +124,18 @@
public void addHostModel( String id )
{
- getPreferences().node( id );
+ if( null != id )
+ {
+ getPreferences().node( id );
+ }
}
public HostManager getHostManager( String id )
{
+ if( null == id )
+ {
+ return null;
+ }
HostManager[] managers = getHostManagers();
for( int i=0; i<managers.length; i++ )
{
@@ -140,6 +150,10 @@
public void removeHostModel( String id ) throws ModelException
{
+ if( null == id )
+ {
+ return;
+ }
try
{
if( getPreferences().nodeExists( id ) )
@@ -176,26 +190,7 @@
cache = new File( anchor, file.toString() );
cache.mkdirs();
}
- if( null == m_cache )
- {
- final String message =
- "Setting cache directory."
- + "\nDirectory: " + cache;
- getLogger().fine( message );
- m_cache = cache;
- }
- else
- {
- if( false == m_cache.equals( cache ) )
- {
- final String message =
- "Changing cache directory."
- + "\nOld: " + m_cache
- + "\nNew: " + cache;
- getLogger().fine( message );
- m_cache = cache;
- }
- }
+ m_cache = cache;
}
/**
@@ -317,7 +312,7 @@
"Unable to add host due to an unresolved host url."
+ "\nPreferences Node: " + event.getChild()
+ "\nHost path: " + event.getChild().get( "base", null );
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
@@ -334,7 +329,7 @@
private void addHostModel( Preferences prefs, boolean notify ) throws
UnknownHostException, IOException
{
Logger logger = getLogger();
- HostModel model = new HostManager( logger, prefs ); // TODO: move to
plugin based creation
+ HostModel model = new HostManager( logger, prefs, m_layout );
String id = model.getID();
int priority = model.getPriority();
synchronized( m_list )
@@ -433,7 +428,7 @@
{
final String error =
"CacheListener host addition notification error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
else if( event instanceof HostRemovedEvent )
@@ -446,7 +441,7 @@
{
final String error =
"CacheListener host removed notification error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
}
@@ -470,7 +465,7 @@
{
final String error =
"CacheListener host addition notification error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
}
@@ -484,7 +479,7 @@
private File resolveCacheDirectory( Preferences prefs )
{
String path = prefs.get( "location", "cache" );
- String location = System.getProperty( CACHE_KEY, path );
+ String location = System.getProperty(
TransitPreferences.CACHE_LOCATION_KEY, path );
String cache = PropertyResolver.resolve( System.getProperties(),
location );
return new File( cache );
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ContentManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ContentManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ContentManager.java
Mon May 30 09:59:27 2005
@@ -20,8 +20,6 @@
import java.util.EventObject;
import java.util.EventListener;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.util.prefs.Preferences;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
@@ -31,6 +29,7 @@
import net.dpml.transit.model.PluginChangeEvent;
import net.dpml.transit.model.ContentEvent;
import net.dpml.transit.model.ContentListener;
+import net.dpml.transit.model.Logger;
/**
* Default implementation of a content manager that maintains an active
@@ -126,7 +125,7 @@
"A content handler plugin preference node change event
references an unrecognized key."
+ "\nPreference Node: " + prefs
+ "\nKey: " + key;
- getLogger().log( Level.SEVERE, warning );
+ getLogger().warn( warning );
}
}
@@ -177,7 +176,7 @@
{
final String error =
"ContentListener title change notification error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CredentialsHelper.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CredentialsHelper.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CredentialsHelper.java
Mon May 30 09:59:27 2005
@@ -29,7 +29,7 @@
import java.io.OutputStream;
import java.io.Serializable;
-import net.dpml.io.CascadingIOException;
+import net.dpml.transit.TransitException;
/**
@@ -67,8 +67,8 @@
catch( Throwable e )
{
final String error =
- "Unexpected error while attempting to load object input
stream.";
- throw new CascadingIOException( error, e );
+ "Unexpected error while attempting to load credentials input
stream.";
+ throw new TransitException( error, e );
}
}
@@ -92,7 +92,7 @@
"Unexpected error while attempting to write object to a byte
array."
+ "\nclass: " + object.getClass().getName()
+ "\nreason: " + e.toString();
- throw new CascadingIOException( error, e );
+ throw new TransitException( error, e );
}
finally
{
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/EventProducer.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/event/EventProducer.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/event/EventProducer.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/EventProducer.java
Mon May 30 09:59:27 2005
@@ -16,12 +16,14 @@
* limitations under the License.
*/
-package net.dpml.transit.event;
+package net.dpml.transit.manager;
import java.util.EventObject;
import java.util.EventListener;
import java.util.List;
import java.util.LinkedList;
+import java.util.Map;
+import java.util.WeakHashMap;
import net.dpml.transit.util.ExceptionHelper;
@@ -32,10 +34,7 @@
*/
public abstract class EventProducer
{
- /**
- * Registered event listeners.
- */
- private EventListener[] m_listeners = new EventListener[0];
+ private Map m_listeners = new WeakHashMap();
/**
* Internal synchronization lock.
@@ -62,13 +61,9 @@
{
throw new NullPointerException( "listener" );
}
-
synchronized( m_lock )
{
- Object[] old = m_listeners;
- m_listeners = new EventListener[ old.length + 1 ];
- System.arraycopy( old, 0, m_listeners, 0, old.length );
- m_listeners[old.length] = listener;
+ m_listeners.put( listener, null );
}
startEventDispatchThread();
}
@@ -84,32 +79,9 @@
throw new NullPointerException( "listener" );
}
- synchronized( m_lock )
+ synchronized( m_lock )
{
- if( m_listeners.length == 0 )
- {
- throw new IllegalArgumentException( "Listener not
registered." );
- }
- // create the copy
- EventListener[] replacement = new EventListener[
m_listeners.length - 1 ];
- // copy listeners from 0 up to the listener being removed
- int i=0;
- while( i < replacement.length && m_listeners[i] != listener )
- {
- replacement[i] = m_listeners[i++];
- }
- // check that the listener has been located
- if( i == replacement.length && m_listeners[i] != listener )
- {
- throw new IllegalArgumentException( "Listener not
registered." );
- }
- // complete the copy operation
- while( i < replacement.length )
- {
- replacement[i] = m_listeners[++i];
- }
- // commit the copy
- m_listeners = replacement;
+ m_listeners.remove( listener );
}
}
@@ -175,7 +147,7 @@
final String error =
"Unexpected error while processing event."
+ "\nEvent: " + event
- + "\nSource: " + source;
+ + "\nSource: " + this;
String msg = ExceptionHelper.packException( error,
e, true );
System.err.println( msg );
}
@@ -215,9 +187,9 @@
*/
protected EventListener[] listeners()
{
- synchronized( m_lock )
+ synchronized( m_lock )
{
- return m_listeners;
+ return (EventListener[])m_listeners.keySet().toArray( new
EventListener[0] );
}
}
@@ -228,12 +200,29 @@
*/
protected void enqueueEvent( EventObject event )
{
- if( m_listeners.length != 0 )
+ enqueueEvent( event, true );
+ }
+
+ /**
+ * Enqueue an event for delivery to registered
+ * listeners unless there are no registered
+ * listeners.
+ */
+ protected void enqueueEvent( EventObject event, boolean asynchronouse )
+ {
+ if( m_listeners.size() != 0 )
{
- synchronized( EVENT_QUEUE )
+ if( asynchronouse )
+ {
+ synchronized( EVENT_QUEUE )
+ {
+ EVENT_QUEUE.add( event );
+ EVENT_QUEUE.notify();
+ }
+ }
+ else
{
- EVENT_QUEUE.add( event );
- EVENT_QUEUE.notify();
+ processEvent( event );
}
}
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/HostManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/HostManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/HostManager.java
Mon May 30 09:59:27 2005
@@ -23,8 +23,6 @@
import java.util.ArrayList;
import java.util.EventObject;
import java.util.EventListener;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
@@ -32,18 +30,22 @@
import java.util.prefs.Preferences;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
-import java.util.logging.Logger;
+import net.dpml.transit.model.HostEnabledEvent;
import net.dpml.transit.model.HostModel;
-import net.dpml.transit.model.PluginModel;
-import net.dpml.transit.model.PluginChangeEvent;
import net.dpml.transit.model.HostEvent;
import net.dpml.transit.model.HostChangeEvent;
+import net.dpml.transit.model.HostLayoutEvent;
import net.dpml.transit.model.HostListener;
-import net.dpml.transit.model.EnabledEvent;
-import net.dpml.transit.model.TrustedEvent;
-import net.dpml.transit.model.PriorityEvent;
-import net.dpml.transit.model.NameChangeEvent;
+import net.dpml.transit.model.LayoutModel;
+import net.dpml.transit.model.LayoutRegistryModel;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.HostNameEvent;
+import net.dpml.transit.model.ModelException;
+import net.dpml.transit.model.HostPriorityEvent;
+import net.dpml.transit.model.PluginModel;
+import net.dpml.transit.model.PluginChangeEvent;
+import net.dpml.transit.model.HostTrustedEvent;
import net.dpml.transit.network.RequestIdentifier;
@@ -61,30 +63,39 @@
public class HostManager extends PluginManager implements HostModel
{
private final String m_id;
+ private final LayoutRegistryModel m_layoutRegistry;
private String m_name;
private URL m_base;
private URL m_index;
private boolean m_enabled = true;
private boolean m_trusted = false;
- private URI m_resolver;
+ private LayoutModel m_layout;
private boolean m_available = false;
private int m_priority = 100;
private RequestIdentifier m_identifier;
private PasswordAuthentication m_authentication;
+ private boolean m_bootstrap = false;
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
- public HostManager( Logger logger, Preferences prefs ) throws
UnknownHostException, IOException
+ public HostManager( Logger logger, Preferences prefs,
LayoutRegistryModel registry )
+ throws UnknownHostException, IOException
{
super( logger, prefs );
+ m_layoutRegistry = registry;
+
+ m_bootstrap = prefs.getBoolean( "bootstrap", false );
m_id = prefs.name();
m_name = prefs.get( "name", m_id );
m_trusted = prefs.getBoolean( "trusted", m_trusted );
m_enabled = prefs.getBoolean( "enabled", m_enabled );
m_priority = prefs.getInt( "priority", m_priority );
+ String layout = prefs.get( "layout", "classic" );
+ m_layout = registry.getLayoutModel( layout );
+
m_base = resolveBase( prefs );
if( m_base != null )
{
@@ -124,6 +135,36 @@
prefs.putBoolean( "enabled", flag );
}
+ public void setLayoutModel( LayoutModel layout )
+ {
+ if( null == layout )
+ {
+ throw new NullPointerException( "layout" );
+ }
+ String id = layout.getID();
+ Preferences prefs = getPreferences();
+ prefs.put( "layout", id );
+ }
+
+ /**
+ * Set the host authentication.
+ * @param auth the password authentication to use for host sign-on
+ */
+ public void setAuthentication( PasswordAuthentication auth ) throws
IOException
+ {
+ m_authentication = auth;
+ Preferences prefs = getPreferences();
+ if( null == auth )
+ {
+ prefs.putByteArray( "authentication", new byte[0] );
+ }
+ else
+ {
+ byte[] bytes = CredentialsHelper.exportCredentials(
m_authentication );
+ prefs.putByteArray( "authentication", bytes );
+ }
+ }
+
//----------------------------------------------------------------------
// HostModel
//----------------------------------------------------------------------
@@ -138,6 +179,16 @@
}
/**
+ * Return TRUE if this is a bootstrap host. Bootstrap hosts shall be
+ * provided such that they independent of the Transit respository
+ * service.
+ */
+ public boolean isBootstrap()
+ {
+ return m_bootstrap;
+ }
+
+ /**
* Return the host priority.
* @return the host priority setting
*/
@@ -244,16 +295,16 @@
return m_identifier;
}
}
-
+
/**
- * Return the location resolver plugin uri.
- * @return the uri of the location resolver plugin
+ * Return the layout strategy model.
+ * @return the layout model
*/
- public URI getLocationResolverPluginURI()
+ public LayoutModel getLayoutModel()
{
synchronized( this )
{
- return m_resolver;
+ return m_layout;
}
}
@@ -288,7 +339,7 @@
if( m_enabled != flag )
{
m_enabled = flag;
- EnabledEvent e = new EnabledEvent( this, m_enabled );
+ HostEnabledEvent e = new HostEnabledEvent( this, m_enabled );
enqueueEvent( e );
}
}
@@ -298,7 +349,7 @@
if( m_trusted != flag )
{
m_trusted = flag;
- TrustedEvent e = new TrustedEvent( this, m_trusted );
+ HostTrustedEvent e = new HostTrustedEvent( this, m_trusted );
enqueueEvent( e );
}
}
@@ -308,7 +359,7 @@
if( m_priority != priority )
{
m_priority = priority;
- PriorityEvent e = new PriorityEvent( this, m_priority );
+ HostPriorityEvent e = new HostPriorityEvent( this,
m_priority );
enqueueEvent( e );
}
}
@@ -318,10 +369,28 @@
if( m_name != name )
{
m_name = name;
- NameChangeEvent e = new NameChangeEvent( this, m_name );
+ HostNameEvent e = new HostNameEvent( this, m_name );
enqueueEvent( e );
}
}
+ else if( "layout".equals( key ) )
+ {
+ String id = event.getNewValue();
+ try
+ {
+ setLayoutModel( id );
+ }
+ catch( ModelException e )
+ {
+ final String error =
+ "Host layout not set due to an unexpected error.";
+ getLogger().error( error, e );
+ return;
+ }
+ LayoutModel layout = getLayoutModel();
+ HostLayoutEvent e = new HostLayoutEvent( this, layout );
+ enqueueEvent( e );
+ }
else if( "modified".equals( key ) )
{
// this is a trigger marking modification to any of the
@@ -354,14 +423,14 @@
"Unable to propergate change event due to an
unresolved host."
+ "\nPreferences Node: " + prefs
+ "\nHost path: " + prefs.get( "base", null );
- getLogger().log( Level.SEVERE, error, uhe );
+ getLogger().error( error, uhe );
}
catch( IOException ioe )
{
final String error =
"Unable to propergate change event due to an
unexpected IO error."
+ "\nPreferences Node: " + prefs;
- getLogger().log( Level.SEVERE, error, ioe );
+ getLogger().error( error, ioe );
}
}
}
@@ -371,6 +440,45 @@
// internal
//----------------------------------------------------------------------
+ public void setLayoutModel( String id ) throws ModelException
+ {
+ if( ( null != m_layout ) && m_layout.getID().equals( id ) )
+ {
+ return;
+ }
+ else
+ {
+ LayoutModel layout = m_layoutRegistry.getLayoutModel( id );
+ if( null == layout )
+ {
+ final String error =
+ "Unknown layout identifier: " + id
+ + "\nHost ID: " + getID();
+ throw new ModelException( error );
+ }
+
+ //
+ // if this is a bootstrap host then resolver ids must map to
+ // a resolver model that is based on a classname as opposed to
+ // plugin (because bootstrap hosts are repository indepedent)
+ //
+
+ if( isBootstrap() )
+ {
+ if( null != layout.getPluginURI() )
+ {
+ final String error =
+ "Illegal attempt to assign a plugin based layout to a
bootstrap host."
+ + "\nHost ID: " + getID()
+ + "\nLayout ID: " + id;
+ throw new ModelException( error );
+ }
+ }
+
+ m_layout = layout;
+ }
+ }
+
private RequestIdentifier resolveRequestIdentifier( URL base,
Preferences prefs )
{
String scheme = prefs.get( "scheme", "" );
@@ -410,6 +518,17 @@
{
return null;
}
+
+ //
+ // make sure the base path ends with a "/" otherwise relative url
references
+ // will not be correct
+ //
+
+ if( false == baseSpec.endsWith( "/" ) )
+ {
+ baseSpec = baseSpec + "/";
+ }
+
return new URL( baseSpec );
}
@@ -440,17 +559,21 @@
{
processHostChangeEvent( (HostChangeEvent) event );
}
- else if( event instanceof EnabledEvent )
+ else if( event instanceof HostLayoutEvent )
+ {
+ processHostLayoutEvent( (HostLayoutEvent) event );
+ }
+ else if( event instanceof HostEnabledEvent )
{
- processEnabledEvent( (EnabledEvent) event );
+ processHostEnabledEvent( (HostEnabledEvent) event );
}
- else if( event instanceof TrustedEvent )
+ else if( event instanceof HostTrustedEvent )
{
- processTrustedEvent( (TrustedEvent) event );
+ processHostTrustedEvent( (HostTrustedEvent) event );
}
- else if( event instanceof PriorityEvent )
+ else if( event instanceof HostPriorityEvent )
{
- processPriorityEvent( (PriorityEvent) event );
+ processHostPriorityEvent( (HostPriorityEvent) event );
}
else
{
@@ -461,7 +584,7 @@
}
}
- private void processEnabledEvent( EnabledEvent event )
+ private void processHostEnabledEvent( HostEnabledEvent event )
{
HostListener[] listeners = getHostListeners();
for( int i=0; i<listeners.length; i++ )
@@ -475,12 +598,12 @@
{
final String error =
"HostListener enabled status change notification error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
}
- private void processTrustedEvent( TrustedEvent event )
+ private void processHostTrustedEvent( HostTrustedEvent event )
{
HostListener[] listeners = getHostListeners();
for( int i=0; i<listeners.length; i++ )
@@ -494,12 +617,31 @@
{
final String error =
"HostListener trusted status change notification error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
+ }
+ }
+ }
+
+ private void processHostLayoutEvent( HostLayoutEvent event )
+ {
+ HostListener[] listeners = getHostListeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ HostListener listener = listeners[i];
+ try
+ {
+ listener.layoutChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "HostListener resolver change notification error.";
+ getLogger().error( error, e );
}
}
}
- private void processPriorityEvent( PriorityEvent event )
+ private void processHostPriorityEvent( HostPriorityEvent event )
{
HostListener[] listeners = getHostListeners();
for( int i=0; i<listeners.length; i++ )
@@ -513,7 +655,7 @@
{
final String error =
"HostListener priority change notification error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
}
@@ -532,7 +674,7 @@
{
final String error =
"HostListener change notification error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
}
@@ -557,17 +699,17 @@
// static (utils)
//
------------------------------------------------------------------------
- static class HostEnabledEvent extends HostEvent
+ static class HostHostEnabledEvent extends HostEvent
{
private boolean m_enabled;
/**
- * Creation of a new HostEnabledEvent.
+ * Creation of a new HostHostEnabledEvent.
*
* @param source the object initiating the event
* @param plugin the plugin uri
*/
- public HostEnabledEvent( HostModel source, boolean enabled )
+ public HostHostEnabledEvent( HostModel source, boolean enabled )
{
super( source );
m_enabled = enabled;
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/LayoutManager.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/LayoutManager.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,225 @@
+/*
+ * 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.transit.manager;
+
+import java.util.EventObject;
+import java.util.EventListener;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+
+import net.dpml.transit.model.LayoutModel;
+import net.dpml.transit.model.PluginModel;
+import net.dpml.transit.model.PluginChangeEvent;
+import net.dpml.transit.model.LayoutEvent;
+import net.dpml.transit.model.LayoutListener;
+import net.dpml.transit.model.Logger;
+
+/**
+ * Default implementation of a content manager that maintains an active
+ * configuration model of a pluggable content handler.
+ *
+ * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
+ * @version $Id: HostManager.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
+ */
+public class LayoutManager extends PluginManager implements LayoutModel
+{
+ //----------------------------------------------------------------------
+ // state
+ //----------------------------------------------------------------------
+
+ private final String m_id;
+ private String m_title;
+ private String m_classname;
+
+ //----------------------------------------------------------------------
+ // constructor
+ //----------------------------------------------------------------------
+
+ public LayoutManager( Logger logger, Preferences prefs )
+ {
+ super( logger, prefs );
+ m_id = prefs.name();
+ m_title = prefs.get( "title", m_id );
+ m_classname = prefs.get( "classname", null );
+ }
+
+ //----------------------------------------------------------------------
+ // LayoutModel
+ //----------------------------------------------------------------------
+
+ /**
+ * Return the immutable resolver identifier.
+ * @return the resolver identifier
+ */
+ public String getID()
+ {
+ return m_id;
+ }
+
+ /**
+ * Return a possibly null classname. If the classname is not null the
+ * manager represents a bootstrap resolver.
+ *
+ * @return the resolver classname
+ */
+ public String getClassname()
+ {
+ return m_classname;
+ }
+
+ /**
+ * Returns the human readable name of the resolver.
+ * @return the resolver human readable name
+ */
+ public String getTitle()
+ {
+ return m_title;
+ }
+
+ /**
+ * Add a resolver listener to the model.
+ * @param listener the listener to add
+ */
+ public void addLayoutListener( LayoutListener listener )
+ {
+ super.addListener( listener );
+ }
+
+ /**
+ * Remove a content listener from the director.
+ * @param listener the listener to remove
+ */
+ public void removeLayoutListener( LayoutListener listener )
+ {
+ super.removeListener( listener );
+ }
+
+ //
------------------------------------------------------------------------
+ // PreferencesChangeListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Listen to changes in the preferences object that defines this
descriptor
+ * and reflect the changes in the state of the descriptor class.
+ *
+ * @param event the preference change event
+ */
+ public void preferenceChange( PreferenceChangeEvent event )
+ {
+ if( null == m_classname )
+ {
+ super.preferenceChange( event );
+ }
+
+ String key = event.getKey();
+ String value = event.getNewValue();
+ Preferences prefs = event.getNode();
+ if( "title".equals( key ) )
+ {
+ setTitle( value );
+ }
+ else if( "classname".equals( key ) )
+ {
+ setClassname( value );
+ }
+ else if( "uri".equals( key ) )
+ {
+ // already handled
+ }
+ else
+ {
+ final String warning =
+ "A layout plugin preference node change event contains an
unrecognized key."
+ + "\nPreference Node: " + prefs
+ + "\nKey: " + key;
+ getLogger().warn( warning );
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // Object
+ //
------------------------------------------------------------------------
+
+ public String toString()
+ {
+ return " " + getTitle();
+ }
+
+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ private void setTitle( String title )
+ {
+ m_title = title;
+ LayoutEvent event = new LayoutEvent( this );
+ super.enqueueEvent( event );
+ }
+
+ private void setClassname( String classname )
+ {
+ m_classname = classname;
+ LayoutEvent event = new LayoutEvent( this );
+ super.enqueueEvent( event );
+ }
+
+ public void processEvent( EventObject event )
+ {
+ if( event instanceof PluginChangeEvent )
+ {
+ super.processPluginChangeEvent( (PluginChangeEvent) event );
+ }
+ else if( event instanceof LayoutEvent )
+ {
+ processLayoutEvent( (LayoutEvent) event );
+ }
+ else
+ {
+ final String error =
+ "Event type not regognized."
+ + "\nEvent Class: " + event.getClass();
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ public void processLayoutEvent( LayoutEvent event )
+ {
+ EventListener[] listeners = super.listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener eventListener = listeners[i];
+ if( eventListener instanceof LayoutListener )
+ {
+ LayoutListener listener = (LayoutListener ) eventListener;
+ try
+ {
+ listener.titleChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "LayoutListener title change notification error.";
+ getLogger().error( error, e );
+ }
+ }
+ }
+ }
+}
+
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/LayoutRegistryManager.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/LayoutRegistryManager.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,463 @@
+/*
+ * 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.transit.manager;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
+import java.util.EventObject;
+import java.util.EventListener;
+import java.util.prefs.Preferences;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.BackingStoreException;
+import java.net.URI;
+
+import net.dpml.transit.model.LayoutRegistryModel;
+import net.dpml.transit.model.LayoutModel;
+import net.dpml.transit.model.PluginChangeEvent;
+import net.dpml.transit.model.LayoutRegistryListener;
+import net.dpml.transit.model.LayoutRegistryEvent;
+import net.dpml.transit.model.PluginListener;
+import net.dpml.transit.model.ModelException;
+import net.dpml.transit.model.Logger;
+
+/**
+ * Default implementation of a layout subsystem that maitains
+ * information about the set of registred location resolver configurations.
+ *
+ * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
+ * @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
+ */
+public class LayoutRegistryManager extends PluginManager
+ implements LayoutRegistryModel, NodeChangeListener, PluginListener
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private final List m_list = new LinkedList();
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ public LayoutRegistryManager( Logger logger, Preferences prefs ) throws
ModelException
+ {
+ super( logger, prefs );
+
+ //
+ // construct the location resolver configurations
+ //
+
+ try
+ {
+ String[] names = prefs.childrenNames();
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ Preferences p = prefs.node( name );
+ addLayoutModel( p, false );
+ }
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected exception while reading resolver preferences."
+ + "\nPreferences: " + prefs;
+ throw new ModelException( error, e );
+ }
+
+ //
+ // add a listener to the preferences
+ //
+
+ prefs.addNodeChangeListener( this );
+ }
+
+ //
------------------------------------------------------------------------
+ // LayoutRegistryManager
+ //
------------------------------------------------------------------------
+
+ /**
+ * Return an array of content managers currently assigned to the registry.
+ * @return the content manager array
+ */
+ public LayoutManager[] getLayoutManagers()
+ {
+ return (LayoutManager[]) m_list.toArray( new LayoutManager[0] );
+ }
+
+ public LayoutManager getLayoutManager( String id )
+ {
+ if( null == id )
+ {
+ return null;
+ }
+ LayoutManager[] managers = getLayoutManagers();
+ for( int i=0; i<managers.length; i++ )
+ {
+ LayoutManager manager = managers[i];
+ if( id.equals( manager.getID() ) )
+ {
+ return manager;
+ }
+ }
+ return null;
+ }
+
+ public void removeLayoutModel( String id ) throws ModelException
+ {
+ if( null == id )
+ {
+ return;
+ }
+ try
+ {
+ if( getPreferences().nodeExists( id ) )
+ {
+ LayoutManager manager = getLayoutManager( id );
+ Object[] listeners = manager.listeners();
+ ArrayList consumers = new ArrayList();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ Object listener = listeners[i];
+ if( listener != this )
+ {
+ System.out.println( "# listener: " +
listener.getClass().getName() );
+ consumers.add( listener );
+ }
+ }
+ int n = consumers.size();
+ if( n == 0 )
+ {
+ Preferences prefs = getPreferences().node( id );
+ removeLayoutModel( prefs );
+ }
+ else
+ {
+ // we have a consumer one ormore consumer references
+
+ final String message =
+ "Cannot remove a layout due to "
+ + n
+ + " active consumers.";
+ StringBuffer buffer = new StringBuffer( message );
+ Object[] objects = consumers.toArray();
+ for( int i=0; i<objects.length; i++ )
+ {
+ buffer.append( "\nReference: " + objects[i] );
+ }
+ String error = buffer.toString();
+ throw new ModelException( error );
+ }
+ }
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "Preferences backing store access error during resolver model
removal."
+ + "\nPreferences: " + getPreferences()
+ + "\nResolver ID: " + id;
+ throw new ModelException( error );
+ }
+ }
+
+ /**
+ * Dispose of the manager.
+ */
+ public void dispose()
+ {
+ super.dispose();
+ try
+ {
+ getPreferences().removeNodeChangeListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ LayoutModel[] models = getLayoutModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ LayoutModel model = models[i];
+ try
+ {
+ model.removePluginListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ }
+ }
+
+ public void newLayoutModel( String id )
+ {
+ getPreferences().node( id );
+ }
+
+
+ //
------------------------------------------------------------------------
+ // LayoutRegistryManager
+ //
------------------------------------------------------------------------
+
+ /**
+ * Register a new content model.
+ *
+ * @return the content model
+ */
+ public LayoutModel addLayoutModel( String id, String title, URI uri )
+ {
+ if( null == id )
+ {
+ throw new NullPointerException( "id" );
+ }
+ if( null == title )
+ {
+ throw new NullPointerException( "title" );
+ }
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+
+ Preferences prefs = getPreferences().node( id );
+ prefs.put( "title", title );
+ prefs.put( "uri", uri.toString() );
+ return addLayoutModel( prefs, true );
+ }
+
+ public LayoutModel getLayoutModel( String id )
+ {
+ if( null == id )
+ {
+ return null;
+ }
+ LayoutModel[] models = getLayoutModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ LayoutModel model = models[i];
+ if( id.equals( model.getID() ) )
+ {
+ return model;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return an array of content models currently assigned to the registry.
+ * @return the content model array
+ */
+ public LayoutModel[] getLayoutModels()
+ {
+ return (LayoutModel[]) m_list.toArray( new LayoutModel[0] );
+ }
+
+ /**
+ * Add a regstry change listener.
+ * @param listener the registry change listener to add
+ */
+ public void addLayoutRegistryListener( LayoutRegistryListener listener )
+ {
+ super.addListener( listener );
+ }
+
+ /**
+ * Remove a regstry change listener.
+ * @param listener the registry change listener to remove
+ */
+ public void removeLayoutRegistryListener( LayoutRegistryListener
listener )
+ {
+ super.removeListener( listener );
+ }
+
+ //
------------------------------------------------------------------------
+ // PluginListener (listens to changes to plugin uris)
+ //
------------------------------------------------------------------------
+
+ public void pluginChanged( PluginChangeEvent event )
+ {
+ getLogger().info( "plugin changed: " + event.getPluginURI() );
+ }
+
+ //
------------------------------------------------------------------------
+ // NodeChangeListener (listens to content prefs node addition and
removal)
+ //
------------------------------------------------------------------------
+
+ /**
+ * Handle the addition of a content handler configuration following a
+ * preferences node change.
+ *
+ * @param event the node addition event
+ */
+ public void childAdded( NodeChangeEvent event )
+ {
+ Preferences prefs = event.getChild();
+ addLayoutModel( prefs, true );
+ }
+
+ public void childRemoved( NodeChangeEvent event )
+ {
+ Preferences prefs = event.getChild();
+ removeLayoutModel( prefs );
+ }
+
+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ private LayoutModel addLayoutModel( Preferences prefs, boolean notify )
+ {
+ Logger logger = getLogger();
+ LayoutModel model = new LayoutManager( logger, prefs );
+ String type = model.getID();
+ synchronized( m_list )
+ {
+ Iterator iterator = m_list.iterator();
+ while( iterator.hasNext() )
+ {
+ LayoutModel d = (LayoutModel) iterator.next();
+ if( type.equals( d.getID() ) )
+ {
+ final String error =
+ "Resolver type already registered."
+ + "\nType: " + type;
+ throw new IllegalArgumentException( error );
+ }
+ }
+ m_list.add( model );
+ model.addPluginListener( this );
+ if( notify )
+ {
+ LayoutAddedEvent event = new LayoutAddedEvent( this, model );
+ super.enqueueEvent( event );
+ }
+ return model;
+ }
+ }
+
+ private void removeLayoutModel( Preferences prefs )
+ {
+ synchronized( m_list )
+ {
+ String id = prefs.name();
+ LayoutManager manager = getLayoutManager( id );
+ if( null != manager )
+ {
+ m_list.remove( manager );
+ manager.removePluginListener( this );
+ LayoutRemovedEvent event = new LayoutRemovedEvent( this,
manager );
+ super.enqueueEvent( event );
+ }
+ }
+ }
+
+ public void processEvent( EventObject event )
+ {
+ if( event instanceof PluginChangeEvent )
+ {
+ super.processPluginChangeEvent( (PluginChangeEvent) event );
+ }
+ else if( event instanceof LayoutRegistryEvent )
+ {
+ processLayoutRegistryEvent( (LayoutRegistryEvent) event );
+ }
+ else
+ {
+ final String error =
+ "Event type not regognized."
+ + "\nEvent Class: " + event.getClass();
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private void processLayoutRegistryEvent( LayoutRegistryEvent event )
+ {
+ EventListener[] listeners = super.listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener listener = listeners[i];
+ if( listener instanceof LayoutRegistryListener )
+ {
+ LayoutRegistryListener rl = (LayoutRegistryListener)
listener;
+ if( event instanceof LayoutAddedEvent )
+ {
+ try
+ {
+ rl.layoutAdded( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "LayoutRegistryListener locator addition
notification error.";
+ getLogger().error( error, e );
+ }
+ }
+ else if( event instanceof LayoutRemovedEvent )
+ {
+ try
+ {
+ rl.layoutRemoved( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "LayoutRegistryListener locator removed
notification error.";
+ getLogger().error( error, e );
+ }
+ }
+ }
+ }
+ }
+
+ static class LayoutAddedEvent extends LayoutRegistryEvent
+ {
+ public LayoutAddedEvent( LayoutRegistryModel source, LayoutModel
handler )
+ {
+ super( source, handler );
+ }
+ }
+
+ static class LayoutRemovedEvent extends LayoutRegistryEvent
+ {
+ public LayoutRemovedEvent( LayoutRegistryModel source, LayoutModel
handler )
+ {
+ super( source, handler );
+ }
+ }
+
+ static class LayoutPluginChangeEvent extends PluginChangeEvent
+ {
+ /**
+ * Creation of a new LayoutPluginChangeEvent.
+ *
+ * @param source the object initiating the event
+ * @param plugin the plugin uri
+ */
+ public LayoutPluginChangeEvent( LayoutRegistryModel source, URI
plugin )
+ {
+ super( source, plugin );
+ }
+ }
+}
+
+
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/PluginManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/PluginManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/PluginManager.java
Mon May 30 09:59:27 2005
@@ -20,17 +20,15 @@
import java.net.URI;
import java.util.EventListener;
-import java.util.logging.Logger;
-import java.util.logging.Level;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
-import net.dpml.transit.event.EventProducer;
import net.dpml.transit.model.PluginModel;
import net.dpml.transit.model.PluginChangeEvent;
import net.dpml.transit.model.PluginListener;
+import net.dpml.transit.model.Logger;
/**
* An abstract plugin manager is an implementation that monitors
configuration changes
@@ -70,7 +68,7 @@
m_uri = null;
final String message =
"Setting plugin uri to a null value.";
- m_logger.log( Level.SEVERE, message, e );
+ m_logger.error( message, e );
}
}
@@ -98,6 +96,11 @@
}
}
+ public Logger getLogger()
+ {
+ return m_logger;
+ }
+
//
------------------------------------------------------------------------
// PluginModel
//
------------------------------------------------------------------------
@@ -175,11 +178,6 @@
// internals
//
------------------------------------------------------------------------
- protected Logger getLogger()
- {
- return m_logger;
- }
-
protected Preferences getPreferences()
{
return m_preferences;
@@ -202,7 +200,7 @@
{
final String error =
"PluginListener notification error.";
- m_logger.log( Level.SEVERE, error, e );
+ m_logger.error( error, e );
}
}
}
@@ -223,13 +221,6 @@
}
}
- protected static Logger getLogger( Logger logger, String name )
- {
- String base = logger.getName();
- String category = base = "." + name;
- return Logger.getLogger( category );
- }
-
private static URI getPluginURI( Preferences prefs ) throws
IllegalArgumentException
{
String path = prefs.get( "uri", null );
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
Mon May 30 09:59:27 2005
@@ -24,8 +24,6 @@
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.BackingStoreException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.util.EventObject;
import java.util.EventListener;
import java.net.PasswordAuthentication;
@@ -36,9 +34,9 @@
import net.dpml.transit.model.ProxyExcludesEvent;
import net.dpml.transit.model.ProxyChangeEvent;
import net.dpml.transit.model.ModelException;
+import net.dpml.transit.model.Logger;
import net.dpml.transit.network.RequestIdentifier;
-import net.dpml.transit.event.EventProducer;
/**
* The ProxyManager class maintains an active configuration model of the
@@ -98,10 +96,9 @@
// ProxyManager
//
------------------------------------------------------------------------
- public String getProxyHost()
+ public Logger getLogger()
{
- Preferences prefs = getPreferences();
- return prefs.get( "host", "" );
+ return m_logger;
}
public void setProxyHost( String host )
@@ -123,14 +120,21 @@
/**
* Set the proxy authentication.
- * @param the password authenticatoion to use for proxy sign-on
+ * @param auth the password authentication to use for proxy sign-on
*/
public void setProxyAuthentication( PasswordAuthentication auth ) throws
IOException
{
m_authentication = auth;
Preferences prefs = getPreferences();
- byte[] bytes = CredentialsHelper.exportCredentials( m_authentication
);
- prefs.putByteArray( "authentication", bytes );
+ if( null == auth )
+ {
+ prefs.putByteArray( "authentication", new byte[0] );
+ }
+ else
+ {
+ byte[] bytes = CredentialsHelper.exportCredentials(
m_authentication );
+ prefs.putByteArray( "authentication", bytes );
+ }
}
public void addExclude( String key )
@@ -175,6 +179,27 @@
}
/**
+ * Return the proxy host name. If not defined the implementation returns a
+ * zero length string.
+ * @return the proxy host name
+ */
+ public String getProxyHost()
+ {
+ Preferences prefs = getPreferences();
+ return prefs.get( "host", "" );
+ }
+
+ /**
+ * Return the proxy port.
+ * @return the proxy port
+ */
+ public int getProxyPort()
+ {
+ Preferences prefs = getPreferences();
+ return prefs.getInt( "port", 0 );
+ }
+
+ /**
* Return the proxy authentication or null if not defined.
* @return the proxy authentication credentials
*/
@@ -243,8 +268,8 @@
{
final String error =
"Unexpected error while resolving proxy credentials.";
- getLogger().log( Level.SEVERE, error, e );
- m_authentication = NULL_AUTHENTICATION;
+ getLogger().error( error, e );
+ m_authentication = null;
}
if( null != prefs.get( "host", null ) )
@@ -263,7 +288,7 @@
{
final String error =
"Proxy configuration setup error.";
- m_logger.log( Level.SEVERE, error, e );
+ m_logger.error( error, e );
}
}
else
@@ -300,7 +325,7 @@
{
final String error =
"PluginListener notification error.";
- m_logger.log( Level.SEVERE, error, e );
+ m_logger.error( error, e );
}
}
else if( eventObject instanceof ProxyExcludesEvent )
@@ -314,7 +339,7 @@
{
final String error =
"PluginListener excludes notification error.";
- m_logger.log( Level.SEVERE, error, e );
+ m_logger.error( error, e );
}
}
}
@@ -332,7 +357,7 @@
byte[] bytes = prefs.getByteArray( "authentication", new byte[0] );
if( bytes.length == 0 )
{
- return NULL_AUTHENTICATION;
+ return null;
}
else
{
@@ -381,7 +406,7 @@
final String error =
"Ignoring possible proxy exclude settings due to a
preferences backing store error."
+ "\nPreferences: " + prefs;
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
return new String[0];
}
}
@@ -427,11 +452,6 @@
return m_preferences;
}
- private Logger getLogger()
- {
- return m_logger;
- }
-
private class ModificationHandler implements PreferenceChangeListener
{
public void preferenceChange( PreferenceChangeEvent prefsEvent )
@@ -461,7 +481,7 @@
{
final String error =
"Proxy excludes access error.";
- m_logger.log( Level.SEVERE, error, e );
+ m_logger.error( error, e );
}
}
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
Mon May 30 09:59:27 2005
@@ -27,8 +27,6 @@
import java.util.prefs.NodeChangeEvent;
import java.util.prefs.NodeChangeListener;
import java.util.prefs.BackingStoreException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.net.URI;
import net.dpml.transit.model.RegistryModel;
@@ -38,6 +36,7 @@
import net.dpml.transit.model.RegistryEvent;
import net.dpml.transit.model.PluginListener;
import net.dpml.transit.model.ModelException;
+import net.dpml.transit.model.Logger;
/**
* Default implementation of a content handler registry manager that
maitains
@@ -119,11 +118,6 @@
return null;
}
- public void addContentModel( String type )
- {
- getPreferences().node( type );
- }
-
public void removeContentModel( String type ) throws ModelException
{
try
@@ -173,11 +167,56 @@
}
}
+ public void newContentModel( String type )
+ {
+ getPreferences().node( type );
+ }
+
//
------------------------------------------------------------------------
// RegistryManager
//
------------------------------------------------------------------------
/**
+ * Register a new content model.
+ *
+ * @return the content model
+ */
+ public ContentModel addContentModel( String type, String title, URI uri )
+ {
+ if( null == type )
+ {
+ throw new NullPointerException( "type" );
+ }
+ if( null == title )
+ {
+ throw new NullPointerException( "title" );
+ }
+ if( null == uri )
+ {
+ throw new NullPointerException( "uri" );
+ }
+
+ Preferences prefs = getPreferences().node( type );
+ prefs.put( "title", title );
+ prefs.put( "uri", uri.toString() );
+ return addContentModel( prefs, true );
+ }
+
+ public ContentModel getContentModel( String type )
+ {
+ ContentModel[] models = getContentModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ ContentModel model = models[i];
+ if( type.equals( model.getContentType() ) )
+ {
+ return model;
+ }
+ }
+ return null;
+ }
+
+ /**
* Return an array of content models currently assigned to the registry.
* @return the content model array
*/
@@ -239,21 +278,7 @@
// internal
//
------------------------------------------------------------------------
- private ContentModel findContentModel( String type )
- {
- ContentModel[] models = getContentModels();
- for( int i=0; i<models.length; i++ )
- {
- ContentModel model = models[i];
- if( type.equals( model.getContentType() ) )
- {
- return model;
- }
- }
- return null;
- }
-
- private void addContentModel( Preferences prefs, boolean notify )
+ private ContentModel addContentModel( Preferences prefs, boolean notify )
{
Logger logger = getLogger();
ContentModel model = new ContentManager( logger, prefs );
@@ -279,6 +304,7 @@
ContentAddedEvent event = new ContentAddedEvent( this, model
);
super.enqueueEvent( event );
}
+ return model;
}
}
@@ -287,7 +313,7 @@
synchronized( m_list )
{
String type = prefs.name();
- ContentModel model = findContentModel( type );
+ ContentModel model = getContentModel( type );
if( null != model )
{
m_list.remove( model );
@@ -336,7 +362,7 @@
{
final String error =
"RegistryListener content addition notification
error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
else if( event instanceof ContentRemovedEvent )
@@ -349,7 +375,7 @@
{
final String error =
"RegistryListener content removed notification
error.";
- getLogger().log( Level.SEVERE, error, e );
+ getLogger().error( error, e );
}
}
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RepositoryManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RepositoryManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RepositoryManager.java
Mon May 30 09:59:27 2005
@@ -20,13 +20,13 @@
import java.util.EventObject;
import java.util.EventListener;
-import java.util.logging.Logger;
import java.util.prefs.Preferences;
import java.net.URI;
import net.dpml.transit.model.RepositoryModel;
import net.dpml.transit.model.PluginModel;
import net.dpml.transit.model.PluginChangeEvent;
+import net.dpml.transit.model.Logger;
/**
* Default implementation of a pluggable repository manager.
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
Mon May 30 09:59:27 2005
@@ -20,14 +20,18 @@
import java.io.File;
import java.util.prefs.Preferences;
-import java.util.logging.Logger;
+import java.net.URL;
import net.dpml.transit.model.TransitModel;
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.RegistryModel;
import net.dpml.transit.model.RepositoryModel;
import net.dpml.transit.model.ProxyModel;
+import net.dpml.transit.model.LayoutRegistryModel;
import net.dpml.transit.model.ModelException;
+import net.dpml.transit.model.Logger;
+
+import net.dpml.transit.TransitException;
/**
* The TransitManager class maintains an active configuration of the
@@ -46,13 +50,21 @@
private final RegistryManager m_registry;
private final RepositoryManager m_repository;
private final ProxyManager m_proxy;
+ private final LayoutRegistryManager m_layout;
+ private final Logger m_logger;
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
- public TransitManager( Logger logger, Preferences prefs )
- throws NullPointerException, ModelException
+ public TransitManager( Logger logger, Preferences prefs )
+ throws NullPointerException, TransitException
+ {
+ this( logger, prefs, null );
+ }
+
+ public TransitManager( Logger logger, Preferences prefs, URL authority )
+ throws NullPointerException, TransitException
{
if( null == prefs )
{
@@ -62,6 +74,30 @@
{
throw new NullPointerException( "logger" );
}
+
+ //
+ // check for virgin prefs
+ //
+
+ if( null != authority )
+ {
+ TransitPreferences.setupPreferences( prefs, authority );
+ }
+ else
+ {
+ long install = prefs.getLong( "installation", -1 );
+ if( install < 0 )
+ {
+ TransitPreferences.setupFactoryPreferences( prefs );
+ }
+ }
+
+ //
+ // create the subsystem configurations
+ //
+
+ m_logger = logger;
+ m_layout = createLayoutRegistryModel( logger, prefs );
m_cache = createCacheModel( logger, prefs );
m_registry = createRegistryModel( logger, prefs );
m_repository = createRepositoryModel( logger, prefs );
@@ -112,11 +148,30 @@
return m_repository;
}
+ /**
+ * Return the model maintaining configuration information about
+ * the available location resolvers.
+ *
+ * @return the layout model
+ */
+ public LayoutRegistryManager getLayoutRegistryManager()
+ {
+ return m_layout;
+ }
+
//
------------------------------------------------------------------------
// TransitModel
//
------------------------------------------------------------------------
/**
+ * Return the assigned logging channel.
+ */
+ public Logger getLogger()
+ {
+ return m_logger;
+ }
+
+ /**
* Return the proxy model.
* @return the proxy configuration model.
*/
@@ -156,6 +211,17 @@
return getRepositoryManager();
}
+ /**
+ * Return the model maintaining configuration information about
+ * the available location resolvers.
+ *
+ * @return the layout model
+ */
+ public LayoutRegistryModel getLayoutRegistryModel()
+ {
+ return getLayoutRegistryManager();
+ }
+
//
------------------------------------------------------------------------
// AbstractManager
//
------------------------------------------------------------------------
@@ -169,6 +235,7 @@
m_registry.dispose();
m_repository.dispose();
m_proxy.dispose();
+ m_layout.dispose();
}
//
------------------------------------------------------------------------
@@ -178,36 +245,36 @@
private CacheManager createCacheModel( Logger logger, Preferences root )
throws ModelException
{
Preferences prefs = root.node( "cache" );
- Logger log = getLogger( logger, "cache" );
- return new CacheManager( log, prefs );
+ Logger log = logger.getChildLogger( "cache" );
+ return new CacheManager( log, prefs, m_layout );
}
private RegistryManager createRegistryModel( Logger logger, Preferences
root ) throws ModelException
{
Preferences prefs = root.node( "content" );
- Logger log = getLogger( logger, "content" );
+ Logger log = logger.getChildLogger( "content" );
return new RegistryManager( log, prefs );
}
private RepositoryManager createRepositoryModel( Logger logger,
Preferences root )
{
Preferences prefs = root.node( "repository" );
- Logger log = getLogger( logger, "repository" );
+ Logger log = logger.getChildLogger( "repository" );
return new RepositoryManager( log, prefs );
}
private ProxyManager createProxyModel( Logger logger, Preferences root )
{
Preferences prefs = root.node( "proxy" );
- Logger log = getLogger( logger, "proxy" );
+ Logger log = logger.getChildLogger( "proxy" );
return new ProxyManager( log, prefs );
}
- private Logger getLogger( Logger logger, String name )
+ private LayoutRegistryManager createLayoutRegistryModel( Logger logger,
Preferences root ) throws ModelException
{
- String base = logger.getName();
- String category = base = "." + name;
- return Logger.getLogger( category );
+ Preferences prefs = root.node( "layout" );
+ Logger log = logger.getChildLogger( "layout" );
+ return new LayoutRegistryManager( log, prefs );
}
}
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitPreferences.java
(from r2659,
development/main/transit/core/handler/src/main/net/dpml/transit/TransitPreferences.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/TransitPreferences.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitPreferences.java
Mon May 30 09:59:27 2005
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package net.dpml.transit;
+package net.dpml.transit.manager;
import java.io.File;
import java.io.IOException;
@@ -23,7 +23,9 @@
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
+import java.io.FileNotFoundException;
import java.net.URL;
+import java.net.MalformedURLException;
import java.util.prefs.Preferences;
import java.util.prefs.BackingStoreException;
import java.util.jar.JarFile;
@@ -40,40 +42,45 @@
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.cache.CacheHandler;
+import net.dpml.transit.layout.Layout;
+import net.dpml.transit.layout.ClassicLayout;
+import net.dpml.transit.layout.EclipseLayout;
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
+public class TransitPreferences
{
//--------------------------------------------------------------------------
// static
//--------------------------------------------------------------------------
+ public static final String HOST_ID_KEY = "dpml.transit.host.id";
+ public static final String HOST_BASE_KEY = "dpml.transit.host.base";
+ public static final String HOST_INDEX_KEY = "dpml.transit.host.index";
+ public static final String HOST_PRIORITY_KEY =
"dpml.transit.host.priority";
+ public static final String HOST_USERNAME_KEY =
"dpml.transit.host.username";
+ public static final String HOST_PASSWORD_KEY =
"dpml.transit.host.password";
+ public static final String HOST_PROMPT_KEY = "dpml.transit.host.prompt";
+ public static final String HOST_SCHEME_KEY = "dpml.transit.host.scheme";
+ public static final String HOST_LAYOUT_KEY = "dpml.transit.host.layout";
+ public static final String HOST_ENABLED_KEY =
"dpml.transit.host.enabled";
+ public static final String HOST_TRUSTED_KEY =
"dpml.transit.host.trusted";
+ public static final String HOST_BOOTSTRAP_KEY =
"dpml.transit.host.bootstrap";
+
+ public static final String CACHE_LOCATION_KEY =
"dpml.transit.cache.location";
+ public static final String CACHE_CLASS_KEY = "dpml.transit.cache.class";
+ public static final String CACHE_LAYOUT_KEY =
"dpml.transit.cache.layout";
+
/**
* 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.
@@ -82,17 +89,120 @@
*/
public static void setupFactoryPreferences( Preferences root ) throws
TransitException
{
+ ClassLoader classloader = Transit.class.getClassLoader();
+ URL cacheUrl = classloader.getResource(
"transit/authority/cache.properties" );
try
{
+ Preferences layout = root.node( "layout" );
Preferences cache = root.node( "cache" );
- setupCachePreferences( cache );
Preferences hosts = cache.node( "hosts" );
+ setupLayoutPreferences( layout );
+ setupCachePreferences( cacheUrl, cache );
setupHostsPreferences( hosts );
root.putLong( "installation", new Date().getTime() );
}
catch( BackingStoreException e )
{
final String error =
+ "Unable to establish default transit preferences due to a
backing store error.";
+ throw new TransitException( error, e );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to resolve default transit preferences due to an
unexpected error.";
+ throw new TransitException( error, e );
+ }
+ }
+
+ /**
+ * Setup the factory preferences for the Transit system using the value
declared by
+ * the authority attribute.
+ *
+ * @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 setupPreferences( Preferences root, URL authority )
throws TransitException
+ {
+ String protocol = authority.getProtocol();
+ Preferences cachePrefs = root.node( "cache" );
+ Preferences hostsPrefs = cachePrefs.node( "hosts" );
+ Preferences layoutPrefs = root.node( "layout" );
+ setupLayoutPreferences( layoutPrefs );
+
+ try
+ {
+ if( "file".equals( protocol ) )
+ {
+ //
+ // convert the url to a local file and work from there
+ //
+
+ String authorative = authority.toExternalForm().substring(
FILE_PROTOCOL_LENGTH );
+ while ( authorative.startsWith( "//" ) )
+ {
+ authorative = authorative.substring( 1 );
+ }
+
+ File base = new File( authorative );
+ if( !base.exists() )
+ {
+ final String error =
+ "Authorative base url references to a location that
does not exist."
+ + "\nAuthorative URL: " + authority
+ + "\nResolve authority base directory: " + base;
+ throw new FileNotFoundException( error );
+ }
+
+ //
+ // setup cache preferences
+ //
+
+ File cacheConfig = new File( base, "cache.properties" );
+ if( cacheConfig.exists() )
+ {
+ URL cacheUrl = cacheConfig.toURL();
+ setupCachePreferences( cacheUrl, cachePrefs );
+ }
+
+ //
+ // setup host preferences
+ //
+
+ File hosts = new File( base, "hosts" );
+ if( hosts.exists() )
+ {
+ File[] files = hosts.listFiles();
+ for( int i=0; i < files.length; i++ )
+ {
+ File file = files[i];
+ String name = file.getName();
+ if( name.indexOf( "." ) > -1 )
+ {
+ name = name.substring( 0, name.indexOf( "." ) );
+ }
+ Preferences host = hostsPrefs.node( name );
+ URL hostUrl = fileToURL( file );
+ Properties properties = Util.readProps( hostUrl );
+ setupHost( properties, host );
+ }
+ }
+ }
+ else
+ {
+ URL index = new URL( authority, REMOTE_LIST_FILENAME );
+ String[] paths = Util.readListFile( index );
+ for( int i=0; i < paths.length; i++ )
+ {
+ String path = paths[i];
+ URL spec = new URL( path );
+ setupHost( hostsPrefs, spec );
+ }
+ }
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
"Unable to resolve transit preferences due to a backing store
error.";
throw new TransitException( error, e );
}
@@ -104,25 +214,44 @@
}
}
- private static void setupCachePreferences( Preferences prefs ) throws
IOException, BackingStoreException
+ /**
+ * Setup the bootrap resolver entries.
+ * @param prefs the layout preferences node
+ */
+ private static void setupLayoutPreferences( Preferences prefs )
+ {
+ Preferences classic = prefs.node( "classic" );
+ classic.put( "title", "Classic Layout" );
+ classic.put( "classname", ClassicLayout.class.getName() );
+ Preferences eclipse = prefs.node( "eclipse" );
+ eclipse.put( "title", "Eclipse Layout" );
+ eclipse.put( "classname", EclipseLayout.class.getName() );
+ }
+
+ private static void setupCachePreferences( URL resource, 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 );
+ setupCachePreferences( properties, prefs );
+ }
+
+ private static void setupCachePreferences( Properties properties,
Preferences prefs )
+ throws IOException, BackingStoreException
+ {
+ String location = properties.getProperty( CACHE_LOCATION_KEY );
if( null != location )
{
prefs.put( "location", location );
}
- String classname = properties.getProperty(
CacheHandler.CACHE_CLASS_KEY );
+ String classname = properties.getProperty( CACHE_CLASS_KEY );
if( null != classname )
{
prefs.put( "classname", classname );
}
- String resolver = properties.getProperty(
CacheHandler.RESOLVER_CLASS_KEY );
+ String resolver = properties.getProperty( CACHE_LAYOUT_KEY );
if( null != resolver )
{
- prefs.put( "resolver", resolver );
+ prefs.put( "layout", resolver );
}
}
@@ -138,14 +267,32 @@
{
URL url = Transit.class.getClassLoader().getResource( resource );
Preferences host = prefs.node( name );
- setupHost( host, url );
+ Properties properties = Util.readProps( url );
+ setupHost( properties, host );
+ }
+
+ private static void setupHost( Preferences prefs, URL hostDef ) throws
IOException, TransitException
+ {
+ Properties properties = Util.readProps( hostDef );
+ String id = properties.getProperty( HOST_ID_KEY );
+ if( null == id )
+ {
+ final String error =
+ "Remote host description does not declare '"
+ + HOST_ID_KEY
+ + "' property."
+ + "\nHost descriptor URL: " + hostDef;
+ throw new TransitException( error );
+ }
+ Preferences host = prefs.node( id );
+ setupHost( properties, host );
}
- private static void setupHost( Preferences prefs, URL hostDef ) throws
TransitException
+ private static void setupHost( Properties properties, Preferences prefs
) throws TransitException
{
- if( null == hostDef )
+ if( null == properties )
{
- throw new NullArgumentException( "hostDef" );
+ throw new NullArgumentException( "properties" );
}
if( null == prefs )
{
@@ -155,62 +302,54 @@
String name = prefs.name();
try
{
- Properties props = Util.readProps( hostDef );
- String base = Util.getProperty( props,
"dpml.transit.resourcehost.base", null );
+ String base = Util.getProperty( properties, HOST_BASE_KEY, null
);
if( base == null )
{
final String error =
"Invalid host defintion (no base url declaration)."
- + "\nHost Definition Resource: " + hostDef;
+ + "\nHost ID: " + prefs.name();
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 );
+ String index = Util.getProperty( properties, HOST_INDEX_KEY,
null );
+ String priorityText = Util.getProperty( properties,
HOST_PRIORITY_KEY, 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" );
+ String username = Util.getProperty( properties,
HOST_USERNAME_KEY, "" );
+ String password = Util.getProperty( properties,
HOST_USERNAME_KEY, "" );
+ String prompt = Util.getProperty( properties, HOST_PROMPT_KEY,
"" );
+ String scheme = Util.getProperty( properties, HOST_SCHEME_KEY,
"" );
+ String resolverID = Util.getProperty( properties,
HOST_LAYOUT_KEY, "classic" );
boolean enabled =
- Util.getProperty(
- props, "dpml.transit.resourcehost.enabled", "true"
).equalsIgnoreCase( "true" );
+ Util.getProperty( properties, HOST_ENABLED_KEY, "true"
).equalsIgnoreCase( "true" );
boolean trusted =
- Util.getProperty(
- props, "dpml.transit.resourcehost.trusted", "false"
).equalsIgnoreCase( "true" );
-
- prefs.put( "classname", classname );
+ Util.getProperty( properties, HOST_TRUSTED_KEY, "false"
).equalsIgnoreCase( "true" );
+ boolean bootstrap =
+ Util.getProperty( properties, HOST_BOOTSTRAP_KEY, "false"
).equalsIgnoreCase( "true" );
+
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.putBoolean( "enabled", enabled );
+ prefs.putBoolean( "trusted", trusted );
+ prefs.put( "username", username ); // TODO
+ prefs.put( "password", password ); // TODO
prefs.put( "scheme", scheme );
- prefs.put( "resolver", resolverclass );
+ prefs.put( "layout", resolverID );
prefs.putBoolean( "available", true );
+ prefs.putBoolean( "bootstrap", bootstrap );
}
catch( Throwable e )
{
final String error =
"Unexpected error occured while attempting to construct a
default host preferences."
+ "\nHost Name: " + name
- + "\nResource URL: " + hostDef;
+ + "\nProperties: " + properties;
throw new TransitException( error, e );
}
}
@@ -238,5 +377,71 @@
private TransitPreferences()
{
}
+
+ /**
+ * File protocol name length.
+ */
+ private static final int FILE_PROTOCOL_LENGTH = 5;
+
+ /**
+ * Filename of the remote file index.
+ */
+ private static final String REMOTE_LIST_FILENAME = "index.lst";
+
+ /**
+ * Return the url of a file.
+ * @param file the file to convert
+ * @return the equivalent url
+ * @exception TransitException if a error occurs in file to url conversion
+ */
+ private static URL fileToURL( File file ) throws TransitException
+ {
+ try
+ {
+ return file.toURL();
+ }
+ catch( MalformedURLException mue )
+ {
+ final String error =
+ "The file ["
+ + file
+ + "] ("
+ + file.exists()
+ + ") raised a malformed url exception with the message '"
+ + mue.getMessage()
+ + "'.";
+ throw new TransitException( error );
+ }
+ }
+
+ private static URL resolveAuthority( Preferences prefs ) throws
TransitException
+ {
+ String authority = prefs.get( "authority", null );
+ if( null == authority )
+ {
+ final String error =
+ "Authority attribute is undefined."
+ + "\nPreferences: " + prefs;
+ throw new TransitException( error );
+ }
+ try
+ {
+ if( authority.indexOf( ":" ) > -1 )
+ {
+ return new URL( authority );
+ }
+ else
+ {
+ return new File( authority ).toURL();
+ }
+ }
+ catch( IOException e )
+ {
+ final String error =
+ "Unable to resolve the Transit authority url."
+ + "\nPreferences: " + prefs;
+ throw new TransitException( error, e );
+ }
+ }
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/CacheModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/CacheModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/CacheModel.java
Mon May 30 09:59:27 2005
@@ -29,11 +29,6 @@
public interface CacheModel extends PluginModel
{
/**
- * Cache property key.
- */
- static final String CACHE_KEY = "dpml.transit.cache.location";
-
- /**
* Return the directory to be used by the cache handler as the cache
directory.
* @return the cache directory.
*/
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostEnabledEvent.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/model/EnabledEvent.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/EnabledEvent.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostEnabledEvent.java
Mon May 30 09:59:27 2005
@@ -21,11 +21,11 @@
/**
* An event signalling the change in the enabled status of a host model.
*/
-public class EnabledEvent extends HostEvent
+public class HostEnabledEvent extends HostEvent
{
private final boolean m_enabled;
- public EnabledEvent( HostModel host, boolean enabled )
+ public HostEnabledEvent( HostModel host, boolean enabled )
{
super( host );
m_enabled = enabled;
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostLayoutEvent.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostLayoutEvent.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,38 @@
+/*
+ * 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.transit.model;
+
+/**
+ * An event signalling the change to the layout model assigned to a host
model.
+ */
+public class HostLayoutEvent extends HostEvent
+{
+ private final LayoutModel m_layout;
+
+ public HostLayoutEvent( HostModel host, LayoutModel layout )
+ {
+ super( host );
+ m_layout = layout;
+ }
+
+ public LayoutModel getLayoutModel()
+ {
+ return m_layout;
+ }
+}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostListener.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostListener.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostListener.java
Mon May 30 09:59:27 2005
@@ -38,19 +38,25 @@
* Notify a consumer of a change to the enabled state.
* @param event the host event
*/
- void enabledStateChanged( EnabledEvent event );
+ void enabledStateChanged( HostEnabledEvent event );
/**
* Notify a consumer of a change to the trusted state.
* @param event the host event
*/
- void trustedStateChanged( TrustedEvent event );
+ void trustedStateChanged( HostTrustedEvent event );
/**
* Notify a consumer of a change to the host priority.
* @param event the host event
*/
- void priorityChanged( PriorityEvent event );
+ void priorityChanged( HostPriorityEvent event );
+
+ /**
+ * Notify a consumer of a change to the host resolver.
+ * @param event the host resolver change event
+ */
+ void layoutChanged( HostLayoutEvent event );
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostModel.java
Mon May 30 09:59:27 2005
@@ -35,24 +35,20 @@
*/
public interface HostModel extends PluginModel
{
- // Based on the resource descriptor, this interface attempt to reduce
- // down the information needed at instantiation and subsequent runtime.
- // It assumes that the host implementation class is immutable.
- // Host priority has been moved to the CacheListener class.
- //
- // Password and username have been reflected as an authenticator instance
- // however - some additional info may be needed related to sceme and
promopt
- // but these are not included as these feel like authenticator
implementation
- // concerns (not sure on this one). At least its fair to say that an
authenticator
- // is a network host concern which would suggest that there is a
NetworkHostModel.
-
/**
* Return an immutable host identifier. The host identifier shall be
- * guranteed to be unique and constant for the life of the director.
+ * guranteed to be unique and constant for the life of the model.
*/
String getID();
/**
+ * Return TRUE if this is a bootstrap host. Bootstrap hosts shall be
+ * provided such that they independent of the Transit respository
+ * service.
+ */
+ boolean isBootstrap();
+
+ /**
* Return the available status. A host model may declare itself as
unavailable
* if its data model is incomplete or inconsitent.
*
@@ -109,10 +105,10 @@
public RequestIdentifier getRequestIdentifier();
/**
- * Return the location resolver plugin uri.
- * @return the uri of the location resolver plugin
+ * Return the layout strategy model.
+ * @return the layout model
*/
- URI getLocationResolverPluginURI();
+ LayoutModel getLayoutModel();
/**
* Add a host change listener to the director.
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostNameEvent.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/model/NameChangeEvent.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/NameChangeEvent.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostNameEvent.java
Mon May 30 09:59:27 2005
@@ -21,11 +21,11 @@
/**
* An event signalling the change of name of a host.
*/
-public class NameChangeEvent extends HostEvent
+public class HostNameEvent extends HostEvent
{
private final String m_name;
- public NameChangeEvent( HostModel host, String name )
+ public HostNameEvent( HostModel host, String name )
{
super( host );
m_name = name;
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostPriorityEvent.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/model/PriorityEvent.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/PriorityEvent.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostPriorityEvent.java
Mon May 30 09:59:27 2005
@@ -21,11 +21,11 @@
/**
* An event signalling the change in priority of a host.
*/
-public class PriorityEvent extends HostEvent
+public class HostPriorityEvent extends HostEvent
{
private final int m_priority;
- public PriorityEvent( HostModel host, int priority )
+ public HostPriorityEvent( HostModel host, int priority )
{
super( host );
m_priority = priority;
Copied:
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostTrustedEvent.java
(from r2658,
development/main/transit/core/handler/src/main/net/dpml/transit/model/TrustedEvent.java)
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/TrustedEvent.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/HostTrustedEvent.java
Mon May 30 09:59:27 2005
@@ -21,11 +21,11 @@
/**
* An event signalling the change in the trusted status of a host.
*/
-public class TrustedEvent extends HostEvent
+public class HostTrustedEvent extends HostEvent
{
private final boolean m_trusted;
- public TrustedEvent( HostModel host, boolean trusted )
+ public HostTrustedEvent( HostModel host, boolean trusted )
{
super( host );
m_trusted = trusted;
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutEvent.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutEvent.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,47 @@
+/*
+ * 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.transit.model;
+
+import java.util.EventObject;
+
+/**
+ * A event pertaining to content model changes.
+ */
+public class LayoutEvent extends EventObject
+{
+ /**
+ * Creation of a new LayoutEvent signalling modification of
+ * location resolver configuration.
+ *
+ * @param model the resolver model
+ */
+ public LayoutEvent( LayoutModel model )
+ {
+ super( model );
+ }
+
+ /**
+ * Return the resolver that was modified.
+ * @return the resolver model
+ */
+ public LayoutModel getLayoutModel()
+ {
+ return (LayoutModel) getSource();
+ }
+}
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutListener.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutListener.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,35 @@
+/*
+ * 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.model;
+
+import java.util.EventListener;
+
+/**
+ * A ContentListener maintains information about the configuration of
+ * content type.
+ */
+public interface LayoutListener extends EventListener
+{
+ /**
+ * Notify a listener of the change to the human readable name of
+ * a location resolver plaugin.
+ * @param event the resolver model event
+ */
+ void titleChanged( LayoutEvent event );
+}
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutModel.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutModel.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,62 @@
+/*
+ * 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.model;
+
+import java.net.URI;
+
+/**
+ * A LayoutModel maintains information about the configuration
+ * of a location resolver.
+ */
+public interface LayoutModel extends PluginModel
+{
+ /**
+ * Return the immutable resolver identifier.
+ * @return the resolver identifier
+ */
+ String getID();
+
+ /**
+ * Return a possibly null classname. If the classname is not null the
+ * manager represents a bootstrap resolver. Bootstrap resolver plugin
+ * uris shall return a null value.
+ *
+ * @return the resolver classname
+ */
+ String getClassname();
+
+ /**
+ * Returns the human readable name of the location resolver.
+ * @return the layout human readable name
+ */
+ public String getTitle();
+
+ /**
+ * Add a resolver model listener.
+ * @param listener the listener to add
+ */
+ void addLayoutListener( LayoutListener listener );
+
+ /**
+ * Remove a resolver listener from the model.
+ * @param listener the listener to remove
+ */
+ void removeLayoutListener( LayoutListener listener );
+
+}
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryEvent.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryEvent.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,64 @@
+/*
+ * 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.transit.model;
+
+import java.util.EventObject;
+
+/**
+ * An event issued by a registry signalling changes tye addition or removal
+ * of a content model.
+ */
+public abstract class LayoutRegistryEvent extends EventObject
+{
+ private final LayoutModel m_resolver;
+ private final LayoutRegistryModel m_system;
+
+ /**
+ * Creation of a new LayoutRegistryEvent signalling the addition
+ * or removal of a layout resolver.
+ *
+ * @param system the layout model
+ * @param resolver the layout resolver model that was added or removed
+ */
+ public LayoutRegistryEvent( LayoutRegistryModel system, LayoutModel
resolver )
+ {
+ super( system );
+ m_system = system;
+ m_resolver = resolver;
+ }
+
+ /**
+ * Return the model initiating the event.
+ * @return the layout model
+ */
+ public LayoutRegistryModel getLayoutRegistryModel()
+ {
+ return m_system;
+ }
+
+ /**
+ * Return the resolver model that was added or removed.
+ * @return the resolver model
+ */
+ public LayoutModel getLayoutModel()
+ {
+ return m_resolver;
+ }
+}
+
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryListener.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryListener.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,42 @@
+/*
+ * 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.model;
+
+import java.util.EventListener;
+
+/**
+ * A RegistryListener maintains information about the configuration of a
Transit
+ * content management system. An implementation of this interface would be
supplied
+ * a ContentRegistry implementation.
+ */
+public interface LayoutRegistryListener extends EventListener
+{
+ /**
+ * Notify all listeners of the addition of a location resolver model.
+ * @param event the layout event
+ */
+ void layoutAdded( LayoutRegistryEvent event );
+
+ /**
+ * Notify all listeners of the removal of a location resolver model.
+ * @param event the layout event
+ */
+ void layoutRemoved( LayoutRegistryEvent event );
+
+}
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryModel.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/LayoutRegistryModel.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,66 @@
+/*
+ * 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.model;
+
+import java.net.URI;
+
+/**
+ * A LayoutRegistryModel maintains information about the configuration of
the Transit
+ * location resolver models.
+ */
+public interface LayoutRegistryModel extends PluginModel
+{
+ /**
+ * Return the set of location resolver models.
+ * @return the model array.
+ */
+ LayoutModel[] getLayoutModels();
+
+ /**
+ * Return a layout resolver model matching the supplied id. If the id is
unknown
+ * an implementation shall return a null value.
+ *
+ * @return the layout model
+ */
+ LayoutModel getLayoutModel( String id );
+
+ /**
+ * Register a new layout resolver model.
+ *
+ * @param id the layout identifier
+ * @param title the title of the layout resolver model
+ * @param plugin the plugin uri
+ * @return the layout resolver model
+ */
+ LayoutModel addLayoutModel( String id, String title, URI plugin );
+
+ /**
+ * Add a change listener.
+ * @param listener the registry change listener to add
+ */
+ void addLayoutRegistryListener( LayoutRegistryListener listener );
+
+ /**
+ * Remove a change listener.
+ * @param listener the registry change listener to remove
+ */
+ void removeLayoutRegistryListener( LayoutRegistryListener listener );
+
+}
+
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/Logger.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/Logger.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,86 @@
+/*
+ * 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.transit.model;
+
+import java.net.URL;
+
+
+/**
+ * Transit Logger is a interface through which different logging solutions
+ * can be provided. Typical examples of logging implementations include
+ * java.util.logging.Logger or Ant's Project.log() function.
+ *
+ * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
+ * @version $Id: Adapter.java 2445 2005-04-28 23:44:22Z niclas AT hedhman.org $
+ */
+public interface Logger
+{
+ /**
+ * Return TRUE is debug level logging is enabled.
+ * @return the enabled state of debug logging
+ */
+ boolean isDebugEnabled();
+
+ /**
+ * Return TRUE is info level logging is enabled.
+ * @return the enabled state of info logging
+ */
+ boolean isInfoEnabled();
+
+ /**
+ * Return TRUE is error level logging is enabled.
+ * @return the enabled state of error logging
+ */
+ boolean isErrorEnabled();
+
+ /**
+ * Record a debug level message.
+ * @param message the debug message to record
+ */
+ void debug( String message );
+
+ /**
+ * Record a informative message.
+ * @param message the info message to record
+ */
+ void info( String message );
+
+ /**
+ * Record a warning message.
+ * @param message the warning message to record
+ */
+ void warn( String message );
+
+ /**
+ * Record a error level message.
+ * @param message the error message to record
+ */
+ void error( String message );
+
+ /**
+ * Record a error level message.
+ * @param message the error message to record
+ * @param e the error
+ */
+ void error( String message, Throwable e );
+
+ Logger getChildLogger( String category );
+}
+
+
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/Model.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/Model.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,31 @@
+/*
+ * 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.model;
+
+/**
+ * The abstract model interface.
+ */
+public interface Model
+{
+ /**
+ * Return the logging channel.
+ * @return the logging channel.
+ */
+ Logger getLogger();
+}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ModelException.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/ModelException.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ModelException.java
Mon May 30 09:59:27 2005
@@ -18,14 +18,14 @@
package net.dpml.transit.model;
-import java.net.ProtocolException;
+import net.dpml.transit.TransitException;
/**
* Exception to indicate that there was a configuration model related error.
*
* @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
*/
-public class ModelException extends Exception
+public class ModelException extends TransitException
{
/**
* Construct a new <code>ModelException</code> instance.
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/PluginModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/PluginModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/PluginModel.java
Mon May 30 09:59:27 2005
@@ -24,7 +24,7 @@
* A PluginModel maintains information about the configuration of
* a pluggable subsystem.
*/
-public interface PluginModel
+public interface PluginModel extends Model
{
/**
* Return the uri of the plugin to be used for cache management.
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
Mon May 30 09:59:27 2005
@@ -27,7 +27,7 @@
* The ProxyModel is an interface implemented by objects that
* manage the configuration of a running transit system.
*/
-public interface ProxyModel
+public interface ProxyModel extends Model
{
/**
* Returns TRUE if a proxy configuration is enabled.
@@ -36,6 +36,20 @@
boolean isProxyEnabled();
/**
+ * Return the proxy host name. If not defined an implementation shall
+ * returns a zero length string.
+ *
+ * @return the proxy host name
+ */
+ public String getProxyHost();
+
+ /**
+ * Return the proxy port or 0 is undefined.
+ * @return the proxy port
+ */
+ public int getProxyPort();
+
+ /**
* Return the proxy authentication or null if not defined.
* @return the proxy authentication credentials
*/
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/RegistryModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/RegistryModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/RegistryModel.java
Mon May 30 09:59:27 2005
@@ -28,6 +28,24 @@
public interface RegistryModel extends PluginModel
{
/**
+ * Register a new content model.
+ *
+ * @param type the content type identifier
+ * @param title the title of the content model
+ * @param plugin the content plugin uri
+ * @return the content model
+ */
+ ContentModel addContentModel( String type, String title, URI plugin );
+
+ /**
+ * Return a content model matching the supplied type. If the type is
unknown
+ * an implementation shall return a null value.
+ *
+ * @return the content model
+ */
+ ContentModel getContentModel( String type );
+
+ /**
* Return an array of content directors currently assigned to the
registry.
* @return the content director array
*/
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitModel.java
Mon May 30 09:59:27 2005
@@ -22,7 +22,7 @@
* The TransitModel is an interface implemented by objects that
* manage the configuration of a running transit system.
*/
-public interface TransitModel
+public interface TransitModel extends Model
{
/**
* Return the proxy model.
@@ -51,4 +51,13 @@
* @return the repository model
*/
RepositoryModel getRepositoryModel();
+
+ /**
+ * Return the model maintaining configuration information about
+ * the available location resolvers.
+ *
+ * @return the layout model
+ */
+ LayoutRegistryModel getLayoutRegistryModel();
+
}
Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
Mon May 30 09:59:27 2005
@@ -23,18 +23,19 @@
import java.io.FileOutputStream;
import java.net.PasswordAuthentication;
import java.util.Date;
-import java.util.logging.Logger;
import java.util.prefs.Preferences;
import junit.framework.TestCase;
import net.dpml.transit.Transit;
+import net.dpml.transit.adapter.LoggingAdapter;
import net.dpml.transit.model.RepositoryModel;
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.RegistryModel;
import net.dpml.transit.model.ProxyChangeEvent;
import net.dpml.transit.model.ProxyExcludesEvent;
import net.dpml.transit.model.ProxyListener;
+import net.dpml.transit.model.Logger;
/**
* @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
@@ -52,8 +53,7 @@
System.setProperty( "dpml.data", path );
Preferences prefs = Preferences.userNodeForPackage( Transit.class );
m_prefs = prefs.node( "test" );
- Logger logger = Logger.getLogger( "test" );
- m_manager = new TransitManager( logger, m_prefs );
+ m_manager = new TransitManager( new LoggingAdapter(), m_prefs );
}
public void tearDown() throws Exception
@@ -200,7 +200,7 @@
{
System.setProperty(
"java.util.logging.config.class",
- "net.dpml.transit.logging.ConfigurationHandler" );
+ "net.dpml.transit.util.ConfigurationHandler" );
}
}
Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
Mon May 30 09:59:27 2005
@@ -22,15 +22,16 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Date;
-import java.util.logging.Logger;
import java.util.prefs.Preferences;
import junit.framework.TestCase;
import net.dpml.transit.Transit;
+import net.dpml.transit.adapter.LoggingAdapter;
import net.dpml.transit.model.RepositoryModel;
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.RegistryModel;
+import net.dpml.transit.model.Logger;
/**
* @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
@@ -48,8 +49,7 @@
System.setProperty( "dpml.data", path );
Preferences prefs = Preferences.userNodeForPackage( Transit.class );
m_prefs = prefs.node( "test" );
- Logger logger = Logger.getLogger( "test" );
- m_manager = new TransitManager( logger, m_prefs );
+ m_manager = new TransitManager( new LoggingAdapter(), m_prefs );
}
public void tearDown() throws Exception
@@ -60,10 +60,10 @@
}
}
- public void testCacheDirectory()
+ public void testCacheDirectory() throws Exception
{
File cache = m_manager.getCacheModel().getCacheDirectory();
- File dir = new File( m_data, "cache" );
+ File dir = new File( m_data, "cache" ).getAbsoluteFile();
assertEquals( "cache", dir, cache );
}
}
Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/test/ArtifactTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/test/ArtifactTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/test/ArtifactTestCase.java
Mon May 30 09:59:27 2005
@@ -19,8 +19,8 @@
package net.dpml.transit.test;
import junit.framework.TestCase;
-import net.dpml.transit.layout.ClassicResolver;
-import net.dpml.transit.layout.LocationResolver;
+import net.dpml.transit.layout.ClassicLayout;
+import net.dpml.transit.layout.Layout;
import net.dpml.transit.artifact.Artifact;
/**
@@ -274,7 +274,7 @@
assertEquals( "version", version, artifact.getVersion() );
assertEquals( "type", type, artifact.getType() );
- LocationResolver resolver = new ClassicResolver();
+ Layout resolver = new ClassicLayout();
String base = group + "/" + type + "s";
assertEquals( "base", base, resolver.resolveBase( artifact ) );
Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
Mon May 30 09:59:27 2005
@@ -22,11 +22,17 @@
import net.dpml.transit.artifact.ArtifactNotFoundException;
import net.dpml.transit.link.Link;
import net.dpml.transit.util.StreamUtils;
+import net.dpml.transit.manager.TransitManager;
+import net.dpml.transit.adapter.LoggingAdapter;
+import net.dpml.transit.Transit;
import java.io.File;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
+import java.util.prefs.Preferences;
+import java.util.logging.Logger;
+import java.util.logging.Level;
/**
*
@@ -35,15 +41,26 @@
*/
public class LinkTestCase extends TestCase
{
+ private static Transit TRANSIT;
+
protected void setUp() throws Exception
{
- System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
- System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.logging.ConfigurationHandler" );
- System.setProperty( "dpml.transit.secured.disable", "true" );
- System.setProperty( "dpml.transit.authority.file",
"target/test/test.authority" );
- String test = System.getProperty( "project.dir" );
- File old = new File( test, "target/test/cache" );
- old.delete();
+ new File( "target/test/cache" ).delete();
+ if( null == TRANSIT )
+ {
+ System.setProperty( "java.protocol.handler.pkgs",
"net.dpml.transit" );
+ System.setProperty( "dpml.transit.secured.disable", "true" );
+ System.setProperty( "java.util.logging.config.class",
+ "net.dpml.transit.util.ConfigurationHandler" );
+ Preferences prefs =
+ Preferences.userNodeForPackage( Transit.class
).node("test").node( "link-test" );
+ URL authority = new File( "target/test" ).toURL();
+ Logger logger = Logger.getLogger( "test" );
+ //logger.setLevel( Level.parse( "FINE" ) );
+ LoggingAdapter adapter = new LoggingAdapter( logger );
+ TransitManager manager = new TransitManager( adapter, prefs,
authority );
+ TRANSIT = Transit.getInstance( manager );
+ }
}
/**
Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/test/OfflineTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/test/OfflineTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/test/OfflineTestCase.java
Mon May 30 09:59:27 2005
@@ -24,12 +24,19 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
-
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.prefs.Preferences;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.Date;
import junit.framework.TestCase;
+import net.dpml.transit.manager.TransitManager;
+import net.dpml.transit.adapter.LoggingAdapter;
+import net.dpml.transit.Transit;
+
/**
* URL Handler TestCase for Offline operations.
*
@@ -38,16 +45,26 @@
*/
public class OfflineTestCase extends TestCase
{
- protected void setUp()
- throws Exception
+ private static Transit TRANSIT;
+
+ protected void setUp() throws Exception
{
- System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
- System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.logging.ConfigurationHandler" );
- System.setProperty( "dpml.transit.secured.disable", "true" );
- System.setProperty( "dpml.transit.authority.file",
"target/test/test.authority" );
- String test = System.getProperty( "project.dir" );
- File old = new File( test, "target/test/cache/" );
- delete( old );
+ new File( "target/test/cache" ).delete();
+ if( null == TRANSIT )
+ {
+ System.setProperty( "java.protocol.handler.pkgs",
"net.dpml.transit" );
+ System.setProperty( "dpml.transit.secured.disable", "true" );
+ System.setProperty( "java.util.logging.config.class",
+ "net.dpml.transit.util.ConfigurationHandler" );
+ Preferences prefs =
+ Preferences.userNodeForPackage( Transit.class
).node("test").node( "offline-test" );
+ URL authority = new File( "target/test" ).toURL();
+ Logger logger = Logger.getLogger( "test" );
+ //logger.setLevel( Level.parse( "FINE" ) );
+ LoggingAdapter adapter = new LoggingAdapter( logger );
+ TransitManager manager = new TransitManager( adapter, prefs,
authority );
+ TRANSIT = Transit.getInstance( manager );
+ }
}
public void testDownloadNoVersion()
@@ -121,7 +138,9 @@
public void testWriteNewArtifact()
throws Exception
{
- URL url = new URL( "artifact:txt:dpml/test/sample" );
+ String name = "" + new Date().getTime();
+ String spec = "artifact:txt:dpml/test/" + name;
+ URL url = new URL( spec );
OutputStream out = url.openConnection().getOutputStream();
for( int i = 65 ; i < 91 ; i++ )
{
@@ -130,7 +149,7 @@
out.write( 10 );
out.close();
- url = new URL( "artifact:txt:dpml/test/sample" );
+ url = new URL( spec );
InputStream in = url.openStream();
StringBuffer result = new StringBuffer();
while( true )
Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/test/OnlineTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/test/OnlineTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/test/OnlineTestCase.java
Mon May 30 09:59:27 2005
@@ -39,7 +39,7 @@
protected void setUp() throws Exception
{
System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
- System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.logging.ConfigurationHandler" );
+ System.setProperty( "java.util.logging.config.class",
"net.dpml.transit.util.ConfigurationHandler" );
}
public void testStackedJarUrl() throws Exception
Added:
development/main/transit/core/handler/src/test/net/dpml/transit/util/ConfigurationHandler.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/util/ConfigurationHandler.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,87 @@
+/*
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Properties;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.prefs.Preferences;
+
+/**
+ * Utility class used to establish the logging configuration for forked
testcases.
+ */
+public class ConfigurationHandler
+{
+ /**
+ * Creation of the logging controller.
+ */
+ public ConfigurationHandler()
+ {
+ this( "INFO" );
+ }
+
+ /**
+ * Creation of the logging controller.
+ */
+ public ConfigurationHandler( String level )
+ {
+ Preferences prefs =
+ Preferences.userNodeForPackage( ConfigurationHandler.class ).node(
"nodes" );
+ String rootLevel = prefs.get( "level", level );
+
+ Properties properties = new Properties();
+ properties.setProperty(
+ "handlers",
+ "java.util.logging.ConsoleHandler" );
+ properties.setProperty(
+ "java.util.logging.ConsoleHandler.formatter",
+ "net.dpml.transit.logging.StandardFormatter" );
+
+ //
+ // set the default level by setting the root logger level
+ //
+
+ properties.setProperty( ".level", rootLevel );
+
+ //
+ // set the level that the console handler will handle
+ //
+
+ properties.setProperty(
+ "java.util.logging.ConsoleHandler.level",
+ "FINEST" );
+
+ try
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ properties.store( out, "DPML Logging properties" );
+ byte[] bytes = out.toByteArray();
+ ByteArrayInputStream input = new ByteArrayInputStream( bytes );
+ LogManager manager = LogManager.getLogManager();
+ manager.readConfiguration( input );
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ }
+ }
+}
Added:
development/main/transit/core/handler/src/test/net/dpml/transit/util/StandardFormatter.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/util/StandardFormatter.java
Mon May 30 09:59:27 2005
@@ -0,0 +1,76 @@
+/*
+ * 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.util;
+
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+import net.dpml.transit.util.ExceptionHelper;
+
+/**
+ * Logging message formatter that includes the category in the logging
statement.
+ */
+public class StandardFormatter extends Formatter
+{
+ private String lineSeparator =
+ (String) java.security.AccessController.doPrivileged(
+ new sun.security.action.GetPropertyAction("line.separator"));
+
+ /**
+ * Format a LogRecord using the classic style.
+ * @param record the log record to be formatted.
+ * @return a formatted log record
+ */
+ public synchronized String format( LogRecord record )
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ String header = getLogHeader( record );
+ buffer.append( header );
+ if( null != record.getLoggerName() )
+ {
+ buffer.append( "(" + record.getLoggerName() + "): " );
+ }
+ else
+ {
+ buffer.append( "() " );
+ }
+ String message = formatMessage( record );
+ buffer.append( message );
+ buffer.append( lineSeparator );
+ if( record.getThrown() != null )
+ {
+ boolean trace = record.getLevel().intValue() > 900;
+ Throwable cause = record.getThrown();
+ String error = ExceptionHelper.packException( cause, trace );
+ buffer.append( error );
+ }
+ return buffer.toString();
+ }
+
+ private String getLogHeader( LogRecord record )
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "[" );
+ buffer.append( record.getLevel().getLocalizedName() );
+ buffer.append( " " );
+ String tag = buffer.toString();
+ return tag.substring( 0, 8 ) + "] ";
+ }
+}
Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/AntAdapter.java
==============================================================================
---
development/main/transit/core/tools/src/main/net/dpml/transit/tools/AntAdapter.java
(original)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/AntAdapter.java
Mon May 30 09:59:27 2005
@@ -22,6 +22,7 @@
import net.dpml.transit.adapter.Adapter;
import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.model.Logger;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
@@ -126,6 +127,11 @@
}
}
+ public Logger getChildLogger( String category )
+ {
+ return this;
+ }
+
/**
* Hnadle download notification.
* @param resource the resource under attention
Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/ImportArtifactTask.java
==============================================================================
---
development/main/transit/core/tools/src/main/net/dpml/transit/tools/ImportArtifactTask.java
(original)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/ImportArtifactTask.java
Mon May 30 09:59:27 2005
@@ -20,6 +20,7 @@
import java.io.File;
import java.net.URL;
+import java.util.prefs.Preferences;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
@@ -28,6 +29,9 @@
import net.dpml.transit.Transit;
import net.dpml.transit.artifact.Handler;
import net.dpml.transit.monitors.Monitor;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.TransitModel;
+import net.dpml.transit.manager.TransitManager;
/**
* Ant task that provides support for the import of build file templates
@@ -44,18 +48,21 @@
public void setProject( Project project )
{
- super.setProject( project );
-
- try
- {
- Transit.getInstance();
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error while initializing Transit";
- throw new BuildException( error, e );
- }
+ super.setProject( project );
+ setTaskName( "import" );
+ try
+ {
+ Logger logger = new AntAdapter( this );
+ Preferences prefs = Preferences.userNodeForPackage(
Transit.class );
+ TransitModel model = new TransitManager( logger, prefs );
+ Transit.getInstance( model );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Internal error while initializing Transit";
+ throw new BuildException( error, e );
+ }
}
//
------------------------------------------------------------------------
Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/MainTask.java
==============================================================================
---
development/main/transit/core/tools/src/main/net/dpml/transit/tools/MainTask.java
(original)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/MainTask.java
Mon May 30 09:59:27 2005
@@ -21,6 +21,9 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ComponentHelper;
@@ -116,7 +119,6 @@
public void execute() throws BuildException
{
Project project = getProject();
-
checkProperties( project );
if( !m_INIT )
{
- svn commit: r2674 - in development/main/transit/core: handler handler/etc/setup/authority handler/etc/setup/authority/hosts handler/etc/test/hosts handler/src/main/net/dpml/io handler/src/main/net/dpml/transit handler/src/main/net/dpml/transit/adapter handler/src/main/net/dpml/transit/artifact handler/src/main/net/dpml/transit/cache handler/src/main/net/dpml/transit/content handler/src/main/net/dpml/transit/event handler/src/main/net/dpml/transit/host handler/src/main/net/dpml/transit/layout handler/src/main/net/dpml/transit/link handler/src/main/net/dpml/transit/logging handler/src/main/net/dpml/transit/manager handler/src/main/net/dpml/transit/model handler/src/test/net/dpml/transit/manager handler/src/test/net/dpml/transit/test handler/src/test/net/dpml/transit/util tools/src/main/net/dpml/transit/tools, mcconnell, 05/29/2005
Archive powered by MHonArc 2.6.24.