tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1094826 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure: ComponentPageElementImpl.java InternalComponentResourcesImpl.java
Date Tue, 19 Apr 2011 00:18:31 GMT
Author: hlship
Date: Tue Apr 19 00:18:31 2011
New Revision: 1094826

URL: http://svn.apache.org/viewvc?rev=1094826&view=rev
Log:
TAP5-1308: Replace usage of CaseInsensitiveMap with NamedSet inside component instances

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java?rev=1094826&r1=1094825&r2=1094826&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
Tue Apr 19 00:18:31 2011
@@ -14,13 +14,24 @@
 
 package org.apache.tapestry5.internal.structure;
 
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.tapestry5.*;
+import org.apache.tapestry5.Binding;
+import org.apache.tapestry5.Block;
+import org.apache.tapestry5.BlockNotFoundException;
+import org.apache.tapestry5.ComponentEventCallback;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.EventContext;
+import org.apache.tapestry5.Link;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.Renderable;
+import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.TapestryMarkers;
 import org.apache.tapestry5.annotations.AfterRender;
 import org.apache.tapestry5.annotations.AfterRenderBody;
 import org.apache.tapestry5.annotations.AfterRenderTemplate;
@@ -34,6 +45,7 @@ import org.apache.tapestry5.internal.Int
 import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.services.ComponentEventImpl;
 import org.apache.tapestry5.internal.services.Instantiator;
+import org.apache.tapestry5.internal.util.NamedSet;
 import org.apache.tapestry5.internal.util.NotificationEventCallback;
 import org.apache.tapestry5.ioc.BaseLocatable;
 import org.apache.tapestry5.ioc.Invokable;
@@ -495,11 +507,11 @@ public class ComponentPageElementImpl ex
         }
     }
 
-    private Map<String, Block> blocks;
+    private NamedSet<Block> blocks;
 
     private BlockImpl bodyBlock;
 
-    private Map<String, ComponentPageElement> children;
+    private NamedSet<ComponentPageElement> children;
 
     private final String elementName;
 
@@ -534,10 +546,9 @@ public class ComponentPageElementImpl ex
 
     /**
      * Map from mixin id (the simple name of the mixin class) to resources for the mixin.
Created
-     * when first mixin is
-     * added.
+     * when first mixin is added.
      */
-    private Map<String, InternalComponentResources> mixinIdToComponentResources;
+    private NamedSet<InternalComponentResources> mixinIdToComponentResources;
 
     private final String nestedId;
 
@@ -643,10 +654,9 @@ public class ComponentPageElementImpl ex
 
         Set<Class> handled = coreResources.getComponentModel().getHandledRenderPhases();
 
-        if (mixinIdToComponentResources != null)
+        for (ComponentResources r : NamedSet.getValues(mixinIdToComponentResources))
         {
-            for (ComponentResources r : mixinIdToComponentResources.values())
-                handled.addAll(r.getComponentModel().getHandledRenderPhases());
+            handled.addAll(r.getComponentModel().getHandledRenderPhases());
         }
 
         if (!handled.contains(CleanupRender.class))
