Class Invocable
- java.lang.Object
-
- org.glassfish.jersey.server.model.Invocable
-
- All Implemented Interfaces:
Parameterized,ResourceModelComponent
public final class Invocable extends java.lang.Object implements Parameterized, ResourceModelComponent
A common interface for invocable resource components. This includes resource methods, sub-resource methods and sub-resource locators bound to a concrete handler class and a Java method (either directly or indirectly) declared & implemented by the handler class. Invocable component information is used at runtime by a Java method dispatcher when processing requests.Class defines two kinds of
java methods:definition methodandhandling method. Definition method is the javaMethodthat is defined by the user to be executed. This can be javaMethodof the class but also method of the interface. If it is the method of the interface (method handler class is theclassbut method itself is from theinterface) then the definition method is the method from the inheritedclass. In other words, the handling method is the concrete method but definition method can be its parent abstract definition. However, in most cases these methods are the same.- See Also:
ResourceMethod,ResourceMethodDispatcher
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.reflect.MethodAPPLY_INFLECTOR_METHODMethod instance representing theInflector.apply(Object)method.private java.lang.reflect.MethoddefinitionMethodprivate MethodHandlerhandlerprivate java.lang.reflect.MethodhandlingMethodprivate java.util.List<Parameter>parametersprivate java.lang.Class<?>rawResponseTypeprivate java.lang.Class<?>rawRoutingResponseTypeprivate java.lang.reflect.TyperesponseTypeprivate java.lang.reflect.TyperoutingResponseType
-
Constructor Summary
Constructors Modifier Constructor Description privateInvocable(MethodHandler handler, java.lang.reflect.Method definitionMethod, java.lang.reflect.Method handlingMethod, boolean encodedParameters, java.lang.reflect.Type routingResponseType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(ResourceModelVisitor visitor)A component should call the visitor back with an appropriate visitor interface method to give it a chance to process.static Invocablecreate(java.lang.Class<? extends Inflector> inflectorClass)Create a new resource method invocable model backed by an inflector class.static <T> Invocablecreate(Inflector<javax.ws.rs.core.Request,T> inflector)Create a new resource method invocable model backed by an inflector instance.static Invocablecreate(MethodHandler handler, java.lang.reflect.Method handlingMethod)Create a new resource method invocable model.static Invocablecreate(MethodHandler handler, java.lang.reflect.Method definitionMethod, boolean encodedParameters)Create a new resource method invocable model.static Invocablecreate(MethodHandler handler, java.lang.reflect.Method definitionMethod, java.lang.reflect.Method handlingMethod, boolean encodedParameters)Create a new resource method invocable model.static Invocablecreate(MethodHandler handler, java.lang.reflect.Method definitionMethod, java.lang.reflect.Method handlingMethod, boolean encodedParameters, java.lang.reflect.Type routingResponseType)Create a new resource method invocable model.java.util.List<? extends ResourceModelComponent>getComponents()Should return all existing resource model sub-components.java.lang.reflect.MethodgetDefinitionMethod()Getter for the Java method that should be executed.MethodHandlergetHandler()Get the model of the resource method handler that will be used to invoke thehandling resource methodon.java.lang.reflect.MethodgetHandlingMethod()Getter for the Java methodjava.util.List<Parameter>getParameters()Provides access to all parameters associated with given Parameterized instance.java.lang.Class<?>getRawResponseType()Get the resource method raw response type.java.lang.Class<?>getRawRoutingResponseType()Get the responseClassof thehandlingMethodthat will be used during the routing for the purpose of selection of the resource method.java.lang.reflect.TypegetResponseType()Get the resource method generic response type information.java.lang.reflect.TypegetRoutingResponseType()Get the response type of thehandlingMethodthat will be used during the routing for the purpose of selection of the resource method.private static java.lang.reflect.MethodinitApplyMethod()booleanisInflector()Check if the invocable represents aninflector processing method.booleanrequiresEntity()Provides information on presence of an entity parameter.java.lang.StringtoString()
-
-
-
Field Detail
-
APPLY_INFLECTOR_METHOD
static final java.lang.reflect.Method APPLY_INFLECTOR_METHOD
Method instance representing theInflector.apply(Object)method.
-
handler
private final MethodHandler handler
-
definitionMethod
private final java.lang.reflect.Method definitionMethod
-
handlingMethod
private final java.lang.reflect.Method handlingMethod
-
parameters
private final java.util.List<Parameter> parameters
-
rawResponseType
private final java.lang.Class<?> rawResponseType
-
responseType
private final java.lang.reflect.Type responseType
-
routingResponseType
private final java.lang.reflect.Type routingResponseType
-
rawRoutingResponseType
private final java.lang.Class<?> rawRoutingResponseType
-
-
Constructor Detail
-
Invocable
private Invocable(MethodHandler handler, java.lang.reflect.Method definitionMethod, java.lang.reflect.Method handlingMethod, boolean encodedParameters, java.lang.reflect.Type routingResponseType)
-
-
Method Detail
-
initApplyMethod
private static java.lang.reflect.Method initApplyMethod()
-
create
public static <T> Invocable create(Inflector<javax.ws.rs.core.Request,T> inflector)
Create a new resource method invocable model backed by an inflector instance.- Parameters:
inflector- inflector processing the request method.- Returns:
- Invocable.
-
create
public static Invocable create(java.lang.Class<? extends Inflector> inflectorClass)
Create a new resource method invocable model backed by an inflector class.- Parameters:
inflectorClass- inflector syb-type processing the request method.- Returns:
- Invocable.
-
create
public static Invocable create(MethodHandler handler, java.lang.reflect.Method handlingMethod)
Create a new resource method invocable model. Parameter values will be automatically decoded.- Parameters:
handler- resource method handler.handlingMethod- handling Java method.- Returns:
- Invocable.
-
create
public static Invocable create(MethodHandler handler, java.lang.reflect.Method definitionMethod, boolean encodedParameters)
Create a new resource method invocable model.- Parameters:
handler- resource method handler.definitionMethod- method that is defined to be executed on thehandler.encodedParameters-trueif the automatic parameter decoding should be disabled, false otherwise.- Returns:
- Invocable
-
create
public static Invocable create(MethodHandler handler, java.lang.reflect.Method definitionMethod, java.lang.reflect.Method handlingMethod, boolean encodedParameters)
Create a new resource method invocable model.- Parameters:
handler- resource method handler.definitionMethod- method that is defined to be executed on thehandler.handlingMethod- specific and concrete method to be actually executed as a resource method. Ifnullthen thedefinitionMethodwill be used.encodedParameters-trueif the automatic parameter decoding should be disabled, false otherwise.- Returns:
- Invocable.
-
create
public static Invocable create(MethodHandler handler, java.lang.reflect.Method definitionMethod, java.lang.reflect.Method handlingMethod, boolean encodedParameters, java.lang.reflect.Type routingResponseType)
Create a new resource method invocable model.- Parameters:
handler- resource method handler.definitionMethod- method that is defined to be executed on thehandler.handlingMethod- specific and concrete method to be actually executed as a resource method. Ifnullthen thedefinitionMethodwill be used.encodedParameters-trueif the automatic parameter decoding should be disabled, false otherwise.routingResponseType- response type that will be used during the routing for purpose of selection of the resource method to be executed. If this parameter is non-nullthen it will override the return type of thethe Java handling method) for purposes of resource method selection. This might be useful in cases when resource method returns a typeAbut thanks to registered providers (eg.WriterInterceptor) it will be always converted to typeB. Then the method selecting algorithm would check presence ofMessageBodyWriterfor typeA(which will never be actually needed) and might result in choosing undesired method. If the parameter isnullthen the default response type will be used.- Returns:
- Invocable.
-
getHandler
public MethodHandler getHandler()
Get the model of the resource method handler that will be used to invoke thehandling resource methodon.- Returns:
- resource method handler model.
-
getHandlingMethod
public java.lang.reflect.Method getHandlingMethod()
Getter for the Java method- Returns:
- corresponding Java method
-
getDefinitionMethod
public java.lang.reflect.Method getDefinitionMethod()
Getter for the Java method that should be executed.- Returns:
- corresponding Java method.
-
getResponseType
public java.lang.reflect.Type getResponseType()
Get the resource method generic response type information.The returned value provides the Type information that contains additional generic declaration information for generic Java class types.
- Returns:
- resource method generic response type information.
-
getRawResponseType
public java.lang.Class<?> getRawResponseType()
Get the resource method raw response type.The returned value provides information about the raw Java class.
- Returns:
- resource method raw response type information.
-
isInflector
public boolean isInflector()
Check if the invocable represents aninflector processing method.- Returns:
true, if this invocable represents an inflector invocation,falseotherwise.
-
requiresEntity
public boolean requiresEntity()
Description copied from interface:ParameterizedProvides information on presence of an entity parameter.- Specified by:
requiresEntityin interfaceParameterized- Returns:
- true if entity parameter is present, false otherwise
-
getParameters
public java.util.List<Parameter> getParameters()
Description copied from interface:ParameterizedProvides access to all parameters associated with given Parameterized instance.- Specified by:
getParametersin interfaceParameterized- Returns:
- list of actual parameters
-
accept
public void accept(ResourceModelVisitor visitor)
Description copied from interface:ResourceModelComponentA component should call the visitor back with an appropriate visitor interface method to give it a chance to process.- Specified by:
acceptin interfaceResourceModelComponent- Parameters:
visitor- resource model visitor.
-
getComponents
public java.util.List<? extends ResourceModelComponent> getComponents()
Description copied from interface:ResourceModelComponentShould return all existing resource model sub-components.- Specified by:
getComponentsin interfaceResourceModelComponent- Returns:
- list of all sub-components
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getRoutingResponseType
public java.lang.reflect.Type getRoutingResponseType()
Get the response type of thehandlingMethodthat will be used during the routing for the purpose of selection of the resource method. Returned value is in most cases equal to theresponse type. If returned value is different then it overrides the response type for purposes of resource method selection and will be used to look for availablemessage body writers.- Returns:
- Response type used for the routing.
-
getRawRoutingResponseType
public java.lang.Class<?> getRawRoutingResponseType()
Get the responseClassof thehandlingMethodthat will be used during the routing for the purpose of selection of the resource method. Returned value is in most cases equal to theresponse type. If returned value is different then it overrides the response type for purposes of resource method selection and will be used to look for availablemessage body writers.- Returns:
- Response type used for the routing.
-
-