You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by cz...@apache.org on 2001/11/16 15:55:08 UTC
cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source SourceResolverImpl.java
cziegeler 01/11/16 06:55:08
Modified: src/scratchpad/org/apache/avalon/excalibur/source
SourceResolverImpl.java
Log:
Use a ComponentSelector to get a SourceFactory instead of using a configuration on the SourceResolver
Revision Changes Path
1.6 +15 -67 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SourceResolverImpl.java 2001/11/14 15:58:03 1.5
+++ SourceResolverImpl.java 2001/11/16 14:55:08 1.6
@@ -12,6 +12,7 @@
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -27,13 +28,10 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
/**
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version $Id: SourceResolverImpl.java,v 1.5 2001/11/14 15:58:03 cziegeler Exp $
+ * @version $Id: SourceResolverImpl.java,v 1.6 2001/11/16 14:55:08 cziegeler Exp $
*/
public class SourceResolverImpl
extends AbstractLoggable
@@ -43,7 +41,7 @@
protected ComponentManager manager;
/** The special Source factories */
- protected Map sourceFactories;
+ protected ComponentSelector factorySelector;
/** The context */
protected Context context;
@@ -64,34 +62,6 @@
} catch (MalformedURLException mue) {
throw new ConfigurationException("Malformed URL for user.dir");
}
-
- // get the configured factories
- try {
- getLogger().debug("Getting the SourceFactories");
- HashMap factories = new HashMap();
- Configuration[] configs = conf.getChildren("protocol");
- SourceFactory sourceFactory = null;
- String protocol = null;
- for (int i = 0; i < configs.length; i++) {
- protocol = configs[i].getAttribute("name");
- if (factories.containsKey(protocol) == true) {
- throw new ConfigurationException("SourceFactory defined twice for protocol: " + protocol);
- }
-
- getLogger().debug("\tfor protocol: " + protocol + " " + configs[i].getAttribute("class"));
-
- sourceFactory = (SourceFactory) Class.forName(configs[i].getAttribute("class")).newInstance();
- this.init(sourceFactory);
- factories.put(protocol, sourceFactory);
- }
- this.sourceFactories = java.util.Collections.synchronizedMap(factories);
- } catch (ConfigurationException e) {
- throw e;
- } catch (Exception e) {
- getLogger().error("Could not get SourceFactories", e);
- throw new ConfigurationException("Could not get parameters because: " +
- e.getMessage());
- }
}
/**
@@ -109,19 +79,17 @@
public void compose(ComponentManager manager)
throws ComponentException {
this.manager = manager;
+ this.factorySelector = (ComponentSelector)this.manager.lookup(SourceFactory.ROLE + "Selector");
}
/**
* Dispose
*/
public void dispose() {
- Iterator iter = this.sourceFactories.values().iterator();
- SourceFactory current;
- while (iter.hasNext() == true) {
- current = (SourceFactory) iter.next();
- this.deinit(current);
+ if (this.manager != null) {
+ this.manager.release(this.factorySelector);
+ this.factorySelector = null;
}
- this.sourceFactories = null;
}
/**
@@ -214,9 +182,14 @@
final int protocolPos = systemID.indexOf(':');
if ( protocolPos != -1 ) {
final String protocol = systemID.substring(0, protocolPos);
- final SourceFactory factory = ( SourceFactory )this.sourceFactories.get( protocol );
- if (factory != null) {
- source = factory.getSource( systemID, parameters );
+ if ( this.factorySelector.hasComponent(protocol) ) {
+ SourceFactory factory = null;
+ try {
+ factory = ( SourceFactory )this.factorySelector.select( protocol );
+ source = factory.getSource( systemID, parameters );
+ } finally {
+ this.factorySelector.release( factory );
+ }
}
}
@@ -258,31 +231,6 @@
}
if ( source instanceof Disposable ) {
((Disposable) source).dispose();
- }
- }
-
- /**
- * Init a source factory
- */
- private void init(SourceFactory factory)
- throws ContextException, ComponentException {
- if (factory instanceof Loggable) {
- ((Loggable) factory).setLogger(getLogger());
- }
- if (factory instanceof Contextualizable) {
- ((Contextualizable) factory).contextualize (this.context);
- }
- if (factory instanceof Composable) {
- ((Composable) factory).compose(this.manager);
- }
- }
-
- /**
- * Deinit a source factory
- */
- private void deinit(SourceFactory factory) {
- if (factory instanceof Disposable) {
- ((Disposable) factory).dispose();
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>