Example usage for org.apache.commons.collections BeanMap get

List of usage examples for org.apache.commons.collections BeanMap get

Introduction

In this page you can find the example usage for org.apache.commons.collections BeanMap get.

Prototype

public Object get(Object name) 

Source Link

Document

Returns the value of the bean's property with the given name.

Usage

From source file:com.krawler.workflow.module.dao.DataObjectOperationDAOImpl.java

@Override
public boolean updateDataObject(Object dataObject, String keyName) {
    boolean result = true;

    try {//w w w . j a v  a2s . c  om
        StringBuilder query = new StringBuilder(
                "UPDATE " + getTableName(dataObject.getClass().getSimpleName()) + " SET ");
        BeanMap bm = new BeanMap(dataObject);
        ArrayList arr = new ArrayList();
        Iterator itr = bm.keyIterator();

        while (itr.hasNext()) {
            String key = (String) itr.next();
            if (key.equals(keyName) || "class".equals(key))
                continue;
            query.append(key).append("=?");
            arr.add(bm.get(key));

            if (itr.hasNext())
                query.append(",");
        }

        query.append(" WHERE ").append(keyName).append(" = ?");
        arr.add(bm.get(keyName));
        getJdbcTemplate().update(query.toString(), arr.toArray());
    } catch (Exception e) {
        LOG.warn("Can not update record", e);
        result = false;
    }

    return result;
}

From source file:nl.nn.adapterframework.jms.JmsRealm.java

/**
 * copies matching properties to any other class
 *//*from   www .  j  a  va 2 s  .c o  m*/
public void copyRealm(Object destination) {
    String logPrefixDest = destination.getClass().getName() + " ";
    if (destination instanceof INamedObject) {
        INamedObject namedDestination = (INamedObject) destination;
        logPrefixDest += "[" + namedDestination.getName() + "] ";
    }
    try {
        BeanMap thisBeanMap = new BeanMap(this);
        BeanMap destinationBeanMap = new BeanMap(destination);
        Iterator<String> iterator = thisBeanMap.keyIterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object value = thisBeanMap.get(key);
            if (value != null && !key.equals("class") && destinationBeanMap.containsKey(key)) {
                PropertyUtils.setProperty(destination, key, value);
            }
        }
    } catch (Exception e) {
        log.error(logPrefixDest + "unable to copy properties of JmsRealm", e);
    }
    log.info(logPrefixDest + "loaded properties from jmsRealm [" + toString() + "]");
}

From source file:org.apache.jackrabbit.core.config.BeanConfig.java

/**
 * Creates a new instance of the configured bean class.
 *
 * @return new bean instance/*from   ww w.ja  v  a2s  . c  o m*/
 * @throws ConfigurationException on bean configuration errors
 */
public Object newInstance() throws ConfigurationException {
    try {
        Class objectClass = Class.forName(getClassName(), true, getClassLoader());
        Object object = objectClass.newInstance();
        BeanMap map = new BeanMap(object);
        Iterator iterator = map.keyIterator();
        while (iterator.hasNext()) {
            String name = (String) iterator.next();
            String value = properties.getProperty(name);
            if (value != null) {
                map.put(name, properties.getProperty(name));
            }
        }
        Iterator it = properties.keySet().iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            if (map.get(key) == null && properties.getProperty(key) != null) {
                log.warn(object.getClass().getName() + " does not support '" + key
                        + "'; the setting is ignored.");
            }
        }
        return object;
    } catch (ClassNotFoundException e) {
        throw new ConfigurationException(
                "Configured bean implementation class " + getClassName() + " was not found.", e);
    } catch (InstantiationException e) {
        throw new ConfigurationException(
                "Configured bean implementation class " + getClassName() + " can not be instantiated.", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException(
                "Configured bean implementation class " + getClassName() + " is protected.", e);
    }
}

From source file:se.vgregion.portal.innovatinosslussen.domain.TypesBeanTest.java

void doGetterSetterValuesMatch(Object o) throws IllegalAccessException, InstantiationException {
    BeanMap bm = new BeanMap(o);

    final String javaLangPackageName = String.class.getPackage().getName();

    for (Object key : bm.keySet()) {
        String name = (String) key;

        if ("ideaContentPrivate".equals(name) || "ideaPerson".equals(name)
                || "ideaContentPublic".equals(name)) {
            continue;
        }//from w  w  w .  jav  a 2s  . c  o  m

        if (bm.getWriteMethod(name) != null) {
            if (bm.getType(name).equals(String.class)) {
                bm.put(name, name);
                Assert.assertTrue(name == bm.get(name));
            } else {
                Class clazz = bm.getType(name);

                if (!clazz.getName().startsWith(javaLangPackageName) && !clazz.isEnum()) {
                    Object value = defaultPrim.get(clazz);
                    if (value == null) {
                        value = clazz.newInstance();
                    }
                    bm.put(name, value);
                    Assert.assertTrue("1, " + o.getClass() + "." + key, value.equals(bm.get(name)));
                    Assert.assertTrue("2, " + o.getClass() + "." + key,
                            value.hashCode() == bm.get(name).hashCode());
                }
            }
        }

    }
}

From source file:se.vgregion.service.innovationsslussen.ldap.PersonTest.java

@Test
public void beanStringPropertiesGetterSetters() {
    KivPerson person = new KivPerson();
    BeanMap bm = new BeanMap(person);
    int i = 0;/*from ww w .  j ava  2 s .c  o m*/
    for (Object key : bm.keySet()) {
        String name = (String) key;
        if (bm.getWriteMethod(name) != null) {
            if (bm.getType(name).equals(String.class)) {
                String setterValue = "" + i++;
                bm.put(key, setterValue);
                String getterValue = (String) bm.get(key);
                Assert.assertEquals(setterValue, getterValue);
            }
        }
    }
}