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

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

Introduction

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

Prototype

public Object get(Object name) 

Source Link

Document

æ ¹æ?®å±žæ€§çš„å??称得到对应属性的值

给定的属性å??称必须是 String 而且必须ä¸?能为 null; å?¦åˆ™è¿™ä¸ªæ–¹æ³•返回 null.

Usage

From source file:com.googlecode.commons.swing.value.GenericValueGetterSetter.java

public Object getValue(Component component) {
    BeanMap map = new BeanMap(component);
    return map.get(getterName);
}

From source file:com.trickl.crawler.handle.BeanMemberHandler.java

@SuppressWarnings("unchecked")
@Override//from  w w  w . ja  v  a 2s.com
public void handle(T task, BeanType bean) throws DroidsException, IOException {
    if (task == null || bean == null)
        throw new NullPointerException();

    if (outputHandler != null) {
        BeanMap beanMap = new BeanMap(bean);
        BeanMemberType beanMember = (BeanMemberType) beanMap.get(propertyName);

        if (beanMember == null) {
            throw new DroidsException("Bean does not contain a value for member '" + propertyName + "'");
        }
        outputHandler.handle(task, beanMember);
    }
}

From source file:com.funambol.lanciadelta.LanciaDeltaBeanMap.java

public LanciaDeltaBeanMap(final String prefix, final Object o) {
    BeanMap bm = new BeanMap(o);

    String key = null;// w  ww.j  av  a  2s  .c  om
    Iterator i = bm.keyIterator();
    while (i.hasNext()) {
        key = (String) i.next();

        put(prefix + "." + key, bm.get(key));
    }
}

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

/**
 * Helper method to retrieve a property from the provided bean.
 * /*from  www  . j a  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);
    }
}

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

protected void displayResults(Object result, int level) {
    if (null == result) {
        return;//  ww  w .java  2 s .  c  om
    }

    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.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

private T mapResults(T instance, List results, ArrayList<String> pList)
        throws InstantiationException, IllegalAccessException, IllegalArgumentException {
    pList.parallelStream().forEach(e -> {
        Object o = instance;// ww  w .  ja  va  2  s.c  o  m
        for (String fieldName : e.split("\\.")) {
            BeanMap m = new BeanMap(o);
            Class type = m.getType(fieldName);
            if (isRedisEntity(type)) {
                o = m.get(fieldName);
            } else {
                Object value;
                Object result = results.get(pList.indexOf(e));
                if (result == null) {
                    value = null;
                } else if (String.class.isAssignableFrom(type)) {
                    value = result.toString();
                } else if (type.isEnum()) {
                    try {
                        value = type.getMethod("valueOf", String.class).invoke(null,
                                results.get(pList.indexOf(e)));
                    } catch (NoSuchMethodException | SecurityException | IllegalAccessException
                            | IllegalArgumentException | InvocationTargetException ex) {
                        throw new IllegalArgumentException(ex);
                    }
                } else if (result.getClass().isAssignableFrom(type)) {
                    value = type.cast(result);
                } else {
                    try {
                        value = type.getConstructor(result.getClass()).newInstance(result);
                    } catch (NoSuchMethodException | SecurityException | InstantiationException
                            | IllegalAccessException | IllegalArgumentException
                            | InvocationTargetException ex) {
                        throw new IllegalArgumentException(ex);
                    }
                }
                m.put(fieldName, value);
            }
        }
    });
    return instance;
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

private void prepareEnsuerIndex(String id, T r, JsonObject instance, Boolean isNew, RBatch redissonBatch,
        ArrayList<String> pList, String parent) throws RepositoryException {
    try {/*from  w w  w  .  j ava  2  s.  c o  m*/
        BeanMap pMap = new BeanMap(r == null ? cls.newInstance() : r);
        pMap.keySet().forEach(e -> {
            if ("class".equals(e) || instance.getValue(e.toString()) == null) {
                return;
            }
            Class type = pMap.getType(e.toString());
            String fieldName = (parent == null ? "" : parent.concat(".")).concat(e.toString());
            if (isRedisEntity(type)) {
                try {
                    RedisRepositoryImpl innerRepo = (RedisRepositoryImpl) factory.instance(type);
                    innerRepo.prepareEnsuerIndex(id, pMap.get(e), instance.getJsonObject(e.toString()), isNew,
                            redissonBatch, pList, fieldName);
                } catch (RepositoryException ex) {
                    throw new RuntimeException(ex);
                }
            } else {
                try {
                    if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonIndex.class)) {
                        RedissonIndex index = cls.getDeclaredField(e.toString())
                                .getAnnotation(RedissonIndex.class);
                        if (index.indexOnSave()) {
                            prepareEnsuerIndex(id, r, instance, redissonBatch, index, e.toString(),
                                    pMap.get(e));
                        }
                    } else if (cls.getDeclaredField(e.toString())
                            .isAnnotationPresent(RedissonIndex.List.class)) {
                        RedissonIndex.List indexList = cls.getDeclaredField(e.toString())
                                .getAnnotation(RedissonIndex.List.class);
                        Arrays.stream(indexList.value()).filter(f -> f.indexOnSave())
                                .forEach(index -> prepareEnsuerIndex(id, r, instance, redissonBatch, index,
                                        e.toString(), pMap.get(e)));
                    }
                    if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonCounter.class)) {
                        RedissonCounter counter = cls.getDeclaredField(e.toString())
                                .getAnnotation(RedissonCounter.class);
                        prepareEnsuerCounter(id, r, instance, isNew, redissonBatch, counter, e.toString(),
                                pMap.get(e));
                    } else if (cls.getDeclaredField(e.toString())
                            .isAnnotationPresent(RedissonCounter.List.class)) {
                        RedissonCounter.List counterList = cls.getDeclaredField(e.toString())
                                .getAnnotation(RedissonCounter.List.class);
                        Arrays.stream(counterList.value()).forEach(index -> prepareEnsuerCounter(id, r,
                                instance, isNew, redissonBatch, index, e.toString(), pMap.get(e)));
                    }
                } catch (NoSuchFieldException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
    } catch (InstantiationException | IllegalAccessException | RuntimeException ex) {
        throw new RepositoryException(ex);
    }
}

