Coverage Report - org.seasar.teeda.core.config.faces.handler.SimpleStringTagHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleStringTagHandler
86%
24/28
83%
10/12
2.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.config.faces.handler;
 17  
 
 18  
 import java.lang.reflect.Method;
 19  
 
 20  
 import org.seasar.framework.log.Logger;
 21  
 import org.seasar.framework.xml.TagHandlerContext;
 22  
 import org.seasar.teeda.core.util.TagConvertUtil;
 23  
 
 24  
 /**
 25  
  * @author shot
 26  
  */
 27  
 public class SimpleStringTagHandler extends JsfTagHandler {
 28  
 
 29  1
     private static Logger logger = Logger
 30  1
             .getLogger(SimpleStringTagHandler.class);
 31  
 
 32  
     private static final long serialVersionUID = 3257284721212863026L;
 33  
 
 34  
     private static final int SINGLE_PARAMETER = 1;
 35  
 
 36  
     private String tagName;
 37  
 
 38  777
     public SimpleStringTagHandler(String tagName) {
 39  777
         this.tagName = tagName;
 40  777
     }
 41  
 
 42  
     public void end(TagHandlerContext context, String body) {
 43  141
         setAppropriateProperty(context.peek(), body);
 44  141
     }
 45  
 
 46  
     protected void setAppropriateProperty(Object tag, String context) {
 47  141
         if (context == null) {
 48  0
             return;
 49  
         }
 50  141
         String[] setters = TagConvertUtil.convertToSetter(tagName);
 51  141
         Method[] methods = tag.getClass().getDeclaredMethods();
 52  141
         String setterName = null;
 53  141
         Method method = null;
 54  423
         for (int i = 0; i < setters.length; i++) {
 55  282
             setterName = setters[i];
 56  2944
             for (int j = 0; j < methods.length; j++) {
 57  2662
                 method = methods[j];
 58  2662
                 boolean isSameSetter = isSameSetter(method, setterName);
 59  2662
                 boolean isSingleParameter = isSingleParameter(method);
 60  2662
                 if (isSameSetter && isSingleParameter) {
 61  
                     try {
 62  141
                         method.invoke(tag, new Object[] { context });
 63  0
                     } catch (Exception ignore) {
 64  0
                         logger.log(ignore);
 65  
                         break;
 66  0
                     } finally {
 67  
                         /*
 68  
                          if (logger.isDebugEnabled()) {
 69  
                          logger.debug("<" + tagName + ">" + context + "</"
 70  
                          + tagName + ">");
 71  
                          }
 72  
                          */
 73  141
                     }
 74  
                 }
 75  
             }
 76  
         }
 77  141
     }
 78  
 
 79  
     private static boolean isSameSetter(Method method, String setterName) {
 80  2662
         return setterName.equals(method.getName());
 81  
     }
 82  
 
 83  
     private static boolean isSingleParameter(Method method) {
 84  2662
         return (method.getParameterTypes().length == SINGLE_PARAMETER);
 85  
     }
 86  
 
 87  
 }