Coverage Report - org.apache.tapestry.binding.ClientIdBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
ClientIdBinding
0%
0/11
N/A
1.75
 
 1  
 // Copyright 2006 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.binding;
 16  
 
 17  
 import org.apache.hivemind.ApplicationRuntimeException;
 18  
 import org.apache.hivemind.Location;
 19  
 import org.apache.hivemind.util.Defense;
 20  
 import org.apache.tapestry.IBinding;
 21  
 import org.apache.tapestry.IComponent;
 22  
 import org.apache.tapestry.coerce.ValueConverter;
 23  
 
 24  
 /**
 25  
  * An implementation of Tapestry {@link IBinding} that simplifies 
 26  
  * access to a component's clientId.<br/>
 27  
  * You can use this binding in order to safely find out the 
 28  
  * client-side id that was (or will be) generated for a given 
 29  
  * component.
 30  
  * 
 31  
  * <p/>
 32  
  * Here's an example of how to get the client id of a Tapestry component:
 33  
  * <code>
 34  
  * &lt;span jwcid="@Any" dojoType="myDojoComponent" contentId="clientId:content" /&gt;
 35  
  * </code>
 36  
  * <p/>
 37  
  * The previous code can also be written using the ognl binding:
 38  
  * <code>
 39  
  * &lt;span jwcid="@Any" dojoType="myDojoComponent" contentId="ognl:components.content.clientId" /&gt;
 40  
  * </code>
 41  
  * but the clientId binding is more compact and performs much faster.
 42  
  */
 43  
 public class ClientIdBinding extends AbstractBinding
 44  
 {
 45  
     private final IComponent _component;
 46  
 
 47  
     private final String _componentId;
 48  
 
 49  
     public ClientIdBinding(String description, ValueConverter valueConverter, Location location,
 50  
             IComponent component, String componentId)
 51  
     {
 52  0
         super(description, valueConverter, location);
 53  
 
 54  0
         Defense.notNull(component, "component");
 55  0
         Defense.notNull(componentId, "componentId");
 56  
 
 57  0
         _component = component;
 58  0
         _componentId = componentId;
 59  0
     }
 60  
 
 61  
     public Object getObject()
 62  
     {
 63  
         try
 64  
         {
 65  0
             return _component.getComponent(_componentId).getClientId();
 66  
         }
 67  0
         catch (Exception ex)
 68  
         {
 69  0
             throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex);
 70  
         }
 71  
     }
 72  
 
 73  
     public Object getComponent()
 74  
     {
 75  0
         return _component;
 76  
     }
 77  
         
 78  
     public boolean isInvariant()
 79  
     {
 80  
         // clientId can change even for the same component, so ...
 81  0
         return false;
 82  
     }
 83  
 
 84  
 }