public final class KlassUtility extends Object
Modifier and Type | Method and Description |
---|---|
static Class<?> |
forName(String s)
Returns a class based on its name just like the method
Class.forName(String) . |
static Class<?> |
forNameEx(String s)
Returns a class based on its name just like the method
Class.forName(String) . |
static Object |
getField(Object object,
String fieldName)
Get the value of a field of an object and return it.
|
static void |
setField(Object object,
String fieldName,
Object valueObject) |
public static void setField(Object object, String fieldName, Object valueObject) throws BasicRuntimeException
object
- fieldName
- valueObject
- BasicRuntimeException
public static Object getField(Object object, String fieldName) throws ExecutionException
Current implementation uses the field. TODO implement access as a last resort calling the method INVENT_NAME passing the field name as argument if the class of the object implements the interface INVENT_INTERFACE_NAME. The names should include the word BASIC, or better SCRIPTBASIC. Perhaps ScriptBasicMagicBean or something.
object
- fieldName
- ExecutionException
public static Class<?> forName(String s) throws ClassNotFoundException
Class.forName(String)
. The search for the class is
extended. For example if this method is called
Class<?> klass = KlassUtility.forName("a.b.c.d");the method tries to locate he class
a.b.c.d
. If it can not locate
that it will try to locate a.b.c$d
because it may happen that
a.b.c
is not a package but rather a class itself and the class to
be located is an inner class. This continues until the class is located
or until the last dot (starting from the end of the class name string) is
replaced by the character '$
'. In other words the method will try
to locate the classes a.b$c$d
and a$b$c$d
until it finds
one.
If this algorithm can not load any class then the exception caught the first time is thrown.
s
- the name of the class to be loadedClassNotFoundException
- the exception thrown by the class loader the first time if
the algorithm can not find any class to load.public static Class<?> forNameEx(String s) throws GenericSyntaxException
Class.forName(String)
. If the name of the class is
byte short char double float long int booleanthen the method will return the primitive class named. Otherwise it calls
forName(String)
to load the class.s
- GenericSyntaxException
Copyright © 2013 Verhas and Verhas Software Craftsmen. All Rights Reserved.