tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r534213 - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/internal/event/ java/org/apache/tapestry/internal/event/impl/ java/org/apache/tapestry/pageload/ java/org/apache/tapestry/services/impl/ java/org/apache...
Date Tue, 01 May 2007 19:39:21 GMT
Author: jkuhnert
Date: Tue May  1 12:39:20 2007
New Revision: 534213

URL: http://svn.apache.org/viewvc?view=rev&rev=534213
Log:
Fixed bug in EventConnectionVisitor logic where component specifications being resolved /
not and their subsequent mappings in IComponentEventInvoker wasn't taking into account situations
where the same components would be embedded in multiple pages....Move getIdPath() over to
use getExtendedId() in the hope that this resolves this sob finally.

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/ComponentEventProperty.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/EventBoundListener.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/impl/ComponentEventInvoker.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/EventConnectionVisitor.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/IEventListener.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/ComponentEventPropertyTest.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/impl/ComponentEventInvokerTest.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestEventConnectionVisitor.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/spec/TestComponentSpecification.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/ComponentEventProperty.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/ComponentEventProperty.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/ComponentEventProperty.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/ComponentEventProperty.java
Tue May  1 12:39:20 2007
@@ -23,13 +23,13 @@
  * a component and the events that may be optionally listened
  * for on the client browser.
  */
