| java.lang.Object com.versant.core.util.BeanUtils
BeanUtils | public class BeanUtils (Code) | | Static utility methods for working with java beans.
|
Inner Class :public static class CmdLineResult | |
Method Summary | |
public static void | fillFields(Object o, String prefix, Map props, Set fieldsToIgnore) Fill o by introspecting all of its public non-static, non-final fields
that are int, Integer, boolean, Boolean or String and looking for
properties named prefix + fieldname to populate them. | public static Set | getAllProperties(Class cls) Get all the valid properties for this class. | public static Object | getPropertyValue(Object bean, String property) Get the value of a property of bean. | public static boolean | isSupportedFieldType(Class t) | public static Class | loadClass(String name, boolean initialize, ClassLoader loader) Load the class with name using loaded. | public static Object | newInstance(String cname, ClassLoader loader, Class mustBe) Create a new instance of cname using loader. | public static void | parseProperties(String ps, Properties props) Add any properties from a semicolon delimited String ps to props. | public static void | parseProperties(String props, Object bean) Parse semicolon delimited properties from props and set them on bean. | public static void | printUsage(Object o, String[] requiredFields, String toolName, String toolDescription, boolean hasProps, PrintStream out) Print command line usage information by introspecting o to find all
of its public non-static, non-final fields that are int, Integer,
boolean, Boolean or String. | public static CmdLineResult | processCmdLine(String[] args, ClassLoader loader, Object o, String[] requiredFields, String toolName, String toolDescription, boolean hasProps) Process command line arguments. | public static void | setCommandLineArgs(Object bean, String[] args, String[] expected) Process a list of command line arguments in [-propertyname value]+
format setting each on the bean. | public static void | setProperties(Object bean, Map props) Find and set all properties or public fields on bean from key/value
pairs in props. | public static void | setProperty(Object bean, String prop, String value) Set a property on bean. | public static Class | toClass(String primitiveName) Convert a primitive name (int, byte etc.) to a class or null if the
name is not a primitive. |
fillFields | public static void fillFields(Object o, String prefix, Map props, Set fieldsToIgnore)(Code) | | Fill o by introspecting all of its public non-static, non-final fields
that are int, Integer, boolean, Boolean or String and looking for
properties named prefix + fieldname to populate them.
|
getAllProperties | public static Set getAllProperties(Class cls)(Code) | | Get all the valid properties for this class.
|
isSupportedFieldType | public static boolean isSupportedFieldType(Class t)(Code) | | |
loadClass | public static Class loadClass(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException(Code) | | Load the class with name using loaded. The name may be a primitive
(int, byte etc) or a single dimensional array (e.g. int[]).
|
newInstance | public static Object newInstance(String cname, ClassLoader loader, Class mustBe)(Code) | | Create a new instance of cname using loader. It must be an instance of
mustBe.
|
parseProperties | public static void parseProperties(String ps, Properties props)(Code) | | Add any properties from a semicolon delimited String ps to props.
|
parseProperties | public static void parseProperties(String props, Object bean)(Code) | | Parse semicolon delimited properties from props and set them on bean.
This can handle String, int and boolean properties.
exception: IllegalArgumentException - on errors |
printUsage | public static void printUsage(Object o, String[] requiredFields, String toolName, String toolDescription, boolean hasProps, PrintStream out)(Code) | | Print command line usage information by introspecting o to find all
of its public non-static, non-final fields that are int, Integer,
boolean, Boolean or String. For each field a public static final
String field named HELP_fieldname is used to provided a description
of the field if present. The values of the fields in o are assumed
to be the defaults.
If hasProps is true the information on how to specify key=value
properties is also printed.
|
processCmdLine | public static CmdLineResult processCmdLine(String[] args, ClassLoader loader, Object o, String[] requiredFields, String toolName, String toolDescription, boolean hasProps)(Code) | | Process command line arguments. Arguments starting with a dash are
expected to match the names of public fields in o (like
BeanUtils.fillFields ) with non-boolean fields requiring an argument.
If a boolean field does not have an argument then it is set to true.
If hasProps is true then there is an implicit -p arguement to
specify the resource name or filename of a properties file to load and
return. The default name is versant.properties. The argument is first
treated as a file and if this fails then as a resource. System
properties starting with "versant." or "javax.jdo.option." are added
after the properties are loaded. Finally command line arguments of the
form key=value are added i.e. they override any previous value.
Errors are printed to System.err followed by usage information and
an IllegalArgumentException is thrown.
If one of the args is /? or -help or --help then the usage is printed
and an IllegalArgumentException is thrown.
The fieldsFilled set contains the names of all fields that wereset from the command line. If hasProps is true then the properties fieldon the result holds all properties with overrides already appliedotherwise it is null. |
setCommandLineArgs | public static void setCommandLineArgs(Object bean, String[] args, String[] expected) throws IllegalArgumentException(Code) | | Process a list of command line arguments in [-propertyname value]+
format setting each on the bean.
Parameters: args - Command line arguments as passed to a main method Parameters: expected - Names of allowed properties exception: IllegalArgumentException - if args are invalid |
setProperties | public static void setProperties(Object bean, Map props) throws IllegalArgumentException(Code) | | Find and set all properties or public fields on bean from key/value
pairs in props. Only int, String and boolean properties and fields may
be set. This is a NOP if props or bean is null.
exception: IllegalArgumentException - if any are invalid |
toClass | public static Class toClass(String primitiveName)(Code) | | Convert a primitive name (int, byte etc.) to a class or null if the
name is not a primitive.
|
|
|