Package org.apache.felix.gogo.runtime
Class Reflective
- java.lang.Object
-
- org.apache.felix.gogo.runtime.Reflective
-
public final class Reflective extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Reflective()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Object
coerce(CommandSession session, java.lang.Class<?> type, java.lang.Object arg, int[] convert)
converts given argument to specified type and increments convert[0] if any conversion was needed.private static int
coerce(CommandSession session, java.lang.Object target, java.lang.reflect.Method m, java.lang.Class<?>[] types, java.lang.Object[] out, java.util.List<java.lang.Object> in)
Complex routein to convert the arguments given from the command line to the arguments of the method call.private static int
docoerce(CommandSession session, java.lang.Object target, java.lang.reflect.Method m, java.lang.Class<?>[] types, java.lang.Object[] out, java.util.List<java.lang.Object> in)
static java.lang.Object
invoke(CommandSession session, java.lang.Object target, java.lang.String name, java.util.List<java.lang.Object> args)
invokes the named method on the given target using the supplied args, which are converted if necessary.private static java.lang.Class<?>
primitiveToObject(java.lang.Class<?> type)
private static java.lang.String
toString(java.lang.Object arg)
private static java.util.List<java.lang.Object>
transformParameters(java.lang.reflect.Method method, java.util.List<java.lang.Object> in)
transform name/value parameters into ordered argument list.private static void
writeValue(java.lang.StringBuilder sb, java.lang.Object o)
-
-
-
Field Detail
-
NO_MATCH
public static final java.lang.Object NO_MATCH
-
MAIN
public static final java.lang.String MAIN
- See Also:
- Constant Field Values
-
KEYWORDS
public static final java.util.Set<java.lang.String> KEYWORDS
-
-
Method Detail
-
invoke
public static java.lang.Object invoke(CommandSession session, java.lang.Object target, java.lang.String name, java.util.List<java.lang.Object> args) throws java.lang.Exception
invokes the named method on the given target using the supplied args, which are converted if necessary.- Parameters:
session
- the sessiontarget
- the targetname
- the nameargs
- the args- Returns:
- the result of the invoked method
- Throws:
java.lang.Exception
- on exception
-
transformParameters
private static java.util.List<java.lang.Object> transformParameters(java.lang.reflect.Method method, java.util.List<java.lang.Object> in)
transform name/value parameters into ordered argument list. params: --param2, value2, --flag1, arg3 args: true, value2, arg3- Returns:
- new ordered list of args.
-
coerce
private static int coerce(CommandSession session, java.lang.Object target, java.lang.reflect.Method m, java.lang.Class<?>[] types, java.lang.Object[] out, java.util.List<java.lang.Object> in)
Complex routein to convert the arguments given from the command line to the arguments of the method call. First, an attempt is made to convert each argument. If this fails, a check is made to see if varargs can be applied. This happens when the last method argument is an array.- Returns:
- -1 if arguments can't be coerced; 0 if no coercion was necessary; > 0 if coercion was needed.
-
docoerce
private static int docoerce(CommandSession session, java.lang.Object target, java.lang.reflect.Method m, java.lang.Class<?>[] types, java.lang.Object[] out, java.util.List<java.lang.Object> in)
-
coerce
public static java.lang.Object coerce(CommandSession session, java.lang.Class<?> type, java.lang.Object arg, int[] convert)
converts given argument to specified type and increments convert[0] if any conversion was needed.- Parameters:
session
- the sessiontype
- the typearg
- the argconvert
- convert[0] is incremented according to the conversion needed, to allow the "best" conversion to be determined.- Returns:
- converted arg or NO_MATCH if no conversion possible.
-
toString
private static java.lang.String toString(java.lang.Object arg)
-
writeValue
private static void writeValue(java.lang.StringBuilder sb, java.lang.Object o)
-
primitiveToObject
private static java.lang.Class<?> primitiveToObject(java.lang.Class<?> type)
-
-