notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r1901 - in development/main: metro transit/core/handler/etc/setup/authority transit/core/handler/src/main/net/dpml/transit/artifact
- From: mcconnell AT netcompartner.com
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r1901 - in development/main: metro transit/core/handler/etc/setup/authority transit/core/handler/src/main/net/dpml/transit/artifact
- Date: Fri, 25 Feb 2005 14:54:32 +0100
Author: mcconnell
Date: Fri Feb 25 14:54:32 2005
New Revision: 1901
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ResourceManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/StandardResourceManager.java
Removed:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/CacheHandlerFactory.java
Modified:
development/main/metro/index.xml
development/main/transit/core/handler/etc/setup/authority/transit.properties
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
Log:
Update the transit implementation to enable the introduction of a custom
resource manager that handles CacheHandler establishment (or resolution).
Modified: development/main/metro/index.xml
==============================================================================
--- development/main/metro/index.xml (original)
+++ development/main/metro/index.xml Fri Feb 25 14:54:32 2005
@@ -1016,7 +1016,7 @@
<info>
<group>qdox</group>
<name>qdox</name>
- <version>1.4</version>
+ <version>1.6</version>
<type>jar</type>
</info>
</resource>
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
Fri Feb 25 14:54:32 2005
@@ -1,8 +1,13 @@
+
+# Classname of a custom manager responsible for the establishment
+# of a CacheHandler. If not defied, the default implementation uses
+# the net.dpml.transit.artifact.CacheHandlerFactory class.
+#dpml.transit.authority.resourcemanager.classname=
+
# If true, artifacts that doesn't have a valid checksum will not be loaded
# Not yet implemented.
dpml.transit.authority.checksum.required=false
-
# If true, checksums will only be downloaded from the trusted repository
hosts.
# Not yet implemented.
dpml.authority.checksum.from.trusted=true
@@ -23,5 +28,3 @@
# If true, signatures will only be downloaded from the trusted repository
hosts.
# Not yet implemented.
dpml.transit.authority.signature.from.trusted=true
-
-
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ResourceManager.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ResourceManager.java
Fri Feb 25 14:54:32 2005
@@ -0,0 +1,60 @@
+/*
+ * 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.artifact;
+
+import java.lang.reflect.Constructor;
+
+import java.net.URL;
+import java.util.Properties;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+
+import net.dpml.transit.TransitException;
+import net.dpml.transit.monitors.Monitor;
+import net.dpml.transit.monitors.SystemMonitor;
+
+/**
+ * Interface implemented by a resource manager responsible for the
establishment
+ * of a transit cache handler.
+ */
+public interface ResourceManager
+{
+ /**
+ * The default resource manager classname key.
+ */
+ String TRANSIT_RESOURCE_MANAGER_CLASSNAME_KEY =
+ "dpml.transit.authority.resourcemanager.classname";
+
+ /**
+ * The default resource manager classname key.
+ */
+ String TRANSIT_RESOURCE_MANAGER_CLASSNAME =
+ "net.dpml.transit.artifact.StandardResourceManager";
+
+ /**
+ * Creation of a new cache handler.
+ * @param authorative the authorative base url
+ * @param monitor the internal monitor
+ * @return the cache handler
+ * @exception IOException if an io error occurs
+ * @exception TransitException if a transit system error occurs
+ */
+ CacheHandler createCacheHandler( URL authorative, SystemMonitor monitor )
+ throws TransitException, IOException;
+}
\ No newline at end of file
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
Fri Feb 25 14:54:32 2005
@@ -135,11 +135,6 @@
private URL m_authorativeHost;
/**
- * The set of resource hosts established relative to the authority anchor.
- */
- private ResourceHost[] m_resourceHosts;
-
- /**
* Return the singleton context.
* @return the secure context
*/
@@ -196,10 +191,11 @@
{
URL authorative = establishAuthority( monitor );
monitor.notifyAuthority( authorative );
- CacheHandlerFactory chFactory = new CacheHandlerFactory(
authorative, monitor );
- CacheHandler ch = chFactory.createCacheHandler();
+ Properties props = getTransitProperties( authorative );
+ ResourceManager manager = createResourceManager( props );
+ CacheHandler ch = manager.createCacheHandler( authorative,
monitor );
monitor.notifyCacheHandlerCreation( ch );
- m_CONTEXT = new SecuredTransitContext( authorative, ch );
+ m_CONTEXT = new SecuredTransitContext( authorative, ch, props );
return m_CONTEXT;
}
catch( IOException e )
@@ -209,20 +205,50 @@
}
}
+ /**
+ * 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 props the transit properties
+ * @return the resource manager
+ */
+ private static ResourceManager createResourceManager( Properties props )
throws TransitException
+ {
+ String classname =
+ props.getProperty(
+ ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME_KEY,
+ ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME );
+ try
+ {
+ Class cls = ResourceManager.class.getClassLoader().loadClass(
classname );
+ return (ResourceManager) cls.newInstance();
+ }
+ catch( Throwable e )
+ {
+ String error =
+ "Unable to establish the ResourceManager using the class ["
+ + classname
+ + "].";
+ throw new TransitException( error, e );
+ }
+ }
+
/** This constructor should only be used for the testcases.
* @param authorative the authorative url
* @param hosts the set of hosts
* @param handler the cache handler
* @exception TransitException if a context creation error occurs
*/
- private SecuredTransitContext( URL authorative, CacheHandler handler )
+ private SecuredTransitContext( URL authorative, CacheHandler handler,
Properties props )
throws TransitException
{
m_authorativeHost = authorative;
m_cacheHandler = handler;
try
{
- Properties props = getTransitProperties( authorative );
setupAuthenticator( props );
}
catch( IOException e )
@@ -231,7 +257,7 @@
}
}
- private Properties getTransitProperties( URL authorative ) throws
IOException
+ private static Properties getTransitProperties( URL authorative ) throws
IOException
{
try
{
@@ -240,13 +266,12 @@
}
catch( FileNotFoundException fnfe )
{
- URL url = getClass().getClassLoader().getResource(
+ URL url =
SecuredTransitContext.class.getClassLoader().getResource(
"transit/authority/" + TRANSIT_PROPERTIES_FILENAME );
return Util.readProps( url );
}
}
-
/**
* Return cache handler directory.
*
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/StandardResourceManager.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/StandardResourceManager.java
Fri Feb 25 14:54:32 2005
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2004-2005 Stephen J. McConnell.
+ * Copyright 2004 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.artifact;
+
+import java.lang.reflect.Constructor;
+
+import java.net.URL;
+import java.util.Properties;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+
+import net.dpml.transit.TransitException;
+import net.dpml.transit.monitors.Monitor;
+import net.dpml.transit.monitors.SystemMonitor;
+
+/**
+ * Internal resource manager that establishes a CacheHandler implementation
using
+ * the property 'dpml.transit.cache.class' from the file cache.properties.
+ *
+ * The CacheHandler constructor MUST have the signature of;
+ * <code><pre>
+ * MyCacheHandler( Monitor monitor, ResourceHost[] hosts, Properties
propsm LocationResolver resolve )
+ * </pre></code>
+ * @return the cache handler
+ * @exception IOException if an io error occurs
+ * @exception TransitException if a transit system error occurs
+ */
+public class StandardResourceManager implements ResourceManager
+{
+ //
------------------------------------------------------------------------
+ // static
+ //
------------------------------------------------------------------------
+
+ /**
+ * The cache properties filename.
+ */
+ private static final String TRANSIT_CACHE_PROPERTIES_FILENAME =
"cache.properties";
+
+ /**
+ * The default cache handler classname.
+ */
+ private static final String TRANSIT_CACHE_DEFAULT_HANDLER_CLASSNAME =
+ "net.dpml.transit.artifact.FileCacheHandler";
+
+ /**
+ * The default cache handler classname.
+ */
+ private static final String TRANSIT_CACHE_DEFAULT_RESOLVER_CLASSNAME =
+ "net.dpml.transit.artifact.ClassicResolver";
+
+ //
------------------------------------------------------------------------
+ // implementation
+ //
------------------------------------------------------------------------
+
+ /**
+ * Creation of a new cache handler.
+ * @param authorative the authorative base url
+ * @param monitor the internal monitor
+ * @return the cache handler
+ * @exception IOException if an io error occurs
+ * @exception TransitException if a transit system error occurs
+ */
+ public CacheHandler createCacheHandler( URL authorative, SystemMonitor
monitor )
+ throws TransitException, IOException
+ {
+ ResourceHostFactory factory = new ResourceHostFactory( authorative,
monitor );
+ ResourceHost[] hosts = factory.createResourceHosts();
+
+ Properties props = getCacheProperties( authorative );
+ LocationResolver resolver = createResolver( props );
+
+ String classname =
+ props.getProperty( CacheHandler.CACHE_CLASS_KEY,
TRANSIT_CACHE_DEFAULT_HANDLER_CLASSNAME );
+
+ try
+ {
+ Class cls = getClass().getClassLoader().loadClass( classname );
+ Class[] params = new Class[]{
+ Monitor.class,
+ ResourceHost[].class,
+ Properties.class,
+ LocationResolver.class};
+ Object[] args = new Object[]{
+ monitor,
+ hosts,
+ props,
+ resolver};
+ Constructor cons = cls.getConstructor( params );
+ return (CacheHandler) cons.newInstance( args );
+ }
+ catch( Exception e )
+ {
+ throw new TransitException( "Unable to create CacheHandler: " +
classname, e );
+ }
+ }
+
+ private LocationResolver createResolver( Properties props )
+ {
+ String classname =
+ props.getProperty( CacheHandler.RESOLVER_CLASS_KEY,
TRANSIT_CACHE_DEFAULT_RESOLVER_CLASSNAME );
+ try
+ {
+ Class cls = getClass().getClassLoader().loadClass( classname );
+ return (LocationResolver) cls.newInstance();
+ } catch( Exception e )
+ {
+ // Niclas: Should we throw exception instead???
+ return new ClassicResolver();
+ }
+ }
+
+ private Properties getCacheProperties( URL authorative ) throws
IOException
+ {
+ try
+ {
+ URL url = new URL( authorative,
TRANSIT_CACHE_PROPERTIES_FILENAME );
+ return Util.readProps( url );
+ }
+ catch( FileNotFoundException fnfe )
+ {
+ String resource = "transit/authority/" +
TRANSIT_CACHE_PROPERTIES_FILENAME;
+ ClassLoader classloader = getClass().getClassLoader();
+ URL url = classloader.getResource( resource );
+ return Util.readProps( url );
+ }
+ }
+}
\ No newline at end of file
- svn commit: r1901 - in development/main: metro transit/core/handler/etc/setup/authority transit/core/handler/src/main/net/dpml/transit/artifact, mcconnell, 02/25/2005
Archive powered by MHonArc 2.6.24.