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.Method;
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: ReflectedMethodInstanceFactoryIntrospector.java 155436 2005-02-26 13:17:48Z dirkv $
030     */
031    public class ReflectedMethodInstanceFactoryIntrospector
032        implements ReflectedInstanceFactoryIntrospector 
033    {
034    
035        /**
036         * @see ReflectedInstanceFactoryIntrospector#introspectInstanceFactories(ReflectedClazz, Class)
037         */
038        public List introspectInstanceFactories(
039            ReflectedClazz clazz,
040            Class javaClass) 
041        {
042            ArrayList list = new ArrayList();
043            Method methods[] = javaClass.getMethods();
044            for (int i = 0; i < methods.length; i++) {
045                Method method = methods[i];
046                int modifiers = method.getModifiers();
047                if (Modifier.isStatic(modifiers)
048                    && javaClass.equals(method.getReturnType())) {
049                    list.add(new ReflectedMethodInstanceFactory(clazz, method));
050                }
051            }
052            return list;
053        }
054    }