List of usage examples for org.apache.commons.beanutils LazyDynaBean LazyDynaBean
public LazyDynaBean(DynaClass dynaClass)
DynaBean
associated with the specified DynaClass
instance - if its not a MutableDynaClass
then a new LazyDynaClass
is created and the properties copied. From source file:ddf.catalog.data.dynamic.impl.DynamicMetacardImplTest.java
@Before public void setUp() throws Exception { properties = new DynaProperty[] { new DynaProperty(STRING, String.class), new DynaProperty(BOOLEAN, Boolean.class), new DynaProperty(DATE, Date.class), new DynaProperty(SHORT, Short.class), new DynaProperty(INTEGER, Integer.class), new DynaProperty(LONG, Long.class), new DynaProperty(FLOAT, Float.class), new DynaProperty(DOUBLE, Double.class), new DynaProperty(BINARY, Byte[].class, Byte.class), new DynaProperty(XML, String.class), new DynaProperty(OBJECT, Object.class), new DynaProperty(STRING_LIST, List.class, String.class) }; baseClass = new LazyDynaClass("test", properties); baseBean = new LazyDynaBean(baseClass); metacard = new DynamicMetacardImpl(baseBean); }
From source file:ddf.catalog.data.dynamic.impl.MetacardFactoryImpl.java
/** * Creates a new metacard instance corresponding the the name provided. Any registered metacard type * can be generated. Returns null if the requested metacard type has not been registered. * @param name the name of the type of metacard to create * @return an instance of the specified type of metacard, or null if the specified type has not been registered *///from w ww.j a v a2 s .co m @Override public DynamicMetacard newInstance(String name) { //throws InstantiationException, IllegalAccessException { LOGGER.debug("Creating a new metacard of type {}", name); DynamicMetacard dynamicMetacard = null; LazyDynaBean lazyDynaBean = null; LazyDynaClass dynaClass = typeClasses.get(name); if (dynaClass != null) { lazyDynaBean = new LazyDynaBean(dynaClass); dynamicMetacard = new DynamicMetacardImpl(lazyDynaBean); } return dynamicMetacard; }
From source file:nl.ucan.navigate.NestedPath.java
private static DynaBean getDynaBean(Object instance) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { WrapDynaClass dynaClass = WrapDynaClass.createDynaClass(instance.getClass()); LazyDynaBean lazyBean = new LazyDynaBean(dynaClass); PropertyUtils.copyProperties(lazyBean, instance); return lazyBean; }
From source file:org.apache.commons.validator.example.ValidateExample.java
/** * This is the main method that will be called to initialize the Validator, create some sample beans, and * run the Validator against them./*from ww w . ja va2 s . com*/ */ public static void main(String[] args) throws ValidatorException, IOException, SAXException { InputStream in = null; ValidatorResources resources = null; try { // Create a new instance of a ValidatorResource, then get a stream // handle on the XML file with the actions in it, and initialize the // resources from it. This would normally be done by a servlet // run during JSP initialization or some other application-startup // routine. in = ValidateExample.class.getResourceAsStream("validator-example.xml"); resources = new ValidatorResources(in); } finally { // Make sure we close the input stream. if (in != null) { in.close(); } } // Create a test bean to validate against. //ValidateBean bean = new ValidateBean(); LazyDynaClass dynaClass = new LazyDynaClass(); dynaClass.add("lastName", String.class); dynaClass.add("firstName", String.class); dynaClass.add("street1", String.class); dynaClass.add("city", String.class); dynaClass.add("state", String.class); dynaClass.add("postalCode", String.class); dynaClass.add("age", String.class); LazyDynaBean dynaBean = new LazyDynaBean(dynaClass); // Create a validator with the ValidateBean actions for the bean // we're interested in. Validator validator = new Validator(resources, "ValidateBean"); // Tell the validator which bean to validate against. validator.setParameter(Validator.BEAN_PARAM, dynaBean); ValidatorResults results = null; // Run the validation actions against the bean. Since all of the properties // are null, we expect them all to error out except for street2, which has // no validations (it's an optional property) results = validator.validate(); printResults(dynaBean, results, resources); // Now set all the required properties, but make the age a non-integer. // You'll notice that age will pass the required test, but fail the int // test. dynaBean.set("lastName", "Tester"); dynaBean.set("firstName", "John"); dynaBean.set("street1", "1 Test Street"); dynaBean.set("city", "Testville"); dynaBean.set("state", "TE"); dynaBean.set("postalCode", "12345"); dynaBean.set("age", "Too Old"); results = validator.validate(); printResults(dynaBean, results, resources); // Now only report failed fields validator.setOnlyReturnErrors(true); results = validator.validate(); printResults(dynaBean, results, resources); // Now everything should pass. validator.setOnlyReturnErrors(false); dynaBean.set("age", "123"); results = validator.validate(); printResults(dynaBean, results, resources); }