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

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

Introduction

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

Prototype

public BeanMap(Object bean) 

Source Link

Document

构造一个新的BeanMap�作指定的bean, 如果给定的bean是null, 那么 这个map将会是empty。

Usage

From source file:egovframework.com.ext.ldapumt.service.impl.DeptManageLdapDAO.java

/**
 * ?? ? ? .//from  w ww .  j ava 2 s . c om
 * @param vo  Vo
 * @return deptManageVO  Vo
 * @param bannerVO
 */
public UcorgVO selectDeptManage(UcorgVO vo) throws Exception {
    final ContainerCriteria criteria = query().where("objectclass").is("ucorg2");

    @SuppressWarnings("unchecked")
    Map<String, Object> introspected = new BeanMap(vo);

    for (String key : introspected.keySet()) {
        if (key.equals("dn") || key.equals("class") || introspected.get(key) == null
                || introspected.get(key).equals(""))
            continue;

        ContainerCriteria c = query().where(key).is(String.valueOf(introspected.get(key)));
        criteria.and(c);
    }

    List<Object> list = null;
    try {
        list = ldapTemplate.search(criteria, new ObjectMapper<UcorgVO>(UcorgVO.class));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return (UcorgVO) list.get(0);
}

From source file:egovframework.com.ext.ldapumt.service.impl.OrgManageLdapDAO.java

/**
 * vo? field  ? /*from  ww w  . j ava 2 s. com*/
 * @param vo
 * @param e
 */
private void introspect(LdapObject vo, Executable e) {
    @SuppressWarnings("unchecked")
    Map<String, Object> introspected = new BeanMap(vo);

    for (String key : introspected.keySet()) {
        if (key.equals("dn") || key.equals("class") || introspected.get(key) == null
                || introspected.get(key).equals(""))
            continue;

        e.execute(key, introspected.get(key));
    }

}

From source file:com.rodaxsoft.mailgun.ListMember.java

/**
 * @return A map representation of the object
 *//*from  w  w  w .  j  a  v a 2  s  .  co m*/
public Map<Object, Object> toMap() {
    return new BeanMap(this);
}

From source file:io.lightlink.oracle.AbstractOracleType.java

protected STRUCT createStruct(Connection con, Object value, String type) throws SQLException {

    if (value == null)
        return null;

    Map mapValue;//from w w w  . jav a  2 s  . co m
    if (value instanceof Map) {
        mapValue = (Map) value;
        mapValue = new CaseInsensitiveMap(mapValue);
    } else { // create a Map from bean
        Map map = new CaseInsensitiveMap(new BeanMap(value));
        map.remove("class");
        mapValue = map;
    }

    STRUCT struct;
    StructDescriptor structType = safeCreateStructureDescriptor(type, con);
    ResultSetMetaData stuctMeteData = structType.getMetaData();

    List<Object> orderedValues = new ArrayList<Object>();

    if (stuctMeteData.getColumnCount() == 1 && mapValue.size() == 1) {
        orderedValues.add(mapValue.values().iterator().next());
    } else {
        for (int col = 1; col <= stuctMeteData.getColumnCount(); col++) {
            Object v = mapValue.get(stuctMeteData.getColumnName(col));
            if (v == null) {
                v = mapValue.get(stuctMeteData.getColumnName(col).replaceAll("_", ""));
            }

            String typeName = stuctMeteData.getColumnTypeName(col);
            int columnType = stuctMeteData.getColumnType(col);
            if (columnType == OracleTypes.ARRAY) {
                v = createArray(con, v, typeName);
            } else if (columnType == OracleTypes.JAVA_STRUCT || columnType == OracleTypes.JAVA_OBJECT
                    || columnType == OracleTypes.STRUCT) {
                v = createStruct(con, v, typeName);
            }

            orderedValues.add(v);
        }
    }

    Object[] values = orderedValues.toArray();

    for (int j = 0; j < values.length; j++) {

        Object v = values[j];
        if (v instanceof Long && stuctMeteData.getColumnTypeName(j + 1).equalsIgnoreCase("TIMESTAMP")) {
            values[j] = new Timestamp((Long) v);
        } else if (v instanceof Long && stuctMeteData.getColumnTypeName(j + 1).equalsIgnoreCase("DATE")) {
            values[j] = new Date((Long) v);
        }

    }

    struct = new STRUCT(structType, con, values);

    return struct;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.common.vbb.impl.MixedColorCodingDecorator.java

/**{@inheritDoc}**/
public void setVisualVariables(EObject visualVariables) {
    BeanMap bm = new BeanMap(this);
    for (EAttribute att : this.visualVariableClass.getEAllAttributes()) {
        VisualVariableHelper.setVisualVariableValue(bm, visualVariables, att);
    }/*from   ww  w .j  a  va 2s  . c  om*/
    if (DECORATION_MODE_DISCRETE.equals(this.decorationMode)) {
        subDecorator = new DiscreteColorCodingDecorator(getDecoratedVBB());
    } else if (DECORATION_MODE_CONTINUOUS.equals(this.decorationMode)) {
        subDecorator = new ContinuousColorCodingDecorator(getDecoratedVBB());
    }
    BeanMap subBeanMap = new BeanMap(subDecorator);
    for (EAttribute att : this.visualVariableClass.getEAllAttributes()) {
        VisualVariableHelper.setVisualVariableValue(subBeanMap, visualVariables, att);
    }
    this.getDecoratedVBB().setVisualVariables(visualVariables);
}

From source file:de.hska.ld.content.service.impl.AbstractContentService.java

public List<String> compare(T oldT, T newT)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    BeanMap map = new BeanMap(oldT);
    PropertyUtilsBean propUtils = new PropertyUtilsBean();
    //StringBuilder sb = new StringBuilder();
    //sb.append("UPDATE process: >> object=[class=" + newT.getClass() + ", " + newT.getId() + "]:");
    List<String> differentProperties = new ArrayList<>();
    for (Object propNameObject : map.keySet()) {
        String propertyName = (String) propNameObject;
        if (propertyName.endsWith("List"))
            continue;
        try {// w w w  .j  a v a 2s. c  om
            Object property1 = propUtils.getProperty(oldT, propertyName);
            Object property2 = propUtils.getProperty(newT, propertyName);
            if (property1 != null) {
                if (!(property1 instanceof List) && !(property1 instanceof Date)) {
                    if (property1.equals(property2)) {
                        //sb.append(" ||" + propertyName + " is equal ||");
                    } else {
                        try {
                            //sb.append(" ||> " + propertyName + " is different (oldValue=\"" + property1 + "\", newValue=\"" + property2 + "\") ||");
                            differentProperties.add(propertyName);
                        } catch (Exception e) {
                            //sb.append(" ||> " + propertyName + " is different (newValue=\"" + property2 + "\") ||");
                            differentProperties.add(propertyName);
                        }
                    }
                }
            } else {
                if (property2 == null) {
                    //sb.append(" ||" + propertyName + " is equal ||");
                } else {
                    if (!(property2 instanceof List) && !(property2 instanceof Date)) {
                        //sb.append(" ||> " + propertyName + " is different (newValue=\"" + property2 + "\") ||");
                        differentProperties.add(propertyName);
                    }
                }
            }
        } catch (Exception e) {
            //sb.append(" ||> Could not compute difference for property with name=" + propertyName + "||");
        }
    }
    //sb.append(" <<");
    //LOGGER.info(sb.toString());
    return differentProperties;
}

From source file:com.autobizlogic.abl.util.BeanUtil.java

/**
 * Given two beans of the same entity, determine whether they are equal. This is done by
 * looking at the value of all the attributes, and the value of all the parent
 * relationships. If there is any difference, false is returned.
 *//*from w ww.  j a  v  a  2 s.  co  m*/
@SuppressWarnings("rawtypes")
public static boolean beansAreEqual(MetaEntity metaEntity, Object bean1, Object bean2) {

    // First the easy cases
    if (bean1 == null && bean2 == null)
        return true;
    if (bean1 == null && bean2 != null)
        return false;
    if (bean1 != null && bean2 == null)
        return false;
    if (bean1 == bean2) // You never know...
        return true;

    Map beanMap1 = null;
    Map beanMap2 = null;
    if (metaEntity.isMap()) {
        beanMap1 = (Map) bean1;
        beanMap2 = (Map) bean2;
    } else {
        beanMap1 = new BeanMap(bean1);
        beanMap2 = new BeanMap(bean2);
    }

    // Compare the attributes - return at first difference
    Set<MetaAttribute> metaAttributes = metaEntity.getMetaAttributes();
    for (MetaAttribute metaAttribute : metaAttributes) {
        Object val1 = beanMap1.get(metaAttribute.getName());
        Object val2 = beanMap2.get(metaAttribute.getName());
        if (val1 == null && val2 == null)
            continue;
        if (val1 != null && val2 != null && val1 == val2)
            continue;
        if (val1 != null && val2 != null && val1.equals(val2))
            continue;

        return false;
    }

    Set<MetaRole> metaRoles = metaEntity.getRolesFromChildToParents();
    for (MetaRole metaRole : metaRoles) {
        Object val1 = beanMap1.get(metaRole.getRoleName());
        Object val2 = beanMap2.get(metaRole.getRoleName());
        if (val1 == null && val2 == null)
            continue;
        if (val1 != null && val2 != null && val1 == val2)
            continue;
        if (val1 != null && val2 != null && val1.equals(val2))
            continue;

        return false;
    }

    return true;
}

From source file:net.mojodna.sprout.SproutAutoLoaderPlugIn.java

@SuppressWarnings("unchecked")
private void loadAction(final Class bean) {
    final Annotation[] annotations = bean.getAnnotations();

    for (int i = 0; i < annotations.length; i++) {
        final Annotation a = annotations[i];
        final Class type = a.annotationType();

        if (type.equals(SproutAction.class)) {
            final SproutAction form = (SproutAction) a;
            final String path = form.path();
            final Class<ActionConfig> mappingClass = form.mappingClass();
            final String scope = form.scope();
            final String name = form.name();
            final boolean validate = form.validate();
            final String input = form.input();
            final SproutProperty[] properties = form.properties();
            final SproutForward[] forwards = form.forwards();
            ActionConfig actionConfig = null;

            try {
                Constructor<ActionConfig> constructor = mappingClass.getDeclaredConstructor(new Class[] {});

                actionConfig = constructor.newInstance(new Object[] {});
            } catch (NoSuchMethodException nsme) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + nsme.getMessage());
            } catch (InstantiationException ie) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + ie.getMessage());
            } catch (IllegalAccessException iae) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + iae.getMessage());
            } catch (InvocationTargetException ite) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + ite.getMessage());
            }/* ww  w .j av a2 s  .  co m*/

            if (actionConfig != null) {
                actionConfig.setPath(path);
                actionConfig.setType(bean.getName());
                actionConfig.setScope(scope);
                actionConfig.setValidate(validate);

                if (name.length() > 0) {
                    actionConfig.setName(name);
                }
                if (input.length() > 0) {
                    actionConfig.setInput(input);
                }

                if (properties != null && properties.length > 0) {
                    Map actionConfigBeanMap = new BeanMap(actionConfig);

                    for (int j = 0; j < properties.length; j++) {
                        actionConfigBeanMap.put(properties[j].property(), properties[j].value());
                    }
                }

                if (forwards != null && forwards.length > 0) {
                    for (int j = 0; j < forwards.length; j++) {
                        String fcModule = forwards[j].module();

                        actionConfig.addForwardConfig(makeForward(forwards[j].name(), forwards[j].path(),
                                forwards[j].redirect(), fcModule.length() == 0 ? null : fcModule));
                    }
                }
            }

            if (log.isDebugEnabled()) {
                log.debug("Action " + path + " -> " + bean.getName());
            }

            getModuleConfig().addActionConfig(actionConfig);
        }
    }
}

