Class NativeRegistry
- java.lang.Object
-
- com.tonic.analysis.execution.invoke.NativeRegistry
-
public final class NativeRegistry extends Object
Thread-safe registry mapping owner.name+descriptor keys to native-method handlers.
-
-
Constructor Summary
Constructors Constructor Description NativeRegistry()Creates an empty registry.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConcreteValueexecute(MethodEntry method, ObjectInstance receiver, ConcreteValue[] args, NativeContext context)Runs the registered handler for the given method.ConcreteValueexecute(String owner, String name, String descriptor, ObjectInstance receiver, ConcreteValue[] args, NativeContext context)Runs the registered handler for the identified method.NativeMethodHandlergetHandler(MethodEntry method)Looks up the handler for the given method.NativeMethodHandlergetHandler(String owner, String name, String descriptor)Looks up the handler for the identified method.booleanhasHandler(MethodEntry method)Checks whether a handler is registered for the given method.booleanhasHandler(String owner, String name, String descriptor)Checks whether a handler is registered for the identified method.static StringmethodKey(MethodEntry method)Builds the registry key for the given method.static StringmethodKey(String owner, String name, String descriptor)Builds the registry key for the identified method.voidregister(String key, NativeMethodHandler handler)Registers a handler under a precomputed method key.voidregister(String owner, String name, String descriptor, NativeMethodHandler handler)Registers a handler for the identified method.voidregisterDefaults()Registers all built-in handler families covering the core JDK surface.voidregisterProvider(NativeHandlerProvider provider)Lets the given provider register its handlers with this registry.
-
-
-
Method Detail
-
register
public void register(String owner, String name, String descriptor, NativeMethodHandler handler)
Registers a handler for the identified method.- Parameters:
owner- internal name of the declaring classname- the method namedescriptor- the method descriptorhandler- the handler to invoke for the method
-
register
public void register(String key, NativeMethodHandler handler)
Registers a handler under a precomputed method key.- Parameters:
key- a key produced by methodKeyhandler- the handler to invoke for the method
-
hasHandler
public boolean hasHandler(String owner, String name, String descriptor)
Checks whether a handler is registered for the identified method.- Parameters:
owner- internal name of the declaring classname- the method namedescriptor- the method descriptor- Returns:
- true if a handler is registered
-
hasHandler
public boolean hasHandler(MethodEntry method)
Checks whether a handler is registered for the given method.- Parameters:
method- the method to look up- Returns:
- true if a handler is registered
-
getHandler
public NativeMethodHandler getHandler(String owner, String name, String descriptor)
Looks up the handler for the identified method.- Parameters:
owner- internal name of the declaring classname- the method namedescriptor- the method descriptor- Returns:
- the registered handler
- Throws:
IllegalArgumentException- if no handler is registered
-
getHandler
public NativeMethodHandler getHandler(MethodEntry method)
Looks up the handler for the given method.- Parameters:
method- the method to look up- Returns:
- the registered handler
- Throws:
IllegalArgumentException- if no handler is registered
-
execute
public ConcreteValue execute(MethodEntry method, ObjectInstance receiver, ConcreteValue[] args, NativeContext context) throws NativeException
Runs the registered handler for the given method.- Parameters:
method- the method to executereceiver- the receiver instance, or null for static methodsargs- the argument valuescontext- the native execution environment- Returns:
- the handler's result, or null for void
- Throws:
NativeException- if the handler raises a guest exceptionIllegalArgumentException- if no handler is registered
-
execute
public ConcreteValue execute(String owner, String name, String descriptor, ObjectInstance receiver, ConcreteValue[] args, NativeContext context) throws NativeException
Runs the registered handler for the identified method.- Parameters:
owner- internal name of the declaring classname- the method namedescriptor- the method descriptorreceiver- the receiver instance, or null for static methodsargs- the argument valuescontext- the native execution environment- Returns:
- the handler's result, or null for void
- Throws:
NativeException- if the handler raises a guest exceptionIllegalArgumentException- if no handler is registered
-
methodKey
public static String methodKey(String owner, String name, String descriptor)
Builds the registry key for the identified method.- Parameters:
owner- internal name of the declaring classname- the method namedescriptor- the method descriptor- Returns:
- the composite key
-
methodKey
public static String methodKey(MethodEntry method)
Builds the registry key for the given method.- Parameters:
method- the method to key- Returns:
- the composite key
-
registerProvider
public void registerProvider(NativeHandlerProvider provider)
Lets the given provider register its handlers with this registry.- Parameters:
provider- the handler contributor
-
registerDefaults
public void registerDefaults()
Registers all built-in handler families covering the core JDK surface.
-
-