cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r604021 - in /cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel: ./ library/
Date Thu, 13 Dec 2007 20:37:22 GMT
Author: vgritsenko
Date: Thu Dec 13 12:37:20 2007
New Revision: 604021

URL: http://svn.apache.org/viewvc?rev=604021&view=rev
Log:
'localLibrary' is never null.
wrap context change into try/finally.

Modified:
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.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/FormDefinitionBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/ImportDefinitionBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionBuilderContext.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java?rev=604021&r1=604020&r2=604021&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java
Thu Dec 13 12:37:20 2007
@@ -25,7 +25,6 @@
  *
  * @version $Id$
  */
-
 public abstract class AbstractContainerDefinitionBuilder extends AbstractWidgetDefinitionBuilder
{
 
     protected void setupContainer(Element element, String widgetsElementName, AbstractContainerDefinition
definition)
@@ -40,33 +39,35 @@
 
         // All child elements of the widgets element are widgets
         Element[] widgetElements = DomHelper.getChildElements(widgetsElement, FormsConstants.DEFINITION_NS);
-        WidgetDefinitionBuilderContext oldContext = this.context;
 
-        for (int i = 0; i < widgetElements.length; i++) {
-            Element widgetElement = widgetElements[i];
-
-            this.context = new WidgetDefinitionBuilderContext(oldContext);
-            this.context.setSuperDefinition(null);
+        WidgetDefinitionBuilderContext oldContext = this.context;
+        try {
+            for (int i = 0; i < widgetElements.length; i++) {
+                Element widgetElement = widgetElements[i];
+
+                this.context = new WidgetDefinitionBuilderContext(oldContext);
+                this.context.setSuperDefinition(null);
+
+                String newId = DomHelper.getAttribute(widgetElement, "extends", null);
+                if (newId != null) {
+                    WidgetDefinition def;
+                    if ((def = this.context.getLocalLibrary().getDefinition(newId)) != null)
{
+                        this.context.setSuperDefinition(def);
+                    } else if ((def = definition.getWidgetDefinition(newId)) != null) {
+                        this.context.setSuperDefinition(def);
+                    }
+                    // throw new FormsException("Widget to inherit from ("+newId+") not
+                    // found!", DomHelper.getLocationObject(element));
+                }
 
-            String newId = DomHelper.getAttribute(widgetElement, "extends", null);
-            WidgetDefinition def;
-            if (newId != null) {
-                if ((def = this.context.getLocalLibrary().getDefinition(newId)) != null)
{
-                    this.context.setSuperDefinition(def);
-                } else if ((def = definition.getWidgetDefinition(newId)) != null) {
-                    this.context.setSuperDefinition(def);
+                WidgetDefinition widgetDefinition = buildAnotherWidgetDefinition(widgetElement);
+                if (widgetDefinition != null) {
+                    definition.addWidgetDefinition(widgetDefinition);
                 }
-                // throw new FormsException("Widget to inherit from ("+newId+") not
-                // found!", DomHelper.getLocationObject(element));
-            }
 
-            WidgetDefinition widgetDefinition = buildAnotherWidgetDefinition(widgetElement);
-            if (widgetDefinition != null) {
-                definition.addWidgetDefinition(widgetDefinition);
             }
-
+        } finally {
+            this.context = oldContext;
         }
-
-        this.context = oldContext;
     }
 }

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?rev=604021&r1=604020&r2=604021&view=diff
==============================================================================
--- 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
Thu Dec 13 12:37:20 2007
@@ -59,18 +59,18 @@
     throws Exception {
         // so changes don't pollute upper levels
         this.context = new WidgetDefinitionBuilderContext(context);
+        try {
+            WidgetDefinition def = buildWidgetDefinition(widgetElement);
 
-        WidgetDefinition def = buildWidgetDefinition(widgetElement);
+            // register this class with the local library, if any.
+            if (DomHelper.getAttributeAsBoolean(widgetElement, "register", false)) {
+                this.context.getLocalLibrary().addDefinition(def);
+            }
 
-        // register this class with the local library, if any.
-        if (DomHelper.getAttributeAsBoolean(widgetElement, "register", false) &&
-                this.context != null &&
-                this.context.getLocalLibrary() != null) {
-            this.context.getLocalLibrary().addDefinition(def);
+            return def;
+        } finally {
+            this.context = null;
         }
-
-        this.context = null;
-        return def;
     }
 
     protected void setupDefinition(Element widgetElement, AbstractWidgetDefinition definition)
@@ -139,7 +139,7 @@
     protected WidgetDefinition buildAnotherWidgetDefinition(Element widgetDefinition)
     throws Exception {
         String widgetName = widgetDefinition.getLocalName();
-        WidgetDefinitionBuilder builder = (WidgetDefinitionBuilder)widgetDefinitionBuilders.get(widgetName);
+        WidgetDefinitionBuilder builder = (WidgetDefinitionBuilder) widgetDefinitionBuilders.get(widgetName);
         if (builder == null) {
             throw new FormsException("Unknown kind of widget '" + widgetName + "'.",
                                      DomHelper.getLocationObject(widgetDefinition));

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java?rev=604021&r1=604020&r2=604021&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
Thu Dec 13 12:37:20 2007
@@ -32,6 +32,10 @@
 
     protected LibraryManager libraryManager;
 
+    public void setLibraryManager(LibraryManager libraryManager) {
+        this.libraryManager = libraryManager;
+    }
+
     public WidgetDefinition buildWidgetDefinition(Element widgetElement, WidgetDefinitionBuilderContext
context)
     throws Exception {
         throw new UnsupportedOperationException("Please use the other signature without WidgetDefinitionBuilderContext!");
@@ -39,32 +43,29 @@
 
     public WidgetDefinition buildWidgetDefinition(Element formElement) throws Exception {
         FormDefinition formDefinition = new FormDefinition(libraryManager);
-        this.context = new WidgetDefinitionBuilderContext();
-        this.context.setLocalLibrary(formDefinition.getLocalLibrary());
+        this.context = new WidgetDefinitionBuilderContext(formDefinition.getLocalLibrary());
 
-        // set local URI
-        formDefinition.getLocalLibrary().setSourceURI(LocationAttributes.getURI(formElement));
+        try {
+            // set local URI
+            formDefinition.getLocalLibrary().setSourceURI(LocationAttributes.getURI(formElement));
 
-        Iterator i = buildEventListeners(formElement, "on-processing-phase", ProcessingPhaseListener.class).iterator();
-        while (i.hasNext()) {
-            formDefinition.addProcessingPhaseListener((ProcessingPhaseListener) i.next());
-        }
+            Iterator i = buildEventListeners(formElement, "on-processing-phase", ProcessingPhaseListener.class).iterator();
+            while (i.hasNext()) {
+                formDefinition.addProcessingPhaseListener((ProcessingPhaseListener) i.next());
+            }
 
-        super.setupDefinition(formElement, formDefinition);
-        setDisplayData(formElement, formDefinition);
+            super.setupDefinition(formElement, formDefinition);
+            setDisplayData(formElement, formDefinition);
 
-        setupContainer(formElement,"widgets",formDefinition);
+            setupContainer(formElement,"widgets",formDefinition);
 
-        formDefinition.resolve();
+            formDefinition.resolve();
 
-        formDefinition.makeImmutable();
+            formDefinition.makeImmutable();
+        } finally {
+            this.context = null;
+        }
 
-        this.context = null;
         return formDefinition;
-    }
-
-    public void setLibraryManager( LibraryManager libraryManager )
-    {
-        this.libraryManager = libraryManager;
     }
 }

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/ImportDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/ImportDefinitionBuilder.java?rev=604021&r1=604020&r2=604021&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/ImportDefinitionBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/ImportDefinitionBuilder.java
Thu Dec 13 12:37:20 2007
@@ -35,11 +35,6 @@
      */
     public WidgetDefinition buildWidgetDefinition(Element widgetElement)
     throws Exception {
-        if (this.context == null || this.context.getLocalLibrary() == null) {
-            throw new FormsException("Import statement seen and context is empty.",
-                                     DomHelper.getLocationObject(widgetElement));
-        }
-
         Library lib = this.context.getLocalLibrary();
         String prefix = DomHelper.getAttribute(widgetElement, PREFIX_ATTRIBUTE);
         String uri = DomHelper.getAttribute(widgetElement, URI_ATTRIBUTE);

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionBuilderContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionBuilderContext.java?rev=604021&r1=604020&r2=604021&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionBuilderContext.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionBuilderContext.java
Thu Dec 13 12:37:20 2007
@@ -25,16 +25,17 @@
  */
 public class WidgetDefinitionBuilderContext {
 
-    protected WidgetDefinition superDefinition;
     protected Library localLibrary;
+    protected WidgetDefinition superDefinition;
 
 
-    public WidgetDefinitionBuilderContext() {
+    public WidgetDefinitionBuilderContext(Library localLibrary) {
+        this.localLibrary = localLibrary;
     }
 
-    public WidgetDefinitionBuilderContext(WidgetDefinitionBuilderContext other) {
-        this.superDefinition = other.superDefinition;
-        this.localLibrary = other.localLibrary;
+    public WidgetDefinitionBuilderContext(WidgetDefinitionBuilderContext parent) {
+        this.localLibrary = parent.localLibrary;
+        this.superDefinition = parent.superDefinition;
     }
 
     public WidgetDefinition getSuperDefinition() {
@@ -47,9 +48,5 @@
 
     public Library getLocalLibrary() {
         return localLibrary;
-    }
-
-    public void setLocalLibrary(Library lib) {
-        localLibrary = lib;
     }
 }

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?rev=604021&r1=604020&r2=604021&view=diff
==============================================================================
--- 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
Thu Dec 13 12:37:20 2007
@@ -61,8 +61,7 @@
 
     public Library(LibraryManager lm, Map builderSelector) {
         manager = lm;
-        context = new WidgetDefinitionBuilderContext();
-        context.setLocalLibrary(this);
+        context = new WidgetDefinitionBuilderContext(this);
         widgetDefinitionBuilders = builderSelector;
     }
 
@@ -180,7 +179,7 @@
             context.setSuperDefinition(getDefinition(extend));
         }
 
-        return builder.buildWidgetDefinition(widgetDefinition,context);
+        return builder.buildWidgetDefinition(widgetDefinition, context);
     }
 
 



Mime
View raw message