Coverage Report - org.seasar.teeda.core.util.MethodBindingUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
MethodBindingUtil
11%
3/27
0%
0/16
4.4
 
 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.util;
 17  
 
 18  
 import javax.faces.context.FacesContext;
 19  
 import javax.faces.el.EvaluationException;
 20  
 import javax.faces.el.MethodBinding;
 21  
 import javax.faces.event.AbortProcessingException;
 22  
 
 23  
 import org.seasar.framework.util.AssertionUtil;
 24  
 
 25  
 public class MethodBindingUtil {
 26  
 
 27  0
     private MethodBindingUtil() {
 28  0
     }
 29  
 
 30  
     public static String getComponentName(final String fromAction) {
 31  0
         if (fromAction == null) {
 32  0
             return null;
 33  
         }
 34  0
         if (!BindingUtil.isValueReference(fromAction)) {
 35  0
             return null;
 36  
         }
 37  0
         int index = fromAction.indexOf('.');
 38  0
         if (index > 0) {
 39  0
             return fromAction.substring(2, index);
 40  
         }
 41  0
         return null;
 42  
     }
 43  
 
 44  
     public static String getMethodName(final String fromAction) {
 45  0
         if (fromAction == null) {
 46  0
             return null;
 47  
         }
 48  0
         if (!BindingUtil.isValueReference(fromAction)) {
 49  0
             return null;
 50  
         }
 51  0
         int index = fromAction.lastIndexOf('.');
 52  0
         if (index > 0) {
 53  0
             return fromAction.substring(index + 1, fromAction.length() - 1);
 54  
         }
 55  0
         return null;
 56  
     }
 57  
 
 58  
     public static String getFromAction(String componentName, String methodName) {
 59  1
         AssertionUtil.assertNotNull("componentName", componentName);
 60  1
         AssertionUtil.assertNotNull("methodName", methodName);
 61  1
         return "#{" + componentName + "." + methodName + "}";
 62  
     }
 63  
 
 64  
     public static String invoke(MethodBinding methodBinding,
 65  
             FacesContext context) {
 66  
         try {
 67  0
             return (String) methodBinding.invoke(context, null);
 68  0
         } catch (EvaluationException e) {
 69  0
             Throwable cause = e.getCause();
 70  0
             if (cause != null && cause instanceof AbortProcessingException) {
 71  0
                 throw (AbortProcessingException) cause;
 72  
             }
 73  0
             throw e;
 74  
         }
 75  
     }
 76  
 }