Coverage Report - org.seasar.teeda.core.taglib.core.ValueChangeListenerTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValueChangeListenerTag
53%
16/30
42%
5/12
3.75
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.taglib.core;
 17  
 
 18  
 import javax.faces.component.EditableValueHolder;
 19  
 import javax.faces.component.UIComponent;
 20  
 import javax.faces.context.FacesContext;
 21  
 import javax.faces.el.ValueBinding;
 22  
 import javax.faces.event.ValueChangeListener;
 23  
 import javax.faces.internal.ValueBindingUtil;
 24  
 import javax.faces.webapp.UIComponentTag;
 25  
 import javax.servlet.jsp.JspException;
 26  
 import javax.servlet.jsp.tagext.TagSupport;
 27  
 
 28  
 import org.seasar.framework.util.ClassUtil;
 29  
 import org.seasar.teeda.core.exception.NoEditableValueHolderRuntimeException;
 30  
 
 31  
 /**
 32  
  * @author yone
 33  
  */
 34  4
 public class ValueChangeListenerTag extends TagSupport {
 35  
 
 36  
     private static final long serialVersionUID = 1L;
 37  
 
 38  4
     private String type = null;
 39  
 
 40  
     public void setType(String type) {
 41  3
         this.type = type;
 42  3
     }
 43  
 
 44  
     public String getType() {
 45  4
         return type;
 46  
     }
 47  
 
 48  
     public int doStartTag() throws JspException {
 49  3
         final String type = getType();
 50  3
         if (type == null) {
 51  1
             throw new JspException("type attribute not set");
 52  
         }
 53  2
         UIComponentTag tag = UIComponentTag
 54  
                 .getParentUIComponentTag(pageContext);
 55  2
         if (tag == null) {
 56  1
             throw new JspException("Not nested in a UIComponentTag");
 57  
         }
 58  1
         if (!tag.getCreated()) {
 59  1
             return SKIP_BODY;
 60  
         }
 61  
 
 62  0
         UIComponent component = tag.getComponentInstance();
 63  0
         if (component == null) {
 64  0
             throw new JspException(
 65  
                     "No component associated with UIComponentTag");
 66  
         }
 67  0
         if (component instanceof EditableValueHolder) {
 68  0
             String className = null;
 69  0
             if (UIComponentTag.isValueReference(type)) {
 70  0
                 FacesContext context = FacesContext.getCurrentInstance();
 71  0
                 ValueBinding vb = ValueBindingUtil.createValueBinding(context,
 72  
                         type);
 73  0
                 className = (String) vb.getValue(context);
 74  
             } else {
 75  0
                 className = type;
 76  
             }
 77  0
             ValueChangeListener listener = (ValueChangeListener) ClassUtil
 78  
                     .newInstance(className);
 79  0
             ((EditableValueHolder) component).addValueChangeListener(listener);
 80  
         } else {
 81  0
             throw new NoEditableValueHolderRuntimeException(component
 82  
                     .getClass());
 83  
         }
 84  0
         return SKIP_BODY;
 85  
     }
 86  
 
 87  
     public void release() {
 88  1
         super.release();
 89  1
         type = null;
 90  1
     }
 91  
 
 92  
 }