<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FReflection%2FInterface</id>
		<title>Java/Reflection/Interface - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FReflection%2FInterface"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Reflection/Interface&amp;action=history"/>
		<updated>2026-04-23T02:50:57Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Reflection/Interface&amp;diff=6079&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Reflection/Interface&amp;diff=6079&amp;oldid=prev"/>
				<updated>2010-06-01T06:01:53Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:01, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Reflection/Interface&amp;diff=6078&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Reflection/Interface&amp;diff=6078&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:43Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Class Reflection: implemented interfaces ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
/* From http://java.sun.ru/docs/books/tutorial/index.html */&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Permission to use, copy, modify, and distribute this software and its&lt;br /&gt;
 * documentation for NON-COMMERCIAL purposes and without fee is hereby granted&lt;br /&gt;
 * provided that this copyright notice appears in all copies. Please refer to&lt;br /&gt;
 * the file &amp;quot;copyright.html&amp;quot; for further important copyright and licensing&lt;br /&gt;
 * information.&lt;br /&gt;
 * &lt;br /&gt;
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE&lt;br /&gt;
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED&lt;br /&gt;
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR&lt;br /&gt;
 * NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY&lt;br /&gt;
 * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS&lt;br /&gt;
 * DERIVATIVES.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.RandomAccessFile;&lt;br /&gt;
