Coverage Report - org.apache.myfaces.view.facelets.tag.composite.ClientBehaviorAttachedObjectTargetImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ClientBehaviorAttachedObjectTargetImpl
0%
0/41
0%
0/24
2.9
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.view.facelets.tag.composite;
 20  
 
 21  
 import java.io.Serializable;
 22  
 import java.util.ArrayList;
 23  
 import java.util.Collections;
 24  
 import java.util.List;
 25  
 
 26  
 import javax.el.ValueExpression;
 27  
 import javax.faces.FacesException;
 28  
 import javax.faces.component.UIComponent;
 29  
 import javax.faces.component.behavior.ClientBehaviorHolder;
 30  
 import javax.faces.context.FacesContext;
 31  
 
 32  
 import org.apache.myfaces.shared.util.StringUtils;
 33  
 
 34  
 /**
 35  
  * @author Leonardo Uribe (latest modification by $Author$)
 36  
  * @version $Revision$ $Date$
 37  
  */
 38  
 public class ClientBehaviorAttachedObjectTargetImpl 
 39  
     implements ClientBehaviorAttachedObjectTarget, Serializable
 40  
 {
 41  
 
 42  
     /**
 43  
      * 
 44  
      */
 45  
     private static final long serialVersionUID = -4645087262404844925L;
 46  
 
 47  
     protected ValueExpression _name;
 48  
     
 49  
     protected ValueExpression _targets;
 50  
     
 51  
     protected ValueExpression _event;
 52  
     
 53  
     protected boolean _default;
 54  
 
 55  
     public ClientBehaviorAttachedObjectTargetImpl()
 56  0
     {
 57  0
     }
 58  
 
 59  
     public String getName()
 60  
     {
 61  0
         if (_name != null)
 62  
         {
 63  0
             return (String) _name.getValue(FacesContext.getCurrentInstance().getELContext());
 64  
         }        
 65  0
         return null;
 66  
     }
 67  
 
 68  
     public List<UIComponent> getTargets(UIComponent topLevelComponent)
 69  
     {
 70  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 71  0
         String [] targetsArray = getTargets(facesContext);
 72  
         
 73  0
         if (targetsArray.length > 0)
 74  
         {
 75  0
             List<UIComponent> targetsList = new ArrayList<UIComponent>(targetsArray.length);
 76  0
             for (String target : targetsArray)
 77  
             {
 78  0
                 UIComponent innerComponent = topLevelComponent.findComponent(target);
 79  
                 
 80  0
                 if (innerComponent != null)
 81  
                 {
 82  0
                     if (innerComponent instanceof ClientBehaviorHolder ||
 83  
                         UIComponent.isCompositeComponent(innerComponent))
 84  
                     {
 85  0
                         targetsList.add(
 86  
                                 new ClientBehaviorRedirectEventComponentWrapper(innerComponent, getName(), getEvent()));
 87  
                     }
 88  
                     else
 89  
                     {
 90  0
                         throw new FacesException("Component with clientId " + innerComponent.getClientId(facesContext)
 91  
                                                  + "should be instance of ClientBehaviorHolder");
 92  
                     }
 93  
                 }
 94  
             }
 95  0
             return targetsList;
 96  
         }
 97  
         else
 98  
         {
 99  
             // composite:actionSource/valueHolder/editableValueHolder
 100  
             // "name" description says if targets is not set, name is 
 101  
             // the component id of the target component where
 102  
             // it should be mapped to
 103  0
             String name = getName();
 104  0
             if (name != null)
 105  
             {
 106  0
                 UIComponent innerComponent = topLevelComponent.findComponent(getName());
 107  0
                 if (innerComponent != null)
 108  
                 {
 109  0
                     if (innerComponent instanceof ClientBehaviorHolder ||
 110  
                         UIComponent.isCompositeComponent(innerComponent))
 111  
                     {
 112  0
                         List<UIComponent> targetsList = new ArrayList<UIComponent>(1);
 113  0
                         targetsList.add(
 114  
                                 new ClientBehaviorRedirectEventComponentWrapper(innerComponent, getName(), getEvent()));
 115  0
                         return targetsList;
 116  
                     }
 117  
                     else
 118  
                     {
 119  0
                         throw new FacesException("Component with clientId "+ innerComponent.getClientId(facesContext)
 120  
                                                  + "should be instance of ClientBehaviorHolder");
 121  
                     }
 122  
                 }
 123  
             }
 124  0
             return Collections.emptyList();
 125  
         }
 126  
     }
 127  
     
 128  
     public String [] getTargets(FacesContext context)
 129  
     {
 130  0
         if (_targets != null)
 131  
         {
 132  0
             return StringUtils.splitShortString((String) _targets.getValue(context.getELContext()), ' ');
 133  
         }
 134  0
         return org.apache.myfaces.shared.util.ArrayUtils.EMPTY_STRING_ARRAY;
 135  
     }
 136  
     
 137  
     public void setName(ValueExpression name)
 138  
     {
 139  0
         _name = name;
 140  0
     }
 141  
     
 142  
     public void setTargets(ValueExpression ve)
 143  
     {
 144  0
         _targets = ve;
 145  0
     }
 146  
     
 147  
     public String getEvent()
 148  
     {
 149  0
         if (_event != null)
 150  
         {
 151  0
             return (String) _event.getValue(FacesContext.getCurrentInstance().getELContext());
 152  
         }        
 153  0
         return null;
 154  
     }
 155  
     
 156  
     public void setEvent(ValueExpression event)
 157  
     {
 158  0
         this._event = event;
 159  0
     }
 160  
 
 161  
     public boolean isDefaultEvent()
 162  
     {
 163  0
         return _default;
 164  
     }
 165  
 
 166  
     public void setDefault(boolean default1)
 167  
     {
 168  0
         _default = default1;
 169  0
     }
 170  
 }