From source file:org.beanfuse.model.EntityUtils.java

/**
 * ().<br>//ww w. j  a v  a  2  s  . c  om
 * 
 * <pre>
 *  hibernate????.
 *  (Entity)???id??.
 *  ?
 * &lt;code&gt;
 * Component
 * &lt;/code&gt;
 *  ?
 *  ?????????.
 *  // evict collection
 *  if (value instanceof Collection) {
 *    if (((Collection) value).isEmpty())
 *    map.put(attr, null);
 *  }
 * </pre>
 * 
 * @see ValidEntityPredicate
 * @param entity
 */
public static void evictEmptyProperty(Object entity) {
    if (null == entity) {
        return;
    }
    boolean isEntity = false;
    if (entity instanceof Entity) {
        isEntity = true;
    }
    BeanMap map = new BeanMap(entity);
    List attList = new ArrayList();
    attList.addAll(map.keySet());
    attList.remove("class");
    for (Iterator iter = attList.iterator(); iter.hasNext();) {
        String attr = (String) iter.next();
        if (!PropertyUtils.isWriteable(entity, attr)) {
            continue;
        }
        Object value = map.get(attr);
        if (null == value) {
            continue;
        } else {
            // evict invalid entity key
            if (isEntity && attr.equals(((Entity) entity).key())) {
                if (!ValidEntityKeyPredicate.getInstance().evaluate(value)) {
                    map.put(attr, null);
                }
            }
            // evict invalid entity
            if (value instanceof Entity && !ValidEntityPredicate.getInstance().evaluate(value)) {
                map.put(attr, null);
            } else if (value instanceof Component) {
                // evict component recursively
                evictEmptyProperty(value);
            }
        }
    }
}

From source file:org.beanfuse.model.EntityUtils.java

/**
 * ?//from  w w w .j  a v a 2 s  .co  m
 * 
 * @param entity
 * @param ignoreDefault
 *            
 * @return
 */
public static boolean isEmpty(Entity entity, boolean ignoreDefault) {
    BeanMap map = new BeanMap(entity);
    List attList = new ArrayList();
    attList.addAll(map.keySet());
    attList.remove("class");
    try {
        for (Iterator iter = attList.iterator(); iter.hasNext();) {
            String attr = (String) iter.next();
            if (!PropertyUtils.isWriteable(entity, attr)) {
                continue;
            }
            Object value = map.get(attr);
            if (null == value) {
                continue;
            }
            if (ignoreDefault) {
                if (value instanceof Number) {
                    if (((Number) value).intValue() != 0) {
                        return false;
                    }
                } else if (value instanceof String) {
                    String str = (String) value;
                    if (StringUtils.isNotEmpty(str)) {
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    } catch (Exception e) {
        logger.error("isEmpty error", e);
    }
    return true;
}

From source file:org.beangle.model.persist.hibernate.CriterionUtils.java

/**
 * ?. ??./*w  ww. java2 s.c  o  m*/
 * 
 * @param entity
 * @param excludePropertes
 * @param mode
 * @return
 */
@SuppressWarnings("rawtypes")
public static List<Criterion> getEntityCriterions(String nestedName, Object entity, String[] excludePropertes,
        MatchMode mode, boolean ignoreZero) {
    if (null == entity) {
        return Collections.emptyList();
    }
    List<Criterion> criterions = CollectUtils.newArrayList();
    BeanMap map = new BeanMap(entity);
    Set keySet = map.keySet();
    Collection properties = null;
    if (null == excludePropertes) {
        List proList = CollectUtils.newArrayList();
        proList.addAll(keySet);
        properties = proList;
    } else {
        properties = CollectionUtils.subtract(keySet, Arrays.asList(excludePropertes));
    }
    properties.remove("class");

    for (Iterator iter = properties.iterator(); iter.hasNext();) {
        String propertyName = (String) iter.next();
        if (!PropertyUtils.isWriteable(entity, propertyName)) {
            continue;
        }
        Object value = map.get(propertyName);
        addCriterion(nestedName, entity, excludePropertes, propertyName, value, criterions, mode, ignoreZero);
    }
    return criterions;
}