From source file:br.com.ingenieux.mojo.aws.AbstractAWSMojo.java

protected void displayResults(Object result, int level) {
    if (null == result) {
        return;/*from w w  w . j a va2s  .  com*/
    }

    String prefix = StringUtils.repeat(" ", level * 2) + " * ";

    if (Collection.class.isAssignableFrom(result.getClass())) {
        @SuppressWarnings("unchecked")
        Collection<Object> coll = Collection.class.cast(result);

        for (Object o : coll) {
            displayResults(o, 1 + level);
        }

        return;
    } else if ("java.lang".equals(result.getClass().getPackage().getName())) {
        getLog().info(prefix + CredentialsUtil.redact("" + result) + " [class: "
                + result.getClass().getSimpleName() + "]");

        return;
    }

    BeanMap beanMap = new BeanMap(result);

    for (Iterator<?> itProperty = beanMap.keyIterator(); itProperty.hasNext();) {
        String propertyName = "" + itProperty.next();
        Object propertyValue = beanMap.get(propertyName);

        if ("class".equals(propertyName)) {
            continue;
        }

        if (null == propertyValue) {
            continue;
        }

        Class<?> propertyClass = null;

        try {
            propertyClass = beanMap.getType(propertyName);
        } catch (Exception e) {
            getLog().warn("Failure on property " + propertyName, e);
        }

        if (null == propertyClass) {
            getLog().info(prefix + propertyName + ": " + CredentialsUtil.redact("" + propertyValue));
        } else {
            getLog().info(prefix + propertyName + ": " + CredentialsUtil.redact("" + propertyValue)
                    + " [class: " + propertyClass.getSimpleName() + "]");
        }
    }
}

From source file:com.google.feedserver.client.FeedServerClient.java

/**
 * Helper method to retrieve a property from the provided bean.
 * /*from  w  ww .  ja v  a  2s . c o  m*/
 * @param propertyName the property to read from the bean.
 * @param bean the bean to read from.
 * @return the container supplied.
 * @throws FeedServerClientException if any problems exist with the bean.
 */
private Object getBeanProperty(String propertyName, T bean) throws FeedServerClientException {
    try {
        BeanMap beanMap = new BeanMap(bean);
        return beanMap.get(propertyName);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Invalid bean " + bean.getClass().getName(), e);
    } catch (SecurityException e) {
        throw new RuntimeException("Invalid bean " + bean.getClass().getName(), e);
    }
}