Coverage Report - javax.faces.component.behavior.ClientBehaviorBase
 
Classes in this File Line Coverage Branch Coverage Complexity
ClientBehaviorBase
0%
0/32
0%
0/18
2.667
 
 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 javax.faces.component.behavior;
 20  
 
 21  
 import java.util.Collections;
 22  
 import java.util.Set;
 23  
 
 24  
 import javax.faces.component.UIComponent;
 25  
 import javax.faces.context.FacesContext;
 26  
 import javax.faces.render.ClientBehaviorRenderer;
 27  
 
 28  
 /**
 29  
  * @since 2.0
 30  
  */
 31  
 public class ClientBehaviorBase extends BehaviorBase implements ClientBehavior
 32  
 {
 33  
 
 34  
     private transient FacesContext _facesContext;
 35  
     
 36  
     /**
 37  
      * 
 38  
      */
 39  
     public ClientBehaviorBase()
 40  0
     {
 41  0
     }
 42  
 
 43  
     /**
 44  
      * {@inheritDoc}
 45  
      */
 46  
     public void decode(FacesContext context, UIComponent component)
 47  
     {
 48  0
         if (context == null)
 49  
         {
 50  0
             throw new NullPointerException("context");
 51  
         }
 52  
         
 53  0
         if (component == null)
 54  
         {
 55  0
             throw new NullPointerException("component");
 56  
         }
 57  
         
 58  
         // If a BehaviorRenderer is available for the specified behavior renderer type, this method delegates 
 59  
         // to the BehaviorRenderer's decode() method. Otherwise, no decoding is performed. 
 60  0
         ClientBehaviorRenderer renderer = getRenderer(context);
 61  0
         if (renderer != null)
 62  
         {
 63  0
             renderer.decode(context, component, this);
 64  
         }
 65  0
     }
 66  
 
 67  
     /**
 68  
      * {@inheritDoc}
 69  
      */
 70  
      public Set<ClientBehaviorHint> getHints()
 71  
     {
 72  0
         return Collections.<ClientBehaviorHint>emptySet();
 73  
     }
 74  
 
 75  
     /**
 76  
      * {@inheritDoc}
 77  
      */
 78  
     public String getRendererType()
 79  
     {
 80  0
         return null;
 81  
     }
 82  
 
 83  
     /**
 84  
      * {@inheritDoc}
 85  
      */
 86  
     public String getScript(ClientBehaviorContext behaviorContext)
 87  
     {
 88  0
         if (behaviorContext == null)
 89  
         {
 90  0
             throw new NullPointerException("behaviorContext");
 91  
         }
 92  
         
 93  0
         ClientBehaviorRenderer renderer = getRenderer(behaviorContext.getFacesContext());
 94  0
         if (renderer != null)
 95  
         {
 96  
             // If a BehaviorRenderer is available for the specified behavior renderer type, this method delegates 
 97  
             // to the BehaviorRenderer.getScript method.
 98  
             try
 99  
             {
 100  0
                 setCachedFacesContext(behaviorContext.getFacesContext());
 101  0
                 return renderer.getScript(behaviorContext, this);
 102  
             }
 103  
             finally
 104  
             {
 105  0
                 setCachedFacesContext(null);
 106  
             }
 107  
         }
 108  
         
 109  
         // Otherwise, this method returns null.
 110  0
         return null;
 111  
     }
 112  
     
 113  
     protected ClientBehaviorRenderer getRenderer(FacesContext context)
 114  
     {
 115  0
         if (context == null)
 116  
         {
 117  0
             throw new NullPointerException("context");
 118  
         }
 119  
         
 120  0
         String rendererType = getRendererType();
 121  0
         if (rendererType != null)
 122  
         {
 123  0
             return context.getRenderKit().getClientBehaviorRenderer(rendererType);
 124  
         }
 125  
         
 126  0
         return null;
 127  
     }
 128  
     
 129  
     FacesContext getFacesContext()
 130  
     {
 131  0
         if (_facesContext == null)
 132  
         {
 133  0
             return FacesContext.getCurrentInstance();
 134  
         }
 135  
         else
 136  
         {
 137  0
             return _facesContext;
 138  
         }
 139  
     }
 140  
     
 141  
     boolean isCachedFacesContext()
 142  
     {
 143  0
         return _facesContext != null;
 144  
     }
 145  
     
 146  
     void setCachedFacesContext(FacesContext facesContext)
 147  
     {
 148  0
         _facesContext = facesContext;
 149  0
     }
 150  
 }