notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r1808 - in development/main/home/transit/handler: etc/setup/authority src/main/net/dpml/transit/artifact
- From: niclas AT netcompartner.com
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r1808 - in development/main/home/transit/handler: etc/setup/authority src/main/net/dpml/transit/artifact
- Date: Fri, 18 Feb 2005 10:16:47 +0100
Author: niclas
Date: Fri Feb 18 10:16:47 2005
New Revision: 1808
Added:
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/ClassicResolver.java
(contents, props changed)
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/LocationResolver.java
(contents, props changed)
Modified:
development/main/home/transit/handler/etc/setup/authority/cache.properties
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/Artifact.java
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/CacheHandler.java
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/CacheHandlerFactory.java
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
Log:
Added a LocationResolver system, so we can decouple the layout from the
artifact.
Modified:
development/main/home/transit/handler/etc/setup/authority/cache.properties
==============================================================================
---
development/main/home/transit/handler/etc/setup/authority/cache.properties
(original)
+++
development/main/home/transit/handler/etc/setup/authority/cache.properties
Fri Feb 18 10:16:47 2005
@@ -4,3 +4,4 @@
# The class that implements the cache handler
dpml.transit.cache.class=net.dpml.transit.artifact.FileCacheHandler
+dpml.transit.cache.locationresolver.class=net.dpml.transit.artifact.ClassicResolver
Modified:
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/Artifact.java
==============================================================================
---
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/Artifact.java
(original)
+++
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/Artifact.java
Fri Feb 18 10:16:47 2005
@@ -311,8 +311,8 @@
return ver;
}
}
-
- /**
+/*
+ **
* Return the base path for this artifact. The base path is derived from
* the artifact group and type. For an artifact group of "metro/cache"
and a
* type equal to "jar", the base value will be translated using the
pattern
@@ -321,13 +321,13 @@
* this artifact.
*
* @return the base path
- */
+ *
public final String getBase()
{
return getGroup() + "/" + getType() + "s";
}
- /**
+ **
* Returns the full path of the artifact relative to a logical root
directory.
* The full path is equivalent to the base path and artifact filename
using the
* pattern "[base]/[filename]". Path values may be used to resolve an
artifact
@@ -338,18 +338,18 @@
* @see #getBase
* @see #getFilename
* @return the logical artifact path
- */
+ *
public final String getPath()
{
return getBase() + "/" + getFilename();
}
- /**
+ **
* Return the expanded filename of the artifact. The filename is
expressed
* as [name]-[version].[type] or in case of a null version simply
[name].[type].
*
* @return the artifact expanded filename
- */
+ *
public String getFilename()
{
String ver = getVersion();
@@ -362,7 +362,7 @@
return m_name + "-" + ver + "." + m_type;
}
}
-
+*/
/**
* Create an artifact url backed by the repository.
*
Modified:
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/CacheHandler.java
==============================================================================
---
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/CacheHandler.java
(original)
+++
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/CacheHandler.java
Fri Feb 18 10:16:47 2005
@@ -26,7 +26,7 @@
import net.dpml.transit.TransitException;
/**
- * The CacheHandler interface defines the contract for classes capable of
+ * The CacheHandler interface defines the contract for classes capable of
* supporting the cache mentement aspects of a transit system. Cache
management
* encompasses the retreval of resources based on artifact identifiers.
Cache
* manager implementations may provide varying levels of quality-of-services.
@@ -38,7 +38,7 @@
/**
* The domain identifier.
*/
- static final String DOMAIN = SecuredTransitContext.DOMAIN;
+ static final String DOMAIN = SecuredTransitContext.DOMAIN;
/**
* Cache property key.
@@ -50,6 +50,11 @@
*/
static final String CACHE_CLASS_KEY = DOMAIN + ".cache.class";
+ /**
+ * Cache location resolver classname key.
+ */
+ static final String RESOLVER_CLASS_KEY = DOMAIN +
".cache.locationresolver.class";
+
/**
* Return a set of features describing the implementation. Keys
* and values may be implementation dependent.
Modified:
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/CacheHandlerFactory.java
==============================================================================
---
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/CacheHandlerFactory.java
(original)
+++
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/CacheHandlerFactory.java
Fri Feb 18 10:16:47 2005
@@ -49,6 +49,12 @@
static final String TRANSIT_CACHE_DEFAULT_HANDLER_CLASSNAME =
"net.dpml.transit.artifact.FileCacheHandler";
+ /**
+ * The default cache handler classname.
+ */
+ static final String TRANSIT_CACHE_DEFAULT_RESOLVER_CLASSNAME =
+ "net.dpml.transit.artifact.ClassicResolver";
+
//
------------------------------------------------------------------------
// state
//
------------------------------------------------------------------------
@@ -96,6 +102,7 @@
throws TransitException, IOException
{
Properties props = getCacheProperties();
+ LocationResolver resolver = createResolver( props );
String classname =
props.getProperty( CacheHandler.CACHE_CLASS_KEY,
TRANSIT_CACHE_DEFAULT_HANDLER_CLASSNAME );
@@ -106,13 +113,15 @@
{
Monitor.class,
ResourceHost[].class,
- Properties.class
+ Properties.class,
+ LocationResolver.class
};
Object[] args = new Object[]
{
m_monitor,
hosts,
- props
+ props,
+ resolver
};
Constructor cons = cls.getConstructor( params );
return (CacheHandler) cons.newInstance( args );
@@ -123,6 +132,21 @@
}
}
+ 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() throws IOException
{
try
@@ -132,8 +156,9 @@
}
catch( FileNotFoundException fnfe )
{
- URL url = getClass().getClassLoader().getResource(
- "transit/authority/" + TRANSIT_CACHE_PROPERTIES_FILENAME );
+ String resource = "transit/authority/" +
TRANSIT_CACHE_PROPERTIES_FILENAME;
+ ClassLoader classloader = getClass().getClassLoader();
+ URL url = classloader.getResource( resource );
return Util.readProps( url );
}
}
Added:
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/ClassicResolver.java
==============================================================================
--- (empty file)
+++
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/ClassicResolver.java
Fri Feb 18 10:16:47 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2004 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;
+
+/** The ClassicResolver 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;
+ * <code>[group]/[type]s/[name]-[version].[type]</code>.
+ * 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
+{
+ /**
+ * Return the base path for an artifact. The base path is derived from
+ * the artifact group and type. For an artifact group of "metro/cache"
and a
+ * type equal to "jar", the base value will be translated using the
pattern
+ * "[group]/[type]s" to form "metro/cache/jars". The base path value
represents
+ * the directory path relative to a repository root of the directory
containing
+ * this artifact.
+ *
+ * @return the base path
+ */
+ public final String resolveBase( Artifact artifact )
+ {
+ return artifact.getGroup() + "/" + artifact.getType() + "s";
+ }
+
+ /**
+ * Returns the full path of the artifact relative to a logical root
directory.
+ * The full path is equivalent to the base path and artifact filename
using the
+ * pattern "[base]/[filename]". Path values may be used to resolve an
artifact
+ * from a remote repository or local cache relative to the repository or
cache
+ * root. An artifact such as
<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>.
+ *
+ * @see #getBase
+ * @see #getFilename
+ * @return the logical artifact path
+ */
+ public final String resolvePath( Artifact artifact )
+ {
+ return resolveBase( artifact ) + "/" + resolveFilename( artifact );
+ }
+
+ /**
+ * Return the expanded filename of the artifact. The filename is
expressed
+ * as [name]-[version].[type] or in case of a null version simply
[name].[type].
+ *
+ * @return the artifact expanded filename
+ */
+ public String resolveFilename( Artifact artifact )
+ {
+ String ver = artifact.getVersion();
+ if( null == ver )
+ {
+ return artifact.getName() + "." + artifact.getType();
+ }
+ else
+ {
+ return artifact.getName() + "-" + ver + "." + artifact.getType();
+ }
+ }
+
+}
Modified:
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
==============================================================================
---
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
(original)
+++
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
Fri Feb 18 10:16:47 2005
@@ -122,6 +122,8 @@
*/
private WeakHashMap m_connections;
+ private LocationResolver m_resolver;
+
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
@@ -148,6 +150,7 @@
boolean enabled, boolean trusted, String username, String password,
String scheme, String prompt )
throws UnknownHostException
{
+ m_resolver = new ClassicResolver();
m_locks = new HashMap();
m_connections = new WeakHashMap();
m_baseUrl = base;
@@ -200,7 +203,7 @@
return m_baseUrl.getHost();
}
- /**
+ /**
* Returns the full host url.
*
* @return the host url
@@ -476,7 +479,7 @@
private URL createRemoteUrl( Artifact artifact )
throws MalformedURLException
{
- String path = artifact.getPath();
+ String path = m_resolver.resolvePath( artifact );
URL url = new URL( m_baseUrl, path );
return url;
}
Modified:
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
==============================================================================
---
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
(original)
+++
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
Fri Feb 18 10:16:47 2005
@@ -55,6 +55,8 @@
*/
private TreeMap m_resourceHosts;
+ private LocationResolver m_resolver;
+
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
@@ -65,8 +67,9 @@
* @param hosts the assigned hosts
* @param props the properties against which this instance will be
configured
*/
- public FileCacheHandler( Monitor monitor, ResourceHost[] hosts,
Properties props )
+ public FileCacheHandler( Monitor monitor, ResourceHost[] hosts,
Properties props, LocationResolver resolver )
{
+ m_resolver = resolver;
m_resourceHosts = new TreeMap();
for( int i=0; i < hosts.length; i++ )
{
@@ -134,7 +137,7 @@
monitor.resourceRequested( artifact );
}
- String path = artifact.getPath();
+ String path = m_resolver.resolvePath( artifact );
File destination = new File( m_cacheDir, path );
boolean exist = destination.exists();
Added:
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/LocationResolver.java
==============================================================================
--- (empty file)
+++
development/main/home/transit/handler/src/main/net/dpml/transit/artifact/LocationResolver.java
Fri Feb 18 10:16:47 2005
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+/** The LocationResolver abstracts the decoding process of the location
+ * of artifacts in various filesystems.
+ */
+public interface LocationResolver
+{
+ /**
+ * Return the base path for an artifact. The base path is the location
+ * where the file will be found. The base + "/" filename is equal to the
+ * full path.
+ *
+ * @param artifact the Artifact to resolve.
+ * @return the base path
+ */
+ String resolveBase( Artifact artifact );
+
+ /**
+ * Returns the full path of the artifact relative to a logical root
directory.
+ * The base + "/" filename is equal to the full path.
+ *
+ * @see #getBase
+ * @see #getFilename
+ * @param artifact the Artifact to resolve.
+ * @return the logical artifact path
+ */
+ String resolvePath( Artifact artifact );
+
+ /**
+ * Return the filename for an artifact. The base + "/" filename is equal
+ * to the full path.
+ *
+ * @see #resolveBase
+ * @see #resolveFilename
+ * @param artifact the Artifact to resolve.
+ * @return the logical artifact path
+ */
+ String resolveFilename( Artifact artifact );
+}
- svn commit: r1808 - in development/main/home/transit/handler: etc/setup/authority src/main/net/dpml/transit/artifact, niclas, 02/18/2005
Archive powered by MHonArc 2.6.24.