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