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:org.beangle.model.persist.hibernate.CriterionUtils.java

public static List<Criterion> getEqCriterions(Object entity, String[] properties) {
    List<Criterion> criterions = CollectUtils.newArrayList();
    BeanMap map = new BeanMap(entity);
    for (int i = 0; i < properties.length; i++) {
        criterions.add(Restrictions.eq(properties[i], map.get(properties[i])));
    }//from ww  w  .  j av  a 2s  .  co m
    return criterions;
}

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

public static List<Criterion> getForeignerCriterions(Object entity, Collection<String> properties) {
    List<Criterion> criterions = CollectUtils.newArrayList();
    BeanMap map = new BeanMap(entity);
    for (Iterator<String> iter = properties.iterator(); iter.hasNext();) {
        String propertyName = iter.next();
        Object foreigner = map.get(propertyName);
        if (foreigner instanceof Entity) {
            BeanMap foreignerMap = new BeanMap(foreigner);
            Object foreignKey = foreignerMap.get("id");
            // ???String??String??.
            if (ValidEntityKeyPredicate.getInstance().evaluate(foreignKey)) {
                // .
                criterions.add(Restrictions.eq(propertyName + ".id", foreignKey));
            }//from   w ww. ja  v a2 s . c om
        }
    }
    return criterions;
}

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

/**
 * ?like?//  ww  w.j  av  a  2s.  c o m
 * 
 * @param entity
 * @param properties
 * @param mode
 * @return
 */
public static List<Criterion> getLikeCriterions(Object entity, String[] properties, MatchMode mode) {
    List<Criterion> criterions = CollectUtils.newArrayList();
    BeanMap map = new BeanMap(entity);
    for (int i = 0; i < properties.length; i++) {
        Object value = map.get(properties[i]);
        if ((value instanceof String) && (StringUtils.isNotEmpty((String) value))) {
            criterions.add(Restrictions.like(properties[i], (String) value, mode));
        }
    }
    return criterions;
}

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

/**
 * ?/*from  w w  w  .  jav  a2 s  .  c om*/
 * 
 * @param entity
 * @param excludePropertes
 * @param path
 * @param value
 * @param criterions
 * @param mode
 */
private static void addCriterion(String nestedName, Object entity, String[] excludePropertes, String path,
        Object value, List<Criterion> criterions, MatchMode mode, boolean ignoreZero) {
    if (null == value) {
        return;
    }
    addPrimativeCriterion(nestedName + path, value, criterions, ignoreZero);

    if (value instanceof String) {
        if (StringUtils.isNotEmpty((String) value)) {
            criterions.add(likeCriterion(nestedName + path, (String) value, mode));
        }
    } else if (value instanceof Entity) {
        BeanMap foreignerMap = new BeanMap(value);
        Object foreignKey = foreignerMap.get("id");
        // ???String??String??.
        if (ValidEntityKeyPredicate.getInstance().evaluate(foreignKey)) {
            // .
            criterions.add(eqCriterion(nestedName + path + ".id", foreignKey));
        }
    } else if (value instanceof Component) {
        criterions.addAll(getComponentCriterions(nestedName, entity, path, excludePropertes, mode, ignoreZero));
    }
}

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

/**
 * ?//from  w ww. j  a va2s .c  o  m
 * 
 * @param entity
 * @param property
 *            ????outcomponent.innercomponent
 * @param excludePropertes
 *            ??entityProperty.componentProperty
 * @param enableLike
 * @return
 */
private static List<Criterion> getComponentCriterions(String nestedName, Object entity, String property,
        String[] excludePropertes, MatchMode mode, boolean ignoreZero) {
    List<Criterion> criterions = CollectUtils.newArrayList();
    Component component = null;
    try {
        component = (Component) PropertyUtils.getProperty(entity, property);
    } catch (Exception e) {
        return Collections.emptyList();
    }
    if (null == component) {
        return Collections.emptyList();
    }
    BeanMap map = new BeanMap(component);
    Set<String> properties = map.keySet();
    Set<String> excludeSet = null;
    if (null == excludePropertes) {
        excludeSet = Collections.emptySet();
    } else {
        excludeSet = CollectUtils.newHashSet();
        excludeSet.addAll(Arrays.asList(excludePropertes));
    }
    for (Iterator<String> iter = properties.iterator(); iter.hasNext();) {
        String propertyName = iter.next();
        String cascadeName = property + "." + propertyName;
        if (excludeSet.contains(cascadeName) || "class".equals(propertyName)) {
            continue;
        }
        if (!PropertyUtils.isWriteable(component, propertyName)) {
            continue;
        }
        Object value = map.get(propertyName);

        addCriterion(nestedName, entity, excludePropertes, cascadeName, value, criterions, mode, ignoreZero);
    }
    return criterions;
}

