public class ProxyFactory
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.HashMap<java.lang.String,java.lang.Class<?>> |
classDescriptor |
private static java.util.HashMap<ConstructorClass<?>,Constructor<?>> |
constructorClass |
private static java.util.HashMap<java.lang.reflect.Field,GetProperty<?>> |
fieldGetClass |
private static java.util.HashMap<java.lang.reflect.Field,SetProperty> |
fieldSetClass |
private static java.util.HashMap<MemberBSClass<?>,Callable<?>> |
invokedynamicClass |
private static java.util.HashMap<MemberClass<?>,Callable<?>> |
memberClass |
private static java.util.HashMap<MemberBIClass<?>,MemberBIClass<?>> |
memberMethod |
private static java.util.HashMap<java.lang.reflect.Method,Callable<?>> |
methodsClass |
private static java.util.HashMap<PropertyClass<?>,GetProperty<?>> |
propertyGetClass |
private static java.util.HashMap<PropertyClass<?>,SetProperty> |
propertySetClass |
Constructor and Description |
---|
ProxyFactory() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
generateCallable(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<T> interfaceCallable)
Generates an object to provide instance method invocation using invokedynamic, passing the name of the method and class as parameters.
|
static <T> Callable<T> |
generateCallable(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<T> returnType,
java.lang.Class<?>... parametersType)
Generates a Callable instance to perform dynamic invocations to an instance method, indicating its signature.
|
static <T> Callable<T> |
generateCallable(java.lang.reflect.Method method)
Generates a Callable instance to perform dynamic invocations to an instance method, indicating a Method instance.
|
static <T> Callable<T> |
generateCallable(java.lang.Object object,
java.lang.String methodName,
java.lang.Class<T> returnType,
java.lang.Class<?>... parametersType)
Generates a Callable instance to perform dynamic invocations to an instance method, indicating its signature.
|
static <T> Callable<T> |
generateCallable(java.lang.String clazzDescriptor,
java.lang.String methodName,
java.lang.Class<T> returnType,
java.lang.Class<?>... parametersType)
Generates a Callable instance to perform dynamic invocations to an instance method, indicating its signature.
|
static <T> T |
generateConstructor(java.lang.Class<?> clazz,
java.lang.Class<T> interfaceCallable)
Generates an object to provide a constructor invocation using invokedynamic.
|
static <T> Constructor<T> |
generateConstructor(java.lang.Class<T> clazz,
java.lang.Class<?>... parameterstype)
Generates a Constructor instance of the class and parameters passed as arguments.
|
static <T> T |
generateGetProperty(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<T> interfaceCallable)
Generates an object to obtain the value of an instance field by means of invokedynamic.
|
static <T> GetProperty<T> |
generateGetProperty(java.lang.reflect.Field field)
Generates a GetProperty instance to obtain the value of a Field by means of invokedynamic.
|
static <T> GetProperty<T> |
generateGetProperty(java.lang.Object object,
java.lang.String property,
java.lang.Class<T> type)
Generates a GetProperty instance to obtain the value of an instance field by means of invokedynamic.
|
static <T> GetProperty<T> |
generateGetProperty(java.lang.String clazzDescriptor,
java.lang.String property,
java.lang.String typeDescriptor)
Generates a GetProperty instance to obtain the value of an instance field by means of invokedynamic.
|
static <T> T |
generateInvokeDynamic(Bootstrap bootstrap,
java.lang.Class<T> interfaceCallable)
Generates an object to provide instance method invocation using invokedynamic, passing the bootstrap method as parameter.
|
static <T> Callable<T> |
generateInvokeDynamicCallable(Bootstrap bootstrap,
MethodSignature methodSignature)
Generates a Callable instance to perform dynamic invocations to methods, fields and constructors received as a parameter.
|
static <T> T |
generateSetProperty(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<T> interfaceCallable)
Generates an object to modify the value of an instance field by means of invokedynamic.
|
static SetProperty |
generateSetProperty(java.lang.reflect.Field field)
Generates a SetProperty instance to modify the value of a Field by means of invokedynamic.
|
static SetProperty |
generateSetProperty(java.lang.Object object,
java.lang.String property,
java.lang.Class<?> type)
Generates a SetProperty instance to modify the value of an instance field by means of invokedynamic.
|
static SetProperty |
generateSetProperty(java.lang.String clazzDescriptor,
java.lang.String property,
java.lang.String typeDescriptor)
Generates a SetProperty instance to modify the value of an instance field by means of invokedynamic.
|
static <T> T |
generateStaticCallable(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<T> interfaceCallable)
Generates an object to provide static method invocation using invokedynamic, passing the name of the method and class as parameters.
|
static <T> Callable<T> |
generateStaticCallable(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<T> returnType,
java.lang.Class<?>... parametersType)
Generates a Callable instance to perform dynamic invocations to a static method, indicating its signature.
|
static <T> Callable<T> |
generateStaticCallable(java.lang.Object object,
java.lang.String methodName,
java.lang.Class<T> returnType,
java.lang.Class<?>... parametersType)
Generates a Callable instance to perform dynamic invocations to a static method, indicating its signature.
|
static <T> Callable<T> |
generateStaticCallable(java.lang.String clazzDescriptor,
java.lang.String methodName,
java.lang.Class<T> returnType,
java.lang.Class<?>... parametersType)
Generates a Callable instance to perform dynamic invocations to a static method, indicating its signature.
|
static <T> T |
generateStaticGetProperty(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<T> interfaceCallable)
Generates an object to obtain the value of an static field by means of invokedynamic.
|
static <T> GetProperty<T> |
generateStaticGetProperty(java.lang.Object object,
java.lang.String property,
java.lang.Class<T> type)
Generates a GetProperty instance to obtain the value of a static field by means of invokedynamic.
|
static <T> GetProperty<T> |
generateStaticGetProperty(java.lang.String clazzDescriptor,
java.lang.String property,
java.lang.String typeDescriptor)
Generates a GetProperty instance to obtain the value of a static field by means of invokedynamic.
|
static <T> T |
generateStaticInvokeDynamic(Bootstrap bootstrap,
java.lang.Class<T> interfaceCallable)
Generates an object to provide static method invocation using invokedynamic, passing the bootstrap method as parameter.
|
static <T> T |
generateStaticSetProperty(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<T> interfaceCallable)
Generates an object to modify the value of an static field by means of invokedynamic.
|
static SetProperty |
generateStaticSetProperty(java.lang.Object object,
java.lang.String property,
java.lang.Class<?> type)
Generates a SetProperty instance to modify the value of a static field by means of invokedynamic.
|
static SetProperty |
generateStaticSetProperty(java.lang.String clazzDescriptor,
java.lang.String property,
java.lang.String typeDescriptor)
Generates a SetProperty instance to modify the value of a static field by means of invokedynamic.
|
private static <T> Callable<T> |
getCallable(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?> rtype,
java.lang.Class<?>[] parametersType,
TypeModifier typeModifier)
Returns a Callable object.
|
private static java.lang.Class<?> |
getClassToDescriptor(java.lang.String descriptor)
Returns an object whose type is represented by a type descriptor.
|
private static <T> GetProperty<T> |
getGetProperty(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?> type,
TypeModifier typeModifier)
Returns a GetProperty object.
|
private static <T> T |
getInstance(MemberBIClass<T> member)
Returns an object of type T.
|
private static <T> Callable<T> |
getInvokedynamicCallable(Bootstrap bootstrap,
MethodSignature methodSignature)
Returns a Callable object.
|
private static <T> SetProperty |
getSetProperty(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?> type,
TypeModifier typeModifier)
Returns a SetProperty object.
|
static <T> T |
invokeDynamic(Bootstrap bootstrap,
MethodSignature methodSignature,
java.lang.Object object,
java.lang.Object... args)
Performs dynamic invocations to methods, fields and constructors received as a parameter.
|
private static java.util.HashMap<java.lang.String,java.lang.Class<?>> classDescriptor
private static final java.util.HashMap<MemberBSClass<?>,Callable<?>> invokedynamicClass
private static final java.util.HashMap<MemberBIClass<?>,MemberBIClass<?>> memberMethod
private static final java.util.HashMap<java.lang.reflect.Field,GetProperty<?>> fieldGetClass
private static final java.util.HashMap<java.lang.reflect.Field,SetProperty> fieldSetClass
private static final java.util.HashMap<java.lang.reflect.Method,Callable<?>> methodsClass
private static final java.util.HashMap<MemberClass<?>,Callable<?>> memberClass
private static final java.util.HashMap<ConstructorClass<?>,Constructor<?>> constructorClass
private static final java.util.HashMap<PropertyClass<?>,GetProperty<?>> propertyGetClass
private static final java.util.HashMap<PropertyClass<?>,SetProperty> propertySetClass
public static final <T> T invokeDynamic(Bootstrap bootstrap, MethodSignature methodSignature, java.lang.Object object, java.lang.Object... args) throws java.lang.InstantiationException, java.lang.IllegalAccessException
bootstrap
- Bootstrap responsible for generating a bootstrap handle.methodSignature
- The signature of the method to be invoked.object
- Implicit object used to perform the dynamic invocation.args
- Arguments of the method invocation.java.lang.ClassCastException
- If the types of the actual arguments do not match the type of the formal parameters.java.lang.NullPointerException
- If object is null and the method to be invoked is an instance method.java.lang.NoSuchMethodException
- There is no method with the specified signature.java.lang.InstantiationException
- The class could not be instantiated.java.lang.IllegalAccessException
- If the class of the member to be invoked is not public.Bootstrap
,
MethodSignature
public static final <T> Callable<T> generateInvokeDynamicCallable(Bootstrap bootstrap, MethodSignature methodSignature) throws java.lang.InstantiationException, java.lang.IllegalAccessException
bootstrap
- Bootstrap responsible for generating a bootstrap handle.methodSignature
- The signature of the method to be invoked.java.lang.NoSuchMethodException
- There is no method with the specified signature.java.lang.InstantiationException
- The class could not be instantiated.java.lang.IllegalAccessException
Bootstrap
,
MethodSignature
public static final <T> T generateStaticInvokeDynamic(Bootstrap bootstrap, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException, java.lang.IllegalAccessException
bootstrap
- Bootstrap responsible for generating a bootstrap handle.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.IllegalAccessException
Bootstrap
public static final <T> T generateInvokeDynamic(Bootstrap bootstrap, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException, java.lang.IllegalAccessException
bootstrap
- Bootstrap responsible for generating a bootstrap handle.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.IllegalAccessException
Bootstrap
public static final <T> Constructor<T> generateConstructor(java.lang.Class<T> clazz, java.lang.Class<?>... parameterstype) throws java.lang.InstantiationException
The following code dynamically invokes a constructor of the Counter class with no parameter:
Constructor<Counter> constructor = ProxyFactory.<Contructor<Counter>>generateConstructor(Counter.class);
Counter counter = constructor.newInstance();
clazz
- The class we want to create a new instance of.parameterstype
- Type of the parameters of the constructor to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.public static final <T> Callable<T> generateStaticCallable(java.lang.Object object, java.lang.String methodName, java.lang.Class<T> returnType, java.lang.Class<?>... parametersType) throws java.lang.InstantiationException
The following code shows how to dynamically invoke the static method concat
of the Counter
class. The method returns
a String
and receives two String
as parameters:
Callable<String> callable = ProxyFactory.<Callable<String>>generateStaticCallable(counter,"concat",String.class, String.class,String.class);
String cad = callable.invoke(null,"Hello", "World");
object
- Object of the class of the method to be invoked.methodName
- Name of the method to be invoked. It must be static.returnType
- The return type of the method to be invoked.parametersType
- Type of the parameters of the method to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.public static final <T> Callable<T> generateCallable(java.lang.Object object, java.lang.String methodName, java.lang.Class<T> returnType, java.lang.Class<?>... parametersType) throws java.lang.InstantiationException
The following code shows how to dynamically invoke the instance method increase
of the Counter
class. The method return a long
and receives
no parameters:
Callable<Long> callable = ProxyFactory.<Callable<Long>>generateCallable(counter,"increase", long.class);
long value = callable.invoke(counter);
object
- Object of the class of the method to be invoked.methodName
- Name of the instance method to be invoked.returnType
- The return type of the method to be invoked.parametersType
- Type of the parameters of the method to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.public static final <T> Callable<T> generateStaticCallable(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<T> returnType, java.lang.Class<?>... parametersType) throws java.lang.InstantiationException
The following code shows how to dynamically invoke the static method concat
of the Counter
class. The method returns a String
and
receives two String
as parameters:
Callable<String> callable = ProxyFactory.<Callable<String>>generateStaticCallable(Counter.class,"concat",String.class, String.class,String.class);
String cad = callable.invoke(null,"Hello", "World");
clazz
- Class of the method to be invoked.methodName
- Name of the method to be invoked. It must be static.returnType
- The return type of the method to be invoked.parametersType
- Type of the parameters of the method to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.public static final <T> Callable<T> generateCallable(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<T> returnType, java.lang.Class<?>... parametersType) throws java.lang.InstantiationException
The following code shows how to dynamically invoke the instance method increase
of the Counter
class. The method returns a long
and receives no parameter:
Callable<Long> callable = ProxyFactory.<Callable<Long>>generateCallable(Counter.class,"increase", long.class);
long value = callable.invoke(counter);
clazz
- Class of the method to be invoked.methodName
- Name of the instance method to be invoked.returnType
- The return type of the method to be invoked.parametersType
- Type of the parameters of the method to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.public static final <T> Callable<T> generateStaticCallable(java.lang.String clazzDescriptor, java.lang.String methodName, java.lang.Class<T> returnType, java.lang.Class<?>... parametersType) throws java.lang.InstantiationException, java.lang.ClassNotFoundException
The following code shows how to dynamically invoke the static method concat
of the Counter
class. The method returns a String
and receives two String
as parameters:
Callable<String> callable = ProxyFactory.<Callable<String>>generateStaticCallable("paquete.Counter","concat",String.class, String.class,String.class);
String cad = callable.invoke(null,"Hello", "World");
clazzDescriptor
- Class descriptor of the method to be invoked.methodName
- Name of the method to be invoked. It must be static.returnType
- The return type of the method to be invoked.parametersType
- Type of the parameters of the method to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.java.lang.ClassNotFoundException
- If the class specified by the descriptor cannot be found.public static <T> Callable<T> generateCallable(java.lang.String clazzDescriptor, java.lang.String methodName, java.lang.Class<T> returnType, java.lang.Class<?>... parametersType) throws java.lang.InstantiationException, java.lang.ClassNotFoundException
The following code shows how to dynamically invoke the instance method increase
of the Counter
class. The method returns a long
and receives no parameter
Callable<Long> callable = ProxyFactory.<Callable<Long>>generateCallable("paquete.Counter","increase", long.class);
long value = callable.invoke(counter);
clazzDescriptor
- Class descriptor of the method to be invoked.methodName
- Name of the method to be invoked. It must be an instance method.returnType
- The return type of the method to be invoked.parametersType
- Type of the parameters of the method to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.java.lang.ClassNotFoundException
- If the class specified by the descriptor cannot be found.public static final <T> Callable<T> generateCallable(java.lang.reflect.Method method) throws java.lang.InstantiationException
The following code shows how to dynamically invoke the method represented by the method
Method:
Callable<T> callable = ProxyFactory.generateCallable(method);
Object value = callable.invoke(counter);
method
- An instance of Method representing the method to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.public static final <T> GetProperty<T> generateStaticGetProperty(java.lang.Object object, java.lang.String property, java.lang.Class<T> type) throws java.lang.InstantiationException
The following code shows how to obtain the STATIC_COUNTER
static field of the Counter
class,
whose type is long
:
GetProperty<Long> getProperty = ProxyFactory.<GetProperty<Long>>generateStaticGetProperty(counter,"STATIC_COUNTER", long.class);
long value = getProperty.get(null);
object
- The object of the class the property belongs to.property
- Name of the static property to be invoked.type
- Type of the static property to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- If no method with the appropriate signature belongs to the class.public static final <T> GetProperty<T> generateGetProperty(java.lang.Object object, java.lang.String property, java.lang.Class<T> type) throws java.lang.InstantiationException
The following code shows how to obtain the instance_counter
field of the Counter class, whose type is long
:
GetProperty<Long> getProperty = ProxyFactory.<GetProperty<Long>>generateGetProperty(counter,"instance_counter", long.class);
long value = getProperty.get(counter);
object
- The object of the class the property belongs to.property
- Name of the instance property to be invoked.type
- Type of the static property to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.public static final <T> GetProperty<T> generateStaticGetProperty(java.lang.String clazzDescriptor, java.lang.String property, java.lang.String typeDescriptor) throws java.lang.InstantiationException, java.lang.ClassNotFoundException
The following code shows how to obtain the STATIC_COUNTER
static field of the Counter class, whose type is Long
:
GetProperty<Long> getProperty = ProxyFactory.<GetProperty<Long>>generateStaticGetProperty("paquete.Counter","STATIC_COUNTER", "java.lang.Long");
long value = getProperty.get(null);
clazzDescriptor
- Descriptor of the class the property belongs to.property
- Name of the static property to be invoked.typeDescriptor
- Descriptor of the type of the static property to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.java.lang.ClassNotFoundException
- If the class specified by the descriptor cannot be found.public static <T> GetProperty<T> generateGetProperty(java.lang.String clazzDescriptor, java.lang.String property, java.lang.String typeDescriptor) throws java.lang.InstantiationException, java.lang.ClassNotFoundException
The following code shows how to obtain the instance_counter
field of the Counter class, whose type is Long
:
GetProperty<Long> getProperty = ProxyFactory.<GetProperty<Long>>generateGetProperty("paquete.Counter","instance_counter", "java.lang.Long");
long value = getProperty.get(counter);
clazzDescriptor
- Descriptor of the class the property belongs to.property
- Name of the instance property to be invoked.typeDescriptor
- Descriptor or the type of the static property to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.NoSuchMethodException
- There is no method with the specified signature.java.lang.ClassNotFoundException
- If the class specified by the descriptor cannot be found.public static final <T> GetProperty<T> generateGetProperty(java.lang.reflect.Field field) throws java.lang.InstantiationException
GetProperty<?> getProperty = ProxyFactory.generateGetProperty(field);
Object value = getProperty.get(counter);
field
- Objeto de la clase Field que representa la propiedad a invocar.java.lang.InstantiationException
- If the class could not be instantiated.public static final SetProperty generateStaticSetProperty(java.lang.Object object, java.lang.String property, java.lang.Class<?> type) throws java.lang.InstantiationException
The following code shows how to modify the value of the STATIC_COUNTER
static field of the Counter
class, whose type is long
:
SetProperty setProperty = ProxyFactory.<SetProperty>generateStaticSetProperty(counter,"STATIC_COUNTER", long.class);
setProperty.set(null,newValue);
object
- Object of the class the property belongs to.property
- Name of the static property to be invoked.type
- Type of the static property to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.public static final SetProperty generateSetProperty(java.lang.Object object, java.lang.String property, java.lang.Class<?> type) throws java.lang.InstantiationException
The following code shows how to modify the value of the instance_counter
field of the Counter
class, whose type is long
:
SetProperty setProperty = ProxyFactory.<SetProperty>generateSetProperty(counter,"instance_counter", long.class);
setProperty.set(counter,newValue);
object
- Object of the class the property belongs to.property
- Name of the instance property to be invoked.type
- Type of the static property to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.public static final SetProperty generateStaticSetProperty(java.lang.String clazzDescriptor, java.lang.String property, java.lang.String typeDescriptor) throws java.lang.InstantiationException, java.lang.ClassNotFoundException
The following code shows how to modify the value of the STATIC_COUNTER
static field of the Counter
class, whose type is Long
:
SetProperty setProperty = ProxyFactory.<SetProperty>generateStaticSetProperty("paquete.Counter","STATIC_COUNTER", "java.lang.Long");
setProperty.set(null,newValue);
clazzDescriptor
- Descriptor of the class the property belongs to.property
- Name of the static property to be invoked.typeDescriptor
- Type of the static property to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.ClassNotFoundException
- If the class specified by the descriptor cannot be found.public static SetProperty generateSetProperty(java.lang.String clazzDescriptor, java.lang.String property, java.lang.String typeDescriptor) throws java.lang.InstantiationException, java.lang.ClassNotFoundException
The following code shows how to modify the value of the instance_counter
field of the Counter
class, whose type is Long
:
SetProperty setProperty = ProxyFactory.<SetProperty>generateSetProperty("paquete.Counter","instance_counter", "java.lang.Long");
setProperty.set(counter,newValue);
clazzDescriptor
- Descriptor of the class the property belongs to.property
- Name of the instance property to be invoked.typeDescriptor
- Type of the static property to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.java.lang.ClassNotFoundException
- If the class specified by the descriptor cannot be found.public static final SetProperty generateSetProperty(java.lang.reflect.Field field) throws java.lang.InstantiationException
SetProperty setProperty = ProxyFactory.<SetProperty>generateSetProperty(field);
setProperty.set(counter, newValue);
field
- A Field instance representing que the field whose value is going to be modified.java.lang.InstantiationException
- If the class could not be instantiated.public static final <T> T generateCallable(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException
The next example shows how to declare an interface and invoke its method using invokedynamic.
We want to invoke the increase
instance method in the Counter
class. This method returns a long
and receives no parameter.
We create the following interface:
public interface CallablelongCounter{
public long invoke(Counter counter);
}
Then, we generate the Callable instance:
CallablelongCounter callable = ProxyFactory.<CallablelongCounter> generateCallable(Counter.class, "increase", CallablelongCounter.class);
And the method is invoked with invokedynamic:
long value = callable.invoke(counter);
clazz
- Class of the method to be invoked.methodName
- Name of the method to be invoked. It must be an instance method.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.public static final <T> T generateStaticCallable(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException
The next example shows how to declare an interface and invoke its method using invokedynamic.
We want to invoke the concat
static method in the Counter
class. This method returns a String
and receives two String
parameter.
We create the following interface:
public interface CallableString2String{
public String invoke(String cad1, String cad2);
}
Then, the Callable is generated:
CallableString2String callable = ProxyFactory.<CallableString2String> generateStaticCallable(Counter.class, "concat", CallableString2String.class);
And the method can be dynamically invoked:
String cad = callable.invoke("Hello", "World");
clazz
- Class of the method to be invoked.methodName
- Name of the method to be invoked. It must be an static method.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.public static final <T> T generateGetProperty(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException
The next example shows how to declare an interface and obtain the value of an instance field by means of invokedynamic.
We want to the value of instance_concat
a instance field in the Counter
class with long
type.
We create the following interface:
public interface CallablelongCounter{
public long invoke(Counter counter);
}
Then, the Callable is generated:
CallablelongCounter callable = ProxyFactory.<CallablelongCounter> generateGetProperty(Counter.class, "instance_concat", CallablelongCounter.class);
And the field can be dynamically invoked:
long value = callable.invoke(counter);
clazz
- Class of the field to be invoked.propertyName
- Name of the instance field to be invoked.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.public static final <T> T generateStaticGetProperty(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException
The next example shows how to declare an interface and obtain the value of an static field by means of invokedynamic.
We want to the value of STATIC_COUNTER
a static field in the Counter
class with long
type.
We create the following interface:
public interface Callablelong{
public long invoke();
}
Then, the Callable is generated:
Callablelong callable = ProxyFactory.<Callablelong> generateStaticGetProperty(Counter.class, "STATIC_COUNTER", Callablelong.class);
And the field can be dynamically invoked:
long value = callable.invoke();
clazz
- Class of the field to be invoked.propertyName
- Name of the static field to be invoked.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.public static final <T> T generateSetProperty(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException
The next example shows how to declare an interface and modify the value of an instance field by means of invokedynamic
We want to modify the value of instance_concat
a instance field in the Counter
class with long
type.
We create the following interface:
public interface CallablevoidCounterlong{
public void invoke(Counter counter, long newValue);
}
Then, the Callable is generated:
CallablevoidCounterlong callable = ProxyFactory.<CallablevoidCounterlong> generateSetProperty(Counter.class, "instance_concat", CallablevoidCounterlong.class);
And the field can be dynamically invoked:
callable.invoke(counter,newValue);
clazz
- Class of the field to be invoked.propertyName
- Name of the instance field to be invoked.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.public static final <T> T generateStaticSetProperty(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException
The next example shows how to declare an interface and modify the value of an static field by means of invokedynamic
We want to modify the value of STATIC_COUNTER
a static field in the Counter
class with long
type.
We create the following interface:
public interface Callablevoidlong{
public void invoke(long newValue);
}
Then, the Callable is generated:
Callablevoidlong callable = ProxyFactory.<Callablevoidlong> generateStaticSetProperty(Counter.class, "STATIC_COUNTER", Callablevoidlong.class);
And the field can be dynamically invoked:
callable.invoke(newValue);
clazz
- Class of the field to be invoked.propertyName
- Name of the static field to be invoked.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.public static final <T> T generateConstructor(java.lang.Class<?> clazz, java.lang.Class<T> interfaceCallable) throws java.lang.InstantiationException
The next example shows how to declare an interface and dynamically invokes a constructor
we want to create a new instance of Counter
class and invoke a constructor with a long
type parameter.
We create the following interface:
public interface CallableCounterlong{
public Counter invoke(long value);
}
Then, the Callable is generated:
CallableCounterlong callable = ProxyFactory.<CallableCounterlong> generateConstructor(Counter.class, CallableCounterlong.class);
And the method can be dynamically invoked:
Counter counter = callable.invoke(value);
clazz
- Class of the constructor to be invoked.interfaceCallable
- The interface with one single method.java.lang.InstantiationException
- If the class could not be instantiated.private static <T> SetProperty getSetProperty(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?> type, TypeModifier typeModifier) throws java.lang.InstantiationException
clazz
- Class the property belongs to.name
- Name of the property.type
- Type of the property.typeModifier
- Indicates if the member is instance or class (static).java.lang.InstantiationException
- If the class could not be instantiated.private static <T> Callable<T> getCallable(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?> rtype, java.lang.Class<?>[] parametersType, TypeModifier typeModifier) throws java.lang.InstantiationException
clazz
- Class the method belongs to.name
- Name of the method.rtype
- Return type of the methodparametersType
- Type of the parameters of the method.typeModifier
- Indicates if the member is instance or class (static).java.lang.InstantiationException
- If the class could not be instantiated.private static <T> Callable<T> getInvokedynamicCallable(Bootstrap bootstrap, MethodSignature methodSignature) throws java.lang.InstantiationException
bootstrap
- responsible for generating the Handle used to invoke the appropriate bootstrap class.methodSignature
- The signature of the method to be invoked.java.lang.InstantiationException
- If the class could not be instantiated.private static <T> GetProperty<T> getGetProperty(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?> type, TypeModifier typeModifier) throws java.lang.InstantiationException
clazz
- Class the field belongs to.name
- Name of the property.type
- Type of the property.typeModifier
- Indicates if the member is instance or class (static).java.lang.InstantiationException
- If the class could not be instantiated.private static <T> T getInstance(MemberBIClass<T> member) throws java.lang.InstantiationException
member
- Represent a bootstrap and an interface.java.lang.InstantiationException
- If the class could not be instantiated.private static final java.lang.Class<?> getClassToDescriptor(java.lang.String descriptor) throws java.lang.ClassNotFoundException
descriptor
- The class descriptor.java.lang.ClassNotFoundException
- If the class specified by the descriptor cannot be found.