Author: andyhot
Date: Sun Nov  5 05:21:26 2006
New Revision: 471419

URL: http://svn.apache.org/viewvc?view=rev&rev=471419
Log:
New binding type for easily getting to those client-side ids

Added:
    
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBinding.java
    
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBindingFactory.java
Modified:
    
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml

Modified: 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml?view=diff&rev=471419&r1=471418&r2=471419
==============================================================================
--- 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml
 (original)
+++ 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml
 Sun Nov  5 05:21:26 2006
@@ -131,6 +131,17 @@
     
   </service-point>
   
+  <service-point id="ClientIdBindingFactory" interface="BindingFactory">  
+      
+      Creates bindings where the path is a HiveMind object reference.
+      
+    <invoke-factory>
+      <construct class="ClientIdBindingFactory">
+        <set-object property="valueConverter" 
value="infrastructure:valueConverter"/>
+      </construct>
+    </invoke-factory>
+  </service-point> 
+  
   <configuration-point id="BindingFactories">
     
     Used to map binding prefixes to binding factories.
@@ -165,6 +176,7 @@
     <binding prefix="component" service-id="ComponentBindingFactory"/>
     <binding prefix="state" service-id="StateBindingFactory"/>
     <binding prefix="hivemind" service-id="HiveMindBindingFactory"/>
+    <binding prefix="clientId" service-id="ClientIdBindingFactory"/>
   </contribution>
   
   <service-point id="BindingSource">

Added: 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBinding.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBinding.java?view=auto&rev=471419
==============================================================================
--- 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBinding.java
 (added)
+++ 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBinding.java
 Sun Nov  5 05:21:26 2006
@@ -0,0 +1,79 @@
+// Copyright 2006 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.
+
+package org.apache.tapestry.binding;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.util.Defense;
+import org.apache.tapestry.IComponent;
+import org.apache.tapestry.binding.AbstractBinding;
+import org.apache.tapestry.coerce.ValueConverter;
+
+/**
+ * A binding returning the client-side id of a component.
+ */
+public class ClientIdBinding extends AbstractBinding
+{
+    private final IComponent _component;
+
+    private final String _componentId;
+
+    public ClientIdBinding(String description, ValueConverter valueConverter, 
Location location,
+            IComponent component, String componentId)
+    {
+        super(description, valueConverter, location);
+
+        Defense.notNull(component, "component");
+        Defense.notNull(componentId, "componentId");
+
+        _component = component;
+        _componentId = componentId;
+    }
+
+    /**
+     * The client-side id of a component. Null is returned of the component in 
question 
+     * hasn't already rendered.
+     */
+    public Object getObject()
+    {
+        try
+        {            
+            return 
_component.getPage().getRequestCycle().getAttribute("org.apache.tapestry.lastId."
 
+                    + _componentId);
+            // could try checking for null here and returning the following
+            // but this still isn't really correct.
+            // return _component.getComponent(_componentId).getClientId();
+        }
+        catch (Exception ex)
+        {
+            throw new ApplicationRuntimeException(ex.getMessage(), 
getLocation(), ex);
+        }
+    }
+
+    public Object getComponent()
+    {
+        return _component;
+    }
+        
+    /**
+     * Not invariant 'cause the same component might have multiple client-side 
ids 
+     * when rendered more than once.
+     */
+    public boolean isInvariant()
+    {
+        return false;
+    }
+
+}

Added: 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBindingFactory.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBindingFactory.java?view=auto&rev=471419
==============================================================================
--- 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBindingFactory.java
 (added)
+++ 
tapestry/tapestry4/branches/4.1.1-clientIds/tapestry-framework/src/java/org/apache/tapestry/binding/ClientIdBindingFactory.java
 Sun Nov  5 05:21:26 2006
@@ -0,0 +1,33 @@
+// Copyright 2006 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.
+
+package org.apache.tapestry.binding;
+
+import org.apache.hivemind.Location;
+import org.apache.tapestry.IBinding;
+import org.apache.tapestry.IComponent;
+import org.apache.tapestry.binding.AbstractBindingFactory;
+
+/**
+ * Factory for [EMAIL PROTECTED] 
org.apache.tapestry.binding.ClientIdBinding}instances, which are mapped to
+ * the "clientId:" prefix.
+ */
+public class ClientIdBindingFactory extends AbstractBindingFactory
+{
+    public IBinding createBinding(IComponent root, String description, String 
expression,
+            Location location)
+    {
+        return new ClientIdBinding(description, getValueConverter(), location, 
root, expression);
+    }
+}


Reply via email to