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.common;
017    
018    import java.lang.reflect.Constructor;
019    import java.lang.reflect.Modifier;
020    import java.util.ArrayList;
021    import java.util.List;
022    
023    import org.apache.commons.clazz.reflect.ReflectedClazz;
024    import org.apache.commons.clazz.reflect.ReflectedInstanceFactoryIntrospector;
025    
026    /**
027     * 
028     * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
029     * @version $Id: ReflectedConstructorInstanceFactoryIntrospector.java 155436 2005-02-26 13:17:48Z dirkv $
030     */
031    public class ReflectedConstructorInstanceFactoryIntrospector
032        implements ReflectedInstanceFactoryIntrospector 
033    {
034        /**
035         * @see ReflectedInstanceFactoryIntrospector#introspectInstanceFactories(ReflectedClazz, Class)
036         */
037        public List introspectInstanceFactories(
038                ReflectedClazz clazz,
039                Class javaClass) 
040        {
041            ArrayList list = new ArrayList();
042            Constructor constructors[] = javaClass.getDeclaredConstructors();
043            for (int i = 0; i < constructors.length; i++) {
044                Constructor constructor = constructors[i];
045                if (Modifier.isPublic(constructor.getModifiers())) {
046                    list.add(
047                        new ReflectedConstructorInstanceFactory(
048                            clazz,
049                            constructor));
050                }
051            }
052            return list;
053        }
054    
055    }