Coverage Report - org.apache.myfaces.event.SetPropertyActionListener
 
Classes in this File Line Coverage Branch Coverage Complexity
SetPropertyActionListener
0%
0/34
0%
0/8
1.727
 
 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.event;
 20  
 
 21  
 import javax.el.ELContext;
 22  
 import javax.el.ValueExpression;
 23  
 import javax.faces.component.StateHolder;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.event.AbortProcessingException;
 26  
 import javax.faces.event.ActionEvent;
 27  
 import javax.faces.event.ActionListener;
 28  
 
 29  
 /**
 30  
  * The MyFaces implementation of the <code>SetPropertyActionListener</code>.
 31  
  * 
 32  
  * @author Dennis Byrne
 33  
  * @since 1.2
 34  
  */
 35  
 public class SetPropertyActionListener implements ActionListener, StateHolder
 36  
 {
 37  
 
 38  
     private ValueExpression target;
 39  
     
 40  
     private ValueExpression value;
 41  
     
 42  
     private boolean _transient ;
 43  
     
 44  0
     public SetPropertyActionListener(){}
 45  
     
 46  
     public SetPropertyActionListener(ValueExpression target, ValueExpression value)
 47  0
     {
 48  0
         this.target = target;
 49  0
         this.value = value;
 50  0
     }
 51  
     
 52  
     public void processAction(ActionEvent actionEvent) throws AbortProcessingException
 53  
     {
 54  
         
 55  0
         if( target == null )
 56  0
             throw new AbortProcessingException("@target has not been set");
 57  
 
 58  0
         if( value == null )
 59  0
             throw new AbortProcessingException("@value has not been set");
 60  
         
 61  0
         FacesContext ctx = FacesContext.getCurrentInstance();
 62  
         
 63  0
         if( ctx == null )
 64  0
             throw new AbortProcessingException("FacesContext ctx is null");
 65  
         
 66  0
         ELContext ectx = ctx.getELContext();
 67  
         
 68  0
         if( ectx == null )
 69  0
             throw new AbortProcessingException("ELContext ectx is null");
 70  
         
 71  
         // TODO use a Converter before calling setValue 
 72  
         
 73  0
         target.setValue(ectx, value.getValue(ectx));
 74  
         
 75  0
     }
 76  
 
 77  
     public Object saveState(FacesContext context)
 78  
     {
 79  0
         Object[] state = new Object[2];
 80  0
         state[0] = target;
 81  0
         state[1] = value;
 82  0
         return state;
 83  
     }
 84  
 
 85  
     public void restoreState(FacesContext context, Object state)
 86  
     {
 87  0
         Object[] values = (Object[]) state;
 88  0
         target = (ValueExpression) values[0];
 89  0
         value = (ValueExpression) values[1];
 90  0
     }
 91  
 
 92  
     public boolean isTransient()
 93  
     {
 94  0
         return _transient;
 95  
     }
 96  
 
 97  
     public void setTransient(boolean _transient)
 98  
     {
 99  0
         this._transient = _transient;
 100  0
     }
 101  
 
 102  
     public ValueExpression getTarget()
 103  
     {
 104  0
         return target;
 105  
     }
 106  
 
 107  
     public void setTarget(ValueExpression target)
 108  
     {
 109  0
         this.target = target;
 110  0
     }
 111  
 
 112  
     public ValueExpression getValue()
 113  
     {
 114  0
         return value;
 115  
     }
 116  
 
 117  
     public void setValue(ValueExpression value)
 118  
     {
 119  0
         this.value = value;
 120  0
     }
 121  
 
 122  
 }