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) 

Source Link

Document

Construct a property that accepts any data type.

Usage

From source file:com.eas.client.reports.JSDynaClass.java

@Override
public DynaProperty getDynaProperty(String aName) {
    if (name != null) {
        if (properties.isEmpty()) {
            if (delegate.hasMember(aName)) {
                Object oMember = delegate.getMember(aName);
                if (!(oMember instanceof JSObject) || !((JSObject) oMember).isFunction()) {
                    return new DynaProperty(aName);
                }//from   w ww.ja v  a  2s  . com
                return null;
            }
        } else {
            return properties.get(aName);
        }
    }
    throw new IllegalArgumentException("No property name specified");
}

From source file:com.eas.client.reports.JSDynaClass.java

@Override
public DynaProperty[] getDynaProperties() {
    if (properties.isEmpty()) {
        delegate.keySet().forEach((String key) -> {
            Object oMember = delegate.getMember(key);
            if (!(oMember instanceof JSObject) || !((JSObject) oMember).isFunction()) {
                properties.put(key, new DynaProperty(key));
            }//  w  w w  .j  a v a 2 s .  c  o m
        });
    }
    return properties.values().toArray(new DynaProperty[] {});
}

From source file:org.apache.ddlutils.platform.ModelBasedResultSetIterator.java

/**
 * Initializes this iterator from the resultset metadata.
 * /*  ww w . ja v a  2s. c  o  m*/
 * @param model The database model
 */
private void initFromMetaData(Database model) throws SQLException {
    ResultSetMetaData metaData = _resultSet.getMetaData();
    String tableName = null;
    boolean singleKnownTable = true;

    for (int idx = 1; idx <= metaData.getColumnCount(); idx++) {
        String columnName = metaData.getColumnName(idx);
        String tableOfColumn = metaData.getTableName(idx);
        Table table = null;

        if ((tableOfColumn != null) && (tableOfColumn.length() > 0)) {
            // jConnect might return a table name enclosed in quotes
            if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"")
                    && (tableOfColumn.length() > 1)) {
                tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
            }
            // the JDBC driver gave us enough meta data info
            table = model.findTable(tableOfColumn, _caseSensitive);
        }
        if (table == null) {
            // not enough info in the meta data of the result set, lets try the
            // user-supplied query hints
            table = (Table) _preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
            tableOfColumn = (table == null ? null : table.getName());
        }
        if (tableName == null) {
            tableName = tableOfColumn;
        } else if (!tableName.equals(tableOfColumn)) {
            singleKnownTable = false;
        }

        String propName = columnName;

        if (table != null) {
            Column column = table.findColumn(columnName, _caseSensitive);

            if (column != null) {
                propName = column.getName();
            }
        }
        _columnsToProperties.put(columnName, propName);
    }
    if (singleKnownTable && (tableName != null)) {
        _dynaClass = model.getDynaClassFor(tableName);
    } else {
        DynaProperty[] props = new DynaProperty[_columnsToProperties.size()];
        int idx = 0;

        for (Iterator it = _columnsToProperties.values().iterator(); it.hasNext(); idx++) {
            props[idx] = new DynaProperty((String) it.next());
        }
        _dynaClass = new BasicDynaClass("result", BasicDynaBean.class, props);
    }
}

From source file:org.catechis.Transformer.java

/**
*<p>Create a Vector of dynamically created beans.
*<p>It only works for flat beans, with one layer of properties.
<p>BasicDynaClass is created like this:
BasicDynaClass(java.lang.String name, java.lang.Class dynaBeanClass, DynaProperty[] properties) 
getComponentType() // w  w w. ja  va  2 s.  c o  m
*/
public static Vector loadElements(List list, String object_name, Class class_name) {
    Vector vector = new Vector();
    //BasicDynaClass bd_class = new BasicDynaClass();
    int size = list.size();
    int i = 0;
    // first construct the class
    Element e = (Element) list.get(i);
    List children = e.getChildren();
    int kids = children.size();
    DynaProperty[] dps = new DynaProperty[kids];
    int j = 0;
    while (i < kids) {
        Element kid = (Element) children.get(i);
        String name = kid.getName();
        try {
            dps[j] = new DynaProperty(name);
        } catch (java.lang.ArrayIndexOutOfBoundsException aioob) {
            break;
        }
        j++;
    }
    BasicDynaClass bd_class = new BasicDynaClass(object_name, class_name, dps);
    // then create the instances and populate them
    while (i < size) {
        BasicDynaBean bd_bean = new BasicDynaBean(bd_class);
        Element ee = (Element) list.get(i);
        List childrens = ee.getChildren();
        int kiddies = childrens.size();
        int jj = 0;
        while (jj < kids) {
            Element kidd = (Element) childrens.get(jj);
            //Element child = kidds.getChild();
            String name = kidd.getName();
            String value = (String) kidd.getChildText(name);
            bd_bean.set(name, value);
            jj++;
        }
        vector.add(bd_bean);
        i++;
    }
    return vector;
}

From source file:org.seasar.struts.action.ActionFormWrapperClassTest.java

/**
 * @throws Exception/* ww w.  j  a v a  2  s  .  c o  m*/
 */
public void testGetDynaProperty() throws Exception {
    S2ActionMapping mapping = new S2ActionMapping();
    mapping.setName("hoge");
    ActionFormWrapperClass wrapperClass = new ActionFormWrapperClass(mapping);
    DynaProperty property = new DynaProperty("aaa");
    wrapperClass.addDynaProperty(property);
    assertSame(property, wrapperClass.getDynaProperty("aaa"));
}

From source file:org.seasar.struts.action.ActionFormWrapperClassTest.java

/**
 * @throws Exception/*from   www  . j a v a  2s. c  o m*/
 */
public void testGetDynaProperties() throws Exception {
    S2ActionMapping mapping = new S2ActionMapping();
    mapping.setName("hoge");
    ActionFormWrapperClass wrapperClass = new ActionFormWrapperClass(mapping);
    DynaProperty property = new DynaProperty("aaa");
    wrapperClass.addDynaProperty(property);
    DynaProperty[] properties = wrapperClass.getDynaProperties();
    assertEquals(1, properties.length);
    assertSame(property, properties[0]);
}