Coverage Report - org.apache.commons.clazz.reflect.common.ReflectedConstructorInstanceFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ReflectedConstructorInstanceFactory
0%
0/23
0%
0/8
2
 
 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.reflect.common;
 17  
 
 18  
 import java.lang.reflect.Constructor;
 19  
 
 20  
 import org.apache.commons.clazz.Clazz;
 21  
 import org.apache.commons.clazz.ClazzAccessException;
 22  
 import org.apache.commons.clazz.ClazzInstanceFactory;
 23  
 import org.apache.commons.clazz.ClazzLoader;
 24  
 import org.apache.commons.clazz.common.ClazzFeatureSupport;
 25  
 
 26  
 /**
 27  
  * A wrapper for a java constructor.
 28  
  * 
 29  
  * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
 30  
  * @version $Id: ReflectedConstructorInstanceFactory.java 155436 2005-02-26 13:17:48Z dirkv $
 31  
  */
 32  
 public class ReflectedConstructorInstanceFactory extends ClazzFeatureSupport
 33  
         implements ClazzInstanceFactory
 34  
 {   
 35  
     private Constructor constructor;
 36  
     private String signature;
 37  0
     private static final Clazz[] EMPTY_CLAZZ_ARRAY = new Clazz[0];
 38  
     private Clazz[] parameterClazzes;
 39  
 
 40  
     /**
 41  
      * Constructor for ReflectedClazzProperty.
 42  
      */
 43  
     public ReflectedConstructorInstanceFactory(
 44  
             Clazz declaringClazz,
 45  
             Constructor constructor)
 46  
     {
 47  0
         super(declaringClazz);
 48  0
         this.constructor = constructor;
 49  0
     }
 50  
 
 51  
     public Constructor getConstructor() {
 52  0
         return constructor;
 53  
     }
 54  
 
 55  
     public String getName() {
 56  0
         return null;
 57  
     }
 58  
 
 59  
     /**
 60  
      * @see org.apache.commons.clazz.ClazzOperation#getSignature()
 61  
      */
 62  
     public String getSignature() {
 63  0
         if (signature == null) {
 64  0
             signature =
 65  
                 Clazz.constructSignature(null, constructor.getParameterTypes());
 66  
         }
 67  0
         return signature;
 68  
     }
 69  
 
 70  
     /**
 71  
      * @see org.apache.commons.clazz.ClazzOperation#getParameterClazzes()
 72  
      */
 73  
     public Clazz[] getParameterClazzes() {
 74  0
         if (parameterClazzes == null) {
 75  0
             Class paramClasses[] = constructor.getParameterTypes();
 76  0
             if (paramClasses == null) {
 77  0
                 parameterClazzes = EMPTY_CLAZZ_ARRAY;
 78  
             }
 79  
             else {
 80  0
                 parameterClazzes = new Clazz[paramClasses.length];
 81  0
                 ClazzLoader loader = getDeclaringClazz().getClazzLoader();
 82  0
                 for (int i = 0; i < paramClasses.length; i++) {
 83  0
                     String name = Clazz.getCanonicalClassName(paramClasses[i]);
 84  0
                     parameterClazzes[i] = loader.getClazzForName(name);
 85  
                 }
 86  
             }
 87  
         }
 88  0
         return parameterClazzes;
 89  
     }
 90  
 
 91  
     public Object newInstance(Object[] parameters) {
 92  
         try {
 93  0
             return constructor.newInstance(parameters);
 94  
         }
 95  0
         catch (Throwable e) {
 96  0
             throw new ClazzAccessException(
 97  
                 "Cannot invoke constructor " + getSignature(),
 98  
                 e);
 99  
         }
 100  
     }
 101  
 
 102  
     public String toString() {
 103  0
         return getSignature();
 104  
     }
 105  
 }