Coverage Report - org.seasar.teeda.core.taglib.core.ActionListenerTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionListenerTag
0%
0/27
0%
0/8
2
 
 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.ActionSource;
 19  
 import javax.faces.component.UIComponent;
 20  
 import javax.faces.context.FacesContext;
 21  
 import javax.faces.el.ValueBinding;
 22  
 import javax.faces.event.ActionListener;
 23  
 import javax.faces.internal.ValueBindingUtil;
 24  
 import javax.faces.webapp.UIComponentTag;
 25  
 import javax.servlet.jsp.JspException;
 26  
 import javax.servlet.jsp.tagext.Tag;
 27  
 import javax.servlet.jsp.tagext.TagSupport;
 28  
 
 29  
 import org.seasar.framework.util.ClassUtil;
 30  
 
 31  
 /**
 32  
  * @author shot
 33  
  */
 34  
 public class ActionListenerTag extends TagSupport {
 35  
 
 36  
     private static final long serialVersionUID = 1L;
 37  
 
 38  0
     private String type = null;
 39  
 
 40  0
     public ActionListenerTag() {
 41  0
     }
 42  
 
 43  
     public void setType(String type) {
 44  0
         this.type = type;
 45  0
     }
 46  
 
 47  
     public String getType() {
 48  0
         return type;
 49  
     }
 50  
 
 51  
     public int doStartTag() throws JspException {
 52  0
         UIComponentTag componentTag = UIComponentTag
 53  
                 .getParentUIComponentTag(pageContext);
 54  0
         if (componentTag == null) {
 55  0
             throw new JspException("Not nested in a UIComponentTag");
 56  
         }
 57  0
         if (!componentTag.getCreated()) {
 58  0
             return Tag.SKIP_BODY;
 59  
         }
 60  0
         UIComponent component = componentTag.getComponentInstance();
 61  0
         if (component instanceof ActionSource) {
 62  0
             String className = getActionListenerClassName();
 63  0
             ActionListener actionListener = createActionListener(className);
 64  0
             ((ActionSource) component).addActionListener(actionListener);
 65  
         } else {
 66  0
             throw new JspException("Component:" + component
 67  
                     + " is not instance of ActionSource");
 68  
         }
 69  0
         return Tag.SKIP_BODY;
 70  
     }
 71  
 
 72  
     public void release() {
 73  0
         type = null;
 74  0
     }
 75  
 
 76  
     protected String getActionListenerClassName() {
 77  0
         String className = type;
 78  0
         if (UIComponentTag.isValueReference(type)) {
 79  0
             FacesContext context = FacesContext.getCurrentInstance();
 80  0
             ValueBinding vb = ValueBindingUtil
 81  
                     .createValueBinding(context, type);
 82  0
             className = (String) vb.getValue(context);
 83  
         }
 84  0
         return className;
 85  
     }
 86  
 
 87  
     protected ActionListener createActionListener(String className) {
 88  0
         return (ActionListener) ClassUtil.newInstance(className);
 89  
     }
 90  
 
 91  
 }