Coverage Report - org.apache.commons.clazz.bean.BeanClazzOperation
 
Classes in this File Line Coverage Branch Coverage Complexity
BeanClazzOperation
0%
0/24
0%
0/14
2.333
 
 1  
 /*
 2  
  * Copyright 2002-2004 The Apache Software Foundation
 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, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.clazz.bean;
 17  
 
 18  
 import org.apache.commons.clazz.Clazz;
 19  
 import org.apache.commons.clazz.ClazzLoader;
 20  
 import org.apache.commons.clazz.ClazzOperation;
 21  
 import org.apache.commons.clazz.common.ClazzFeatureSupport;
 22  
 
 23  
 /**
 24  
  * 
 25  
  * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
 26  
  * @version $Id: BeanClazzOperation.java 155436 2005-02-26 13:17:48Z dirkv $
 27  
  */
 28  
 public abstract class BeanClazzOperation
 29  
     extends ClazzFeatureSupport
 30  
     implements ClazzOperation 
 31  
 {
 32  
     private String returnClazzName;
 33  
     private Clazz returnClazz;
 34  
     private String name;
 35  0
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
 36  
     private String[] parameterClazzNames;
 37  
     private Clazz[] parameterClazzes;
 38  
     private String signature;
 39  
     
 40  
     /**
 41  
      * Constructor for BeanClazzOperaiton.
 42  
      * 
 43  
      * @param declaringClazz the Clazz this Operation belongs to
 44  
      * @param returnClazzName the return type of the operation, pass
 45  
      * <code>null</code> for <code>void</code>.
 46  
      * @param name the name of the operation.
 47  
      * @param parameterClazzNames types of operation parameters, pass
 48  
      * <code>null</code> if the operation does not take any parameters.
 49  
      */
 50  
     public BeanClazzOperation(
 51  
             Clazz declaringClazz,
 52  
             String returnClazzName,
 53  
             String name,
 54  
             String[] parameterClazzNames) 
 55  
     {
 56  0
         super(declaringClazz);
 57  0
         this.returnClazzName = returnClazzName;
 58  0
         this.name = name;
 59  0
         this.parameterClazzNames =
 60  
             (parameterClazzNames != null
 61  
                 ? parameterClazzNames
 62  
                 : EMPTY_STRING_ARRAY);
 63  0
     }
 64  
 
 65  
     /**
 66  
      * @see ClazzOperation#getSignature()
 67  
      */
 68  
     public String getSignature() {
 69  0
         if (signature == null) {
 70  0
             signature = Clazz.constructSignature(name, getParameterClazzes());
 71  
         }
 72  
 
 73  0
         return signature;
 74  
     }
 75  
 
 76  
     /**
 77  
      * @see ClazzOperation#getName()
 78  
      */
 79  
     public String getName() {
 80  0
         return name;
 81  
     }
 82  
 
 83  
     /**
 84  
      * @see ClazzOperation#getParameterClazzes()
 85  
      */
 86  
     public Clazz[] getParameterClazzes() {
 87  0
         if (parameterClazzes == null) {
 88  0
             parameterClazzes = new Clazz[parameterClazzNames.length];
 89  0
             ClazzLoader loader = getDeclaringClazz().getClazzLoader();
 90  0
             for (int i = 0; i < parameterClazzes.length; i++) {
 91  0
                 parameterClazzes[i] =
 92  
                     loader.getClazzForName(parameterClazzNames[i]);
 93  0
                 if (parameterClazzes[i] == null) {
 94  0
                     throw new BeanClazzConfigurationException(
 95  
                         "Invalid argument type: "
 96  
                             + parameterClazzNames[i]
 97  
                             + ". Clazz not found.");
 98  
                 }
 99  
             }
 100  
         }
 101  
 
 102  0
         return parameterClazzes;
 103  
     }
 104  
 
 105  
     /**
 106  
      * @see ClazzOperation#getReturnClazz()
 107  
      */
 108  
     public Clazz getReturnClazz() {
 109  0
         if (returnClazzName == null) {
 110  0
             return null;
 111  
         }
 112  
         
 113  0
         if (returnClazz == null) {
 114  0
             ClazzLoader loader = getDeclaringClazz().getClazzLoader();
 115  0
             returnClazz = loader.getClazzForName(returnClazzName);            
 116  
         }
 117  
 
 118  0
         return returnClazz;
 119  
     }
 120  
 
 121  
     /**
 122  
      * @see ClazzOperation#invoke(Object, Object[])
 123  
      */
 124  
     public abstract Object invoke(Object target, Object[] parameters);
 125  
 }