Example usage for org.apache.commons.beanutils DynaProperty DynaProperty

List of usage examples for org.apache.commons.beanutils DynaProperty DynaProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils DynaProperty DynaProperty.

Prototype

public DynaProperty(String name, Class type) 

Source Link

Document

Construct a property of the specified data type.

Usage

From source file:DynaBeansExampleV1.java

private static Object createMovieBean() throws Exception {

    // first create the properties
    DynaProperty properties[] = new DynaProperty[] { new DynaProperty("title", String.class),
            new DynaProperty("dateOfRelease", Date.class), new DynaProperty("keywords", String[].class),
            new DynaProperty("genre", Map.class), new DynaProperty("actors", List.class),
            new DynaProperty("director", DynaBean.class) };

    // next using the properties define the class
    DynaClass movieClass = new BasicDynaClass("movie", null, properties);

    // now, with the class, create a new instance
    DynaBean movieBean = movieClass.newInstance();

    // set its properties
    movieBean.set("title", "The Italian Job");
    movieBean.set("dateOfRelease", new GregorianCalendar(1969, 0, 1).getTime());
    movieBean.set("keywords", new String[] { "Italy", "Bank Robbery" });

    Map genre = new HashMap();
    genre.put("THR", "Thriller");

    movieBean.set("genre", genre);
    movieBean.set("genre", "ACT", "Action");

    DynaBean director = createPersonBean();
    director.set("name", "Peter Collinson");
    director.set("gender", new Integer(1));

    movieBean.set("director", director);

    return movieBean;
}

From source file:ddf.catalog.data.dynamic.impl.MetacardAttributeDescriptorTest.java

@Test
public void testGetAttributeFomat() {
    AttributeType.AttributeFormat format = null;

    DynaProperty dynaProperty = new DynaProperty("test", String.class);
    MetacardAttributeDescriptor descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.STRING.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Boolean.class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.BOOLEAN.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Date.class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.DATE.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Short.class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.SHORT.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Integer.class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.INTEGER.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Long.class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.LONG.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Float.class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.FLOAT.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Double.class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.DOUBLE.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Byte[].class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.BINARY.compareTo(format) == 0);

    dynaProperty = new DynaProperty("test", Object.class);
    descriptor = new MetacardAttributeDescriptor(dynaProperty);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.OBJECT.compareTo(format) == 0);

    // Now test using MetacardPropertyDescriptors to initialize
    MetacardPropertyDescriptorImpl propertyDescriptor = new MetacardPropertyDescriptorImpl("test",
            String.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.STRING.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Boolean.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.BOOLEAN.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Date.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.DATE.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Short.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.SHORT.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Integer.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.INTEGER.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Long.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.LONG.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Float.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.FLOAT.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Double.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.DOUBLE.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Byte[].class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.BINARY.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", String.class);
    propertyDescriptor.setFormat(AttributeType.AttributeFormat.XML);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.XML.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", String.class);
    propertyDescriptor.setFormat(AttributeType.AttributeFormat.GEOMETRY);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.GEOMETRY.compareTo(format) == 0);

    propertyDescriptor = new MetacardPropertyDescriptorImpl("test", Object.class);
    descriptor = new MetacardAttributeDescriptor(propertyDescriptor);
    format = descriptor.getAttributeFormat();
    assertTrue(AttributeType.AttributeFormat.OBJECT.compareTo(format) == 0);
}

From source file:net.sf.excelutils.webwork.OgnlDynaClass.java

/**
 * getDynaProperty//from  w  ww  .  j  a  v  a 2 s.  co  m
 * 
 * @param name
 * @return DynaProperty
 */
public DynaProperty getDynaProperty(String name) {
    DynaProperty property = super.getDynaProperty(name);
    if (null == property) {
        Object value = valueStack.findValue(name);
        if (null != value) {
            property = new DynaProperty(name, value.getClass());
        }
    }
    return property;
}

