bruno 2003/07/16 07:00:30
Modified: src/blocks/woody/java/org/apache/cocoon/woody/acting AbstractWoodyAction.java HandleFormSubmitAction.java MakeFormAction.java src/blocks/woody/java/org/apache/cocoon/woody/datatype DefaultDatatypeManager.java DynamicSelectionList.java src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl AbstractDatatypeBuilder.java src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl AbstractValidationRuleBuilder.java src/blocks/woody/java/org/apache/cocoon/woody/formmodel AbstractWidgetDefinitionBuilder.java AggregateFieldDefinitionBuilder.java FormDefinitionBuilder.java RepeaterDefinitionBuilder.java src/blocks/woody/java/org/apache/cocoon/woody/util SimpleServiceSelector.java Log: use Serviceable instead of Composable, do some extra disposing here and there Revision Changes Path 1.3 +10 -12 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/AbstractWoodyAction.java Index: AbstractWoodyAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/AbstractWoodyAction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractWoodyAction.java 4 Jul 2003 12:50:11 -0000 1.2 +++ AbstractWoodyAction.java 16 Jul 2003 13:59:06 -0000 1.3 @@ -53,31 +53,29 @@ import org.apache.cocoon.woody.FormManager; import org.apache.cocoon.acting.Action; import org.apache.avalon.framework.activity.Disposable; -import org.apache.avalon.framework.component.Component; -import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.ComponentException; -import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.thread.ThreadSafe; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.ServiceException; /** * Abstract base class for Woody actions. */ public abstract class AbstractWoodyAction - implements Action, ThreadSafe, Composable, Disposable { + implements Action, ThreadSafe, Serviceable, Disposable { - protected ComponentManager manager; + protected ServiceManager manager; protected FormManager formManager; - public void compose(ComponentManager componentManager) - throws ComponentException { - this.manager = componentManager; - this.formManager = (FormManager)componentManager.lookup(FormManager.ROLE); + public void service(ServiceManager serviceManager) throws ServiceException { + this.manager = serviceManager; + this.formManager = (FormManager)serviceManager.lookup(FormManager.ROLE); } - + public void dispose() { if ( this.manager != null ) { - this.manager.release( (Component)this.formManager ); + this.manager.release( this.formManager ); this.manager = null; this.formManager = null; } 1.6 +1 -2 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/HandleFormSubmitAction.java Index: HandleFormSubmitAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/HandleFormSubmitAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HandleFormSubmitAction.java 8 Jul 2003 14:04:41 -0000 1.5 +++ HandleFormSubmitAction.java 16 Jul 2003 13:59:12 -0000 1.6 @@ -52,7 +52,6 @@ import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.avalon.framework.parameters.Parameters; -import org.apache.avalon.framework.component.Composable; import org.apache.cocoon.acting.Action; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.SourceResolver; @@ -79,7 +78,7 @@ * <li><strong>attribute-name</strong>: name of the request attribute in which the form instance should be stored * </ul> */ -public class HandleFormSubmitAction extends AbstractWoodyAction implements Action, ThreadSafe, Composable { +public class HandleFormSubmitAction extends AbstractWoodyAction implements Action, ThreadSafe { public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception { 1.5 +6 -6 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/MakeFormAction.java Index: MakeFormAction.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/MakeFormAction.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MakeFormAction.java 8 Jul 2003 14:04:41 -0000 1.4 +++ MakeFormAction.java 16 Jul 2003 13:59:12 -0000 1.5 @@ -60,9 +60,9 @@ import org.apache.excalibur.source.Source; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.avalon.framework.parameters.Parameters; -import org.apache.avalon.framework.component.Composable; -import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.ComponentException; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.ServiceException; import java.util.Map; @@ -75,12 +75,12 @@ * <li><strong>attribute-name</strong>: name of the request attribute in which to store the form instance * </ul> */ -public class MakeFormAction implements Action, ThreadSafe, Composable { +public class MakeFormAction implements Action, ThreadSafe, Serviceable { FormManager formManager; - public void compose(ComponentManager componentManager) throws ComponentException { - formManager = (FormManager)componentManager.lookup(FormManager.ROLE); + public void service(ServiceManager serviceManager) throws ServiceException { + formManager = (FormManager)serviceManager.lookup(FormManager.ROLE); } public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) 1.5 +15 -13 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DefaultDatatypeManager.java Index: DefaultDatatypeManager.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DefaultDatatypeManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DefaultDatatypeManager.java 15 Jul 2003 17:00:32 -0000 1.4 +++ DefaultDatatypeManager.java 16 Jul 2003 13:59:18 -0000 1.5 @@ -51,24 +51,20 @@ package org.apache.cocoon.woody.datatype; import org.apache.avalon.framework.thread.ThreadSafe; -import org.apache.avalon.framework.component.Composable; -import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.CascadingException; import org.apache.cocoon.woody.util.DomHelper; import org.apache.cocoon.woody.util.SimpleServiceSelector; -import org.apache.cocoon.components.LifecycleHelper; import org.w3c.dom.Element; -import java.util.Map; -import java.util.HashMap; - /** * Implementation of the [EMAIL PROTECTED] DatatypeManager} component. * @@ -78,27 +74,28 @@ * become externally configurable in the future. * */ -public class DefaultDatatypeManager extends AbstractLogEnabled implements DatatypeManager, ThreadSafe, Composable, Configurable, Initializable { +public class DefaultDatatypeManager extends AbstractLogEnabled implements DatatypeManager, ThreadSafe, Serviceable, + Configurable, Initializable, Disposable { private SimpleServiceSelector typeBuilderSelector; private SimpleServiceSelector validationRuleBuilderSelector; - private ComponentManager componentManager; + private ServiceManager serviceManager; private Configuration configuration; public void configure(Configuration configuration) throws ConfigurationException { this.configuration = configuration; } - public void compose(ComponentManager componentManager) throws ComponentException { - this.componentManager = componentManager; + public void service(ServiceManager serviceManager) throws ServiceException { + this.serviceManager = serviceManager; } public void initialize() throws Exception { typeBuilderSelector = new SimpleServiceSelector("datatype", DatatypeBuilder.class); - typeBuilderSelector.compose(componentManager); + typeBuilderSelector.service(serviceManager); typeBuilderSelector.configure(configuration.getChild("datatypes")); validationRuleBuilderSelector = new SimpleServiceSelector("validation-rule", ValidationRuleBuilder.class); - validationRuleBuilderSelector.compose(componentManager); + validationRuleBuilderSelector.service(serviceManager); validationRuleBuilderSelector.configure(configuration.getChild("validation-rules")); configuration = null; @@ -124,5 +121,10 @@ throw new CascadingException("Unknown validation rule \"" + name + "\" specified at " + DomHelper.getLocation(validationRuleElement), e); } return builder.build(validationRuleElement); + } + + public void dispose() { + typeBuilderSelector.dispose(); + validationRuleBuilderSelector.dispose(); } } 1.3 +6 -6 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DynamicSelectionList.java Index: DynamicSelectionList.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DynamicSelectionList.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DynamicSelectionList.java 15 Jul 2003 14:11:03 -0000 1.2 +++ DynamicSelectionList.java 16 Jul 2003 13:59:18 -0000 1.3 @@ -53,7 +53,7 @@ import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.Attributes; -import org.apache.avalon.framework.component.ComponentManager; +import org.apache.avalon.framework.service.ServiceManager; import org.apache.excalibur.source.SourceResolver; import org.apache.excalibur.source.Source; import org.apache.cocoon.components.source.SourceUtil; @@ -77,12 +77,12 @@ public class DynamicSelectionList implements SelectionList { private String src; private Datatype datatype; - private ComponentManager componentManager; + private ServiceManager serviceManager; - public DynamicSelectionList(Datatype datatype, String src, ComponentManager componentManager) { + public DynamicSelectionList(Datatype datatype, String src, ServiceManager serviceManager) { this.datatype = datatype; this.src = src; - this.componentManager = componentManager; + this.serviceManager = serviceManager; } public Datatype getDatatype() { @@ -93,7 +93,7 @@ SourceResolver sourceResolver = null; Source source = null; try { - sourceResolver = (SourceResolver)componentManager.lookup(SourceResolver.ROLE); + sourceResolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE); source = sourceResolver.resolveURI(src); SelectionListHandler handler = new SelectionListHandler(locale); handler.setContentHandler(contentHandler); @@ -104,7 +104,7 @@ if (sourceResolver != null) { if (source != null) try { sourceResolver.release(source); } catch (Exception e) {} - componentManager.release(sourceResolver); + serviceManager.release(sourceResolver); } } } 1.6 +10 -11 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/AbstractDatatypeBuilder.java Index: AbstractDatatypeBuilder.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/AbstractDatatypeBuilder.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AbstractDatatypeBuilder.java 15 Jul 2003 15:13:00 -0000 1.5 +++ AbstractDatatypeBuilder.java 16 Jul 2003 13:59:18 -0000 1.6 @@ -56,13 +56,12 @@ import org.apache.cocoon.woody.util.DomHelper; import org.apache.cocoon.woody.util.SimpleServiceSelector; import org.apache.cocoon.woody.Constants; -import org.apache.avalon.framework.component.Composable; -import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceManager; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceResolver; import org.w3c.dom.Element; @@ -75,14 +74,14 @@ * Abstract base class for datatype builders, most concrete datatype builders * will derive from this class. */ -public abstract class AbstractDatatypeBuilder implements DatatypeBuilder, Composable, Configurable { - protected ComponentManager componentManager; +public abstract class AbstractDatatypeBuilder implements DatatypeBuilder, Serviceable, Configurable { + protected ServiceManager serviceManager; private SimpleServiceSelector convertorBuilders; private String defaultConvertorHint; private Convertor plainConvertor; - public void compose(ComponentManager componentManager) throws ComponentException { - this.componentManager = componentManager; + public void service(ServiceManager serviceManager) throws ServiceException { + this.serviceManager = serviceManager; } public void configure(Configuration configuration) throws ConfigurationException { @@ -127,14 +126,14 @@ return plainConvertor; } - protected Source resolve(String src) throws ComponentException, IOException { + protected Source resolve(String src) throws IOException, ServiceException { SourceResolver resolver = null; try { - resolver = (SourceResolver)componentManager.lookup(SourceResolver.ROLE); + resolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE); return resolver.resolveURI(src); } finally { if (resolver != null) - componentManager.release(resolver); + serviceManager.release(resolver); } } @@ -149,7 +148,7 @@ selectionListElement = readSelectionList(src); selectionList = SelectionListBuilder.build(selectionListElement, datatype); } else { - selectionList = new DynamicSelectionList(datatype, src, componentManager); + selectionList = new DynamicSelectionList(datatype, src, serviceManager); } } else { // selection list is defined inline 1.2 +13 -6 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/AbstractValidationRuleBuilder.java Index: AbstractValidationRuleBuilder.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/AbstractValidationRuleBuilder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractValidationRuleBuilder.java 22 Apr 2003 12:04:19 -0000 1.1 +++ AbstractValidationRuleBuilder.java 16 Jul 2003 13:59:28 -0000 1.2 @@ -55,9 +55,10 @@ import org.apache.cocoon.woody.Constants; import org.apache.cocoon.woody.expression.ExpressionManager; import org.apache.avalon.framework.CascadingException; -import org.apache.avalon.framework.component.Composable; -import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.ComponentException; +import org.apache.avalon.framework.activity.Disposable; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.ServiceException; import org.w3c.dom.Element; import org.outerj.expression.Expression; import org.outerj.expression.TokenMgrError; @@ -65,11 +66,13 @@ /** * Abstract base class for ValidationRuleBuilder implementations. */ -public abstract class AbstractValidationRuleBuilder implements ValidationRuleBuilder, Composable { +public abstract class AbstractValidationRuleBuilder implements ValidationRuleBuilder, Serviceable, Disposable { protected ExpressionManager expressionManager; + protected ServiceManager serviceManager; - public void compose(ComponentManager componentManager) throws ComponentException { - expressionManager = (ExpressionManager)componentManager.lookup(ExpressionManager.ROLE); + public void service(ServiceManager serviceManager) throws ServiceException { + this.serviceManager = serviceManager; + expressionManager = (ExpressionManager)serviceManager.lookup(ExpressionManager.ROLE); } /** @@ -95,5 +98,9 @@ } catch (Exception e) { throw new CascadingException("Error in expression \"" + exprString + "\" in attribute \"" + attrName + "\" at " + DomHelper.getLocation(element), e); } + } + + public void dispose() { + serviceManager.release(expressionManager); } } 1.3 +31 -10 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractWidgetDefinitionBuilder.java Index: AbstractWidgetDefinitionBuilder.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractWidgetDefinitionBuilder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractWidgetDefinitionBuilder.java 26 Jun 2003 09:13:14 -0000 1.2 +++ AbstractWidgetDefinitionBuilder.java 16 Jul 2003 13:59:36 -0000 1.3 @@ -53,26 +53,30 @@ import org.w3c.dom.Element; import org.apache.cocoon.woody.util.DomHelper; import org.apache.cocoon.woody.Constants; -import org.apache.cocoon.woody.FormManager; import org.apache.cocoon.woody.expression.ExpressionManager; import org.apache.cocoon.woody.datatype.DatatypeManager; -import org.apache.avalon.framework.component.Composable; -import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.ComponentException; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceSelector; +import org.apache.avalon.framework.CascadingException; +import org.apache.avalon.framework.activity.Disposable; /** * Abstract base class for WidgetDefinitionBuilders. Provides functionality * common to many implementations. */ -public abstract class AbstractWidgetDefinitionBuilder implements WidgetDefinitionBuilder, Composable { - protected FormManager formManager; +public abstract class AbstractWidgetDefinitionBuilder implements WidgetDefinitionBuilder, Serviceable, Disposable { + protected ServiceSelector widgetDefinitionBuilderSelector; protected DatatypeManager datatypeManager; protected ExpressionManager expressionManager; + protected ServiceManager serviceManager; - public void compose(ComponentManager componentManager) throws ComponentException { - formManager = (FormManager)componentManager.lookup(FormManager.ROLE); - datatypeManager = (DatatypeManager)componentManager.lookup(DatatypeManager.ROLE); - expressionManager = (ExpressionManager)componentManager.lookup(ExpressionManager.ROLE); + public void service(ServiceManager serviceManager) throws ServiceException { + this.serviceManager = serviceManager; + widgetDefinitionBuilderSelector = (ServiceSelector)serviceManager.lookup( WidgetDefinitionBuilder.class.getName() + "Selector"); + datatypeManager = (DatatypeManager)serviceManager.lookup(DatatypeManager.ROLE); + expressionManager = (ExpressionManager)serviceManager.lookup(ExpressionManager.ROLE); } protected void setId(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception { @@ -88,5 +92,22 @@ Object label = DomHelper.compileElementContent(labelElement); widgetDefinition.setLabel(label); } + } + + protected WidgetDefinition buildAnotherWidgetDefinition(Element widgetDefinition) throws Exception { + String widgetName = widgetDefinition.getLocalName(); + WidgetDefinitionBuilder builder = null; + try { + builder = (WidgetDefinitionBuilder)widgetDefinitionBuilderSelector.select(widgetName); + } catch (ServiceException e) { + throw new CascadingException("Unkown kind of widget \"" + widgetName + "\" specified at " + DomHelper.getLocation(widgetDefinition), e); + } + return builder.buildWidgetDefinition(widgetDefinition); + } + + public void dispose() { + serviceManager.release(widgetDefinitionBuilderSelector); + serviceManager.release(datatypeManager); + serviceManager.release(expressionManager); } } 1.2 +1 -1 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AggregateFieldDefinitionBuilder.java Index: AggregateFieldDefinitionBuilder.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AggregateFieldDefinitionBuilder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AggregateFieldDefinitionBuilder.java 26 Jun 2003 09:09:59 -0000 1.1 +++ AggregateFieldDefinitionBuilder.java 16 Jul 2003 13:59:41 -0000 1.2 @@ -74,7 +74,7 @@ Element childrenElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "children", true); Element[] fieldElements = DomHelper.getChildElements(childrenElement, Constants.WD_NS, "field"); for (int i = 0; i < fieldElements.length; i++) { - FieldDefinition fieldDefinition = (FieldDefinition)formManager.buildWidgetDefinition(fieldElements[i]); + FieldDefinition fieldDefinition = (FieldDefinition)buildAnotherWidgetDefinition(fieldElements[i]); if (!String.class.isAssignableFrom(fieldDefinition.getDatatype().getTypeClass())) throw new Exception("An aggregatefield can only contain fields with datatype string, at " + DomHelper.getLocation(fieldElements[i])); definition.addWidgetDefinition(fieldDefinition); 1.2 +1 -1 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/FormDefinitionBuilder.java Index: FormDefinitionBuilder.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/FormDefinitionBuilder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FormDefinitionBuilder.java 22 Apr 2003 12:04:19 -0000 1.1 +++ FormDefinitionBuilder.java 16 Jul 2003 13:59:45 -0000 1.2 @@ -70,7 +70,7 @@ Element[] widgetElements = DomHelper.getChildElements(formElement, Constants.WD_NS); for (int i = 0; i < widgetElements.length; i++) { Element widgetElement = widgetElements[i]; - WidgetDefinition widgetDefinition = formManager.buildWidgetDefinition(widgetElement); + WidgetDefinition widgetDefinition = buildAnotherWidgetDefinition(widgetElement); formDefinition.addWidgetDefinition(widgetDefinition); } 1.2 +1 -1 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/RepeaterDefinitionBuilder.java Index: RepeaterDefinitionBuilder.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/RepeaterDefinitionBuilder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RepeaterDefinitionBuilder.java 22 Apr 2003 12:04:19 -0000 1.1 +++ RepeaterDefinitionBuilder.java 16 Jul 2003 13:59:45 -0000 1.2 @@ -67,7 +67,7 @@ // the children of the repeater element are widget configuration elements Element[] widgetElements = DomHelper.getChildElements(widgetElement, Constants.WD_NS); for (int i = 0; i < widgetElements.length; i++) { - WidgetDefinition widgetDefinition = formManager.buildWidgetDefinition(widgetElements[i]); + WidgetDefinition widgetDefinition = buildAnotherWidgetDefinition(widgetElements[i]); repeaterDefinition.addWidget(widgetDefinition); } 1.2 +24 -8 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util/SimpleServiceSelector.java Index: SimpleServiceSelector.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util/SimpleServiceSelector.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimpleServiceSelector.java 15 Jul 2003 14:06:16 -0000 1.1 +++ SimpleServiceSelector.java 16 Jul 2003 14:00:20 -0000 1.2 @@ -52,35 +52,37 @@ import org.apache.avalon.framework.service.ServiceSelector; import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.component.Composable; -import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.ComponentException; +import org.apache.avalon.framework.activity.Disposable; import org.apache.cocoon.components.LifecycleHelper; import java.util.Map; import java.util.HashMap; +import java.util.Iterator; /** * A very simple ServiceSelector for ThreadSafe services. */ -public class SimpleServiceSelector extends AbstractLogEnabled implements ServiceSelector, Configurable, LogEnabled, Composable { +public class SimpleServiceSelector extends AbstractLogEnabled implements ServiceSelector, Configurable, LogEnabled, + Serviceable, Disposable { private final String hintShortHand; private final Class componentClass; private Map components = new HashMap(); - private ComponentManager componentManager; + private ServiceManager serviceManager; public SimpleServiceSelector(String hintShortHand, Class componentClass) { this.hintShortHand = hintShortHand; this.componentClass = componentClass; } - public void compose(ComponentManager componentManager) throws ComponentException { - this.componentManager = componentManager; + public void service(ServiceManager serviceManager) throws ServiceException { + this.serviceManager = serviceManager; } public void configure(Configuration configuration) throws ConfigurationException { @@ -102,7 +104,7 @@ Object component = null; try { component = clazz.newInstance(); - LifecycleHelper lifecycleHelper = new LifecycleHelper(getLogger(), null, componentManager, null, null, componentConfs[i]); + LifecycleHelper lifecycleHelper = new LifecycleHelper(getLogger(), null, serviceManager, null, null, componentConfs[i]); lifecycleHelper.setupComponent(component); } catch (Exception e) { throw new ConfigurationException("Error creating " + hintShortHand + " declared at " + componentConfs[i], e); @@ -125,5 +127,19 @@ } public void release(Object o) { + } + + public void dispose() { + Iterator serviceIt = components.values().iterator(); + while (serviceIt.hasNext()) { + Object service = serviceIt.next(); + if (service instanceof Disposable) { + try { + ((Disposable)service).dispose(); + } catch (Exception e) { + getLogger().error("Error disposing service " + service, e); + } + } + } } }