@@ -703,25 +713,25 @@ public class ComponentPageElementImpl ex
     void addEmbeddedElement(ComponentPageElement child)
     {
         if (children == null)
-            children = CollectionFactory.newCaseInsensitiveMap();
+            children = NamedSet.create();
 
         String childId = child.getId();
 
-        ComponentPageElement existing = children.get(childId);
+        if (!children.putIfNew(childId, child))
+        {
+            ComponentPageElement existing = children.get(childId);
 
-        if (existing != null)
             throw new TapestryException(StructureMessages.duplicateChildComponent(this, childId),
child,
                     new TapestryException(StructureMessages.originalChildComponent(this,
childId,
                             existing.getLocation()), existing, null));
-
-        children.put(childId, child);
+        }
     }
 
     public void addMixin(String mixinId, Instantiator instantiator, String... order)
     {
         if (mixinIdToComponentResources == null)
         {
-            mixinIdToComponentResources = CollectionFactory.newCaseInsensitiveMap();
+            mixinIdToComponentResources = NamedSet.create();
             components = CollectionFactory.newList();
         }
 
@@ -753,7 +763,7 @@ public class ComponentPageElementImpl ex
 
     public void bindMixinParameter(String mixinId, String parameterName, Binding binding)
     {
-        InternalComponentResources mixinResources = InternalUtils.get(mixinIdToComponentResources,
mixinId);
+        InternalComponentResources mixinResources = NamedSet.get(mixinIdToComponentResources,
mixinId);
 
         mixinResources.bindParameter(parameterName, binding);
     }
@@ -887,11 +897,11 @@ public class ComponentPageElementImpl ex
 
     public ComponentPageElement getEmbeddedElement(String embeddedId)
     {
-        ComponentPageElement embeddedElement = InternalUtils.get(children, embeddedId);
+        ComponentPageElement embeddedElement = NamedSet.get(children, embeddedId);
 
         if (embeddedElement == null)
         {
-            Set<String> ids = InternalUtils.keys(children);
+            Set<String> ids = NamedSet.getNames(children);
 
             throw new UnknownValueException(String.format("Component %s does not contain
embedded component '%s'.",
                     getCompleteId(), embeddedId), new AvailableValues("Embedded components",
ids));
@@ -925,7 +935,7 @@ public class ComponentPageElementImpl ex
         if (mixinIdToComponentResources == null)
             return null;
 
-        for (InternalComponentResources resources : mixinIdToComponentResources.values())
+        for (InternalComponentResources resources : NamedSet.getValues(mixinIdToComponentResources))
         {
             if (resources.getComponentModel().getComponentClassName().equals(mixinClassName))
{ return resources
                     .getComponent(); }
@@ -936,10 +946,7 @@ public class ComponentPageElementImpl ex
 
     public ComponentResources getMixinResources(String mixinId)
     {
-        ComponentResources result = null;
-
-        if (mixinIdToComponentResources != null)
-            result = mixinIdToComponentResources.get(mixinId);
+        ComponentResources result = NamedSet.get(mixinIdToComponentResources, mixinId);
 
         if (result == null)
             throw new IllegalArgumentException(String.format("Unable to locate mixin '%s'
for component '%s'.",
@@ -1199,8 +1206,14 @@ public class ComponentPageElementImpl ex
 
         addUnboundParameterNames(null, unbound, coreResources);
 
-        for (String name : InternalUtils.sortedKeys(mixinIdToComponentResources))
+        List<String> sortedNames = CollectionFactory.newList(NamedSet.getNames(mixinIdToComponentResources));
+
+        Collections.sort(sortedNames);
+
+        for (String name : sortedNames)
+        {
             addUnboundParameterNames(name, unbound, mixinIdToComponentResources.get(name));
+        }
 
         if (unbound.isEmpty())
             return;
@@ -1231,18 +1244,17 @@ public class ComponentPageElementImpl ex
     public Block findBlock(String id)
     {
         assert InternalUtils.isNonBlank(id);
-        return InternalUtils.get(blocks, id);
+
+        return NamedSet.get(blocks, id);
     }
 
     public void addBlock(String blockId, Block block)
     {
         if (blocks == null)
-            blocks = CollectionFactory.newCaseInsensitiveMap();
+            blocks = NamedSet.create();
 
-        if (blocks.containsKey(blockId))
+        if (!blocks.putIfNew(blockId, block))
             throw new TapestryException(StructureMessages.duplicateBlock(this, blockId),
block, null);
-
-        blocks.put(blockId, block);
     }
 
     public String getPageName()

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java?rev=1094826&r1=1094825&r2=1094826&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
Tue Apr 19 00:18:31 2011
@@ -30,6 +30,7 @@ import org.apache.tapestry5.internal.Int
 import org.apache.tapestry5.internal.bindings.InternalPropBinding;
 import org.apache.tapestry5.internal.services.Instantiator;
 import org.apache.tapestry5.internal.transform.ParameterConduit;
+import org.apache.tapestry5.internal.util.NamedSet;
 import org.apache.tapestry5.ioc.AnnotationProvider;
 import org.apache.tapestry5.ioc.Location;
 import org.apache.tapestry5.ioc.Messages;
@@ -76,11 +77,11 @@ public class InternalComponentResourcesI
     private static final AnnotationProvider NULL_ANNOTATION_PROVIDER = new NullAnnotationProvider();
 
     // Case insensitive map from parameter name to binding
-    private Map<String, Binding> bindings;
+    private NamedSet<Binding> bindings;
 
     // Case insensitive map from parameter name to ParameterConduit, used to support mixins
     // which need access to the containing component's PC's
-    private Map<String, ParameterConduit> conduits;
+    private NamedSet<ParameterConduit> conduits;
 
     private Messages messages;
 
@@ -318,7 +319,7 @@ public class InternalComponentResourcesI
     public void bindParameter(String parameterName, Binding binding)
     {
         if (bindings == null)
-            bindings = CollectionFactory.newCaseInsensitiveMap();
+            bindings = NamedSet.create();
 
         bindings.put(parameterName, binding);
     }
@@ -332,7 +333,7 @@ public class InternalComponentResourcesI
 
     public Binding getBinding(String parameterName)
     {
-        return InternalUtils.get(bindings, parameterName);
+        return NamedSet.get(bindings, parameterName);
     }
 
     public AnnotationProvider getAnnotationProvider(String parameterName)
@@ -446,16 +447,12 @@ public class InternalComponentResourcesI
     {
         Map<String, Binding> result = CollectionFactory.newMap();
 
-        if (bindings != null)
+        for (String name : NamedSet.getNames(bindings))
         {
-            for (String name : bindings.keySet())
-            {
-
-                if (componentModel.getParameterModel(name) != null)
-                    continue;
+            if (componentModel.getParameterModel(name) != null)
+                continue;
 
-                result.put(name, bindings.get(name));
-            }
+            result.put(name, bindings.get(name));
         }
 
         return result;
@@ -527,13 +524,13 @@ public class InternalComponentResourcesI
 
     public synchronized ParameterConduit getParameterConduit(String parameterName)
     {
-        return InternalUtils.get(conduits, parameterName);
+        return NamedSet.get(conduits, parameterName);
     }
 
     public synchronized void setParameterConduit(String parameterName, ParameterConduit conduit)
     {
         if (conduits == null)
-            conduits = CollectionFactory.newCaseInsensitiveMap();
+            conduits = NamedSet.create();
 
         conduits.put(parameterName, conduit);
     }



Mime
View raw message