From source file:com.github.haixing_hu.ilibrary.model.DocumentClass.java

private DynaProperty[] constructProperties(final DocumentTemplate template) {
    final List<DynaProperty> properties = new ArrayList<DynaProperty>();
    properties.add(new DynaProperty("id", Long.class));

    //  adds all the fields as descriptors.
    for (final FieldGroupTemplate group : template.getFieldGroups()) {
        for (final FieldTemplate field : group.getFields()) {
            final DynaProperty property = new DynaProperty(field.getName(), field.getType().toClass());
            properties.add(property);//from w w w.  jav a  2 s  . co  m
        }
    }
    return properties.toArray(new DynaProperty[0]);
}

From source file:com.troyhisted.inputfield.util.DynaList.java

/**
 * Constructor./* w w  w.j a  v  a2s  .  c  o m*/
 *
 * @param listType
 *            the type of object the list will hold
 */
public DynaList(Class<? extends T> listType) {
    this.listDynaProperty = new DynaProperty(null, listType);
}

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:com.manning.junitbook.ch14.servlets.TestAdminServlet.java

/**
 * Creates a java.util.Collection of DynaBean objects to show in the JSP.
 * //from w ww.j ava  2 s .co  m
 * @return
 * @throws Exception
 */
private Collection<DynaBean> createCommandResult() throws Exception {
    List<DynaBean> results = new ArrayList<DynaBean>();

    DynaProperty[] props = new DynaProperty[] { new DynaProperty("id", String.class),
            new DynaProperty("responsetime", Long.class) };
    BasicDynaClass dynaClass = new BasicDynaClass("requesttime", null, props);

    DynaBean request1 = dynaClass.newInstance();
    request1.set("id", "12345");
    request1.set("responsetime", new Long(500));
    results.add(request1);

    DynaBean request2 = dynaClass.newInstance();
    request1.set("id", "56789");
    request1.set("responsetime", new Long(430));
    results.add(request2);

    return results;
}

From source file:com.nfwork.dbfound.json.JSONDynaClass.java

private void process() {
    this.jsonBeanClass = this.type;

    if (!JSONDynaBean.class.isAssignableFrom(this.jsonBeanClass)) {
        throw new IllegalArgumentException("Unnasignable dynaClass " + jsonBeanClass);
    }// w ww.j  a  v  a  2s . com

    try {
        Iterator entries = attributes.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            String pname = (String) entry.getKey();
            Object pclass = entry.getValue();
            DynaProperty dynaProperty = null;
            if (pclass instanceof String) {
                dynaProperty = new DynaProperty(pname, Class.forName((String) pclass));
            } else if (pclass instanceof Class) {
                dynaProperty = new DynaProperty(pname, (Class) pclass);
            } else {
                throw new IllegalArgumentException("Type must be String or Class");
            }
            properties.put(dynaProperty.getName(), dynaProperty);
        }
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    }
}

From source file:junit.mock.TestDynaPropertiesMO.java

private DynaBean createDynaBean() throws Exception {
    DynaProperty[] props = new DynaProperty[] { new DynaProperty("id", String.class),
            new DynaProperty("responsetime", Long.class) };
    BasicDynaClass dynaClass = new BasicDynaClass("requesttime", null, props);

    DynaBean bean = dynaClass.newInstance();
    bean.set("id", "12345");
    bean.set("responsetime", new Long(500));

    return bean;/*  www. j  a va 2 s .com*/
}

From source file:com.troyhisted.inputfield.field.DynaField.java

/**
 * Creates an input field for the specific type of value.
 *
 * <p>/*from w  w w . j  a v  a  2s .  c  o m*/
 * The value type is necessary because generic information is lost during compilation, so any auto-mapping
 * classes need some way to discern the type of the field value. If the value type is not specified, it will
 * default to Object.
 *
 * @param valueType
 *            the type of the value
 */
public DynaField(Class<? extends T> valueType) {
    this.valueDynaProperty = new DynaProperty("value", valueType);
}