Coverage Report - javax.faces.component._MethodBindingToListener
 
Classes in this File Line Coverage Branch Coverage Complexity
_MethodBindingToListener
0%
0/33
0%
0/8
2.222
 
 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  
 
 20  
 package javax.faces.component;
 21  
 
 22  
 import javax.faces.FacesException;
 23  
 import javax.faces.context.FacesContext;
 24  
 import javax.faces.el.EvaluationException;
 25  
 import javax.faces.el.MethodBinding;
 26  
 import javax.faces.event.AbortProcessingException;
 27  
 import javax.faces.event.FacesEvent;
 28  
 
 29  
 /**
 30  
  * Common base class for converting a MethodBinding to a FacesListener
 31  
  */
 32  
 abstract class _MethodBindingToListener implements StateHolder
 33  
 {
 34  
 
 35  
     protected MethodBinding methodBinding;
 36  
 
 37  
     public _MethodBindingToListener()
 38  0
     {
 39  0
     }
 40  
 
 41  
     /**
 42  
      * Creates a new instance of MethodBindingToListener
 43  
      */
 44  
     public _MethodBindingToListener(MethodBinding methodBinding)
 45  0
     {
 46  0
         if (methodBinding == null)
 47  
         {
 48  0
             throw new NullPointerException("methodBinding can not be null");
 49  
         }
 50  0
         if (!(methodBinding instanceof StateHolder))
 51  
         {
 52  0
             throw new IllegalArgumentException("methodBinding must implement the StateHolder interface");
 53  
         }
 54  
 
 55  0
         this.methodBinding = methodBinding;
 56  0
     }
 57  
 
 58  
     private FacesContext getFacesContext()
 59  
     {
 60  0
         return FacesContext.getCurrentInstance();
 61  
     }
 62  
 
 63  
     protected void invokeMethodBinding(FacesEvent event) throws AbortProcessingException
 64  
     {
 65  
         try
 66  
         {
 67  0
             methodBinding.invoke(getFacesContext(), new Object[]{event});
 68  
         }
 69  0
         catch (EvaluationException e)
 70  
         {
 71  0
             Throwable cause = e.getCause();
 72  0
             if (cause != null && cause instanceof AbortProcessingException)
 73  
             {
 74  0
                 throw (AbortProcessingException) cause;
 75  
             }
 76  
 
 77  0
             throw e;
 78  0
         }
 79  0
     }
 80  
 
 81  
     public MethodBinding getMethodBinding()
 82  
     {
 83  0
         return methodBinding;
 84  
     }
 85  
 
 86  
     public void restoreState(FacesContext context, Object state)
 87  
     {
 88  0
         Object[] stateArray = (Object[]) state;
 89  
         try
 90  
         {
 91  0
             methodBinding = (MethodBinding) _ClassUtils.getContextClassLoader()
 92  
                     .loadClass((String) stateArray[0])
 93  
                     .newInstance();
 94  
         }
 95  0
         catch (Exception e)
 96  
         {
 97  0
             throw new FacesException(e);
 98  0
         }
 99  
 
 100  0
         ((StateHolder) methodBinding).restoreState(context, stateArray[1]);
 101  0
     }
 102  
 
 103  
     public Object saveState(FacesContext context)
 104  
     {
 105  0
         Object[] stateArray = new Object[2];
 106  0
         stateArray[0] = methodBinding.getClass().getName();
 107  0
         stateArray[1] = ((StateHolder) methodBinding).saveState(context);
 108  0
         return stateArray;
 109  
     }
 110  
 
 111  
     public void setTransient(boolean newTransientValue)
 112  
     {
 113  0
         ((StateHolder) methodBinding).setTransient(newTransientValue);
 114  0
     }
 115  
 
 116  
     public boolean isTransient()
 117  
     {
 118  0
         return ((StateHolder) methodBinding).isTransient();
 119  
     }
 120  
 
 121  
 }