cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r447002 - in /cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms: ./ formmodel/ formmodel/library/ util/
Date Sun, 17 Sep 2006 02:41:22 GMT
Author: vgritsenko
Date: Sat Sep 16 19:41:22 2006
New Revision: 447002

URL: http://svn.apache.org/viewvc?view=rev&rev=447002
Log:
kill LibraryManager.debug()

Modified:
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/SimpleServiceSelector.java

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java?view=diff&rev=447002&r1=447001&r2=447002
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java
Sat Sep 16 19:41:22 2006
@@ -16,7 +16,6 @@
 package org.apache.cocoon.forms;
 
 import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.component.Component;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
@@ -54,7 +53,7 @@
  */
 public class DefaultFormManager extends AbstractLogEnabled
                                 implements FormManager, Contextualizable, Serviceable, Configurable,
-                                           Initializable, Disposable, ThreadSafe, Component
{
+                                           Disposable, ThreadSafe, Component {
     // NOTE: Component is there to allow this block to run in the 2.1 branch
 
     protected static final String PREFIX = "CocoonForm:";
@@ -71,12 +70,13 @@
     //
 
     public DefaultFormManager() {
-        libraryManager = new LibraryManagerImpl();
         widgetDefinitionBuilderSelector = new SimpleServiceSelector("widget", WidgetDefinitionBuilder.class);
+        libraryManager = new LibraryManagerImpl();
     }
 
     public void enableLogging(Logger logger) {
         super.enableLogging(logger);
+        widgetDefinitionBuilderSelector.enableLogging(getLogger());
         libraryManager.enableLogging(getLogger().getChildLogger("library"));
     }
 
@@ -93,18 +93,14 @@
 
     public void service(ServiceManager manager) throws ServiceException {
         this.manager = manager;
-        this.cacheManager = (CacheManager)manager.lookup(CacheManager.ROLE);
-        libraryManager.service(new FormServiceManager());
+        this.cacheManager = (CacheManager) manager.lookup(CacheManager.ROLE);
         widgetDefinitionBuilderSelector.service(new FormServiceManager());
+        libraryManager.service(new FormServiceManager());
     }
 
     public void configure(Configuration configuration) throws ConfigurationException {
         libraryManager.configure(configuration.getChild("libraries"));
         widgetDefinitionBuilderSelector.configure(configuration.getChild("widgets"));
-    }
-
-    public void initialize() throws Exception {
-        libraryManager.initialize();
     }
 
     public void dispose() {

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java?view=diff&rev=447002&r1=447001&r2=447002
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
Sat Sep 16 19:41:22 2006
@@ -239,8 +239,8 @@
             relativeWidget = getForm();
             relativePath = path.substring(1);
         } else {
-        	if (path.startsWith(".." + Widget.PATH_SEPARATOR))  {
-        		relativeWidget = getParent();
+            if (path.startsWith(".." + Widget.PATH_SEPARATOR))  {
+                relativeWidget = getParent();
                 relativePath = path.substring(3);
             } else {
                 String childId = path.substring(0, sepPosition );
@@ -249,7 +249,10 @@
             }
         }
 
-        if (relativeWidget == null) return null;
+        if (relativeWidget == null) {
+            return null;
+        }
+
         return relativeWidget.lookupWidget(relativePath);
     }
 
@@ -261,7 +264,7 @@
      * @return <code>null</code> if not overriden.
      */
     protected Widget getChild(String id) {
-    	return null;
+        return null;
     }
 
     public Widget getWidget(String id) {
@@ -505,7 +508,7 @@
         }
     }
 
-	public Object getAttribute(String name) {
+    public Object getAttribute(String name) {
         Object result = null;
 
         // First check locally

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java?view=diff&rev=447002&r1=447001&r2=447002
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
Sat Sep 16 19:41:22 2006
@@ -65,22 +65,22 @@
             } else if(this.parent != null) {
                 this.formDefinition = this.parent.getFormDefinition();
             } else {
-            	// no form definition in this widget tree, must be in a library!
-            	return null;
+                // no form definition in this widget tree, must be in a library!
+                return null;
             }
         }
         return this.formDefinition;
     }
 
     public Library getEnclosingLibrary() {
-    	if (this.enclosingLibrary == null) {
-    		this.enclosingLibrary = this.parent.getEnclosingLibrary();
+        if (this.enclosingLibrary == null) {
+            this.enclosingLibrary = this.parent.getEnclosingLibrary();
         }
         return this.enclosingLibrary;
     }
 
     public void setEnclosingLibrary(Library library) {
-    	enclosingLibrary = library;
+        enclosingLibrary = library;
     }
 
     /**

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java?view=diff&rev=447002&r1=447001&r2=447002
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
Sat Sep 16 19:41:22 2006
@@ -100,8 +100,8 @@
 
     protected void setupDefinition(Element widgetElement, AbstractWidgetDefinition definition)
     throws Exception {
-    	// location
-    	definition.setLocation(DomHelper.getLocationObject(widgetElement));
+        // location
+        definition.setLocation(DomHelper.getLocationObject(widgetElement));
 
         if (this.context.getSuperDefinition() != null) {
             definition.initializeFrom(this.context.getSuperDefinition());

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java?view=diff&rev=447002&r1=447001&r2=447002
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java
Sat Sep 16 19:41:22 2006
@@ -20,6 +20,7 @@
 import java.util.Map;
 
 import org.apache.avalon.framework.CascadingException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.cocoon.forms.FormsConstants;
@@ -35,46 +36,46 @@
 /**
  * @version $Id$
  */
-public class Library {
+public class Library extends AbstractLogEnabled {
 
-	public static final String SEPARATOR = ":";
+    public static final String SEPARATOR = ":";
 
-	// managed instances
-	protected ServiceSelector widgetDefinitionBuilderSelector;
+    // managed instances
+    protected ServiceSelector widgetDefinitionBuilderSelector;
 
-	// own references
-	protected LibraryManager manager;
+    // own references
+    protected LibraryManager manager;
 
-	// own instances
-	protected Map definitions = new HashMap();
-	protected Map inclusions = new HashMap();
+    // own instances
+    protected Map definitions = new HashMap();
+    protected Map inclusions = new HashMap();
 
-	// shared object with dependencies
-	protected Object shared = new Object();
+    // shared object with dependencies
+    protected Object shared = new Object();
 
-	protected String sourceURI;
-	protected WidgetDefinitionBuilderContext context;
+    protected String sourceURI;
+    protected WidgetDefinitionBuilderContext context;
 
 
     public Library(LibraryManager lm) {
-		manager = lm;
-		context = new WidgetDefinitionBuilderContext();
-		context.setLocalLibrary(this);
-	}
-
-	public void setSourceURI(String uri) {
-		sourceURI = uri;
-	}
+        manager = lm;
+        context = new WidgetDefinitionBuilderContext();
+        context.setLocalLibrary(this);
+    }
+
+    public void setSourceURI(String uri) {
+        sourceURI = uri;
+    }
 
     public String getSourceURI() {
-		return sourceURI;
-	}
+        return sourceURI;
+    }
 
-	public void setWidgetDefinitionBuilderSelector(ServiceSelector selector) {
-		this.widgetDefinitionBuilderSelector = selector;
-	}
+    public void setWidgetDefinitionBuilderSelector(ServiceSelector selector) {
+        this.widgetDefinitionBuilderSelector = selector;
+    }
 
-	public boolean dependenciesHaveChanged() throws Exception {
+    public boolean dependenciesHaveChanged() throws Exception {
         Iterator i = this.inclusions.values().iterator();
         while (i.hasNext()) {
             Dependency dep = (Dependency) i.next();
@@ -84,20 +85,20 @@
         }
 
         return false;
-	}
+    }
 
-	/**
-	 * "Registers" a library to be referenced later under a certain key or prefix.
-	 * Definitions will be accessible locally through prefixing: "prefix:definitionid"
-	 *
-	 * @param key the key
-	 * @param librarysource the source of the library to be know as "key"
-	 * @return true if there was no such key used before, false otherwise
-	 */
-	public boolean includeAs(String key, String librarysource)
+    /**
+     * "Registers" a library to be referenced later under a certain key or prefix.
+     * Definitions will be accessible locally through prefixing: "prefix:definitionid"
+     *
+     * @param key the key
+     * @param librarysource the source of the library to be know as "key"
+     * @return true if there was no such key used before, false otherwise
+     */
+    public boolean includeAs(String key, String librarysource)
     throws LibraryException {
-		try {
-			// library keys may not contain ":"!
+        try {
+            // library keys may not contain ":"!
             if ((!inclusions.containsKey(key) || key.indexOf(SEPARATOR) > -1) &&
                     manager.getLibrary(librarysource, sourceURI) != null) {
                 inclusions.put(key, new Dependency(librarysource));
@@ -109,10 +110,10 @@
         }
     }
 
-	public WidgetDefinition getDefinition(String key) throws LibraryException {
+    public WidgetDefinition getDefinition(String key) throws LibraryException {
 
-		String librarykey = null;
-		String definitionkey = key;
+        String librarykey = null;
+        String definitionkey = key;
 
         if (key.indexOf(SEPARATOR) > -1) {
             String[] parts = StringUtils.split(key, SEPARATOR);
@@ -138,7 +139,7 @@
         }
     }
 
-	public void buildLibrary(Element libraryElement) throws Exception {
+    public void buildLibrary(Element libraryElement) throws Exception {
         sourceURI = LocationAttributes.getURI(libraryElement);
         Element widgetsElement = DomHelper.getChildElement(libraryElement, FormsConstants.DEFINITION_NS,
"widgets", true);
         // All child elements of the widgets element are widgets
@@ -150,7 +151,7 @@
         }
     }
 
-	public void addDefinition(WidgetDefinition definition) throws LibraryException {
+    public void addDefinition(WidgetDefinition definition) throws LibraryException {
         if (definition == null) {
             return;
         }
@@ -164,17 +165,19 @@
 
         // add def to our list of defs
         definitions.put(definition.getId(), definition);
-        manager.debug(this + ": Put definition with id: " + definition.getId());
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug(this + ": Added definition '" + definition.getId() + "'");
+        }
     }
 
-	protected WidgetDefinition buildWidgetDefinition(Element widgetDefinition) throws Exception
{
+    protected WidgetDefinition buildWidgetDefinition(Element widgetDefinition) throws Exception
{
         String widgetName = widgetDefinition.getLocalName();
         WidgetDefinitionBuilder builder;
         try {
             builder = (WidgetDefinitionBuilder)widgetDefinitionBuilderSelector.select(widgetName);
         } catch (ServiceException e) {
             throw new CascadingException("Unknown kind of widget '" + widgetName + "' at
" +
-                                         DomHelper.getLocation(widgetDefinition), e);
+                    DomHelper.getLocation(widgetDefinition), e);
         }
 
         context.setSuperDefinition(null);
@@ -188,21 +191,21 @@
     }
 
 
-	/**
-	 * Encapsulates a uri to designate an import plus a timestamp so previously reloaded
-	 */
-	public class Dependency {
-		private String dependencySourceURI;
-		private Object shared;
-
-		public Dependency(String dependencySourceURI) throws Exception {
-			this.dependencySourceURI = dependencySourceURI;
-			Library lib = manager.getLibrary(this.dependencySourceURI,sourceURI);
-			this.shared = lib.shared;
-		}
+    /**
+     * Encapsulates a uri to designate an import plus a timestamp so previously reloaded
+     */
+    public class Dependency {
+        private String dependencySourceURI;
+        private Object shared;
+
+        public Dependency(String dependencySourceURI) throws Exception {
+            this.dependencySourceURI = dependencySourceURI;
+            Library lib = manager.getLibrary(this.dependencySourceURI,sourceURI);
+            this.shared = lib.shared;
+        }
 
-		public boolean isValid() throws LibraryException {
-			try {
+        public boolean isValid() throws LibraryException {
+            try {
                 if (manager.libraryInCache(dependencySourceURI, sourceURI)) {
                     Library lib = manager.getLibrary(dependencySourceURI, sourceURI);
 
@@ -215,7 +218,7 @@
             } catch (Exception forward) {
                 throw new LibraryException("Exception occured while checking dependency validity!",
forward);
             }
-		}
-	}
+        }
+    }
 
 }

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java?view=diff&rev=447002&r1=447001&r2=447002
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java
Sat Sep 16 19:41:22 2006
@@ -24,14 +24,12 @@
  */
 public interface LibraryManager {
 
-	String ROLE = LibraryManager.class.getName();
+    String ROLE = LibraryManager.class.getName();
 
-	Library getLibrary(String librarysource) throws Exception;
-	Library getLibrary(String librarysource, String relative) throws Exception;
-	Library getNewLibrary();
+    Library getLibrary(String librarysource) throws Exception;
+    Library getLibrary(String librarysource, String relative) throws Exception;
+    Library getNewLibrary();
 
-	boolean libraryInCache(String librarysource) throws Exception;
-	boolean libraryInCache(String librarysource, String relative) throws Exception;
-
-	void debug(String msg);
+    boolean libraryInCache(String librarysource) throws Exception;
+    boolean libraryInCache(String librarysource, String relative) throws Exception;
 }

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java?view=diff&rev=447002&r1=447001&r2=447002
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java
Sat Sep 16 19:41:22 2006
@@ -17,7 +17,6 @@
 
 import org.apache.avalon.framework.CascadingException;
 import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.component.Component;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
@@ -44,29 +43,41 @@
  */
 public class LibraryManagerImpl extends AbstractLogEnabled
                                 implements LibraryManager, Serviceable, Configurable,
-                                           Initializable, Disposable, ThreadSafe, Component
{
+                                           Disposable, ThreadSafe, Component {
 
     protected static final String PREFIX = "CocoonFormLibrary:";
 
-    private ServiceManager serviceManager;
+    private ServiceManager manager;
     private CacheManager cacheManager;
 
     private ServiceSelector widgetDefinitionBuilderSelector;
 
+    //
+    // Lifecycle
+    //
 
     public void configure(Configuration configuration) throws ConfigurationException {
         // TODO Read config to "preload" libraries
     }
 
     public void service(ServiceManager serviceManager) throws ServiceException {
-        this.serviceManager = serviceManager;
+        this.manager = serviceManager;
         this.cacheManager = (CacheManager)serviceManager.lookup(CacheManager.ROLE);
+        this.widgetDefinitionBuilderSelector = (ServiceSelector) manager.lookup(WidgetDefinitionBuilder.class.getName()
+ "Selector");
     }
 
-    public void initialize() throws Exception {
-        this.widgetDefinitionBuilderSelector = (ServiceSelector) serviceManager.lookup(WidgetDefinitionBuilder.class.getName()
+ "Selector");
+    public void dispose() {
+        if (this.cacheManager != null) {
+            this.manager.release(this.cacheManager);
+            this.cacheManager = null;
+        }
+        this.manager = null;
     }
 
+    //
+    // Business methods
+    //
+
     public boolean libraryInCache(String sourceURI) throws Exception {
         return libraryInCache(sourceURI, null);
     }
@@ -82,7 +93,7 @@
         Library lib;
         boolean result = false;
         try {
-            sourceResolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE);
+            sourceResolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
             source = sourceResolver.resolveURI(sourceURI, baseURI, null);
 
             lib = (Library) this.cacheManager.get(source, PREFIX);
@@ -105,7 +116,7 @@
                 sourceResolver.release(source);
             }
             if (sourceResolver != null) {
-                serviceManager.release(sourceResolver);
+                manager.release(sourceResolver);
             }
         }
 
@@ -137,7 +148,7 @@
         }
 
         try {
-            sourceResolver = (SourceResolver) serviceManager.lookup(SourceResolver.ROLE);
+            sourceResolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
             source = sourceResolver.resolveURI(librarysource, relative, null);
 
             lib = (Library) this.cacheManager.get(source, PREFIX);
@@ -157,7 +168,7 @@
                 try {
                     InputSource inputSource = new InputSource(source.getInputStream());
                     inputSource.setSystemId(source.getURI());
-                    libraryDocument = DomHelper.parse(inputSource, this.serviceManager);
+                    libraryDocument = DomHelper.parse(inputSource, this.manager);
 
                     lib = getNewLibrary();
                     lib.buildLibrary(libraryDocument.getDocumentElement());
@@ -173,7 +184,7 @@
                 sourceResolver.release(source);
             }
             if (sourceResolver != null) {
-                serviceManager.release(sourceResolver);
+                manager.release(sourceResolver);
             }
         }
 
@@ -182,6 +193,7 @@
 
     public Library getNewLibrary() {
         Library lib = new Library(this);
+        lib.enableLogging(getLogger());
         lib.setWidgetDefinitionBuilderSelector(this.widgetDefinitionBuilderSelector);
 
         if (getLogger().isDebugEnabled()) {
@@ -189,17 +201,5 @@
         }
 
         return lib;
-    }
-
-    public void dispose() {
-        this.serviceManager.release(this.cacheManager);
-        this.cacheManager = null;
-        this.serviceManager = null;
-    }
-
-    public void debug(String msg) {
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug(msg);
-        }
     }
 }

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/SimpleServiceSelector.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/SimpleServiceSelector.java?view=diff&rev=447002&r1=447001&r2=447002
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/SimpleServiceSelector.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/SimpleServiceSelector.java
Sat Sep 16 19:41:22 2006
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * 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.
@@ -35,55 +35,62 @@
 
 /**
  * A very simple ServiceSelector for ThreadSafe services.
- * 
+ *
  * @version $Id$
  */
-public class SimpleServiceSelector extends AbstractLogEnabled implements ServiceSelector,
Configurable,
-        Serviceable, Disposable, Contextualizable {
+public class SimpleServiceSelector extends AbstractLogEnabled
+                                   implements ServiceSelector, Configurable,
+                                              Serviceable, Disposable, Contextualizable {
+
+    private Context context;
+    private ServiceManager serviceManager;
+
     private final String hintShortHand;
     private final Class componentClass;
     private Map components = new HashMap();
-    private ServiceManager serviceManager;
-    private Context context;
+
+    //
+    // Lifecycle
+    //
 
     public SimpleServiceSelector(String hintShortHand, Class componentClass) {
         this.hintShortHand = hintShortHand;
         this.componentClass = componentClass;
     }
 
-    public void service(ServiceManager serviceManager) throws ServiceException {
-        this.serviceManager = serviceManager;
-    }
-
     public void contextualize(Context context) throws ContextException {
         this.context = context;
     }
 
+    public void service(ServiceManager serviceManager) throws ServiceException {
+        this.serviceManager = serviceManager;
+    }
+
     public void configure(Configuration configuration) throws ConfigurationException {
         Configuration[] componentConfs = configuration.getChildren(hintShortHand);
         for (int i = 0; i < componentConfs.length; i++) {
             String name = componentConfs[i].getAttribute("name");
             String src = componentConfs[i].getAttribute("src");
 
-            Class clazz = null;
+            Class clazz;
             try {
                 clazz = Class.forName(src);
             } catch (ClassNotFoundException e) {
                 throw new ConfigurationException("Class not found: " + src + ", declared
at " + componentConfs[i].getLocation(), e);
             }
 
-            if (!componentClass.isAssignableFrom(clazz))
+            if (!componentClass.isAssignableFrom(clazz)) {
                 throw new ConfigurationException("The class \"" + src + "\" is of an incorrect
type, it should implement or extend " + componentClass.getName());
+            }
 
-            Object component = null;
+            Object component;
             try {
                 component = clazz.newInstance();
-                LifecycleHelper.setupComponent(
-                		component,
-					getLogger(),
-					context,
-					serviceManager,
-					componentConfs[i]);
+                LifecycleHelper.setupComponent(component,
+					                           getLogger(),
+                                               context,
+					                           serviceManager,
+					                           componentConfs[i]);
             } catch (Exception e) {
                 throw new ConfigurationException("Error creating " + hintShortHand + " declared
at " + componentConfs[i].getLocation(), e);
             }
@@ -92,32 +99,39 @@
         }
     }
 
+    public void dispose() {
+        Iterator i = components.values().iterator();
+        while (i.hasNext()) {
+            Object service = i.next();
+            if (service instanceof Disposable) {
+                try {
+                    ((Disposable) service).dispose();
+                } catch (Exception e) {
+                    getLogger().error("Error disposing service " + service, e);
+                }
+            }
+        }
+        components.clear();
+    }
+
+    //
+    // ServiceSelector
+    //
+
     public Object select(Object hint) throws ServiceException {
-        if (!isSelectable(hint))
-            throw new ServiceException((String)hint, "Non-existing component for this hint");
-        String stringHint = (String)hint;
+        if (!isSelectable(hint)) {
+            throw new ServiceException((String) hint, "Non-existing component for this hint");
+        }
+        String stringHint = (String) hint;
         return components.get(stringHint);
     }
 
     public boolean isSelectable(Object hint) {
-        String stringHint = (String)hint;
+        String stringHint = (String) hint;
         return components.containsKey(stringHint);
     }
 
     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);
-                }
-            }
-        }
-    }
 }



Mime
View raw message