Package com.storedobject.common
Class SimpleMethodInvoker
java.lang.Object
com.storedobject.common.SimpleMethodInvoker
- All Implemented Interfaces:
MethodInvoker
A class that implements the MethodInvoker functional interface to facilitate the invocation
of specific methods from a given class.
The class provides mechanisms to resolve and invoke methods based on naming conventions
such as "get", "is", or direct method names. If the method cannot be found or any errors occur,
the invocation defaults to a null operation.
- Author:
- Syam
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleMethodInvoker(Class<?> objectClass, String name) Constructs a SimpleMethodInvoker by attempting to resolve a method in the specified class using a series of naming conventions.SimpleMethodInvoker(Method method) Constructs a SimpleMethodInvoker instance by associating it with the specifiedMethod. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the name of an attribute associated with this method.Class<?> Determines the return type of the `invoke` method defined in the implementing class.getTail()Retrieves the tail method associated with the implementation.Invokes a method on the provided object.
-
Constructor Details
-
SimpleMethodInvoker
-
SimpleMethodInvoker
Constructs a SimpleMethodInvoker by attempting to resolve a method in the specified class using a series of naming conventions. It first tries to find a method prefixed with "get", then "is", and finally it attempts to locate a method with the exact provided name. If a matching method is found, it is used as the target for invocation; otherwise, the method field is set to null.- Parameters:
objectClass- the class from which the method will be resolved. It must not be null.name- the base name of the method to resolve. This is expected to be the method name without the "get" or "is" prefix, if applicable. Must not be null or empty.
-
-
Method Details
-
getAttributeName
Description copied from interface:MethodInvokerRetrieves the name of an attribute associated with this method.- Specified by:
getAttributeNamein interfaceMethodInvoker- Returns:
- a string representing the attribute name, or null if no attribute name is defined.
-
getTail
Description copied from interface:MethodInvokerRetrieves the tail method associated with the implementation. The tail method typically represents an additional or final processing method in the context of the functional interface's behavior.- Specified by:
getTailin interfaceMethodInvoker- Returns:
- the
Methodinstance representing the tail method, ornullif no such method is defined.
-
getReturnType
Description copied from interface:MethodInvokerDetermines the return type of the `invoke` method defined in the implementing class. If the `invoke` method cannot be located or an exception occurs, defaults to returningString.class.- Specified by:
getReturnTypein interfaceMethodInvoker- Returns:
- the
Classobject representing the return type of the `invoke` method orString.classif the method is not found or an error occurs.
-
invoke
Description copied from interface:MethodInvokerInvokes a method on the provided object.- Specified by:
invokein interfaceMethodInvoker- Parameters:
object- the object on which the method is to be invoked- Returns:
- the result of the method invocation, or null if the invocation fails
-