001    /*
002     * Copyright 2002-2004 The Apache Software Foundation
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.commons.clazz.reflect;
017    
018    import org.apache.commons.clazz.ClazzLoader;
019    import org.apache.commons.clazz.ModelClazzLoader;
020    import org.apache.commons.clazz.common.GroupClazzLoader;
021    
022    /**
023     * A clazz loader that groups multiple <code>ReflectedClazzLoaders</code>.
024     * Its primary purpose is to optimize the methods that are executed the same way
025     * by all <code>ReflectedClazzLoaders</code>, specifically the
026     * <code>getClazzName()</code> method, which is always the same as the
027     * corresponding <b>class</b> name
028     * 
029     * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
030     * @version $Id: ReflectedGroupClazzLoader.java 155436 2005-02-26 13:17:48Z dirkv $
031     */
032    public class ReflectedGroupClazzLoader extends GroupClazzLoader {
033        
034        public ReflectedGroupClazzLoader(ModelClazzLoader modelClazzLoader) {
035            super(modelClazzLoader);
036        }
037    
038        public boolean canAddClazzLoader(ClazzLoader loader) {
039            return loader instanceof ReflectedClazzLoader;
040        }
041            
042        /**
043         * @see org.apache.commons.clazz.ClazzLoader#isMember(java.lang.Object)
044         */
045        public boolean isMember(Object instance) {
046            return true;
047        }
048    
049        /**
050         * @see org.apache.commons.clazz.ClazzLoader#getClazzName(java.lang.Object)
051         */
052        public String getClazzName(Object instance) {
053            if (instance == null) {
054                return null;
055            }
056            return instance.getClass().getName();
057        }
058    }