Example usage for org.apache.commons.beanutils BeanMap put

List of usage examples for org.apache.commons.beanutils BeanMap put

Introduction

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

Prototype

public Object put(Object name, Object value) throws IllegalArgumentException, ClassCastException 

Source Link

Document

Sets the bean property with the given name to the given value.

Usage

From source file:org.ms123.common.data.MultiOperations.java

private static void handleRelatedTo(SessionContext sc, Map sourceMap, String propertyName,
        BeanMap destinationMap, Object destinationObj, Class propertyType) {
    Object id = null;/*from  ww  w .j a v  a  2 s .co  m*/
    try {
        Object _id = sourceMap.get(propertyName);
        if (_id != null) {
            if (_id instanceof Map) {
                id = ((Map) _id).get("id");
            } else {
                String s = String.valueOf(_id);
                if (s.indexOf("/") >= 0) {
                    _id = Utils.extractId(s);
                }
                Class idClass = PropertyUtils.getPropertyType(propertyType.newInstance(), "id");
                id = (idClass.equals(Long.class)) ? Long.valueOf(_id + "") : _id;
            }
        }
    } catch (Exception e) {
    }
    if (id != null && !"".equals(id) && !"null".equals(id)) {
        Object relatedObject = sc.getPM().getObjectById(propertyType, id);
        /*List<Collection> candidates = TypeUtils.getCandidateLists(relatedObject, destinationObj, null);
        if (candidates.size() == 1) {
           Collection l = candidates.get(0);
           debug("list.contains:" + l.contains(destinationObj));
           if (!l.contains(destinationObj)) {
              l.add(destinationObj);
           }
        }*/
        destinationMap.put(propertyName, relatedObject);
    } /*else {
       Object relatedObject = destinationMap.get(propertyName);
       debug("\trelatedObject:" + relatedObject);
       if (relatedObject != null) {
      List<Collection> candidates = TypeUtils.getCandidateLists(relatedObject, destinationObj, null);
      if (candidates.size() == 1) {
         Collection l = candidates.get(0);
         debug("list.contains:" + l.contains(destinationObj));
         if (l.contains(destinationObj)) {
            l.remove(destinationObj);
         }
      }
       }
       destinationMap.put(propertyName, null);
      }*/
}

From source file:org.ms123.common.data.SojoFilterInterceptor.java

public boolean visitElement(Object pvKey, int pvIndex, Object pvValue, int pvType, String pvPath,
        int pvNumberOfRecursion) {
    pvPath = cleanPath(pvPath);/*  w  w  w  . j a v  a 2  s  .c  o  m*/
    if (pvType == Constants.TYPE_SIMPLE) {
        if (m_fieldMap.get(pvPath) == null) {
            return false;
        }
        if (pvKey != null && pvKey.getClass().equals(String.class)) {
            if (m_sessionContext.isFieldPermitted((String) pvKey, m_currentModuleName)) {
                String fieldName = (String) pvKey;
                int index = m_fieldMap.get(pvPath);
                String alias = m_aliasList.get(index);
                if (alias != null && alias.length() > 0 && !(alias.startsWith("@") || alias.startsWith("%"))) {
                    fieldName = alias;
                }
                if (pvValue instanceof java.util.Date) {
                    pvValue = ((java.util.Date) pvValue).getTime();
                }
                ((Map) m_current).put(fieldName, pvValue);
            }
        }
    } else if (pvType == Constants.TYPE_NULL) {
    } else if (pvValue != null) {
        if (pvKey != null) {
            if (m_pathMap.get(pvPath) == null) {
                return true;
            }
        }
        if (pvType == Constants.TYPE_MAP) {
            Object teams = ((Map) pvValue).get("_team_list");
            if (!isAdmin() && teams != null && ((Collection) teams).size() > 0) {
                for (Object _team : ((Collection<Map>) teams)) { //@@@MS Copy the "team.name" from "teamintern" to "team"
                    BeanMap team = new BeanMap(_team);
                    if (team.get("name") == null) {
                        Object _teamintern = (Object) team.get("teamintern");
                        if (_teamintern != null) {
                            BeanMap teamintern = new BeanMap(_teamintern);
                            team.put("name", teamintern.get("name"));
                            team.put("teamintern", null);
                        }
                    }
                }
                if (!m_sessionContext.hasTeamPermission(teams)) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:org.seedstack.seed.core.utils.SeedBeanUtils.java

/**
 * Set properties derived from configuration on a bean.
 *
 * <ul>//w  ww .  j ava2  s  .com
 * <li>[prefix].property.* gives the properties to set.</li>
 * </ul>
 *
 * @param bean the bean to set properties on.
 * @param configuration the configuration to derive properties from.
 * @param prefix the property prefix.
 */
public static void setPropertiesFromConfiguration(Object bean, Configuration configuration, String prefix) {
    BeanMap beanMap = new BeanMap(bean);
    Properties properties = SeedConfigurationUtils.buildPropertiesFromConfiguration(configuration, prefix);
    for (String key : properties.stringPropertyNames()) {
        String value = properties.getProperty(key);
        try {
            PropertyDescriptor propertyDescriptor = PropertyUtils.getPropertyDescriptor(bean, key);
            if (propertyDescriptor == null) {
                throw SeedException.createNew(CoreUtilsErrorCode.PROPERTY_NOT_FOUND).put("property", key)
                        .put("class", bean.getClass().getCanonicalName());
            }

            beanMap.put(key, value);

        } catch (Exception e) {
            throw SeedException.wrap(e, CoreUtilsErrorCode.UNABLE_TO_SET_PROPERTY).put("property", key)
                    .put("class", bean.getClass().getCanonicalName()).put("value", value);
        }
    }
}