-public class ComponentEventProperty
+public class ComponentEventProperty implements Cloneable
 {
     private Map _eventMap = new HashMap();
     private Map _formEventMap = new HashMap();
     
     private String _componentId;
-    
+
     /**
      * Creates a new component event property mapped to the specified component id.
      *
@@ -42,6 +42,23 @@
     }
 
     /**
+     * Used in cloning only currently.
+     *
+     * @param componentId
+     *          The component this property is bound to.
+     * @param events
+     *          The list of event mappings.
+     * @param formEvents
+     *          The list of form event mappings.
+     */
+    public ComponentEventProperty(String componentId, Map events, Map formEvents)
+    {
+        _componentId = componentId;
+        _eventMap = events;
+        _formEventMap = formEvents;
+    }
+
+    /**
      * Adds a listener bound to the specified client side
      * events.
      * @param events
@@ -111,6 +128,8 @@
     public void connectAutoSubmitEvents(String formIdPath)
     {
         Iterator it = getEvents().iterator();
+        List removeKeys = new ArrayList();
+        
         while (it.hasNext()) {
             String key = (String)it.next();
 
@@ -122,7 +141,7 @@
 
                 listener.setFormId(formIdPath);
                 lit.remove();
-
+                
                 List formListeners = getFormEventListeners(key);
                 if (!formListeners.contains(listener))
                     formListeners.add(listener);
@@ -130,8 +149,29 @@
             
             // remove mapping if empty
             
-            if (listeners.size() == 0)
-                it.remove();
+            if (listeners.size() == 0) {
+                removeKeys.add(key);
+            }
+        }
+
+        for (int i=0; i < removeKeys.size(); i++) {
+            
+            _eventMap.remove(removeKeys.get(i));
+        }
+
+        it = getFormEvents().iterator();
+        
+        while (it.hasNext())
+        {
+            String key = (String) it.next();
+            List listeners = (List) _formEventMap.get(key);
+            Iterator lit = listeners.iterator();
+
+            while(lit.hasNext())
+            {
+                EventBoundListener listener = (EventBoundListener) lit.next();
+                listener.setFormId(formIdPath);
+            }
         }
     }
 
@@ -268,5 +308,36 @@
         }
         
         return ret;
+    }
+
+    void cloneEvents(Map source, Map target)
+            throws CloneNotSupportedException
+    {
+        Iterator it = source.keySet().iterator();
+        while (it.hasNext())
+        {
+            String event = (String) it.next();
+            List listeners = (List)source.get(event);
+
+            List newListeners = new ArrayList();
+            for (int i=0; i < listeners.size(); i++) {
+                EventBoundListener listener = (EventBoundListener) listeners.get(i);
+                newListeners.add(listener.clone());
+            }
+
+            target.put(event, newListeners);
+        }
+    }
+
+    public Object clone()
+    throws CloneNotSupportedException
+    {
+        Map events = new HashMap();
+        Map formEvents = new HashMap();
+
+        cloneEvents(_eventMap, events);
+        cloneEvents(_formEventMap, formEvents);
+
+        return new ComponentEventProperty(_componentId, events, formEvents);
     }
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/EventBoundListener.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/EventBoundListener.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/EventBoundListener.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/EventBoundListener.java
Tue May  1 12:39:20 2007
@@ -18,7 +18,7 @@
  * Provides a mapping for listener methods that are bound to events, used
  * internally by {@link ComponentEventProperty}.
  */
-public class EventBoundListener
+public class EventBoundListener implements Cloneable
 {
     // the method name to invoke
     private String _methodName;
@@ -153,6 +153,12 @@
     public boolean isAutoSubmit()
     {
         return _autoSubmit;
+    }
+
+    public Object clone()
+    throws CloneNotSupportedException
+    {
+        return super.clone();
     }
 
     /**

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/impl/ComponentEventInvoker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/impl/ComponentEventInvoker.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/impl/ComponentEventInvoker.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/internal/event/impl/ComponentEventInvoker.java
Tue May  1 12:39:20 2007
@@ -75,7 +75,7 @@
         Defense.notNull(event, "event");
         
         IForm form = formSupport.getForm();
-        String formIdPath = form.getIdPath();
+        String formIdPath = form.getExtendedId();
 
         String targetId = (String)event.getTarget().get("id");
         if (targetId == null)
@@ -131,7 +131,7 @@
     
     void invokeComponentListeners(IComponent component, IRequestCycle cycle, BrowserEvent
event)
     {
-        String idPath = component.getIdPath();
+        String idPath = component.getExtendedId();
         List listeners = getEventListeners(idPath);
         if (listeners == null)
             return;

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/EventConnectionVisitor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/EventConnectionVisitor.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/EventConnectionVisitor.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/EventConnectionVisitor.java
Tue May  1 12:39:20 2007
@@ -13,10 +13,7 @@
 import org.apache.tapestry.internal.event.IComponentEventInvoker;
 import org.apache.tapestry.spec.IComponentSpecification;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Handles connecting up components and forms targeted with the EventListener annotation.
@@ -30,21 +27,15 @@
 
     public void visitComponent(IComponent component)
     {
-        if (component.getSpecification().getTargetsResolved())
-            return;
-
         checkComponentPage(component);
         
         Map events = component.getSpecification().getComponentEvents();
-        Iterator it = events.keySet().iterator();
-
-        String[] idPaths = new String[events.size()];
-        String[] ids = new String[events.size()];
-        int count = 0;
+        Set keySet = events.keySet();
+        String[] compIds = (String[]) keySet.toArray(new String[keySet.size()]);
         
-        while (it.hasNext())
+        for (int i=0; i < compIds.length; i++)
         {
-            String compId = (String)it.next();
+            String compId = compIds[i];
             ComponentEventProperty property = (ComponentEventProperty) events.get(compId);
 
             // find the targeted component
@@ -52,30 +43,22 @@
             IComponent comp = findComponent(compId, component.getPage());
 
             if (comp == null)
-                throw new ApplicationRuntimeException(PageloadMessages.componentNotFound(compId),
component, component.getLocation(), null);
+                continue;
 
             // wire up with idPath
 
-            String idPath = comp.getIdPath();
-
-            idPaths[count] = idPath;
-            ids[count] = compId;
-
-            _invoker.addEventListener(idPath, component.getSpecification());
-            wireFormEvents(comp, component.getSpecification());
+            String idPath = comp.getExtendedId();
             
-            count++;
-        }
-
-        for (int i=0; i < idPaths.length; i++) {
+            component.getSpecification().rewireComponentId(compId, idPath);
             
-            component.getSpecification().rewireComponentId(ids[i], idPaths[i]);
+            _invoker.addEventListener(idPath, component.getSpecification());
+            wireFormEvents(comp, component.getSpecification());
         }
-
+        
         // find form element targets for re-mapping with proper idpath && IEventInvoker
connection
 
         events = component.getSpecification().getElementEvents();
-        it = events.keySet().iterator();
+        Iterator it = events.keySet().iterator();
 
         while (it.hasNext())
         {
@@ -95,10 +78,6 @@
                 }
             }
         }
-
-        // set resolved so we don't do it again
-
-        component.getSpecification().setTargetsResolved(true);
     }
 
     void wireElementFormEvents(EventBoundListener listener, IComponent component, IComponentSpecification
spec)
@@ -124,7 +103,7 @@
         if (form == null)
             throw new ApplicationRuntimeException(PageloadMessages.componentNotFound(listener.getFormId()),
component, component.getLocation(), null);
 
-        String idPath = form.getIdPath();
+        String idPath = form.getExtendedId();
         
         listener.setFormId(idPath);
         _invoker.addFormEventListener(idPath, spec);
@@ -144,8 +123,8 @@
         if (form == null)
             return;
 
-        listener.connectAutoSubmitEvents(component.getId(), form);
-        _invoker.addFormEventListener(form.getIdPath(), listener);
+        listener.connectAutoSubmitEvents(component, form);
+        _invoker.addFormEventListener(form.getExtendedId(), listener);
     }
 
     IComponent findComponent(String id, IComponent target)
@@ -192,7 +171,7 @@
 
             IForm form = (IForm) _forms.get(i);
 
-            IComponent match = findContainedComponent(child.getIdPath(), (Component)form);
+            IComponent match = findContainedComponent(child.getExtendedId(), (Component)form);
             if (match != null)
                 return form;
         }
@@ -204,7 +183,7 @@
     {
         IComponent comp = (IComponent) container;
 
-        if (idPath.equals(comp.getIdPath()))
+        if (idPath.equals(comp.getExtendedId()))
             return comp;
 
         IRender[] children = container.getContainedRenderers();

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java
Tue May  1 12:39:20 2007
@@ -95,7 +95,7 @@
     
     void linkComponentEvents(IRequestCycle cycle, IComponent component)
     {
-        ComponentEventProperty[] props = _invoker.getEventPropertyListeners(component.getIdPath());
+        ComponentEventProperty[] props = _invoker.getEventPropertyListeners(component.getExtendedId());
         if (props == null)
             return;
         
@@ -178,12 +178,12 @@
     
     void mapFormNames(IRequestCycle cycle, IForm form)
     {
-        List names = (List)cycle.getAttribute(FORM_NAME_LIST + form.getIdPath());
+        List names = (List)cycle.getAttribute(FORM_NAME_LIST + form.getExtendedId());
         
         if (names == null) {
             names = new ArrayList();
             
-            cycle.setAttribute(FORM_NAME_LIST + form.getIdPath(), names);
+            cycle.setAttribute(FORM_NAME_LIST + form.getExtendedId(), names);
         }
         
         names.add(form.getName());
@@ -191,7 +191,7 @@
     
     void linkDeferredForm(IRequestCycle cycle, IForm form)
     {
-        List deferred = (List)_deferredFormConnections.remove(form.getIdPath());
+        List deferred = (List)_deferredFormConnections.remove(form.getExtendedId());
         
         for (int i=0; i < deferred.size(); i++) {
             
@@ -208,13 +208,13 @@
             
             linkElementEvents(cycle, component);
             
-            ComponentEventProperty[] props = _invoker.getEventPropertyListeners(component.getIdPath());
+            ComponentEventProperty[] props = _invoker.getEventPropertyListeners(component.getExtendedId());
             if (props == null)
                 continue;
             
             for (int e=0; e < props.length; e++) {
                 
-                Object[][] formEvents = buildFormEvents(cycle, form.getIdPath(), 
+                Object[][] formEvents = buildFormEvents(cycle, form.getExtendedId(), 
                         props[e].getFormEvents(), (Boolean)val[1], (Boolean)val[2], val[3]);
                 
                 scriptParms.put("formEvents", formEvents);
@@ -304,7 +304,7 @@
     boolean isDeferredForm(IComponent component)
     {
         if (IForm.class.isInstance(component) 
-                && _deferredFormConnections.get(((IForm)component).getIdPath()) !=
null)
+                && _deferredFormConnections.get(((IForm)component).getExtendedId())
!= null)
             return true;
         
         return false;

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java
Tue May  1 12:39:20 2007
@@ -19,6 +19,7 @@
 import org.apache.hivemind.Resource;
 import org.apache.hivemind.util.Defense;
 import org.apache.hivemind.util.ToStringBuilder;
+import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IForm;
 import org.apache.tapestry.event.BrowserEvent;
 import org.apache.tapestry.internal.event.ComponentEventProperty;
@@ -166,8 +167,6 @@
     private Map _componentEvents = new HashMap();
     private Map _elementEvents = new HashMap();
 
-    private boolean _targetsResolved = false;
-
     /**
      * @throws ApplicationRuntimeException
      *             if the name already exists.
@@ -706,7 +705,7 @@
             property = new ComponentEventProperty(componentId);
             _componentEvents.put(componentId, property);
         }
-        
+
         property.addListener(events, methodName, formId, validateForm, async, focus, autoSubmit);
     }
     
@@ -721,20 +720,20 @@
             property = new ComponentEventProperty(elementId);
             _elementEvents.put(elementId, property);
         }
-        
+
         property.addListener(events, methodName, formId, validateForm, async, focus, true);
     }
 
-    public void connectAutoSubmitEvents(String componentId, IForm form)
+    public void connectAutoSubmitEvents(IComponent component, IForm form)
     {
         Defense.notNull(form, "form");
         
-        ComponentEventProperty property = getComponentEvents(componentId);
+        ComponentEventProperty property = getComponentEvents(component.getExtendedId());
         
         if (property == null)
             return;
-        
-        property.connectAutoSubmitEvents(form.getIdPath());
+
+        property.connectAutoSubmitEvents(form.getExtendedId());
     }
 
     public void rewireComponentId(String componentId, String idPath)
@@ -743,10 +742,21 @@
         if (prop == null)
             return;
 
-        prop.rewireComponentId(idPath);
-        
-        _componentEvents.remove(componentId);
-        _componentEvents.put(idPath, prop);
+        if (_componentEvents.containsKey(idPath))
+            return;
+
+        try {
+
+            ComponentEventProperty clone = (ComponentEventProperty) prop.clone();
+
+            clone.rewireComponentId(idPath);
+
+            _componentEvents.put(idPath, clone);
+
+        } catch (CloneNotSupportedException e) {
+
+            throw new ApplicationRuntimeException(e);
+        }
     }
 
     /**
@@ -790,7 +800,7 @@
             
             String compId = (String)it.next();
             ComponentEventProperty prop = (ComponentEventProperty)_componentEvents.get(compId);
-            
+
             ret.addAll(prop.getFormEventListeners(formId, event, null));
         }
         
@@ -799,7 +809,7 @@
             
             String compId = (String)it.next();
             ComponentEventProperty prop = (ComponentEventProperty)_elementEvents.get(compId);
-            
+
             ret.addAll(prop.getFormEventListeners(formId, event, null));
         }
         
@@ -812,16 +822,6 @@
     public boolean hasElementEvents()
     {
         return _elementEvents.size() > 0;
-    }
-
-    public boolean getTargetsResolved()
-    {
-        return _targetsResolved;
-    }
-
-    public void setTargetsResolved(boolean resolved)
-    {
-        _targetsResolved = resolved;
     }
 
     /**

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/IEventListener.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/IEventListener.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/IEventListener.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/spec/IEventListener.java
Tue May  1 12:39:20 2007
@@ -13,6 +13,7 @@
 // limitations under the License.
 package org.apache.tapestry.spec;
 
+import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IForm;
 import org.apache.tapestry.event.BrowserEvent;
 import org.apache.tapestry.internal.event.ComponentEventProperty;
@@ -81,10 +82,10 @@
      * Invoked during rendering when a component has been detected as a {@link org.apache.tapestry.form.IFormComponent}
and may
      * possibly need its events to be wired up as form events.
      *
-     * @param componentId The components standard base id.
+     * @param component The component to rewire form events for.
      * @param form The form containing the component.
      */
-    void connectAutoSubmitEvents(String componentId, IForm form);
+    void connectAutoSubmitEvents(IComponent component, IForm form);
 
     /**
      * Checks if any element events are bound to this component.
@@ -147,19 +148,4 @@
      *          The id of the component pre-pended with the path of components containing
it.
      */
     void rewireComponentId(String componentId, String idPath);
-
-    /**
-     * Used during page load to test if this event listener has already had its component
/ form target
-     * id paths resolved.
-     *
-     * @return True if connections have been resolved, false otherwise.
-     */
-    boolean getTargetsResolved();
-
-    /**
-     * Sets the resolved state to that found, ie what is returned by {@link #getTargetsResolved()}.
-     *
-     * @param resolved The resolution state.
-     */
-    void setTargetsResolved(boolean resolved);
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/ComponentEventPropertyTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/ComponentEventPropertyTest.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/ComponentEventPropertyTest.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/ComponentEventPropertyTest.java
Tue May  1 12:39:20 2007
@@ -180,11 +180,12 @@
         assertEquals("compid", prop.getComponentId());
         assertEquals(prop.getEvents().size(), 2);
         assertEquals(prop.getFormEvents().size(), 1);
-
+        
         String path = "new/Path/Id";
         prop.rewireComponentId(path);
 
         assertEquals(prop.getComponentId(), path);
+
 
         Iterator it = prop.getEvents().iterator();
         while (it.hasNext())

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/impl/ComponentEventInvokerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/impl/ComponentEventInvokerTest.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/impl/ComponentEventInvokerTest.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/internal/event/impl/ComponentEventInvokerTest.java
Tue May  1 12:39:20 2007
@@ -104,14 +104,13 @@
         IRequestCycle cycle = newCycle();
         IComponent comp = newComponent();
         checkOrder(comp, false);
-        IPage page = newMock(IPage.class);
-        
-        IComponentSpecification spec = new ComponentSpecification();
         
+        IPage page = newMock(IPage.class);
         ListenerInvoker listenerInvoker = newMock(ListenerInvoker.class);
         ListenerMap listenerMap = newMock(ListenerMap.class);
-        
         IActionListener listener1 = newMock(IActionListener.class);
+
+        IComponentSpecification spec = new ComponentSpecification();
         
         Map comps = new HashMap();
         comps.put("testId", comp);
@@ -127,7 +126,7 @@
                 "fooListener", null, false, false, false, false);
         invoker.addEventListener("testId", spec);
 
-        expect(comp.getIdPath()).andReturn("testId").anyTimes();
+        expect(comp.getExtendedId()).andReturn("testId").anyTimes();
         expect(comp.getSpecification()).andReturn(spec).anyTimes();
         expect(comp.getPage()).andReturn(page);
 
@@ -172,7 +171,7 @@
                 "fooListener", null, false, true, true);
         invoker.addEventListener("testId", spec);
         