public class SampleInterface {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    try {&lt;br /&gt;
      RandomAccessFile r = new RandomAccessFile(&amp;quot;myfile&amp;quot;, &amp;quot;r&amp;quot;);&lt;br /&gt;
      printInterfaceNames(r);&lt;br /&gt;
    } catch (IOException e) {&lt;br /&gt;
      System.out.println(e);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  static void printInterfaceNames(Object o) {&lt;br /&gt;
    Class c = o.getClass();&lt;br /&gt;
    Class[] theInterfaces = c.getInterfaces();&lt;br /&gt;
    for (int i = 0; i &amp;lt; theInterfaces.length; i++) {&lt;br /&gt;
      String interfaceName = theInterfaces[i].getName();&lt;br /&gt;
      System.out.println(interfaceName);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Reflection: is it an interface ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
/* From http://java.sun.ru/docs/books/tutorial/index.html */&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Permission to use, copy, modify, and distribute this software and its&lt;br /&gt;
 * documentation for NON-COMMERCIAL purposes and without fee is hereby granted&lt;br /&gt;
 * provided that this copyright notice appears in all copies. Please refer to&lt;br /&gt;
 * the file &amp;quot;copyright.html&amp;quot; for further important copyright and licensing&lt;br /&gt;
 * information.&lt;br /&gt;
 * &lt;br /&gt;
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE&lt;br /&gt;
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED&lt;br /&gt;
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR&lt;br /&gt;
 * NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY&lt;br /&gt;
 * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS&lt;br /&gt;
 * DERIVATIVES.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.Observable;&lt;br /&gt;
import java.util.Observer;&lt;br /&gt;
public class SampleCheckInterface {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Class observer = Observer.class;&lt;br /&gt;
    Class observable = Observable.class;&lt;br /&gt;
    verifyInterface(observer);&lt;br /&gt;
    verifyInterface(observable);&lt;br /&gt;
  }&lt;br /&gt;
  static void verifyInterface(Class c) {&lt;br /&gt;
    String name = c.getName();&lt;br /&gt;
    if (c.isInterface()) {&lt;br /&gt;
      System.out.println(name + &amp;quot; is an interface.&amp;quot;);&lt;br /&gt;
    } else {&lt;br /&gt;
      System.out.println(name + &amp;quot; is a class.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Determining If a Class Object Represents a Class or Interface ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    Class cls = java.lang.String.class;&lt;br /&gt;
    boolean isClass = !cls.isInterface(); // true&lt;br /&gt;
    cls = java.lang.Cloneable.class;&lt;br /&gt;
    isClass = !cls.isInterface(); // false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Get Super Interfaces ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
/*&lt;br /&gt;
 * The contents of this file are subject to the Sapient Public License&lt;br /&gt;
 * Version 1.0 (the &amp;quot;License&amp;quot;); you may not use this file except in compliance&lt;br /&gt;
 * with the License. You may obtain a copy of the License at&lt;br /&gt;
 * http://carbon.sf.net/License.html.&lt;br /&gt;
 *&lt;br /&gt;
 * Software distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; basis,&lt;br /&gt;
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for&lt;br /&gt;
 * the specific language governing rights and limitations under the License.&lt;br /&gt;
 *&lt;br /&gt;
 * The Original Code is The Carbon Component Framework.&lt;br /&gt;
 *&lt;br /&gt;
 * The Initial Developer of the Original Code is Sapient Corporation&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.Arrays;&lt;br /&gt;
import java.util.HashSet;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Set;&lt;br /&gt;
/**&lt;br /&gt;
 *&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright 2003 Sapient&lt;br /&gt;
 * @since carbon 2.0&lt;br /&gt;
 * @author Greg Hinkle, March 2003&lt;br /&gt;
 * @version $Revision: 1.5 $($Author: dvoet $ / $Date: 2003/05/05 21:21:23 $)&lt;br /&gt;
 */&lt;br /&gt;
public class ClassUtil {&lt;br /&gt;
    /**&lt;br /&gt;
     * Retrieves all interfaces implemented by a specified interface&lt;br /&gt;
     * including all recursively extended interfaces and the classes supplied&lt;br /&gt;
     * int the parameter.&lt;br /&gt;
     * @param childInterfaces a set of interfaces&lt;br /&gt;
     * @return Class[] an array of interfaces that includes those specifed&lt;br /&gt;
     * in childInterfaces plus all of those interfaces&amp;quot; super interfaces&lt;br /&gt;
     */&lt;br /&gt;
    public static Class[] getSuperInterfaces(Class[] childInterfaces) {&lt;br /&gt;
        List allInterfaces = new ArrayList();&lt;br /&gt;
        for (int i = 0; i &amp;lt; childInterfaces.length; i++) {&lt;br /&gt;
            allInterfaces.add(childInterfaces[i]);&lt;br /&gt;
            allInterfaces.addAll(&lt;br /&gt;
                Arrays.asList(&lt;br /&gt;
                    getSuperInterfaces(childInterfaces[i].getInterfaces())));&lt;br /&gt;
        }&lt;br /&gt;
        return (Class[]) allInterfaces.toArray(new Class[allInterfaces.size()]);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Builds an &amp;lt;b&amp;gt;unordered&amp;lt;/b&amp;gt; set of all interface and object classes that&lt;br /&gt;
     * are generalizations of the provided class.&lt;br /&gt;
     * @param classObject the class to find generalization of.&lt;br /&gt;
     * @return a Set of class objects.&lt;br /&gt;
     */&lt;br /&gt;
    public static Set getGeneralizations(Class classObject) {&lt;br /&gt;
        Set generalizations = new HashSet();&lt;br /&gt;
        generalizations.add(classObject);&lt;br /&gt;
        Class superClass = classObject.getSuperclass();&lt;br /&gt;
        if (superClass != null) {&lt;br /&gt;
            generalizations.addAll(getGeneralizations(superClass));&lt;br /&gt;
        }&lt;br /&gt;
        Class[] superInterfaces = classObject.getInterfaces();&lt;br /&gt;
        for (int i = 0; i &amp;lt; superInterfaces.length; i++) {&lt;br /&gt;
            Class superInterface = superInterfaces[i];&lt;br /&gt;
            generalizations.addAll(getGeneralizations(superInterface));&lt;br /&gt;
        }&lt;br /&gt;
        return generalizations;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Listing the Interfaces That a Class Implements ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    Class cls = java.lang.String.class;&lt;br /&gt;
    Class[] intfs = cls.getInterfaces();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Listing the Interfaces That an Interface Extends ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    Class cls = java.util.List.class;&lt;br /&gt;
    Class[] intfs = cls.getInterfaces(); // java.util.Collection&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Returns true if a class implements Serializable and false otherwise. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
/* &lt;br /&gt;
 * JCommon : a free general purpose class library for the Java(tm) platform&lt;br /&gt;
 * &lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.&lt;br /&gt;
 * &lt;br /&gt;
 * Project Info:  http://www.jfree.org/jcommon/index.html&lt;br /&gt;
 *&lt;br /&gt;
 * This library is free software; you can redistribute it and/or modify it &lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as published by &lt;br /&gt;
 * the Free Software Foundation; either version 2.1 of the License, or &lt;br /&gt;
 * (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This library is distributed in the hope that it will be useful, but &lt;br /&gt;
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY &lt;br /&gt;
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public &lt;br /&gt;
 * License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this library; if not, write to the Free Software&lt;br /&gt;
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, &lt;br /&gt;
 * USA.  &lt;br /&gt;
 *&lt;br /&gt;
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. &lt;br /&gt;
 * in the United States and other countries.]&lt;br /&gt;
 * &lt;br /&gt;
 * ------------&lt;br /&gt;
 * IOUtils.java&lt;br /&gt;
 * ------------&lt;br /&gt;
 * (C)opyright 2002-2004, by Thomas Morgner and Contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * Original Author:  Thomas Morgner;&lt;br /&gt;
 * Contributor(s):   David Gilbert (for Object Refinery Limited);&lt;br /&gt;
 *&lt;br /&gt;
 * $Id: IOUtils.java,v 1.8 2009/01/22 08:34:58 taqua Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Changes&lt;br /&gt;
 * -------&lt;br /&gt;
 * 26-Jan-2003 : Initial version&lt;br /&gt;
 * 23-Feb-2003 : Documentation&lt;br /&gt;
 * 25-Feb-2003 : Fixed Checkstyle issues (DG);&lt;br /&gt;
 * 29-Apr-2003 : Moved to jcommon&lt;br /&gt;
 * 04-Jan-2004 : Fixed JDK 1.2.2 issues with createRelativeURL;&lt;br /&gt;
 *               added support for query strings within these urls (TM);&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; if a class implements &amp;lt;code&amp;gt;Serializable&amp;lt;/code&amp;gt;&lt;br /&gt;
   * and &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
   *&lt;br /&gt;
   * @param c  the class.&lt;br /&gt;
   *&lt;br /&gt;
   * @return A boolean.&lt;br /&gt;
   */&lt;br /&gt;
  public static boolean isSerializable(final Class c) {&lt;br /&gt;
      /**&lt;br /&gt;
      final Class[] interfaces = c.getInterfaces();&lt;br /&gt;
      for (int i = 0; i &amp;lt; interfaces.length; i++) {&lt;br /&gt;
          if (interfaces[i].equals(Serializable.class)) {&lt;br /&gt;
              return true;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
      Class cc = c.getSuperclass();&lt;br /&gt;
      if (cc != null) {&lt;br /&gt;
          return isSerializable(cc);&lt;br /&gt;
      }&lt;br /&gt;
       */&lt;br /&gt;
      return (Serializable.class.isAssignableFrom(c));&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Returns true if type is implementing Map ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
// $Id: ReflectionHelper.java 16271 2009-04-07 20:20:12Z hardy.ferentschik $&lt;br /&gt;
/*&lt;br /&gt;
* JBoss, Home of Professional Open Source&lt;br /&gt;
* Copyright 2008, Red Hat Middleware LLC, and individual contributors&lt;br /&gt;
* by the @authors tag. See the copyright.txt in the distribution for a&lt;br /&gt;
* full listing of individual contributors.&lt;br /&gt;
*&lt;br /&gt;
* Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
* you may not use this file except in compliance with the License.&lt;br /&gt;
* You may obtain a copy of the License at&lt;br /&gt;
* http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
* Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
* distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,  &lt;br /&gt;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
* See the License for the specific language governing permissions and&lt;br /&gt;
* limitations under the License.&lt;br /&gt;
*/&lt;br /&gt;
import java.beans.Introspector;&lt;br /&gt;
import java.lang.annotation.Annotation;&lt;br /&gt;
import java.lang.reflect.AccessibleObject;&lt;br /&gt;
import java.lang.reflect.Field;&lt;br /&gt;
import java.lang.reflect.InvocationTargetException;&lt;br /&gt;
import java.lang.reflect.Member;&lt;br /&gt;
import java.lang.reflect.Method;&lt;br /&gt;
import java.lang.reflect.Modifier;&lt;br /&gt;
import java.lang.reflect.ParameterizedType;&lt;br /&gt;
import java.lang.reflect.Type;&lt;br /&gt;
import java.lang.reflect.WildcardType;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.Arrays;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Map;&lt;br /&gt;
/**&lt;br /&gt;
 * Some reflection utility methods.&lt;br /&gt;
 *&lt;br /&gt;
 * @author Hardy Ferentschik&lt;br /&gt;
 */&lt;br /&gt;
public class ReflectionHelper {&lt;br /&gt;
  /**&lt;br /&gt;
   * @param type the type to check.&lt;br /&gt;
   *&lt;br /&gt;
   * @return Returns &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; if &amp;lt;code&amp;gt;type&amp;lt;/code&amp;gt; is implementing &amp;lt;code&amp;gt;Map&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
   */&lt;br /&gt;
  public static boolean isMap(Type type) {&lt;br /&gt;
    if ( type instanceof Class &amp;amp;&amp;amp; isMapClass( ( Class ) type ) ) {&lt;br /&gt;
      return true;&lt;br /&gt;
    }&lt;br /&gt;
    if ( type instanceof ParameterizedType ) {&lt;br /&gt;
      return isMap( ( ( ParameterizedType ) type ).getRawType() );&lt;br /&gt;
    }&lt;br /&gt;
    if ( type instanceof WildcardType ) {&lt;br /&gt;
      Type[] upperBounds = ( ( WildcardType ) type ).getUpperBounds();&lt;br /&gt;
      return upperBounds.length != 0 &amp;amp;&amp;amp; isMap( upperBounds[0] );&lt;br /&gt;
    }&lt;br /&gt;
    return false;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Checks whether the specified class parameter is an instance of a collection class.&lt;br /&gt;
   *&lt;br /&gt;
   * @param clazz &amp;lt;code&amp;gt;Class&amp;lt;/code&amp;gt; to check.&lt;br /&gt;
   *&lt;br /&gt;
   * @return &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;clazz&amp;lt;/code&amp;gt; is instance of a collection class, &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
   */&lt;br /&gt;
  private static boolean isMapClass(Class&amp;lt;?&amp;gt; clazz) {&lt;br /&gt;
    List&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; classes = new ArrayList&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;();&lt;br /&gt;
    computeClassHierarchy( clazz, classes );&lt;br /&gt;
    return classes.contains( Map.class );&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get all superclasses and interfaces recursively.&lt;br /&gt;
   *&lt;br /&gt;
   * @param clazz The class to start the search with.&lt;br /&gt;
   * @param classes List of classes to which to add all found super classes and interfaces.&lt;br /&gt;
   */&lt;br /&gt;
  private static void computeClassHierarchy(Class&amp;lt;?&amp;gt; clazz, List&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; classes) {&lt;br /&gt;
    for ( Class current = clazz; current != null; current = current.getSuperclass() ) {&lt;br /&gt;
      if ( classes.contains( current ) ) {&lt;br /&gt;
        return;&lt;br /&gt;
      }&lt;br /&gt;
      classes.add( current );&lt;br /&gt;
      for ( Class currentInterface : current.getInterfaces() ) {&lt;br /&gt;
        computeClassHierarchy( currentInterface, classes );&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Search over classpath retrieving classes that implement a certain interface ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
/*&lt;br /&gt;
 * The contents of this file are subject to the Sapient Public License&lt;br /&gt;
 * Version 1.0 (the &amp;quot;License&amp;quot;); you may not use this file except in compliance&lt;br /&gt;
 * with the License. You may obtain a copy of the License at&lt;br /&gt;
 * http://carbon.sf.net/License.html.&lt;br /&gt;
 *&lt;br /&gt;
 * Software distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; basis,&lt;br /&gt;
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for&lt;br /&gt;
 * the specific language governing rights and limitations under the License.&lt;br /&gt;
 *&lt;br /&gt;
 * The Original Code is The Carbon Component Framework.&lt;br /&gt;
 *&lt;br /&gt;
 * The Initial Developer of the Original Code is Sapient Corporation&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.HashSet;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.Set;&lt;br /&gt;
import java.util.StringTokenizer;&lt;br /&gt;
import java.util.zip.ZipEntry;&lt;br /&gt;
import java.util.zip.ZipFile;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * &amp;lt;p&amp;gt;This class implements the capability to search over the current classpath&lt;br /&gt;
 * retrieving classes that implement a certain interface.&amp;lt;/p&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright 2001 Sapient&lt;br /&gt;
 * @since carbon 1.0&lt;br /&gt;
 * @author Greg Hinkle, June 2001&lt;br /&gt;
 * @version $Revision: 1.10 $($Author: dvoet $ / $Date: 2003/05/05 21:21:23 $)&lt;br /&gt;
 */&lt;br /&gt;
public class ClassFinder {&lt;br /&gt;
    /**&lt;br /&gt;
     * Tracks the count of classes found that match the&lt;br /&gt;
     * provided criteria.&lt;br /&gt;
     */&lt;br /&gt;
    protected long foundClasses = 0;&lt;br /&gt;
    /**&lt;br /&gt;
     * The super class criteria&lt;br /&gt;
     */&lt;br /&gt;
    protected Class superClass = null;&lt;br /&gt;
    /**&lt;br /&gt;
     * The required substring path criteria for this searcher&lt;br /&gt;
     */&lt;br /&gt;
    protected String requiredPathSubstring = null;&lt;br /&gt;
    /**&lt;br /&gt;
     * The set of classes found matching the provided criteria.&lt;br /&gt;
     */&lt;br /&gt;
    protected Set classes = new HashSet(2000);&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;Instantiates the type of MBeanHarvester that will return all classes&lt;br /&gt;
     * in the entire classpath.&amp;lt;/p&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    public ClassFinder() {&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;Instantiates the type of MBeanHarvester that will return all classes&lt;br /&gt;
     * that are assignable to the supplied class. This would include all&lt;br /&gt;
     * implementations of it, if it is an interface or it and all subclasses&lt;br /&gt;
     * of it if it&amp;quot;s a class.&amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param superClass the Class that should be searched for along with&lt;br /&gt;
     *   implementations and subclasses&lt;br /&gt;
     */&lt;br /&gt;
    public ClassFinder(Class superClass) {&lt;br /&gt;
        this.superClass = superClass;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;Instantiates the type of MBeanHarvester that will return all classes&lt;br /&gt;
     * that are assignable to the supplied class and are part of the supplied&lt;br /&gt;
     * package. This would include all  implementations of it, if it is an&lt;br /&gt;
     * interface or it and all subclasses of it if it&amp;quot;s a class. The&lt;br /&gt;
     * supplied &amp;lt;code&amp;gt;requiredPathSubstring must be part of the fully&lt;br /&gt;
     * qualified classname.&amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param superClass the Class that should be searched for along with&lt;br /&gt;
     *   implementations and subclasses&lt;br /&gt;
     * @param requiredPathSubstring the String part that must be found in the&lt;br /&gt;
     *   classes FQN&lt;br /&gt;
     */&lt;br /&gt;
    public ClassFinder(Class superClass, String requiredPathSubstring) {&lt;br /&gt;
        this.superClass = superClass;&lt;br /&gt;
        this.requiredPathSubstring = requiredPathSubstring;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;Adds a class name to the list of found classes if and only if it meets&lt;br /&gt;
     * the configured requirements.&amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param className the FQN String name of the class to add&lt;br /&gt;
     */&lt;br /&gt;
    protected void addClassName(String className) {&lt;br /&gt;
        // Only add this class if we&amp;quot;re not checking for a particular&lt;br /&gt;
        // substring of the FQN or we find that substring&lt;br /&gt;
        if ((this.requiredPathSubstring == null) ||&lt;br /&gt;
            (className.indexOf(this.requiredPathSubstring) &amp;gt;= 0)) {&lt;br /&gt;
            if (this.superClass == null) {&lt;br /&gt;
                this.classes.add(className);&lt;br /&gt;
            } else {&lt;br /&gt;
                try {&lt;br /&gt;
                    // TODO: GH - add a way to search other classpaths and the&lt;br /&gt;
                    // system classpath.&lt;br /&gt;
                    Class theClass =&lt;br /&gt;
                        Class.forName(&lt;br /&gt;
                            className,&lt;br /&gt;
                            false,&lt;br /&gt;
                            this.getClass().getClassLoader());&lt;br /&gt;
                    if (this.superClass.isAssignableFrom(theClass)) {&lt;br /&gt;
                        this.classes.add(className);&lt;br /&gt;
                    }&lt;br /&gt;
                } catch (ClassNotFoundException cnfe) {&lt;br /&gt;
                    // Used to catch mis-parsed classnames&lt;br /&gt;
                } catch (Throwable t) {&lt;br /&gt;
                    // Used to catch JVM security and linkage errors&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;Used to retrieve the results &amp;lt;code&amp;gt;Set&amp;lt;/code&amp;gt; from this harvester&amp;quot;s&lt;br /&gt;
     * search.&amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @return Set the set of classes that meet this harvester&amp;quot;s requirements&lt;br /&gt;
     */&lt;br /&gt;
    public Set getClasses() {&lt;br /&gt;
        // 1) tokenize classpath&lt;br /&gt;
        String classpath = System.getProperty(&amp;quot;java.class.path&amp;quot;);&lt;br /&gt;
        String pathSeparator = System.getProperty(&amp;quot;path.separator&amp;quot;);&lt;br /&gt;
        StringTokenizer st = new StringTokenizer(classpath,pathSeparator);&lt;br /&gt;
        // 2) for each element in the classpath&lt;br /&gt;
        while (st.hasMoreTokens()) {&lt;br /&gt;
            File currentDirectory = new File(st.nextToken());&lt;br /&gt;
            processFile(currentDirectory.getAbsolutePath(),&amp;quot;&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        return this.classes;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Recursively search through Directories with special checks to recognize&lt;br /&gt;
     * zip and jar files. (Zip and Jar files return true from&lt;br /&gt;
     * &amp;amp;lt;File&amp;amp;gt;.isDirectory())&lt;br /&gt;
     * @param base the base file path to search&lt;br /&gt;
     * @param current the current recursively searched file path being searched&lt;br /&gt;
     */&lt;br /&gt;
    private void processFile(String base, String current) {&lt;br /&gt;
        File currentDirectory = new File(base + File.separatorChar + current);&lt;br /&gt;
        // Handle special for archives&lt;br /&gt;
        if (isArchive(currentDirectory.getName())) {&lt;br /&gt;
            try {&lt;br /&gt;
                processZip(new ZipFile(currentDirectory));&lt;br /&gt;
            } catch (Exception e) {&lt;br /&gt;
                // The directory was not found so the classpath was probably in&lt;br /&gt;
                // error or we don&amp;quot;t have rights to it&lt;br /&gt;
            }&lt;br /&gt;
            return;&lt;br /&gt;
        } else {&lt;br /&gt;
            Set directories = new HashSet();&lt;br /&gt;
            File[] children = currentDirectory.listFiles();&lt;br /&gt;
            // if no children, return&lt;br /&gt;
            if (children == null || children.length == 0) {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // check for classfiles&lt;br /&gt;
            for (int i = 0; i &amp;lt; children.length; i++) {&lt;br /&gt;
                File child = children[i];&lt;br /&gt;
                if (child.isDirectory()) {&lt;br /&gt;
                    directories.add(children[i]);&lt;br /&gt;
                } else {&lt;br /&gt;
                    if (child.getName().endsWith(&amp;quot;.class&amp;quot;)) {&lt;br /&gt;
                        String className =&lt;br /&gt;
                            getClassName(&lt;br /&gt;
                                current +&lt;br /&gt;
                                ((current == &amp;quot;&amp;quot;) ? &amp;quot;&amp;quot; : File.separator) +&lt;br /&gt;
                                child.getName());&lt;br /&gt;
                        addClassName(className);&lt;br /&gt;
                        this.foundClasses++;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            //call process file on each directory.  This is an iterative call!!&lt;br /&gt;
            for (Iterator i = directories.iterator(); i.hasNext(); ) {&lt;br /&gt;
                processFile(base, current + ((current==&amp;quot;&amp;quot;)?&amp;quot;&amp;quot;:File.separator) +&lt;br /&gt;
                    ((File)i.next()).getName());&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;Looks at the name of a file to determine if it is an archive&amp;lt;/p&amp;gt;&lt;br /&gt;
     * @param name the name of a file&lt;br /&gt;
     * @return true if a file in the classpath is an archive&lt;br /&gt;
     * such as a Jar or Zip file&lt;br /&gt;
     */&lt;br /&gt;
    protected boolean isArchive(String name) {&lt;br /&gt;
        if ((name.endsWith(&amp;quot;.jar&amp;quot;) ||&lt;br /&gt;
            (name.endsWith(&amp;quot;.zip&amp;quot;)))) {&lt;br /&gt;
            return true;&lt;br /&gt;
        } else {&lt;br /&gt;
            return false;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;Returns the Fully Qualified Class name of a class from it&amp;quot;s path&lt;br /&gt;
     * @param fileName the full path to a class&lt;br /&gt;
     * @return the FQN of a class&lt;br /&gt;
     */&lt;br /&gt;
    protected String getClassName(String fileName) {&lt;br /&gt;
        String newName =  fileName.replace(File.separatorChar,&amp;quot;.&amp;quot;);&lt;br /&gt;
        // Because zipfiles don&amp;quot;t have platform specific seperators&lt;br /&gt;
        newName =  newName.replace(&amp;quot;/&amp;quot;,&amp;quot;.&amp;quot;);&lt;br /&gt;
        return newName.substring(0, fileName.length() - 6);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;P&amp;gt;Iterates through the files in a zip looking for files that may be&lt;br /&gt;
     * classes. This is not recursive as zip&amp;quot;s in zip&amp;quot;s are not searched by the&lt;br /&gt;
     * classloader either.&amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param file The ZipFile to be searched&lt;br /&gt;
     */&lt;br /&gt;
    protected void processZip(ZipFile file) {&lt;br /&gt;
        Enumeration files = file.entries();&lt;br /&gt;
        while (files.hasMoreElements()) {&lt;br /&gt;
            Object tfile = files.nextElement();&lt;br /&gt;
            ZipEntry child = (ZipEntry) tfile;&lt;br /&gt;
            if (child.getName().endsWith(&amp;quot;.class&amp;quot;)) {&lt;br /&gt;
                addClassName(getClassName(child.getName()));&lt;br /&gt;
                this.foundClasses++;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== The interfaces for a primitive type is an empty array ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    Class cls = int.class;&lt;br /&gt;
    Class[] intfs = cls.getInterfaces(); // []&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== The superclass of interfaces is always null ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    Class cls = java.lang.Cloneable.class;&lt;br /&gt;
    Class sup = cls.getSuperclass(); // null&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>