home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / Class.java < prev    next >
Text File  |  1997-10-01  |  29KB  |  717 lines

  1. /*
  2.  * @(#)Class.java    1.55 97/07/08
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.lang;
  24. import java.lang.reflect.Member;
  25. import java.lang.reflect.Field;
  26. import java.lang.reflect.Method;
  27. import java.lang.reflect.Constructor;
  28. import java.io.InputStream;
  29.  
  30. /**
  31.  * Instances of the class </code>Class</code> represent classes and 
  32.  * interfaces in a running Java application.
  33.  * Every array also belongs to a class that is reflected as a Class
  34.  * object that is shared by all arrays with the same element type and
  35.  * number of dimensions.  Finally, the either primitive Java types
  36.  * (boolean, byte, char, short, int, long, float, and double) and
  37.  * the keyword void are also represented as Class objects.
  38.  * <p>
  39.  * There is no public constructor for the class </code>Class</code>. 
  40.  * </code>Class</code> objects are constructed automatically by the Java 
  41.  * Virtual Machine as classes are loaded and by calls to the 
  42.  * <code>defineClass</code> method in the class loader. 
  43.  * <p>
  44.  * The following example uses a Class object to print the Class name
  45.  * of an object:
  46.  * <p><pre><blockquote>
  47.  *     void printClassName(Object obj) {
  48.  *         System.out.println("The class of " + obj +
  49.  *                            " is " + obj.getClass().getName());
  50.  *     }
  51.  * </blockquote></pre>
  52.  *
  53.  * @author  unascribed
  54.  * @version 1.55, 07/08/97
  55.  * @see     java.lang.ClassLoader#defineClass(byte[], int, int)
  56.  * @since   JDK1.0
  57.  */
  58. public final
  59. class Class implements java.io.Serializable {
  60.     /*
  61.      * Constructor. Only the Java Virtual Machine creates Class
  62.      * objects.
  63.      */
  64.     private Class() {}
  65.  
  66.     /**
  67.      * Converts the object to a string. The string representation is the 
  68.      * string <code>"class"</code> or <code>"interface"</code> followed 
  69.      * by a space and then the fully qualified name of the class. 
  70.      * If this Class object represents a primitive type,
  71.      * returns the name of the primitive type.
  72.      *
  73.      * @return  a string representation of this class object. 
  74.      * @since   JDK1.0
  75.      */
  76.     public String toString() {
  77.     return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
  78.         + getName();
  79.     }
  80.  
  81.     /**
  82.      * Returns the <code>Class</code> object associated with the class 
  83.      * with the given string name. 
  84.      * Given the fully-qualified name for a class or interface, this
  85.      * method attempts to locate, load and link the class.  If it
  86.      * succeeds, returns the Class object representing the class.  If
  87.      * it fails, the method throws a ClassNotFoundException.
  88.      * <p>
  89.      * For example, the following code fragment returns the runtime 
  90.      * <code>Class</code> descriptor for the class named 
  91.      * <code>java.lang.Thread</code>: 
  92.      * <ul><code>
  93.      *   Class t = Class.forName("java.lang.Thread")
  94.      * </code></ul>
  95.      *
  96.      * @param      className   the fully qualified name of the desired class.
  97.      * @return     the <code>Class</code> descriptor for the class with the
  98.      *             specified name.
  99.      * @exception  ClassNotFoundException  if the class could not be found.
  100.      * @since      JDK1.0
  101.      */
  102.     public static native Class forName(String className)
  103.     throws ClassNotFoundException;
  104.  
  105.     /**
  106.      * Creates a new instance of a class. 
  107.      *
  108.      * @return     a newly allocated instance of the class represented by this
  109.      *             object. This is done exactly as if by a <code>new</code>
  110.      *             expression with an empty argument list.
  111.      * @exception  IllegalAccessException  if the class or initializer is
  112.      *               not accessible.
  113.      * @exception  InstantiationException  if an application tries to
  114.      *               instantiate an abstract class or an interface, or if the
  115.      *               instantiation fails for some other reason.
  116.      * @since     JDK1.0
  117.      */
  118.     public native Object newInstance() 
  119.     throws InstantiationException, IllegalAccessException;
  120.  
  121.     /**
  122.      * This method is the dynamic equivalent of the Java language
  123.      * <code>instanceof</code> operator. The method returns true if
  124.      * the specified Object argument is non-null and can be cast to
  125.      * the reference type represented by this Class object without
  126.      * raising a ClassCastException. It returns false otherwise.
  127.      *
  128.      * <p>Specifically, if this Class object represents a declared
  129.      * class, returns true if the specified Object argument is an
  130.      * instance of the represented class (or of any of its
  131.      * subclasses); false otherwise. If this Class object represents
  132.      * an array class, returns true if the specified Object argument
  133.      * can be converted to an object of the array type by an identity
  134.      * conversion or by a widening reference conversion; false
  135.      * otherwise. If this Class object represents an interface,
  136.      * returns true if the class or any superclass of the
  137.      * specified Object argument implements this interface; false
  138.      * otherwise. If this Class object represents a primitive type,
  139.      * returns false.
  140.      *
  141.      * @param   obj The object to check
  142.      * @since   JDK1.1
  143.      */
  144.     public native boolean isInstance(Object obj);
  145.  
  146.     /**
  147.      * Determines if the class or interface
  148.      * represented by this Class object is either the same as, or is a
  149.      * superclass or superinterface of, the class or interface
  150.      * represented by the specified Class parameter. It returns true
  151.      * if so, false otherwise. If this Class object represents a
  152.      * primitive type, returns true if the specified Class parameter
  153.      * is exactly this Class object, false otherwise.
  154.      *
  155.      * <p>Specifically, this method tests whether the type represented
  156.      * by the specified Class parameter can be converted to the type
  157.      * represented by this Class object via an identity conversion or
  158.      * via a widening reference conversion. See <em>The Java Language
  159.      * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
  160.      *
  161.      * @exception NullPointerException if the specified Class parameter is null.
  162.      * @since   JDK1.1
  163.      */
  164.     public native boolean isAssignableFrom(Class cls);
  165.  
  166.     /**
  167.      * Determines if the specified Class object represents an interface type.
  168.      *
  169.      * @return  <code>true</code> if this object represents an interface;
  170.      *          <code>false</code> otherwise.
  171.      * @since   JDK1.0
  172.      */
  173.     public native boolean isInterface();
  174.  
  175.     /**
  176.      * If this Class object represents an array type, returns true,
  177.      * otherwise returns false.
  178.      *
  179.      * @since   JDK1.1
  180.      */
  181.     public native boolean isArray();
  182.  
  183.     /**
  184.      * Determines if the specified Class object represents a primitive Java
  185.      * type.
  186.      *
  187.      * <p>There are nine predefined Class objects to represent the eight
  188.      * primitive Java types and void.  These are created by the Java
  189.      * Virtual Machine, and have the same names as the primitive types
  190.      * that they represent, namely boolean, byte, char, short, int,
  191.      * long, float, and double, and void.
  192.      *
  193.      * <p>These objects may only be accessed via the following public
  194.      * static final variables, and are the only Class objects for
  195.      * which this method returns true.
  196.      *
  197.      * @see     java.lang.Boolean#TYPE
  198.      * @see     java.lang.Character#TYPE
  199.      * @see     java.lang.Byte#TYPE
  200.      * @see     java.lang.Short#TYPE
  201.      * @see     java.lang.Integer#TYPE
  202.      * @see     java.lang.Long#TYPE
  203.      * @see     java.lang.Float#TYPE
  204.      * @see     java.lang.Double#TYPE
  205.      * @see     java.lang.Void#TYPE
  206.      * @since   JDK1.1
  207.      */
  208.     public native boolean isPrimitive();
  209.  
  210.     /**
  211.      * Returns the fully-qualified name of the type (class, interface,
  212.      * array, or primitive) represented by this Class object, as a String.
  213.      *
  214.      * @return  the fully qualified name of the class or interface
  215.      *          represented by this object.
  216.      * @since   JDK1.0
  217.      */
  218.     public native String getName();
  219.  
  220.     /**
  221.      * Determines the class loader for the class. 
  222.      *
  223.      * @return  the class loader that created the class or interface
  224.      *          represented by this object, or <code>null</code> if the
  225.      *          class was not created by a class loader.
  226.      * @see     java.lang.ClassLoader
  227.      * @since   JDK1.0
  228.      */
  229.     public native ClassLoader getClassLoader();
  230.  
  231.     /**
  232.      * If this object represents any class other than the class 
  233.      * </code>Object</code>, then the object that represents the superclass 
  234.      * of that class is returned. 
  235.      * <p>
  236.      * If this object is the one that represents the class 
  237.      * </code>Object</code> or this object represents an interface, 
  238.      * </code>null</code> is returned. 
  239.      *
  240.      * @return  the superclass of the class represented by this object.
  241.      * @since   JDK1.0
  242.      */
  243.     public native Class getSuperclass();
  244.  
  245.     /**
  246.      * Determines the interfaces implemented by the class or interface 
  247.      * represented by this object. 
  248.      * <p>
  249.      * If this object represents a class, the return value is an array 
  250.      * containing objects representing all interfaces implemented by the 
  251.      * class. The order of the interface objects in the array corresponds 
  252.      * to the order of the interface names in the </code>implements</code> 
  253.      * clause of the declaration of the class represented by this object. 
  254.      * <p>
  255.      * If this object represents an interface, the array contains 
  256.      * objects representing all interfaces extended by the interface. The 
  257.      * order of the interface objects in the array corresponds to the 
  258.      * order of the interface names in the </code>extends</code> clause of 
  259.      * the declaration of the interface represented by this object. 
  260.      * <p>
  261.      * If the class or interface implements no interfaces, the method 
  262.      * returns an array of length 0. 
  263.      *
  264.      * @return  an array of interfaces implemented by this class.
  265.      * @since   JDK1.0
  266.      */
  267.     public native Class[] getInterfaces();
  268.  
  269.     /**
  270.      * If this class represents an array type, returns the Class
  271.      * object representing the component type of the array; otherwise
  272.      * returns null.
  273.      *
  274.      * @see     java.lang.reflect.Array
  275.      * @since   JDK1.1
  276.      */
  277.     public native Class getComponentType();
  278.  
  279.     /**
  280.      * Returns the Java language modifiers for this class or
  281.      * interface, encoded in an integer. The modifiers consist of the
  282.      * Java Virtual Machine's constants for public, protected,
  283.      * private, final, and interface; they should be decoded using the
  284.      * methods of class Modifier.
  285.      *
  286.      * <p>The modifier encodings are defined in <em>The Java Virtual
  287.      * Machine Specification</em>, table 4.1.
  288.      *
  289.      * @see     java.lang.reflect.Modifier
  290.      * @since   JDK1.1
  291.      */
  292.     public native int getModifiers();
  293.  
  294.     /**
  295.      * Get the signers of this class.
  296.      *
  297.      * @since   JDK1.1
  298.      */
  299.     public native Object[] getSigners();
  300.     
  301.     /**
  302.      * Set the signers of this class.
  303.      */
  304.     native void setSigners(Object[] signers);
  305.  
  306.     /**
  307.      * If the class or interface represented by this Class object is
  308.      * a member of another class, returns the Class object
  309.      * representing the class of which it is a member (its
  310.      * <em>declaring class</em>).  Returns null if this class or
  311.      * interface is not a member of any other class.
  312.      *
  313.      * @since   JDK1.1
  314.      */
  315.     public Class getDeclaringClass() {
  316.     return null;                /* not implemented */
  317.     }
  318.  
  319.     /**
  320.      * Returns an array containing Class objects representing all the
  321.      * public classes and interfaces that are members of the class
  322.      * represented by this Class object.  This includes public class
  323.      * and interface members inherited from superclasses and public
  324.      * class and interface members declared by the class.  Returns an
  325.      * array of length 0 if the class has no public member classes or
  326.      * interfaces, or if this Class object represents a primitive
  327.      * type.
  328.      *
  329.      * @since   JDK1.1
  330.      */
  331.     public Class[] getClasses() {
  332.     return new Class[0];            /* not implemented */
  333.     }
  334.  
  335.     /**
  336.      * Returns an array containing Field objects reflecting all the
  337.      * accessible public fields of the class or interface represented
  338.      * by this Class object.  Returns an array of length 0 if the
  339.      * class or interface has no accessible public fields, or if it
  340.      * represents an array type or a primitive type.
  341.      *
  342.      * <p>Specifically, if this Class object represents a class,
  343.      * returns the public fields of this class and of all its
  344.      * superclasses.  If this Class object represents an interface,
  345.      * returns the fields of this interface and of all its
  346.      * superinterfaces.  If this Class object represents an array type
  347.      * or a primitive type, returns an array of length 0.
  348.      *
  349.      * <p>The implicit length field for array types is not reflected
  350.      * by this method. User code should use the methods of class Array
  351.      * to manipulate arrays.
  352.      *
  353.      * <p>See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
  354.      *
  355.      * @exception SecurityException    if access to the information is denied.
  356.      * @see       java.lang.reflect.Field
  357.      * @since     JDK1.1
  358.      */
  359.     public Field[] getFields() throws SecurityException {
  360.     checkMemberAccess(Member.PUBLIC);
  361.     return getFields0(Member.PUBLIC);
  362.     }
  363.  
  364.     /**
  365.      * Returns an array containing Method objects reflecting all the
  366.      * public <em>member</em> methods of the class or interface
  367.      * represented by this Class object, including those declared by
  368.      * the class or interface and and those inherited from
  369.      * superclasses and superinterfaces. Returns an array of length 0
  370.      * if the class or interface has no public member methods.
  371.      *
  372.      * <p>See <em>The Java Language Specification</em>, sections 8.2
  373.      * and 8.4.
  374.      *
  375.      * @exception SecurityException    if access to the information is denied.
  376.      * @see       java.lang.reflect.Method
  377.      * @since     JDK1.1
  378.      */
  379.     public Method[] getMethods() throws SecurityException {
  380.     checkMemberAccess(Member.PUBLIC);
  381.     return getMethods0(Member.PUBLIC);
  382.     }
  383.  
  384.     /**
  385.      * Returns an array containing Constructor objects reflecting
  386.      * all the public constructors of the class represented by this
  387.      * Class object.  An array of length 0 is returned if the class
  388.      * has no public constructors.
  389.      *
  390.      * @exception SecurityException    if access to the information is denied.
  391.      * @see       java.lang.reflect.Constructor
  392.      * @since     JDK1.1
  393.      */
  394.     public Constructor[] getConstructors() throws SecurityException {
  395.     checkMemberAccess(Member.PUBLIC);
  396.     return getConstructors0(Member.PUBLIC);
  397.     }
  398.  
  399.     /**
  400.      * Returns a Field object that reflects the specified public
  401.      * member field of the class or interface represented by
  402.      * this Class object. The name parameter is a String specifying
  403.      * the simple name of the desired field.
  404.      *
  405.      * <p>The field to be reflected is located by searching all the
  406.      * member fields of the class or interface represented by this
  407.      * Class object for a public field with the specified name.
  408.      *
  409.      * <p>See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
  410.      *
  411.      * @exception NoSuchFieldException if a field with the specified name is
  412.      *              not found.
  413.      * @exception SecurityException    if access to the information is denied.
  414.      * @see       java.lang.reflect.Field
  415.      * @since     JDK1.1
  416.      */
  417.     public Field getField(String name)
  418.     throws NoSuchFieldException, SecurityException {
  419.     checkMemberAccess(Member.PUBLIC);
  420.     return getField0(name, Member.PUBLIC);
  421.     }
  422.  
  423.     /**
  424.      * Returns a Method object that reflects the specified public
  425.      * member method of the class or interface represented by this
  426.      * Class object. The name parameter is a String specifying the
  427.      * simple name the desired method, and the parameterTypes
  428.      * parameter is an array of Class objects that identify the
  429.      * method's formal parameter types, in declared order.
  430.      *
  431.      * <p>The method to reflect is located by searching all the member
  432.      * methods of the class or interface represented by this Class
  433.      * object for a public method with the specified name and exactly
  434.      * the same formal parameter types.
  435.      *
  436.      * <p>See <em>The Java Language Specification</em>, sections 8.2
  437.      * and 8.4.
  438.      *
  439.      * @exception NoSuchMethodException if a matching method is not found.
  440.      * @exception SecurityException    if access to the information is denied.
  441.      * @see       java.lang.reflect.Method
  442.      * @since     JDK1.1
  443.      */
  444.     public Method getMethod(String name, Class[] parameterTypes)
  445.     throws NoSuchMethodException, SecurityException {
  446.     checkMemberAccess(Member.PUBLIC);
  447.     return getMethod0(name, parameterTypes, Member.PUBLIC);
  448.     }
  449.  
  450.     /**
  451.      * Returns a Constructor object that reflects the specified public
  452.      * constructor of the class represented by this Class object. The
  453.      * parameterTypes parameter is an array of Class objects that
  454.      * identify the constructor's formal parameter types, in declared
  455.      * order.
  456.      *
  457.      * <p>The constructor to reflect is located by searching all the
  458.      * constructors of the class represented by this Class object for
  459.      * a public constructor with the exactly the same formal parameter
  460.      * types.
  461.      *
  462.      * @exception NoSuchMethodException if a matching method is not found.
  463.      * @exception SecurityException     if access to the information is denied.
  464.      * @see       java.lang.reflect.Constructor
  465.      * @since     JDK1.1
  466.      */
  467.     public Constructor getConstructor(Class[] parameterTypes)
  468.     throws NoSuchMethodException, SecurityException {
  469.     checkMemberAccess(Member.PUBLIC);
  470.     return getConstructor0(parameterTypes, Member.PUBLIC);
  471.     }
  472.  
  473.     /**
  474.      * Returns an array of Class objects reflecting all the classes
  475.      * and interfaces declared as members of the class represented by
  476.      * this Class object. This includes public, protected, default
  477.      * (package) access, and private classes and interfaces declared
  478.      * by the class, but excludes inherited classes and interfaces.
  479.      * Returns an array of length 0 if the class declares no classes
  480.      * or interfaces as members, or if this Class object represents a
  481.      * primitive type.
  482.      *
  483.      * @exception SecurityException    if access to the information is denied.
  484.      * @since     JDK1.1
  485.      */
  486.     public Class[] getDeclaredClasses() throws SecurityException {
  487.     checkMemberAccess(Member.DECLARED);
  488.     return new Class[0];            /* not implemented */
  489.     }
  490.  
  491.     /**
  492.      * Returns an array of Field objects reflecting all the fields
  493.      * declared by the class or interface represented by this Class
  494.      * object. This includes public, protected, default (package)
  495.      * access, and private fields, but excludes inherited
  496.      * fields. Returns an array of length 0 if the class or interface
  497.      * declares no fields, or if this Class object represents a
  498.      * primitive type.
  499.      *
  500.      * See <em>The Java Language Specification</em>, sections 8.2 and
  501.      * 8.3.
  502.      *
  503.      * @exception SecurityException    if access to the information is denied.
  504.      * @see       java.lang.reflect.Field
  505.      * @since     JDK1.1
  506.      */
  507.     public Field[] getDeclaredFields() throws SecurityException {
  508.     checkMemberAccess(Member.DECLARED);
  509.     return getFields0(Member.DECLARED);
  510.     }
  511.  
  512.     /**
  513.      * Returns an array of Method objects reflecting all the methods
  514.      * declared by the class or interface represented by this Class
  515.      * object. This includes public, protected, default (package)
  516.      * access, and private methods, but excludes inherited
  517.      * methods. Returns an array of length 0 if the class or interface
  518.      * declares no methods, or if this Class object represents a
  519.      * primitive type.
  520.      *
  521.      * <p>See <em>The Java Language Specification</em>, section 8.2.
  522.      *
  523.      * @exception SecurityException    if access to the information is denied.
  524.      * @see       java.lang.reflect.Method
  525.      * @since     JDK1.1
  526.      */
  527.     public Method[] getDeclaredMethods() throws SecurityException {
  528.     checkMemberAccess(Member.DECLARED);
  529.     return getMethods0(Member.DECLARED);
  530.     }
  531.  
  532.     /**
  533.      * Returns an array of Constructor objects reflecting all the
  534.      * constructors declared by the class represented by this Class
  535.      * object. These are public, protected, default (package) access,
  536.      * and private constructors.  Returns an array of length 0 if this
  537.      * Class object represents an interface or a primitive type.
  538.      *
  539.      * <p>See <em>The Java Language Specification</em>, section 8.2.
  540.      *
  541.      * @exception SecurityException    if access to the information is denied.
  542.      * @see       java.lang.reflect.Constructor
  543.      * @since     JDK1.1
  544.      */
  545.     public Constructor[] getDeclaredConstructors() throws SecurityException {
  546.     checkMemberAccess(Member.DECLARED);
  547.     return getConstructors0(Member.DECLARED);
  548.     }
  549.  
  550.     /**
  551.      * Returns a Field object that reflects the specified declared
  552.      * field of the class or interface represented by this Class
  553.      * object. The name parameter is a String that specifies the
  554.      * simple name of the desired field.
  555.      *
  556.      * @exception NoSuchFieldException if a field with the specified name is
  557.      *              not found.
  558.      * @exception SecurityException    if access to the information is denied.
  559.      * @see       java.lang.reflect.Field
  560.      * @since     JDK1.1
  561.      */
  562.     public Field getDeclaredField(String name)
  563.     throws NoSuchFieldException, SecurityException {
  564.     checkMemberAccess(Member.DECLARED);
  565.     return getField0(name, Member.DECLARED);
  566.     }
  567.  
  568.     /**
  569.      * Returns a Method object that reflects the specified declared
  570.      * method of the class or interface represented by this Class
  571.      * object. The name parameter is a String that specifies the
  572.      * simple name of the desired method, and the parameterTypes
  573.      * parameter is an array of Class objects that identify the
  574.      * method's formal parameter types, in declared order.
  575.      *
  576.      * @exception NoSuchMethodException if a matching method is not found.
  577.      * @exception SecurityException     if access to the information is denied.
  578.      * @see       java.lang.reflect.Method
  579.      * @since     JDK1.1
  580.      */
  581.     public Method getDeclaredMethod(String name, Class[] parameterTypes)
  582.     throws NoSuchMethodException, SecurityException {
  583.     checkMemberAccess(Member.DECLARED);
  584.     return getMethod0(name, parameterTypes, Member.DECLARED);
  585.     }
  586.  
  587.     /**
  588.      * Returns a Constructor object that reflects the specified declared
  589.      * constructor of the class or interface represented by this Class
  590.      * object.  The parameterTypes parameter is an array of Class
  591.      * objects that identify the constructor's formal parameter types,
  592.      * in declared order.
  593.      *
  594.      * @exception NoSuchMethodException if a matching method is not found.
  595.      * @exception SecurityException     if access to the information is denied.
  596.      * @see       java.lang.reflect.Constructor
  597.      * @since     JDK1.1
  598.      */
  599.     public Constructor getDeclaredConstructor(Class[] parameterTypes)
  600.     throws NoSuchMethodException, SecurityException {
  601.     checkMemberAccess(Member.DECLARED);
  602.     return getConstructor0(parameterTypes, Member.DECLARED);
  603.     }
  604.  
  605.     /**
  606.      * Finds a resource with a given name.  Will return null if no
  607.      * resource with this name is found.  The rules for searching a
  608.      * resources associated with a given class are implemented by the
  609.      * ClassLoader of the class.<p>
  610.      *
  611.      * The Class methods delegate to ClassLoader methods, after applying
  612.      * a naming convention: if the resource name starts with "/", it is used
  613.      * as is.  Otherwise, the name of the package is prepended, after
  614.      * converting "." to "/".
  615.      *
  616.      * @param   name the string representing the resource to be found
  617.      * @return  the <code>InputStream</code> object having the 
  618.      *             specified name, or <code>null</code> if no 
  619.      *             resource with the specified name is found.
  620.      * @see     java.lang.ClassLoader
  621.      * @see     java.lang.Class#getResource
  622.      * @since   JDK1.1
  623.      */
  624.     public InputStream getResourceAsStream(String name) {
  625.     name = resolveName(name);
  626.     ClassLoader cl = getClassLoader();
  627.     if (cl==null) {
  628.         // A system class.
  629.         return ClassLoader.getSystemResourceAsStream(name);
  630.     }
  631.     return cl.getResourceAsStream(name);
  632.     }
  633.  
  634.     /**
  635.      * Finds a resource with the specified name. The rules for searching 
  636.      * for resources associated with a given class are implemented by 
  637.      * the class loader of the class.
  638.      * <p>
  639.      * The Class methods delegate to ClassLoader methods, after applying
  640.      * a naming convention: if the resource name starts with "/", it is used
  641.      * as is.  Otherwise, the name of the package is prepended, after
  642.      * converting "." to "/".
  643.      *
  644.      * @param   name the string representing the resource to be found.
  645.      * @return  the <code>URL</code> object having the specified name,  
  646.      *             or <code>null</code> if no resource with the specified 
  647.      *             name is found.
  648.      * @see     java.lang.ClassLoader 
  649.      * @see     java.lang.Class#getResourceAsStream
  650.      * @since   JDK1.1
  651.      */
  652.     public java.net.URL getResource(String name) {
  653.     name = resolveName(name);
  654.     ClassLoader cl = getClassLoader();
  655.     if (cl==null) {
  656.         // A system class.
  657.         return ClassLoader.getSystemResource(name);
  658.     }
  659.     return cl.getResource(name);
  660.     }
  661.  
  662.     /*
  663.      * Return the Virtual Machine's Class object for the named
  664.      * primitive type.
  665.      */
  666.     static native Class getPrimitiveClass(String name);
  667.  
  668.     /*
  669.      * Check if client is allowed to access members.  If access is
  670.      * denied, throw a SecurityException.
  671.      *
  672.      * <p>Default policy: allow all clients access with normal Java
  673.      * access control.
  674.      */
  675.     private void checkMemberAccess(int which) {
  676.     SecurityManager s = System.getSecurityManager();
  677.     if (s != null) {
  678.         s.checkMemberAccess(this, which);
  679.     }
  680.     }
  681.  
  682.     /**
  683.      * Add a package name prefix if the name is not absolute
  684.      * Remove leading "/" if name is absolute
  685.      */
  686.     private String resolveName(String name) {
  687.     if (name == null) {
  688.         return name;
  689.     }
  690.     if (!name.startsWith("/")) {
  691.         Class c = this;
  692.         while (c.isArray()) {
  693.         c = c.getComponentType();
  694.         }
  695.         String baseName = c.getName();
  696.         int index = baseName.lastIndexOf('.');
  697.         if (index != -1) {
  698.         name = baseName.substring(0, index).replace('.', '/')
  699.             +"/"+name;
  700.         }
  701.     } else {
  702.         name = name.substring(1);
  703.     }
  704.     return name;
  705.     }
  706.  
  707.     private native Field[] getFields0(int which);
  708.     private native Method[] getMethods0(int which);
  709.     private native Constructor[] getConstructors0(int which);
  710.     private native Field getField0(String name, int which);
  711.     private native Method getMethod0(String name, Class[] parameterTypes,
  712.     int which);
  713.     private native Constructor getConstructor0(Class[] parameterTypes,
  714.     int which);
  715.  
  716. }
  717.