-        expect(comp.getIdPath()).andReturn("testId").anyTimes();
+        expect(comp.getExtendedId()).andReturn("testId").anyTimes();
         expect(comp.getSpecification()).andReturn(spec).anyTimes();
         expect(comp.getPage()).andReturn(page);
         expect(page.getComponents()).andReturn(comps);
@@ -218,7 +217,7 @@
         invoker.addFormEventListener("form1", spec);
         
         expect(formSupport.getForm()).andReturn(form);
-        expect(form.getIdPath()).andReturn("form1").anyTimes();
+        expect(form.getExtendedId()).andReturn("form1").anyTimes();
         expect(form.getPage()).andReturn(page);
 
         expect(page.getComponents()).andReturn(comps);
@@ -268,7 +267,7 @@
         invoker.addFormEventListener("form1", spec);
         
         expect(formSupport.getForm()).andReturn(form);
-        expect(form.getIdPath()).andReturn("form1").anyTimes();
+        expect(form.getExtendedId()).andReturn("form1").anyTimes();
         expect(form.getPage()).andReturn(page);
         
         expect(page.getComponents()).andReturn(comps);

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestEventConnectionVisitor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestEventConnectionVisitor.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestEventConnectionVisitor.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestEventConnectionVisitor.java
Tue May  1 12:39:20 2007
@@ -1,7 +1,5 @@
 package org.apache.tapestry.pageload;
 
