|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.object.ObjectScraper
Objects can be scraped from or to a pojo/dao using name/value string pairs contained in a Properties objectas required for loading property files and HTML forms into the Java name space.
// Normally loaded from a web post or similar user imput request
class TestObject { integer anInteger; InnerObject innerObject; }
TestObject testObject;
properties.set( "anInteger", "19582003");
properties.set( "innerObject.anotherString", "1of2");
Messages problems = ObjectScraper.fromProperties( testObject, properties, null);
assertTrue( problems.none());
assertTrue( testObject.anInteger == 19582003);
// and the reverse is loading a name/value pair map with values from a pojo or DAO
properties = new Properties();
problems = ObjectScraper.toProperties( properties, null, testObject, null);
assertTrue( properties.get( "anInteger").equals( "19582003");
assertTrue( properties.get( "innerObject.anotherString").equals( "1of2");
// or extract a subset of the object by specifying inclusions
problems = ObjectScraper.toProperties( properties, "anInteger,innerObject.anotherString", testObject, null);
When scraping name/value pairs into an Object, a Translator object can be
provided to special translations of required fields or types. The same
facility is available for getting name/value pairs from an object by
subclassing Formatter.
Formatter,
Translator| Method Summary | |
static Messages |
fromProperties(DAO dao,
Properties properties,
Translator translator)
Scrape string data in Properties format into the a DAO using an explicit translator. |
static Messages |
fromProperties(Object pojo,
Properties properties,
Translator translator)
Scrape string data in Properties format into the a POJO. |
static Messages |
toProperties(Properties properties,
String inclusions,
DAO dao,
Formatter formatter)
Convert a Java Object to a name/value pair set of string properties. |
static Messages |
toProperties(Properties properties,
String inclusions,
Object pojo,
Formatter formatter)
Convert a Java Object to a name/value pair set of string properties. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static Messages fromProperties(DAO dao,
Properties properties,
Translator translator)
dao - object to hold data scraped from propertiesproperties - name/value pairs containing data to be transferred to the pojo.translator - to use for object translation for text to internal format.
public static Messages fromProperties(Object pojo,
Properties properties,
Translator translator)
pojo - object to hold data scraped from propertiesproperties - name/value pairs containing data to be transferred to the pojo.translator - to translate 'difficult' properties to they DAO form
public static Messages toProperties(Properties properties,
String inclusions,
Object pojo,
Formatter formatter)
properties - pre-existing properties to add.inclusions - CSV list of properties to include - or null for all.pojo - Object to extract properties from.formatter - for unusual formatting requirements (null for standard formatting)
Formatter
public static Messages toProperties(Properties properties,
String inclusions,
DAO dao,
Formatter formatter)
properties - pre-existing properties to add.inclusions - CSV list of properties to include - or null for all.dao - Object to extract properties from.formatter - for unusual formatting requirements (null for standard formatting)
Formatter
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||