001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Evgueni Brevnov
019: * @version $Revision: 1.1.2.1.4.4 $
020: */package java.lang.reflect;
021:
022: /**
023: * Provides the package private methods requirered for the
024: * <code>java.lang.reflect</code> package implementation.
025: * <p>
026: * This class must be implemented according to the common policy for porting
027: * interfaces - see the porting interface overview for more detailes.
028: * <p>
029: * <b>Note: </b> this class design is based on requirements for the
030: * {@link Field}, {@link Method} and {@link Constructor} classes from the
031: * <code>java.lang.reflect</code> package. Each class (Field, Method, Constructor)
032: * should have a constructor that accepts an argument of the
033: * {@link java.lang.Object} type. This argument serves as an identifier of
034: * particular item. This identifier should be used later when one needs to
035: * operate with an item. For example, see {@link VMReflection#getFieldType(Object)
036: * VMReflection.getFieldType(Object id)} method.
037: * @api2vm
038: */
039:
040: final class VMReflection {
041:
042: /**
043: * This class is not supposed to be instantiated.
044: */
045: private VMReflection() {
046: }
047:
048: /**
049: * This method satisfies the requirements of the specification for the
050: * {@link Method#getExceptionTypes() Method.getExceptionTypes()} method. But
051: * it takes one additional id parameter.
052: *
053: * @param id an identifier of the caller class.
054: * @api2vm
055: */
056: static native Class<?>[] getExceptionTypes(long id);
057:
058: /**
059: * This method satisfies the requirements of the specification for the
060: * {@link Field#getType() Field.getType()} method. But it takes one
061: * additional id parameter.
062: *
063: * @param id an identifier of the caller class.
064: * @api2vm
065: */
066: static native Class<?> getFieldType(long id);
067:
068: /**
069: * This method satisfies the requirements of the specification for the
070: * {@link Method#getReturnType() Method.getReturnType()} method. But it
071: * takes one additional id parameter.
072: *
073: * @param id an identifier of the caller class.
074: * @api2vm
075: */
076: static native Class<?> getMethodReturnType(long id);
077:
078: /**
079: * This method satisfies the requirements of the specification for the
080: * {@link Method#getParameterTypes() Method.getParameterTypes()} method. But
081: * it takes one additional id parameter.
082: *
083: * @param id an identifier of the caller class.
084: * @api2vm
085: */
086: static native Class<?>[] getParameterTypes(long id);
087:
088: /**
089: * This method satisfies the requirements of the specification for the
090: * {@link Method#invoke(java.lang.Object, java.lang.Object[])
091: * Method.invoke(Object obj, Object[] args)} method. But it differs in
092: * several ways.
093: * <p>
094: * First, it takes one additional <code>id</code> parameter. This parameter
095: * is used as an identifier to invoke corresponding method.
096: * <p>
097: * Second, it doesn't perform access control so it doesn't throw an
098: * <code>IllegalAccessException</code> exception.
099: * <p>
100: * Third, it throws <code>IllegalArgumentException</code> only if the
101: * <code>args</code> argument doesn't fit to the actual method parameters.
102: * <p>
103: * Last, it doesn't throw an <code>NullPointerException</code> exception. If
104: * the <code>id</code> argument corresponds to a static method then the
105: * object argument must be null. An attempt to invoke a static method will
106: * be made in this case. If the <code>id</code> argument corresponds to a
107: * non-static method then corresponding object's method will be invoked.
108: * <p>
109: * <b>Note:</b> Under design yet. Subjected to change.
110: *
111: * @param id the identifier of the method to be invoked.
112: * @api2vm
113: */
114: static native Object invokeMethod(long id, Object object,
115: Object... args) throws InvocationTargetException;
116:
117: /**
118: * This method satisfies the requirements of the specification for the
119: * {@link Array#newInstance(Class, int[])
120: * Array.newInstance(Class componentType, int[] dimensions)} method. But it
121: * differs in several ways.
122: * <p>
123: * First, it it doesn't throw an <code>NullPointerException</code> exception.
124: * <p>
125: * Second, it throws an <code>IllegalArgumentException</code> exception only
126: * if the implementation doesn't support specified number of dimensions.
127: * <p>
128: * <b>Note:</b> Under design yet. Subjected to change.
129: * @api2vm
130: */
131: static native Object newArrayInstance(Class<?> type,
132: 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: }
|