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

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

Introduction

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

Prototype

public BeanMap(Object bean) 

Source Link

Document

Constructs a new BeanMap that operates on the specified bean.

Usage

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

@SuppressWarnings("unchecked")
@Override//  w w  w  .j av  a  2s  . co  m
public boolean createDataObject(Object dataObject) {
    boolean result = true;

    try {
        SimpleJdbcInsert insert = new SimpleJdbcInsert(getJdbcTemplate())
                .withTableName(getTableName(dataObject.getClass().getSimpleName()));
        insert.execute(new BeanMap(dataObject));
    } catch (Exception e) {
        LOG.warn("Can not insert record", e);
        result = false;
    }

    return result;
}

From source file:io.lightlink.dao.LightLinkDAO.java

protected Map<String, Object> doExecute(Object params) throws IOException {
    Map<String, Object> paramsMap;
    if (params instanceof Map)
        paramsMap = (Map<String, Object>) params;
    else//from www. ja  v a2 s.  c  o  m
        paramsMap = new BeanMap(params);
    ObjectBufferResponseStream responseStream = new ObjectBufferResponseStream();
    scriptRunner.execute(action, "", paramsMap, responseStream);
    return responseStream.getDataMap();

}

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

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

    try {//from  w  w  w  .j a  va2s.  co  m
        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
 *///  w  w  w . j a  v a  2  s. c  om
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//  w  ww. j a  va2s  . 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:org.apache.jackrabbit.core.config.BeanConfig.java

/**
 * Creates a new instance of the configured bean class.
 *
 * @return new bean instance/*from w w  w. java 2  s .c  om*/
 * @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));
            }
        }
        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:org.apache.jackrabbit.core.config.BeanConfig.java

/**
 * Creates a new instance of the configured bean class.
 *
 * @return new bean instance/*from  w  w  w  . jav  a2s. co m*/
 * @throws ConfigurationException on bean configuration errors
 */
public Object newInstance() throws ConfigurationException {
    try {
        // Instantiate the object using the default constructor
        Class objectClass = Class.forName(getClassName(), true, getClassLoader());
        Object object = objectClass.newInstance();

        // Set all configured bean properties
        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));
            }
        }

        if (validate) {
            // Check that no invalid property names were configured
            Iterator it = properties.keySet().iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                if (!map.containsKey(key) && properties.getProperty(key) != null) {
                    String msg = "Configured class " + object.getClass().getName()
                            + " does not contain the property " + key
                            + ". Please fix the repository configuration.";
                    log.error(msg);
                    throw new ConfigurationException(msg);
                }
            }
        }

        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:org.apache.jackrabbit.core.TestRepository.java

/**
 * Attempts to retrieve the test repository instance used by the
 * Jackrabbit main test suite without having a direct dependency to any
 * of the classes in src/test/java. This method assumes that we are
 * running within the Jackrabbit main test suite if the AbstractJCRTest
 * class is available. The initialized RepositoryHelper instance is
 * retrieved from the static "helper" field of the AbstractJCRTest class,
 * and the underlying repository and configured superuser credentials are
 * extracted from the helper instance. This information is in turn used
 * to create a custom Repository adapter that delegates calls to the
 * underlying repository and uses the superuser credentials for the login
 * methods where no credentials are passed by the client.
 *
 * @return test repository instance// w  ww .j  av a 2s  .  co  m
 * @throws Exception if the test repository could not be retrieved
 */
private static Repository getIntegratedInstance() throws Exception {
    Class test = Class.forName("org.apache.jackrabbit.test.AbstractJCRTest");
    Map helper = new BeanMap(test.getField("helper").get(null));
    final Repository repository = (Repository) helper.get("repository");
    final Credentials superuser = (Credentials) helper.get("superuserCredentials");
    return new ProxyRepository(new RepositoryFactory() {

        public Repository getRepository() throws RepositoryException {
            return repository;
        }

    }) {

        public Session login(String workspace) throws RepositoryException {
            return repository.login(superuser, workspace);
        }

        public Session login() throws RepositoryException {
            return repository.login(superuser);
        }

    };
}

From source file:org.bpmscript.exec.java.JavaChannel.java

/**
 * Dependency Injection! Wires using a beanmap...
 *//*from   www .  java2  s. c  o  m*/
@SuppressWarnings("unchecked")
protected void wireDefinition() {
    BeanMap map = new BeanMap(definition);
    IDefinitionConfiguration definitionConfiguration = scriptChannel
            .getDefinitionConfiguration(this.definitionName);
    Map<String, Object> properties = definitionConfiguration.getProperties();
    map.putAll(properties);
    if (map.containsKey("log")) {
        map.put("log", log);
    }
}

From source file:org.red5.io.amf.Output.java

/** {@inheritDoc} */
public void writeObject(Object object, Serializer serializer) {
    if (checkWriteReference(object))
        return;/*from  ww  w . j av  a 2 s  .  co m*/

    storeReference(object);
    // Create new map out of bean properties
    BeanMap beanMap = new BeanMap(object);
    // Set of bean attributes
    Set<BeanMap.Entry<?, ?>> set = beanMap.entrySet();
    if ((set.size() == 0) || (set.size() == 1 && beanMap.containsKey("class"))) {
        // BeanMap is empty or can only access "class" attribute, skip it
        writeArbitraryObject(object, serializer);
        return;
    }

    // Write out either start of object marker for class name or "empty" start of object marker
    Class<?> objectClass = object.getClass();
    if (!objectClass.isAnnotationPresent(Anonymous.class)) {
        buf.put(AMF.TYPE_CLASS_OBJECT);
        putString(buf, objectClass.getName());
    } else {
        buf.put(AMF.TYPE_OBJECT);
    }

    if (object instanceof ICustomSerializable) {
        ((ICustomSerializable) object).serialize(this, serializer);
        buf.put((byte) 0x00);
        buf.put((byte) 0x00);
        buf.put(AMF.TYPE_END_OF_OBJECT);
        return;
    }

    // Iterate thru entries and write out property names with separators
    for (BeanMap.Entry<?, ?> entry : set) {
        if (entry.getKey().toString().equals("class")) {
            continue;
        }

        String keyName = entry.getKey().toString();
        // Check if the Field corresponding to the getter/setter pair is transient
        if (dontSerializeField(objectClass, keyName))
            continue;

        putString(buf, keyName);
        serializer.serialize(this, entry.getValue());
    }
    // Write out end of object mark
    buf.put((byte) 0x00);
    buf.put((byte) 0x00);
    buf.put(AMF.TYPE_END_OF_OBJECT);
}