-import org.apache.hivemind.ApplicationRuntimeException;
-import org.apache.hivemind.Location;
 import org.apache.tapestry.BaseComponentTestCase;
 import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IPage;
@@ -23,20 +21,6 @@
 @Test
 public class TestEventConnectionVisitor extends BaseComponentTestCase {
 
-    public void test_Targets_Resolved()
-    {
-        IComponentSpecification spec = new ComponentSpecification();
-        spec.setTargetsResolved(true);
-        
-        IComponent comp = newComponent(spec);
-
-        replay();
-
-        new EventConnectionVisitor().visitComponent(comp);
-
-        verify();
-    }
-
     public void test_Wire_Component_Event()
     {
         IComponentSpecification spec = new ComponentSpecification();
@@ -57,24 +41,6 @@
         verify();
     }
 
-    @Test(expectedExceptions = ApplicationRuntimeException.class)
-    public void test_Component_Not_Found()
-    {
-        IComponentSpecification spec = new ComponentSpecification();
-        spec.addEventListener("comp1", new String[] {"onClick"}, "testFoo", null, false,
false, false, false);
-
-        IComponent comp = newComponent(spec, "comp2");
-        Location l = newLocation();
-
-        expect(comp.getLocation()).andReturn(l);
-
-        replay();
-
-        new EventConnectionVisitor().visitComponent(comp);
-
-        verify();
-    }
-
     public void test_Spec_Rewire_Id()
     {
         IComponentSpecification spec = newMock(IComponentSpecification.class);
@@ -86,15 +52,13 @@
 
         Map compEvents = new HashMap();
         compEvents.put("comp1", p);
-
-        expect(spec.getTargetsResolved()).andReturn(false);
+        
         expect(spec.getComponentEvents()).andReturn(compEvents);
         expect(spec.getElementEvents()).andReturn(Collections.EMPTY_MAP);
 
         invoker.addEventListener("path/comp1", spec);
 
         spec.rewireComponentId("comp1", "path/comp1");
-        spec.setTargetsResolved(true);
 
         replay();
 
@@ -121,7 +85,7 @@
 
         if (args.length > 0) {
         
-            expect(comp.getIdPath()).andReturn(args[0] + findCompId).anyTimes();
+            expect(comp.getExtendedId()).andReturn(args[0] + findCompId).anyTimes();
         }
 
         return comp;

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java
Tue May  1 12:39:20 2007
@@ -124,7 +124,7 @@
         expect(cycle.isRewinding()).andReturn(false);
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(component.getIdPath()).andReturn("comp1").anyTimes();
+        expect(component.getExtendedId()).andReturn("comp1").anyTimes();
         expect(component.getClientId()).andReturn("comp1").anyTimes();
         
         expect(cycle.getAttribute(TapestryUtils.PAGE_RENDER_SUPPORT_ATTRIBUTE)).andReturn(prs).anyTimes();
@@ -166,7 +166,7 @@
         
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(widget.getIdPath()).andReturn("wid1").anyTimes();
+        expect(widget.getExtendedId()).andReturn("wid1").anyTimes();
         expect(widget.getClientId()).andReturn("wid1").anyTimes();
         
         assert widgetSpec.getComponentEvents("wid1") != null;
@@ -253,7 +253,7 @@
         expect(cycle.getAttribute(TapestryUtils.PAGE_RENDER_SUPPORT_ATTRIBUTE)).andReturn(prs);
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(comp1.getIdPath()).andReturn("comp1").anyTimes();
+        expect(comp1.getExtendedId()).andReturn("comp1").anyTimes();
         expect(comp1.getClientId()).andReturn("comp1").anyTimes();
         
         expect(cycle.getAttribute(ComponentEventConnectionWorker.FORM_NAME_LIST + "form1")).andReturn(null);
@@ -266,7 +266,7 @@
         expect(cycle.getAttribute(TapestryUtils.PAGE_RENDER_SUPPORT_ATTRIBUTE)).andReturn(prs);
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(comp2.getIdPath()).andReturn("comp2").anyTimes();
+        expect(comp2.getExtendedId()).andReturn("comp2").anyTimes();
         expect(comp2.getClientId()).andReturn("comp2").anyTimes();
         
         expect(cycle.getAttribute(ComponentEventConnectionWorker.FORM_NAME_LIST + "form1")).andReturn(null);
@@ -279,7 +279,7 @@
         expect(cycle.getAttribute(TapestryUtils.PAGE_RENDER_SUPPORT_ATTRIBUTE)).andReturn(prs);
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(component.getIdPath()).andReturn("comp").anyTimes();
+        expect(component.getExtendedId()).andReturn("comp").anyTimes();
         expect(component.getSpecification()).andReturn(spec);
         
         replay();
@@ -388,7 +388,7 @@
         expect(cycle.getAttribute(TapestryUtils.PAGE_RENDER_SUPPORT_ATTRIBUTE)).andReturn(prs);
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(component.getIdPath()).andReturn("compListener").anyTimes();
+        expect(component.getExtendedId()).andReturn("compListener").anyTimes();
         expect(component.getClientId()).andReturn("compListener").anyTimes();
         expect(component.getSpecification()).andReturn(spec);
         
@@ -398,7 +398,7 @@
         expect(cycle.getAttribute(TapestryUtils.PAGE_RENDER_SUPPORT_ATTRIBUTE)).andReturn(prs);
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(comp1.getIdPath()).andReturn("comp1").anyTimes();
+        expect(comp1.getExtendedId()).andReturn("comp1").anyTimes();
         expect(comp1.getClientId()).andReturn("comp1").anyTimes();
         
         expect(cycle.getAttribute(ComponentEventConnectionWorker.FORM_NAME_LIST + "form1")).andReturn(null);
@@ -411,7 +411,7 @@
         expect(cycle.getAttribute(TapestryUtils.PAGE_RENDER_SUPPORT_ATTRIBUTE)).andReturn(prs);
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(comp2.getIdPath()).andReturn("comp2").anyTimes();
+        expect(comp2.getExtendedId()).andReturn("comp2").anyTimes();
         expect(comp2.getClientId()).andReturn("comp2").anyTimes();
         
         expect(cycle.getAttribute(ComponentEventConnectionWorker.FORM_NAME_LIST + "form1")).andReturn(null);
@@ -441,7 +441,7 @@
         
         expect(cycle.getAttribute(TapestryUtils.FIELD_PRERENDER)).andReturn(null);
         
-        expect(form.getIdPath()).andReturn("form1").anyTimes();
+        expect(form.getExtendedId()).andReturn("form1").anyTimes();
         
         expect(cycle.getAttribute(ComponentEventConnectionWorker.FORM_NAME_LIST + "form1")).andReturn(null);
         cycle.setAttribute(eq(ComponentEventConnectionWorker.FORM_NAME_LIST + "form1"), isA(List.class));
@@ -449,10 +449,10 @@
         expect(form.getName()).andReturn("form1_0").anyTimes();
 
         expect(comp1.getSpecification()).andReturn(comp1Spec);
-        expect(comp1.getIdPath()).andReturn("comp1").anyTimes();
+        expect(comp1.getExtendedId()).andReturn("comp1").anyTimes();
         
         expect(comp2.getSpecification()).andReturn(comp2Spec);
-        expect(comp2.getIdPath()).andReturn("comp2").anyTimes();
+        expect(comp2.getExtendedId()).andReturn("comp2").anyTimes();
         
         List formNames = new ArrayList();
         formNames.add("form1_0");

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/spec/TestComponentSpecification.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/spec/TestComponentSpecification.java?view=diff&rev=534213&r1=534212&r2=534213
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/spec/TestComponentSpecification.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/spec/TestComponentSpecification.java
Tue May  1 12:39:20 2007
@@ -17,6 +17,8 @@
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.Location;
 import org.apache.tapestry.BaseComponentTestCase;
+import org.apache.tapestry.internal.event.ComponentEventProperty;
+import org.apache.tapestry.internal.event.EventBoundListener;
 import org.testng.annotations.Test;
 
 /**
@@ -31,7 +33,7 @@
 @Test
 public class TestComponentSpecification extends BaseComponentTestCase
 {
-    public void testClaimPropertyOK()
+    public void test_Claim_Property_OK()
     {
         InjectSpecificationImpl inject1 = new InjectSpecificationImpl();
         inject1.setProperty("fred");
@@ -47,7 +49,7 @@
         assertEquals(2, cs.getInjectSpecifications().size());
     }
 
-    public void testClaimPropertyConflict()
+    public void test_Claim_Property_Conflict()
     {
         Location l1 = fabricateLocation(13);
         Location l2 = fabricateLocation(97);
@@ -78,7 +80,7 @@
         assertEquals(1, cs.getInjectSpecifications().size());
     }
 
-    public void testAddAssetConflict()
+    public void test_Add_Asset_Conflict()
     {
         Location l1 = fabricateLocation(13);
         Location l2 = fabricateLocation(97);
@@ -104,7 +106,7 @@
         }
     }
 
-    public void testAddComponentConflict()
+    public void test_Add_Component_Conflict()
     {
         Location l1 = fabricateLocation(13);
         Location l2 = fabricateLocation(97);
@@ -130,7 +132,7 @@
         }
     }
 
-    public void testAddParameterConflict()
+    public void test_Add_Parameter_Conflict()
     {
         Location l1 = fabricateLocation(13);
         Location l2 = fabricateLocation(97);
@@ -159,7 +161,7 @@
         }
     }
 
-    public void testAddBeanSpecificationConflict()
+    public void test_Add_Bean_Specification_Conflict()
     {
         Location l1 = fabricateLocation(13);
         Location l2 = fabricateLocation(97);
@@ -186,14 +188,14 @@
         }
     }
 
-    public void testGetRequiredParametersNone()
+    public void test_Get_Required_Parameters_None()
     {
         ComponentSpecification cs = new ComponentSpecification();
 
         assertTrue(cs.getRequiredParameters().isEmpty());
     }
 
-    public void testGetRequiredParametersOptional()
+    public void test_Get_Required_Parameters_Optional()
     {
         ComponentSpecification cs = new ComponentSpecification();
 
@@ -206,7 +208,7 @@
         assertTrue(cs.getRequiredParameters().isEmpty());
     }
 
-    public void testGetRequiredParametersFiltersAliases()
+    public void test_Get_Required_Parameters_Filters_Aliases()
     {
         ComponentSpecification cs = new ComponentSpecification();
 
@@ -218,5 +220,37 @@
         cs.addParameter(ps);
 
         assertListEquals(new Object[] { ps }, cs.getRequiredParameters().toArray());
+    }
+
+    public void test_Rewire_Component_Id()
+    {
+        ComponentSpecification cs = new ComponentSpecification();
+        cs.addEventListener("comp", new String[] {"foo"}, "doFoo", null, false, true, false,
false);
+
+        assertEquals(cs.getComponentEvents().size(), 1);
+        assert cs.getComponentEvents("comp") != null;
+
+        cs.rewireComponentId("unknown", "new/path");
+
+        assertEquals(cs.getComponentEvents().size(), 1);
+
+        cs.rewireComponentId("comp", "page/comp");
+        cs.rewireComponentId("comp", "page/comp");
+
+        assertEquals(cs.getComponentEvents().size(), 2);
+        assert cs.getComponentEvents("comp") != null;
+        assert cs.getComponentEvents("page/comp") != null;
+
+        ComponentEventProperty prop = cs.getComponentEvents("comp");
+        assertEquals(prop.getComponentId(), "comp");
+        assertEquals(prop.getEvents().size(), 1);
+        EventBoundListener listener = (EventBoundListener)prop.getEventListeners("foo").get(0);
+        assertEquals(listener.getComponentId(), "comp");
+
+        prop = cs.getComponentEvents("page/comp");
+        assertEquals(prop.getComponentId(), "page/comp");
+        assertEquals(prop.getEvents().size(), 1);
+        listener = (EventBoundListener)prop.getEventListeners("foo").get(0);
+        assertEquals(listener.getComponentId(), "page/comp");
     }
 }



Mime
View raw message