cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel AbstractWidgetDefinitionBuilder.java
Date Tue, 27 Apr 2004 12:02:13 GMT
bruno       2004/04/27 05:02:13

  Modified:    src/blocks/forms/java/org/apache/cocoon/forms/event/impl
                        JavaClassWidgetListenerBuilder.java
                        JavaScriptWidgetListener.java
                        JavaScriptWidgetListenerBuilder.java
               src/blocks/forms/java/org/apache/cocoon/forms/formmodel
                        AbstractWidgetDefinitionBuilder.java
  Added:       src/blocks/forms/conf forms-widgetlisteners.xconf
                        forms-widgetlisteners.xroles
  Removed:     src/blocks/forms/java/org/apache/cocoon/forms/event
                        WidgetListenerBuilderUtil.java
  Log:
  WidgetListenerBuilders managed as Avalon components.
  One less quick hack.
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/forms/conf/forms-widgetlisteners.xconf
  
  Index: forms-widgetlisteners.xconf
  ===================================================================
  <?xml version="1.0"?>
  <!--
    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.
    See the License for the specific language governing permissions and
    limitations under the License.
  -->
  
  <xconf xpath="/cocoon" unless="forms-widgetlisteners">
  
    <forms-widgetlisteners>
      <listener name="java" class="org.apache.cocoon.forms.event.impl.JavaClassWidgetListenerBuilder"/>
      <listener name="javascript" class="org.apache.cocoon.forms.event.impl.JavaScriptWidgetListenerBuilder"/>
    </forms-widgetlisteners>
  
  </xconf>
  
  
  1.1                  cocoon-2.1/src/blocks/forms/conf/forms-widgetlisteners.xroles
  
  Index: forms-widgetlisteners.xroles
  ===================================================================
  <?xml version="1.0"?>
  <!--
    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.
    See the License for the specific language governing permissions and
    limitations under the License.
  -->
  
  <xroles xpath="/role-list" unless="role[@name='org.apache.cocoon.forms.event.WidgetListenerBuilderSelector']">
  
    <role name="org.apache.cocoon.forms.event.WidgetListenerBuilderSelector"
          shorthand="forms-widgetlisteners"
          default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
  </xroles>
  
  
  
  1.2       +3 -4      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaClassWidgetListenerBuilder.java
  
  Index: JavaClassWidgetListenerBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaClassWidgetListenerBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaClassWidgetListenerBuilder.java	9 Mar 2004 10:34:10 -0000	1.1
  +++ JavaClassWidgetListenerBuilder.java	27 Apr 2004 12:02:13 -0000	1.2
  @@ -19,6 +19,7 @@
   import org.apache.cocoon.forms.event.WidgetListenerBuilder;
   import org.apache.cocoon.forms.util.DomHelper;
   import org.apache.cocoon.util.ClassUtils;
  +import org.apache.avalon.framework.thread.ThreadSafe;
   import org.w3c.dom.Element;
   
   /**
  @@ -32,9 +33,7 @@
    * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
    * @version CVS $Id$
    */
  -public class JavaClassWidgetListenerBuilder implements WidgetListenerBuilder {
  -
  -    public static final JavaClassWidgetListenerBuilder INSTANCE = new JavaClassWidgetListenerBuilder();
  +public class JavaClassWidgetListenerBuilder implements WidgetListenerBuilder, ThreadSafe
{
   
       public WidgetListener buildListener(Element element, Class listenerClass) throws Exception
{
   
  
  
  
  1.4       +13 -14    cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListener.java
  
  Index: JavaScriptWidgetListener.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListener.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JavaScriptWidgetListener.java	25 Apr 2004 12:12:09 -0000	1.3
  +++ JavaScriptWidgetListener.java	27 Apr 2004 12:02:13 -0000	1.4
  @@ -19,10 +19,9 @@
   import java.util.Map;
   
   import org.apache.avalon.framework.CascadingRuntimeException;
  -import org.apache.cocoon.components.CocoonComponentManager;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.cocoon.components.ContextHelper;
   import org.apache.cocoon.components.flow.FlowHelper;
  -import org.apache.cocoon.environment.ObjectModelHelper;
  -import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.forms.event.ActionEvent;
   import org.apache.cocoon.forms.event.ActionListener;
   import org.apache.cocoon.forms.event.ValueChangedEvent;
  @@ -40,9 +39,11 @@
   public abstract class JavaScriptWidgetListener {
       
       private Script script;
  -    
  -    public JavaScriptWidgetListener(Script script) {
  +    private Context context;
  +
  +    public JavaScriptWidgetListener(Script script, Context context) {
           this.script = script;
  +        this.context = context;
       }
       
       /**
  @@ -54,10 +55,8 @@
               HashMap values = new HashMap(2);
               values.put("event", event);
               
  -            // FIXME: remove this ugly hack and get the request from the Avalon context
once
  -            // listener builder are real components
  -            Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel();
  -            
  +            Map objectModel = ContextHelper.getObjectModel(context);
  +
               // Add the biz data that was passed to showForm()
               Object viewData = FlowHelper.getContextObject(objectModel);
               if (viewData != null) {
  @@ -76,8 +75,8 @@
       
       public static class JSActionListener extends JavaScriptWidgetListener implements ActionListener
{
   
  -        public JSActionListener(Script script) {
  -            super(script);
  +        public JSActionListener(Script script, Context context) {
  +            super(script, context);
           }
   
           public void actionPerformed(ActionEvent event) {
  @@ -87,8 +86,8 @@
       
       public static class JSValueChangedListener extends JavaScriptWidgetListener implements
ValueChangedListener {
   
  -        public JSValueChangedListener(Script script) {
  -            super(script);
  +        public JSValueChangedListener(Script script, Context context) {
  +            super(script, context);
           }
   
           public void valueChanged(ValueChangedEvent event) {
  
  
  
  1.2       +13 -5     cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListenerBuilder.java
  
  Index: JavaScriptWidgetListenerBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/event/impl/JavaScriptWidgetListenerBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaScriptWidgetListenerBuilder.java	9 Mar 2004 10:34:10 -0000	1.1
  +++ JavaScriptWidgetListenerBuilder.java	27 Apr 2004 12:02:13 -0000	1.2
  @@ -20,6 +20,10 @@
   import org.apache.cocoon.forms.event.WidgetListener;
   import org.apache.cocoon.forms.event.WidgetListenerBuilder;
   import org.apache.cocoon.forms.util.JavaScriptHelper;
  +import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.avalon.framework.context.Contextualizable;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
   import org.mozilla.javascript.Script;
   import org.w3c.dom.Element;
   
  @@ -39,18 +43,22 @@
    * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
    * @version CVS $Id$
    */
  -public class JavaScriptWidgetListenerBuilder implements WidgetListenerBuilder {
  +public class JavaScriptWidgetListenerBuilder implements WidgetListenerBuilder, ThreadSafe,
Contextualizable {
   
  -    public static final JavaScriptWidgetListenerBuilder INSTANCE = new JavaScriptWidgetListenerBuilder();
  +    private Context context;
  +
  +    public void contextualize(Context context) throws ContextException {
  +        this.context = context;
  +    }
   
       public WidgetListener buildListener(Element element, Class listenerClass) throws Exception
{
   
           Script script = JavaScriptHelper.buildScript(element);
   
           if (listenerClass == ActionListener.class) {
  -            return new JavaScriptWidgetListener.JSActionListener(script);
  +            return new JavaScriptWidgetListener.JSActionListener(script, context);
           } else if (listenerClass == ValueChangedListener.class) {
  -            return new JavaScriptWidgetListener.JSValueChangedListener(script);
  +            return new JavaScriptWidgetListener.JSValueChangedListener(script, context);
           } else {
               throw new Exception("Unkonwn event class: " + listenerClass);
           }
  
  
  
  1.3       +18 -6     cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
  
  Index: AbstractWidgetDefinitionBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractWidgetDefinitionBuilder.java	9 Mar 2004 13:08:45 -0000	1.2
  +++ AbstractWidgetDefinitionBuilder.java	27 Apr 2004 12:02:13 -0000	1.3
  @@ -30,7 +30,7 @@
   import org.apache.cocoon.forms.Constants;
   import org.apache.cocoon.forms.datatype.DatatypeManager;
   import org.apache.cocoon.forms.event.WidgetListener;
  -import org.apache.cocoon.forms.event.WidgetListenerBuilderUtil;
  +import org.apache.cocoon.forms.event.WidgetListenerBuilder;
   import org.apache.cocoon.forms.expression.ExpressionManager;
   import org.apache.cocoon.forms.util.DomHelper;
   import org.apache.cocoon.forms.validation.WidgetValidatorBuilder;
  @@ -48,6 +48,7 @@
   public abstract class AbstractWidgetDefinitionBuilder implements WidgetDefinitionBuilder,
Serviceable, Disposable {
       protected ServiceSelector widgetDefinitionBuilderSelector;
       protected ServiceSelector widgetValidatorBuilderSelector;
  +    protected ServiceSelector widgetListenerBuilderSelector;
       protected DatatypeManager datatypeManager;
       protected ExpressionManager expressionManager;
       protected ServiceManager serviceManager;
  @@ -58,6 +59,7 @@
           this.datatypeManager = (DatatypeManager)serviceManager.lookup(DatatypeManager.ROLE);
           this.expressionManager = (ExpressionManager)serviceManager.lookup(ExpressionManager.ROLE);
           this.widgetValidatorBuilderSelector = (ServiceSelector)serviceManager.lookup(WidgetValidatorBuilder.ROLE
+ "Selector");
  +        this.widgetListenerBuilderSelector = (ServiceSelector)serviceManager.lookup(WidgetListenerBuilder.ROLE
+ "Selector");
       }
   
       protected void setLocation(Element widgetElement, AbstractWidgetDefinition widgetDefinition)
{
  @@ -87,12 +89,21 @@
   
       protected List buildEventListeners(Element widgetElement, String elementName, Class
listenerClass) throws Exception {
           List result = null;
  -        Element listenerElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS,
elementName);
  -        if (listenerElement != null) {
  -            NodeList list = listenerElement.getChildNodes();
  +        Element listenersElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS,
elementName);
  +        if (listenersElement != null) {
  +            NodeList list = listenersElement.getChildNodes();
               for (int i = 0; i < list.getLength(); i++) {
                   if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
  -                    WidgetListener listener = WidgetListenerBuilderUtil.getWidgetListener((Element)list.item(i),
listenerClass);
  +                    Element listenerElement = (Element)list.item(i);
  +                    WidgetListenerBuilder listenerBuilder = null;
  +                    try {
  +                        listenerBuilder = (WidgetListenerBuilder)widgetListenerBuilderSelector.select(listenerElement.getLocalName());
  +                    } catch (ServiceException e) {
  +                        throw new CascadingException("Unknown kind of eventlistener '"
+ listenerElement.getLocalName()
  +                                + "' at " + DomHelper.getLocation(listenerElement), e);
  +                    }
  +                    WidgetListener listener = listenerBuilder.buildListener(listenerElement,
listenerClass);
  +                    widgetListenerBuilderSelector.release(listenerBuilder);
                       if (result == null) result = new ArrayList();
                       result.add(listener);
                   }
  @@ -137,6 +148,7 @@
                       }
   
                       widgetDefinition.addValidator(builder.build(element, widgetDefinition));
  +                    widgetValidatorBuilderSelector.release(builder);
                   }
               }
           }
  
  
  

Mime
View raw message