Coverage Report - org.apache.myfaces.view.facelets.util.FaceletsViewDeclarationLanguageUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
FaceletsViewDeclarationLanguageUtils
0%
0/30
0%
0/12
8.5
 
 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.view.facelets.util;
 20  
 
 21  
 import java.util.ArrayList;
 22  
 import javax.faces.FacesException;
 23  
 import org.apache.myfaces.shared.util.ClassUtils;
 24  
 
 25  
 /**
 26  
  * Utility methods used in FaceletsViewDeclarationLanguage
 27  
  *
 28  
  * @author Leonardo Uribe
 29  
  */
 30  0
 public class FaceletsViewDeclarationLanguageUtils
 31  
 {
 32  
     public static Class getReturnType(String signature)
 33  
     {
 34  0
         int endName = signature.indexOf('(');
 35  0
         if (endName < 0)
 36  
         {
 37  0
             throw new FacesException("Invalid method signature:" + signature);
 38  
         }
 39  0
         int end = signature.lastIndexOf(' ', endName);
 40  0
         if (end < 0)
 41  
         {
 42  0
             throw new FacesException("Invalid method signature:" + signature);
 43  
         }
 44  
         try
 45  
         {
 46  0
             return ClassUtils.javaDefaultTypeToClass(signature.substring(0, end));
 47  
         }
 48  0
         catch (ClassNotFoundException e)
 49  
         {
 50  0
             throw new FacesException("Invalid method signature:" + signature);
 51  
         }
 52  
     }
 53  
 
 54  
     /**
 55  
      * Get the parameters types from the function signature.
 56  
      *
 57  
      * @return An array of parameter class names
 58  
      */
 59  
     public static Class[] getParameters(String signature) throws FacesException
 60  
     {
 61  0
         ArrayList<Class> params = new ArrayList<Class>();
 62  
         // Signature is of the form
 63  
         // <return-type> S <method-name S? '('
 64  
         // < <arg-type> ( ',' <arg-type> )* )? ')'
 65  0
         int start = signature.indexOf('(') + 1;
 66  0
         boolean lastArg = false;
 67  
         while (true)
 68  
         {
 69  0
             int p = signature.indexOf(',', start);
 70  0
             if (p < 0)
 71  
             {
 72  0
                 p = signature.indexOf(')', start);
 73  0
                 if (p < 0)
 74  
                 {
 75  0
                     throw new FacesException("Invalid method signature:" + signature);
 76  
                 }
 77  0
                 lastArg = true;
 78  
             }
 79  0
             String arg = signature.substring(start, p).trim();
 80  0
             if (!"".equals(arg))
 81  
             {
 82  
                 try
 83  
                 {
 84  0
                     params.add(ClassUtils.javaDefaultTypeToClass(arg));
 85  
                 }
 86  0
                 catch (ClassNotFoundException e)
 87  
                 {
 88  0
                     throw new FacesException("Invalid method signature:" + signature);
 89  0
                 }
 90  
             }
 91  0
             if (lastArg)
 92  
             {
 93  0
                 break;
 94  
             }
 95  0
             start = p + 1;
 96  0
         }
 97  0
         return params.toArray(new Class[params.size()]);
 98  
     }
 99  
 
 100  
 
 101  
 }