001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 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 017/* 018Copyright 2005-2006 Seth Fitzsimmons <seth@note.amherst.edu> 019 020Licensed under the Apache License, Version 2.0 (the "License"); 021you may not use this file except in compliance with the License. 022You may obtain a copy of the License at 023 024 http://www.apache.org/licenses/LICENSE-2.0 025 026Unless required by applicable law or agreed to in writing, software 027distributed under the License is distributed on an "AS IS" BASIS, 028WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 029See the License for the specific language governing permissions and 030limitations under the License. 031*/ 032package com.echothree.view.client.web.struts.sprout.support; 033 034import java.lang.reflect.Method; 035import java.util.ArrayList; 036import java.util.Arrays; 037import java.util.Collection; 038import org.apache.log4j.Logger; 039 040/** 041 * Sprout utility methods. 042 * 043 * @author Seth Fitzsimmons 044 */ 045public class SproutUtils { 046 047 private static final Logger log = Logger.getLogger( SproutUtils.class ); 048 049 /** 050 * Gets a collection of methods declared in a specified range of a given 051 * class' hierarchy. 052 * 053 * @param clazz Class to inspect. 054 * @param upto Methods declared in this class and its subclasses will be 055 * included. Any methods declared in superclasses will be ignored. 056 * @return Collection of methods declared within the specified range. 057 */ 058 public static Collection<Method> getDeclaredMethods(Class clazz, final Class upto) { 059 // collect methods to register (include methods for all classes up to and including this one) 060 final Collection<Method> methods = new ArrayList<>(); 061 while ( !clazz.equals( upto.getSuperclass() ) ) { 062 methods.addAll( Arrays.asList( clazz.getDeclaredMethods() ) ); 063 clazz = clazz.getSuperclass(); 064 } 065 066 return methods; 067 } 068 069}