IReflector インターフェイスの使用
IReflectorすべての iSDK クラスには、 という名前のツールボックス インターフェイスへのアクセス権があります。このインターフェイスは、Java リフレクションの使用を可能にする機能を提供します。いずれかのテンプレートクラスを拡張するクラス内で、ユーザは IReflectionBuilder のインスタンスを取得するために getNewReflectionBuilder() を呼び出すことができます。
getNewReflectionBuilder() は、プラグインクラスのコンストラクタで呼び出す必要があります。別の場所で呼び出された場合は、NullPointerException が発生することがあります。このインターフェイスは、次のメソッドをサポートしています。
/**
* load a class. classLoader specified in the IReflector.execute method
**/
IReflectionBuilder loadClass(String className);
/**
* Create a new object
* @param className class to create
* @param argTypes argument types
* @return this
*/
IReflectionBuilder createObject(String className, String... argTypes);
/**
* Invoke a static method
* @param methodName method to invoke
* @param searchSuperClass search super classes for the method. Else only declared methods are called
* @param argTypes for overloaded methods
* @return this
*/
IReflectionBuilder invokeStaticMethod(String methodName, boolean searchSuperClass, String... argTypes);/**
* Similar to invoke static method, invoke a instance method
* @param methodName method to invoke
* @param searchSuperClass search super classes for the method. Else only declared methods are called
* @param argTypes for overloaded methods
* @return this
*/
IReflectionBuilder invokeInstanceMethod(String methodName, boolean searchSuperClass, String... argTypes);/**
* Access a field
* @param fieldName field name to access
* @param searchSuperClass should search super class for the field name
* @return this
*/
IReflectionBuilder accessFieldValue(String fieldName, boolean searchSuperClass);
These can be called in any order, essentially forming a getter chain. After crafting your chain of calls, the build() method must be called, returning an IReflector.The IReflector is used by invoking its execute() method:
/**
* Execute the reflector chain
* @param classLoader required - classloader referenced to load classes
* @param target The steps will start executing on this object. null if first step is loadClass or staticMethod
* @param params params to be passed to the steps
* @return returns with correct cast
* @throws ReflectorException
*/
<E> E execute(ClassLoader classLoader, Object target, Object[]... params) throws ReflectorException;
/**
* Execute the reflector chain
* @param classLoader required - classloader referenced to load classes
* @param target The steps will start executing on this object. null if first step is loadClass or staticMethod
* @param params params to be passed to the steps
* @return returns with correct cast
* @throws ReflectorException
*/
<E> E execute(ClassLoader classLoader, Object target, OperationParams params)
throws ReflectorException;
多くの場合、これらのリフレクタの使用は、必要な機能(ペイロードからの値の抽出や、相関ヘッダーによるオブジェクトの修飾など)の取得のために非常に重要です。