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.ReflectedOperationIntrospector;
025    
026    /**
027     * A ReflectedOperationIntrospector that discovers an operation for each public
028     * method of the class.
029     * 
030     * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
031     * @version $Id: ReflectedMethodOperationIntrospector.java 155436 2005-02-26 13:17:48Z dirkv $
032     */
033    public class ReflectedMethodOperationIntrospector 
034                implements ReflectedOperationIntrospector 
035    {
036        public List introspectOperations(
037                ReflectedClazz clazz,
038                Class javaClass)
039        {
040            ArrayList list = new ArrayList();
041            Method methods[] = javaClass.getDeclaredMethods();
042            for (int i = 0; i < methods.length; i++) {
043                Method method = methods[i];
044                if (Modifier.isPublic(method.getModifiers())) {
045                    list.add(new ReflectedMethodOperation(clazz, method));
046                }
047            }
048            return list;
049        }
050    }