Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 38886 invoked from network); 7 Jan 2002 08:58:15 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 7 Jan 2002 08:58:15 -0000 Received: (qmail 4895 invoked by uid 97); 7 Jan 2002 08:58:15 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 4566 invoked by uid 97); 7 Jan 2002 08:58:12 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 4239 invoked by uid 97); 7 Jan 2002 08:58:09 -0000 Date: 7 Jan 2002 08:57:56 -0000 Message-ID: <20020107085756.46975.qmail@icarus.apache.org> From: cziegeler@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source SourceResolverImpl.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N cziegeler 02/01/07 00:57:56 Modified: src/scratchpad/org/apache/avalon/excalibur/source SourceResolverImpl.java Log: Make SourceResolve recyclable instead of threadsafe Revision Changes Path 1.11 +107 -47 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolverImpl.java Index: SourceResolverImpl.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolverImpl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SourceResolverImpl.java 27 Dec 2001 15:05:47 -0000 1.10 +++ SourceResolverImpl.java 7 Jan 2002 08:57:56 -0000 1.11 @@ -22,7 +22,6 @@ import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.LogEnabled; -import org.apache.avalon.framework.thread.ThreadSafe; import java.io.File; import java.io.IOException; @@ -46,7 +45,7 @@ * and releasing them. * * @author Carsten Ziegeler - * @version $Id: SourceResolverImpl.java,v 1.10 2001/12/27 15:05:47 cziegeler Exp $ + * @version $Id: SourceResolverImpl.java,v 1.11 2002/01/07 08:57:56 cziegeler Exp $ */ public class SourceResolverImpl extends AbstractLogEnabled @@ -55,7 +54,7 @@ Contextualizable, Disposable, SourceResolver, - ThreadSafe + Recyclable { /** The component manager */ @@ -73,27 +72,37 @@ protected URL baseURL; /** + * The user directory + */ + protected URL userDirectory; + + /** * Configure the SourceFactories */ public void configure(final Configuration conf) - throws ConfigurationException { + throws ConfigurationException + { // set the base URL to the current directory - try { - this.baseURL = new File(System.getProperty("user.dir")).toURL(); + try + { + this.userDirectory = new File(System.getProperty("user.dir")).toURL(); if ( this.getLogger().isDebugEnabled() ) { - this.getLogger().debug("SourceResolver: Using base directory: " + this.baseURL); + this.getLogger().debug("SourceResolver: Using base directory: " + this.userDirectory); } - } catch (MalformedURLException mue) { + } catch (MalformedURLException mue) + { throw new ConfigurationException("Malformed URL for user.dir"); } + this.baseURL = this.userDirectory; } /** * Get the context */ public void contextualize(Context context) - throws ContextException { + throws ContextException + { this.context = context; } @@ -102,7 +111,8 @@ * Composable. */ public void compose(ComponentManager manager) - throws ComponentException { + throws ComponentException + { this.manager = manager; this.factorySelector = (ComponentSelector)this.manager.lookup(SourceFactory.ROLE + "Selector"); } @@ -110,19 +120,30 @@ /** * Dispose */ - public void dispose() { - if (this.manager != null) { + public void dispose() + { + if (this.manager != null) + { this.manager.release(this.factorySelector); this.factorySelector = null; } } /** + * Recycle: reset the base dir + */ + public void recycle() + { + this.baseURL = this.userDirectory; + } + + /** * Set the base URL. All relative references are resolved * according to this URL. */ - public void setBaseURL(URL base) { - if (this.getLogger().isDebugEnabled() == true) { + public void setBaseURL(URL base) + { + if ( this.getLogger().isDebugEnabled() ) { this.getLogger().debug("Changing baseURL to: " + base); } this.baseURL = base; @@ -131,7 +152,8 @@ /** * Get the base URL */ - public URL getBaseURL() { + public URL getBaseURL() + { return this.baseURL; } @@ -139,7 +161,8 @@ * Get a Source object. */ public Source resolve(String location) - throws MalformedURLException, IOException, ComponentException { + throws MalformedURLException, IOException, ComponentException + { return this.resolve(this.baseURL, location, null); } @@ -148,15 +171,17 @@ */ public Source resolve(String location, SourceParameters parameters) - throws MalformedURLException, IOException, ComponentException { - return this.resolve(this.baseURL, location, parameters); + throws MalformedURLException, IOException, ComponentException + { + return this.resolve( this.baseURL, location, parameters ); } /** * Get a Source object. */ public Source resolve(URL base, String location) - throws MalformedURLException, IOException, ComponentException { + throws MalformedURLException, IOException, ComponentException + { return this.resolve(base, location, null); } @@ -167,8 +192,9 @@ public Source resolve(URL base, String location, SourceParameters parameters) - throws MalformedURLException, IOException, ComponentException { - if (this.getLogger().isDebugEnabled() == true) { + throws MalformedURLException, IOException, ComponentException + { + if ( this.getLogger().isDebugEnabled() ) { this.getLogger().debug("Resolving '"+location+"' in context '" + base + "'"); } if (location == null) throw new MalformedURLException("Invalid System ID"); @@ -179,76 +205,107 @@ if (location.length() == 0) { systemID = base.toExternalForm(); - } else if (location.indexOf(":") > 1) { + } else if (location.indexOf(":") > 1) + { systemID = location; - } else if (location.charAt(0) == '/') { + } + else if (location.charAt(0) == '/') + { systemID = new StringBuffer(base.getProtocol()) .append(":").append(location).toString(); // windows: absolute paths can start with drive letter - } else if (location.length() > 1 && location.charAt(1) == ':') { + } + else if (location.length() > 1 && location.charAt(1) == ':') + { systemID = new StringBuffer(base.getProtocol()) .append(":/").append(location).toString(); - } else { - if (base.getProtocol().equals("file") == true) { + } + else + { + if (base.getProtocol().equals("file") == true) + { File temp = new File(base.toExternalForm().substring("file:".length()), location); String path = temp.getAbsolutePath(); // windows paths starts with drive letter - if (path.charAt(0) != File.separator.charAt(0)) { + if (path.charAt(0) != File.separator.charAt(0)) + { systemID = "file:/" + path; - } else { + } + else + { systemID = "file:" + path; } - } else { + } + else + { systemID = new URL(base, location).toExternalForm(); } } - if (this.getLogger().isDebugEnabled() == true) { + if ( this.getLogger().isDebugEnabled() ) + { this.getLogger().debug("Resolved to systemID '"+systemID+"'"); } Source source = null; // search for a SourceFactory implementing the protocol final int protocolPos = systemID.indexOf(':'); - if ( protocolPos != -1 ) { + if ( protocolPos != -1 ) + { final String protocol = systemID.substring(0, protocolPos); - if ( this.factorySelector.hasComponent(protocol) ) { + if ( this.factorySelector.hasComponent(protocol) ) + { SourceFactory factory = null; - try { + try + { factory = ( SourceFactory )this.factorySelector.select( protocol ); source = factory.getSource( systemID, parameters ); - } finally { + } + finally + { this.factorySelector.release( factory ); } } } - if ( source == null ) { + if ( null == source ) + { // no factory found, so usual url handling stuff... - try { - if (this.getLogger().isDebugEnabled() == true) { + try + { + if (this.getLogger().isDebugEnabled() == true) + { getLogger().debug("Making URL from " + systemID); } source = new URLSource(new URL(systemID), parameters); - } catch (MalformedURLException mue) { - if (this.getLogger().isDebugEnabled() == true) { + } + catch (MalformedURLException mue) + { + if ( this.getLogger().isDebugEnabled() ) + { getLogger().debug("Making URL - MalformedURLException in getURL:" , mue); getLogger().debug("Making URL a File (assuming that it is full path):" + systemID); } source = new URLSource((new File(systemID)).toURL(), parameters); } } - if (source instanceof LogEnabled) { + if (source instanceof LogEnabled) + { ((LogEnabled) source).enableLogging(getLogger()); } - try { - if (source instanceof Contextualizable) { + try + { + if (source instanceof Contextualizable) + { ((Contextualizable) source).contextualize (this.context); } - } catch (ContextException ce) { + } + catch (ContextException ce) + { throw new ComponentException("ContextException occured during source resolving.", ce); } - if (source instanceof Composable) { + if (source instanceof Composable) + { ((Composable) source).compose(this.manager); } return source; @@ -257,12 +314,15 @@ /** * Releases a resolved resource */ - public void release( Source source ) { + public void release( Source source ) + { if ( source == null) return; - if ( source instanceof Recyclable ) { + if ( source instanceof Recyclable ) + { ((Recyclable)source).recycle(); } - if ( source instanceof Disposable ) { + if ( source instanceof Disposable ) + { ((Disposable) source).dispose(); } } -- To unsubscribe, e-mail: For additional commands, e-mail: