Coverage Report - org.apache.commons.clazz.bean.BeanClazzLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
BeanClazzLoader
0%
0/14
0%
0/12
2.4
 
 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 java.lang.reflect.Constructor;
 19  
 
 20  
 import org.apache.commons.clazz.Clazz;
 21  
 import org.apache.commons.clazz.ClazzLoader;
 22  
 import org.apache.commons.clazz.ModelClazzLoader;
 23  
 
 24  
 /**
 25  
  * 
 26  
  * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
 27  
  * @version $Id: BeanClazzLoader.java 155436 2005-02-26 13:17:48Z dirkv $
 28  
  */
 29  
 public class BeanClazzLoader extends ClazzLoader {
 30  
     
 31  
     public BeanClazzLoader(ModelClazzLoader modelClazzLoader) {
 32  0
         super(modelClazzLoader);
 33  0
     }
 34  
 
 35  
     /**
 36  
      * @see ClazzLoader#isMember(Object)
 37  
      */
 38  
     public boolean isMember(Object instance) {
 39  0
         return instance instanceof Bean;
 40  
     }
 41  
 
 42  
     public String getClazzName(Object instance) {
 43  0
         if (!isMember(instance)) {
 44  0
             return null;
 45  
         }
 46  
         
 47  0
         return ((Bean) instance).getClazz().getName();
 48  
     }
 49  
         
 50  
     /**
 51  
      * BeanClazzLoader does not cache clazzes, its parent, BeanGroupClazzLoader,
 52  
      * is responsible for caching
 53  
      */
 54  
     public Clazz getClazzForName(String clazzName) {
 55  0
         return null;
 56  
     }
 57  
     
 58  
     /**
 59  
      * @see ClazzLoader#defineClazz(String, Class, Class)
 60  
      */
 61  
     public Clazz defineClazz(String name, Class clazzType, Class instanceClass) 
 62  
     {
 63  0
         if (!BeanClazz.class.isAssignableFrom(clazzType)) {
 64  0
             return null;
 65  
         }
 66  
         try {
 67  0
             Constructor constructor =
 68  
                 clazzType.getConstructor(
 69  
                     new Class[] {
 70  
                         ClazzLoader.class,
 71  
                         String.class,
 72  
                         Class.class });
 73  0
             return (Clazz) constructor.newInstance(
 74  
                 new Object[] { getModelClazzLoader(), name, instanceClass });
 75  
         }
 76  0
         catch (Exception e) {
 77  0
             e.printStackTrace();
 78  0
             throw new BeanClazzConfigurationException(
 79  
                 "Cannot define clazz "
 80  
                     + name
 81  
                     + " of clazz type "
 82  
                     + clazzType.getName(),
 83  
                 e);
 84  
         }
 85  
     }
 86  
 }