Save This Page
Home » openjdk-7 » java » lang » reflect » [javadoc | source]
    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   /**
   18    * @author Evgueni Brevnov
   19    */
   20   
   21   package java.lang.reflect;
   22   
   23   /**
   24    * Provides the package private methods requirered for the
   25    * <code>java.lang.reflect</code> package implementation.
   26    * <p>
   27    * This class must be implemented according to the common policy for porting
   28    * interfaces - see the porting interface overview for more detailes.
   29    * <p>
   30    * <b>Note: </b> this class design is based on requirements for the
   31    * {@link Field}, {@link Method} and {@link Constructor} classes from the
   32    * <code>java.lang.reflect</code> package. Each class (Field, Method, Constructor)
   33    * should have a constructor that accepts an argument of the
   34    * {@link java.lang.Object} type. This argument serves as an identifier of
   35    * particular item. This identifier should be used later when one needs to 
   36    * operate with an item. For example, see {@link VMReflection#getFieldType(Object)
   37    * VMReflection.getFieldType(Object id)} method.
   38    * @api2vm
   39    */
   40    
   41   final class VMReflection {
   42   
   43       /**
   44        * This class is not supposed to be instantiated.
   45        */
   46       private VMReflection() {
   47       }
   48   
   49       /**
   50        * This method satisfies the requirements of the specification for the
   51        * {@link Method#getExceptionTypes() Method.getExceptionTypes()} method. But
   52        * it takes one additional id parameter.
   53        * 
   54        * @param id an identifier of the caller class.
   55        * @api2vm
   56        */
   57       static native Class<?>[] getExceptionTypes(long id);
   58   
   59       /**
   60        * This method satisfies the requirements of the specification for the
   61        * {@link Field#getType() Field.getType()} method. But it takes one
   62        * additional id parameter.
   63        * 
   64        * @param id an identifier of the caller class.
   65        * @api2vm
   66        */
   67       static native Class<?> getFieldType(long id);
   68   
   69       /**
   70        * This method satisfies the requirements of the specification for the
   71        * {@link Method#getReturnType() Method.getReturnType()} method. But it
   72        * takes one additional id parameter.
   73        * 
   74        * @param id an identifier of the caller class.
   75        * @api2vm
   76        */
   77       static native Class<?> getMethodReturnType(long id);
   78   
   79       /**
   80        * This method satisfies the requirements of the specification for the
   81        * {@link Method#getParameterTypes() Method.getParameterTypes()} method. But
   82        * it takes one additional id parameter.
   83        * 
   84        * @param id an identifier of the caller class.
   85        * @api2vm
   86        */
   87       static native Class<?>[] getParameterTypes(long id);
   88   
   89       /**
   90        * This method satisfies the requirements of the specification for the
   91        * {@link Method#invoke(java.lang.Object, java.lang.Object[])
   92        * Method.invoke(Object obj, Object[] args)} method. But it differs in
   93        * several ways.
   94        * <p>
   95        * First, it takes one additional <code>id</code> parameter. This parameter
   96        * is used as an identifier to invoke corresponding method.
   97        * <p>
   98        * Second, it doesn't perform access control so it doesn't throw an
   99        * <code>IllegalAccessException</code> exception. 
  100        * <p>
  101        * Third, it throws <code>IllegalArgumentException</code> only if the
  102        * <code>args</code> argument doesn't fit to the actual method parameters.  
  103        * <p>
  104        * Last, it doesn't throw an <code>NullPointerException</code> exception. If
  105        * the <code>id</code> argument corresponds to a static method then the
  106        * object argument must be null. An attempt to invoke a static method will
  107        * be made in this case. If the <code>id</code> argument corresponds to a
  108        * non-static method then corresponding object's method will be invoked.
  109        * <p>
  110        * <b>Note:</b> Under design yet. Subjected to change.
  111        * 
  112        * @param id the identifier of the method to be invoked.
  113        * @api2vm
  114        */
  115       static native Object invokeMethod(long id, Object object, Object... args)
  116           throws InvocationTargetException;
  117   
  118       /**
  119        * This method satisfies the requirements of the specification for the
  120        * {@link Array#newInstance(Class, int[])
  121        * Array.newInstance(Class componentType, int[] dimensions)} method. But it
  122        * differs in several ways.
  123        * <p>
  124        * First, it it doesn't throw an <code>NullPointerException</code> exception.
  125        * <p>
  126        * Second, it throws an <code>IllegalArgumentException</code> exception only
  127        * if the implementation doesn't support specified number of dimensions.
  128        * <p>
  129        * <b>Note:</b> Under design yet. Subjected to change.
  130        * @api2vm
  131        */
  132       static native Object newArrayInstance(Class<?> type, int[] dimensions);
  133   
  134       /**
  135        * This method satisfies the requirements of the specification for the
  136        * {@link Constructor#newInstance(java.lang.Object[])
  137        * Constructor.newInstance(java.lang.Object[] initargs)} method. But it
  138        * differs in several ways.
  139        * <p>
  140        * First, it takes one additional <code>id</code> parameter. This parameter
  141        * is used as an identifier of the corresponding constructor.
  142        * <p>
  143        * Second, it doesn't perform access control so it doesn't throw an
  144        * <code>IllegalAccessException</code> exception.
  145        * <p>
  146        * Last, it doesn't throw an <code>InstantiationException</code> exception. 
  147        * The <code>id</code> argument must not correspond to an abstract class.
  148        * <p>
  149        * <b>Note:</b> Under design yet. Subjected to change.
  150        * 
  151        * @param id the identifier of the method to be invoked.
  152        * @api2vm
  153        */
  154       static native Object newClassInstance(long id, Object... args)
  155           throws InvocationTargetException;
  156   
  157   }

Save This Page
Home » openjdk-7 » java » lang » reflect » [javadoc | source]