From source file:org.beangle.model.util.EntityUtils.java

/**
 * ?/*from  ww  w.  j av a 2  s. c o  m*/
 * 
 * @param entity
 * @param ignoreDefault
 *            
 * @return
 */
@SuppressWarnings("unchecked")
public static boolean isEmpty(Entity<?> entity, boolean ignoreDefault) {
    BeanMap map = new BeanMap(entity);
    List<String> attList = CollectUtils.newArrayList();
    attList.addAll(map.keySet());
    attList.remove("class");
    try {
        for (final String attr : attList) {
            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.chtijbug.drools.runtime.DroolsFactObjectFactory.java

public static DroolsFactObject createFactObject(Object o, int version) {
    logger.debug(">> createFactObject", o, version);
    DroolsFactObject createFactObject = null;
    try {//ww  w .j a va 2  s . com
        if (o != null) {
            createFactObject = new DroolsFactObject(o, version);
            createFactObject.setFullClassName(o.getClass().getCanonicalName());
            createFactObject.setHashCode(o.hashCode());

            BeanMap m = new BeanMap(o);
            for (Object para : m.keySet()) {
                if (!para.toString().equals("class")) {
                    if (m.get(para) != null) {
                        DroolsFactObjectAttribute attribute = new DroolsFactObjectAttribute(para.toString(),
                                m.get(para).toString(), m.get(para).getClass().getSimpleName());
                        createFactObject.getListfactObjectAttributes().add(attribute);
                    } else {
                        DroolsFactObjectAttribute attribute = new DroolsFactObjectAttribute(para.toString(),
                                "null", "null");
                        createFactObject.getListfactObjectAttributes().add(attribute);
                    }

                }

            }
        }
        return createFactObject;
    } catch (Exception e) {
        logger.error("Not possible to introspect {} for reason {}", o, e);
        throw Throwables.propagate(e);
    } finally {
        logger.debug("<< createFactObject", createFactObject);
    }
}

From source file:org.eclipse.scanning.points.validation.ScanRequestValidator.java

private void validateAnnotations(Map<String, Object> dmodels)
        throws ValidationException, IllegalArgumentException, IllegalAccessException, ScanningException {

    for (String name : dmodels.keySet()) {

        // The model we will validate
        Object model = dmodels.get(name);

        // If the model has an annotated field which points at 
        // a detector, that detector must be in the scan.
        Field[] fields = model.getClass().getDeclaredFields();

        BeanMap beanMap = null; // May need to use newer version of BeanMap in Java9 if it uses setAccessable(true)
        for (Field field : fields) {
            Annotation[] anots = field.getAnnotations();
            for (Annotation annotation : anots) {
                if (annotation instanceof FieldDescriptor) {

                    FieldDescriptor des = (FieldDescriptor) annotation;
                    if (des.device() == DeviceType.RUNNABLE) { // Then its value must be in the devices.

                        if (beanMap == null)
                            beanMap = new BeanMap(model);
                        String reference = beanMap.get(field.getName()).toString();
                        if (!dmodels.containsKey(reference)) {
                            IRunnableDeviceService dservice = ValidatorService.getRunnableDeviceService();
                            if (dservice != null && dservice.getRunnableDevice(reference) != null) {
                                continue;
                            }/*from  w ww.j  a v  a2s. c om*/
                            String label = des.label() != null && des.label().length() > 0 ? des.label()
                                    : field.getName();
                            throw new ModelValidationException("The value of '" + label
                                    + "' references a device (" + reference + ") not a valid device!", model,
                                    field.getName());
                        }
                    }
                }
            }
        }
    }
}

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

public void populate(SessionContext sessionContext, Map from, Object to, Map hintsMap) {
    PersistenceManager pm = sessionContext.getPM();
    if (hintsMap == null) {
        hintsMap = new HashMap();
    }//from   w ww.  j  av a2 s  . c o m
    Map<String, String> expressions = (Map) hintsMap.get("__expressions");
    if (expressions == null)
        expressions = new HashMap();
    BeanMap beanMap = new BeanMap(to);
    String entityName = m_inflector.getEntityName(to.getClass().getSimpleName());
    debug("populate.from:" + from + ",to:" + to + ",BeanMap:" + beanMap + "/hintsMap:" + hintsMap
            + "/entityName:" + entityName);
    if (from == null) {
        return;
    }
    Map permittedFields = sessionContext.getPermittedFields(entityName, "write");
    Iterator<String> it = from.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();
        Object oldValue = beanMap.get(key);
        boolean permitted = m_permissionService.hasAdminRole() || "team".equals(entityName)
                || sessionContext.isFieldPermitted(key, entityName, "write");
        if (!key.startsWith("_") && !permitted) {
            debug("---->populate:field(" + key + ") no write permission");
            continue;
        } else {
            debug("++++>populate:field(" + key + ") write permitted");
        }
        String datatype = null;
        String edittype = null;
        if (!key.startsWith("_")) {
            Map config = (Map) permittedFields.get(key);
            if (config != null) {
                datatype = (String) config.get("datatype");
                edittype = (String) config.get("edittype");
            }
        }

        if (key.equals(STATE_FIELD) && !m_permissionService.hasAdminRole()) {
            continue;
        }
        if ("auto".equals(edittype))
            continue;
        String mode = null;
        Map hm = (Map) hintsMap.get(key);
        if (hm != null) {
            Object m = hm.get("mode");
            if (m != null && m instanceof String) {
                mode = (String) m;
            }
            if (mode == null) {
                m = hm.get("useit");
                if (m != null && m instanceof String) {
                    mode = (String) m;
                }
            }
        }
        if (mode == null) {
            mode = "replace";
        }
        Class clazz = beanMap.getType(key);
        debug("\ttype:" + clazz + "(" + key + "=" + from.get(key) + ")");
        if ("_ignore_".equals(from.get(key))) {
            continue;
        }
        if (clazz == null) {
            debug("\t--- Warning property not found:" + key);
        } else if (clazz.equals(java.util.Date.class)) {
            String value = Utils.getString(from.get(key), beanMap.get(key), mode);
            debug("\tDate found:" + key + "=>" + value);
            Date date = null;
            if (value != null) {
                try {
                    Long val = Long.valueOf(value);
                    date = (Date) ConvertUtils.convert(val, Date.class);
                    debug("\tdate1:" + date);
                } catch (Exception e) {
                    try {
                        DateTime dt = new DateTime(value);
                        date = new Date(dt.getMillis());
                        debug("\tdate2:" + date);
                    } catch (Exception e1) {
                        try {
                            int space = value.indexOf(" ");
                            if (space != -1) {
                                value = value.substring(0, space) + "T" + value.substring(space + 1);
                                DateTime dt = new DateTime(value);
                                date = new Date(dt.getMillis());
                            }
                            debug("\tdate3:" + date);
                        } catch (Exception e2) {
                            debug("\terror setting date:" + e);
                        }
                    }
                }
            }
            debug("\tsetting date:" + date);
            beanMap.put(key, date);
        } else if (clazz.equals(java.util.Map.class)) {
            info("!!!!!!!!!!!!!!!!!!!Map not implemented");
        } else if (clazz.equals(java.util.List.class) || clazz.equals(java.util.Set.class)) {
            boolean isList = clazz.equals(java.util.List.class);
            boolean isSimple = false;
            if (datatype != null && datatype.startsWith("list_")) {
                isSimple = true;
            }
            try {
                Class type = TypeUtils.getTypeForField(to, key);
                debug("type:" + type + " fill with: " + from.get(key) + ",list:" + beanMap.get(key) + "/mode:"
                        + mode);
                Collection valList = isList ? new ArrayList() : new HashSet();
                Object fromVal = from.get(key);
                if (fromVal instanceof String && ((String) fromVal).length() > 0) {
                    info("FromVal is StringSchrott, ignore");
                    continue;
                }
                if (from.get(key) instanceof Collection) {
                    valList = (Collection) from.get(key);
                }
                if (valList == null) {
                    valList = isList ? new ArrayList() : new HashSet();
                }
                Collection toList = (Collection) PropertyUtils.getProperty(to, key);
                debug("toList:" + toList);
                debug("valList:" + valList);
                if (toList == null) {
                    toList = isList ? new ArrayList() : new HashSet();
                    PropertyUtils.setProperty(to, key, toList);
                }
                if ("replace".equals(mode)) {
                    boolean isEqual = false;
                    if (isSimple) {
                        isEqual = Utils.isCollectionEqual(toList, valList);
                        if (!isEqual) {
                            toList.clear();
                        }
                        debug("\tisEqual:" + isEqual);
                    } else {
                        List deleteList = new ArrayList();
                        String namespace = sessionContext.getStoreDesc().getNamespace();
                        for (Object o : toList) {
                            if (type.getName().endsWith(".Team")) {
                                int status = m_teamService.getTeamStatus(namespace, new BeanMap(o), null,
                                        sessionContext.getUserName());
                                debug("populate.replace.teamStatus:" + status + "/"
                                        + new HashMap(new BeanMap(o)));
                                if (status != -1) {
                                    pm.deletePersistent(o);
                                    deleteList.add(o);
                                }
                            } else {
                                pm.deletePersistent(o);
                                deleteList.add(o);
                            }
                        }
                        for (Object o : deleteList) {
                            toList.remove(o);
                        }
                    }
                    debug("populate.replace.toList:" + toList + "/" + type.getName());
                    if (isSimple) {
                        if (!isEqual) {
                            for (Object o : valList) {
                                toList.add(o);
                            }
                        }
                    } else {
                        for (Object o : valList) {
                            Map valMap = (Map) o;
                            Object n = type.newInstance();
                            if (type.getName().endsWith(".Team")) {
                                valMap.remove("id");
                                Object desc = valMap.get("description");
                                Object name = valMap.get("name");
                                Object dis = valMap.get("disabled");
                                String teamid = (String) valMap.get("teamid");
                                Object ti = Utils.getTeamintern(sessionContext, teamid);
                                if (desc == null) {
                                    valMap.put("description", PropertyUtils.getProperty(ti, "description"));
                                }
                                if (name == null) {
                                    valMap.put("name", PropertyUtils.getProperty(ti, "name"));
                                }
                                if (dis == null) {
                                    valMap.put("disabled", false);
                                }
                                pm.makePersistent(n);
                                populate(sessionContext, valMap, n, null);
                                PropertyUtils.setProperty(n, "teamintern", ti);
                            } else {
                                pm.makePersistent(n);
                                populate(sessionContext, valMap, n, null);
                            }
                            debug("populated.add:" + new HashMap(new BeanMap(n)));
                            toList.add(n);
                        }
                    }
                } else if ("remove".equals(mode)) {
                    if (isSimple) {
                        for (Object o : valList) {
                            if (toList.contains(o)) {
                                toList.remove(o);
                            }
                        }
                    } else {
                        for (Object ol : valList) {
                            Map map = (Map) ol;
                            Object o = Utils.listContainsId(toList, map, "teamid");
                            if (o != null) {
                                toList.remove(o);
                                pm.deletePersistent(o);
                            }
                        }
                    }
                } else if ("add".equals(mode)) {
                    if (isSimple) {
                        for (Object o : valList) {
                            toList.add(o);
                        }
                    } else {
                        for (Object ol : valList) {
                            Map map = (Map) ol;
                            Object o = Utils.listContainsId(toList, map, "teamid");
                            if (o != null) {
                                populate(sessionContext, map, o, null);
                            } else {
                                o = type.newInstance();
                                if (type.getName().endsWith(".Team")) {
                                    Object desc = map.get("description");
                                    Object name = map.get("name");
                                    Object dis = map.get("disabled");
                                    String teamid = (String) map.get("teamid");
                                    Object ti = Utils.getTeamintern(sessionContext, teamid);
                                    if (desc == null) {
                                        map.put("description", PropertyUtils.getProperty(ti, "description"));
                                    }
                                    if (name == null) {
                                        map.put("name", PropertyUtils.getProperty(ti, "name"));
                                    }
                                    if (dis == null) {
                                        map.put("disabled", false);
                                    }

                                    pm.makePersistent(o);
                                    populate(sessionContext, map, o, null);
                                    PropertyUtils.setProperty(o, "teamintern", ti);
                                } else {
                                    pm.makePersistent(o);
                                    populate(sessionContext, map, o, null);
                                }
                                toList.add(o);
                            }
                        }
                    }
                } else if ("assign".equals(mode)) {
                    if (!isSimple) {
                        for (Object ol : valList) {
                            Map map = (Map) ol;
                            Object o = Utils.listContainsId(toList, map);
                            if (o != null) {
                                debug("id:" + map + " already assigned");
                            } else {
                                Object id = map.get("id");
                                Boolean assign = Utils.getBoolean(map.get("assign"));
                                Object obj = pm.getObjectById(type, id);
                                if (assign) {
                                    toList.add(obj);
                                } else {
                                    toList.remove(obj);
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                debug("populate.list.failed:" + key + "=>" + from.get(key) + ";" + e);
            }
        } else if (clazz.equals(java.lang.Boolean.class)) {
            try {
                beanMap.put(key, ConvertUtils.convert(from.get(key), Boolean.class));
            } catch (Exception e) {
                debug("populate.boolean.failed:" + key + "=>" + from.get(key) + ";" + e);
            }
        } else if (clazz.equals(java.lang.Double.class)) {
            String value = Utils.getString(from.get(key), beanMap.get(key), mode);
            try {
                beanMap.put(key, Double.valueOf(value));
            } catch (Exception e) {
                debug("populate.double.failed:" + key + "=>" + value + ";" + e);
            }
        } else if (clazz.equals(java.lang.Long.class)) {
            try {
                beanMap.put(key, ConvertUtils.convert(from.get(key), Long.class));
            } catch (Exception e) {
                debug("populate.long.failed:" + key + "=>" + from.get(key) + ";" + e);
            }
        } else if (clazz.equals(java.lang.Integer.class)) {
            debug("Integer:" + ConvertUtils.convert(from.get(key), Integer.class));
            try {
                beanMap.put(key, ConvertUtils.convert(from.get(key), Integer.class));
            } catch (Exception e) {
                debug("populate.integer.failed:" + key + "=>" + from.get(key) + ";" + e);
            }
        } else if ("binary".equals(datatype) || clazz.equals(byte[].class)) {
            InputStream is = null;
            InputStream is2 = null;

            try {
                if (from.get(key) instanceof FileItem) {
                    FileItem fi = (FileItem) from.get(key);
                    String name = fi.getName();
                    byte[] bytes = IOUtils.toByteArray(fi.getInputStream());
                    if (bytes != null) {
                        debug("bytes:" + bytes.length);
                    }
                    beanMap.put(key, bytes);
                    is = fi.getInputStream();
                    is2 = fi.getInputStream();
                } else if (from.get(key) instanceof Map) {
                    Map map = (Map) from.get(key);
                    String storeLocation = (String) map.get("storeLocation");
                    is = new FileInputStream(new File(storeLocation));
                    is2 = new FileInputStream(new File(storeLocation));
                    byte[] bytes = IOUtils.toByteArray(is);
                    if (bytes != null) {
                        debug("bytes2:" + bytes.length);
                    }
                    is.close();
                    beanMap.put(key, bytes);
                    is = new FileInputStream(new File(storeLocation));
                } else if (from.get(key) instanceof String) {
                    String value = (String) from.get(key);
                    if ("ignore".equals(value)) {
                        debug("ignore:");
                        return;
                    }
                    if (value.startsWith("data:")) {
                        int ind = value.indexOf(";base64,");
                        byte b[] = Base64.decode(value.substring(ind + 8));
                        beanMap.put(key, b);
                        is = new ByteArrayInputStream(b);
                        is2 = new ByteArrayInputStream(b);
                    } else {
                        byte b[] = value.getBytes();
                        beanMap.put(key, b);
                        is = new ByteArrayInputStream(b);
                        is2 = new ByteArrayInputStream(b);
                    }
                } else {
                    debug("populate.byte[].no a FileItem:" + key + "=>" + from.get(key));
                    continue;
                }
                Tika tika = new Tika();
                TikaInputStream stream = TikaInputStream.get(is);
                TikaInputStream stream2 = TikaInputStream.get(is2);
                String text = tika.parseToString(is);
                debug("Text:" + text);
                try {
                    beanMap.put("text", text);
                } catch (Exception e) {
                    beanMap.put("text", text.getBytes());
                }
                //@@@MS Hardcoded 
                try {
                    Detector detector = new DefaultDetector();
                    MediaType mime = detector.detect(stream2, new Metadata());
                    debug("Mime:" + mime.getType() + "|" + mime.getSubtype() + "|" + mime.toString());
                    beanMap.put("type", mime.toString());
                    from.put("type", mime.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
                e.printStackTrace();
                debug("populate.byte[].failed:" + key + "=>" + from.get(key) + ";" + e);
            } finally {
                try {
                    is.close();
                    is2.close();
                } catch (Exception e) {
                }
            }
        } else {
            boolean ok = false;
            try {
                Class type = TypeUtils.getTypeForField(to, key);
                if (type != null) {
                    Object o = type.newInstance();
                    boolean hasAnn = type.isAnnotationPresent(PersistenceCapable.class);
                    debug("hasAnnotation:" + hasAnn);
                    if (o instanceof javax.jdo.spi.PersistenceCapable || hasAnn) {
                        Object id = null;
                        try {
                            Object _id = from.get(key);
                            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(o, "id");
                                    id = (idClass.equals(Long.class)) ? Long.valueOf(_id + "") : _id;
                                }
                            }
                        } catch (Exception e) {
                        }
                        if (id != null && !"".equals(id) && !"null".equals(id)) {
                            debug("\tId2:" + id);
                            Object relatedObject = pm.getObjectById(type, id);
                            List<Collection> candidates = TypeUtils.getCandidateLists(relatedObject, to, null);
                            if (candidates.size() == 1) {
                                Collection l = candidates.get(0);
                                debug("list.contains:" + l.contains(to));
                                if (!l.contains(to)) {
                                    l.add(to);
                                }
                            }
                            beanMap.put(key, relatedObject);
                        } else {
                            Object relatedObject = beanMap.get(key);
                            debug("\trelatedObject:" + relatedObject);
                            if (relatedObject != null) {
                                List<Collection> candidates = TypeUtils.getCandidateLists(relatedObject, to,
                                        null);
                                if (candidates.size() == 1) {
                                    Collection l = candidates.get(0);
                                    debug("list.contains:" + l.contains(to));
                                    if (l.contains(to)) {
                                        l.remove(to);
                                    }
                                }
                            }
                            beanMap.put(key, null);
                        }
                        ok = true;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (!ok) {
                String value = Utils.getString(from.get(key), beanMap.get(key), mode);
                // debug("populate:" + key + "=>" + value); 
                // debug("String:" + ConvertUtils.convert(from.get(key), String.class)); 
                try {
                    beanMap.put(key, value);
                } catch (Exception e) {
                    debug("populate.failed:" + key + "=>" + value + ";" + e);
                }
            }
        }
        String expression = expressions.get(key);
        if (!isEmpty(expression)) {
            beanMap.put(key, oldValue);
            Map scriptCache = (Map) sessionContext.getProperty("scriptCache");
            if (scriptCache == null) {
                scriptCache = new HashMap();
                sessionContext.setProperty("scriptCache", scriptCache);
            }
            Object result = Utils.eval(expression, beanMap, scriptCache);
            try {
                if ("string".equals(datatype) && !(result instanceof String)) {
                    beanMap.put(key, ConvertUtils.convert(result, String.class));
                } else {
                    beanMap.put(key, result);
                }
            } catch (Exception e) {
                info("Cannot set value for(" + key + "):" + result + "/" + e.getMessage());
            }
        }
    }
}

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

private void getBinary(SessionContext sessionContext, Object obj, boolean hasTeamSecurity, Map permittedFields,
        HttpServletResponse resp) throws Exception {
    Map<String, Object> map = new HashMap();
    BeanMap beanMap = new BeanMap(obj);
    if (beanMap.getType("_team_list") != null) {
        Set<Object> _teams = (Set<Object>) beanMap.get("_team_list");
        if (hasTeamSecurity && !m_teamService.checkTeams(sessionContext.getStoreDesc().getNamespace(),
                sessionContext.getUserName(), sessionContext.getUserProperties(), _teams)) {
            info("getPropertyMap.notAllowed:" + _teams);
            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }//from  ww w  . j  a v a 2  s  . co m
    }
    if (PropertyUtils.isReadable(obj, "content")) {
        byte[] c = (byte[]) PropertyUtils.getProperty(obj, "content");
        if (PropertyUtils.isReadable(obj, "type")) {
            String t = (String) PropertyUtils.getProperty(obj, "type");
            resp.setContentType(t);
        }
        if (PropertyUtils.isReadable(obj, "filename")) {
            String t = (String) PropertyUtils.getProperty(obj, "filename");
            resp.addHeader("Content-Disposition", "inline;filename=" + t);
        }
        if (c != null) {
            debug("getBinary:length:" + c.length);
            IOUtils.write(c, resp.getOutputStream());
        }
        resp.setStatus(HttpServletResponse.SC_OK);
        resp.getOutputStream().close();
    }
}