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.ms123.common.data.JdoLayerImpl.java

private Map<String, Object> getPropertyMap(SessionContext sessionContext, Object obj, boolean hasTeamSecurity,
        Map permittedFields, List<String> fieldsArray) 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");
        debug("getPropertyMap.hasTeamSecurity:" + hasTeamSecurity);
        if (hasTeamSecurity && !m_teamService.checkTeams(sessionContext.getStoreDesc().getNamespace(),
                sessionContext.getUserName(), sessionContext.getUserProperties(), _teams)) {
            debug("getPropertyMap.notAllowed:" + _teams);
            return null;
        }//from   ww  w  . j  a  v  a  2  s.c o  m
    }
    map.put("id", beanMap.get("id"));
    if (fieldsArray != null) {
        for (String field : fieldsArray) {
            if (beanMap.getType(field) == null) {
                m_logger.error("getPropertyMap.property_not_found:" + field);
                continue;
            }
            Map cm = (Map) permittedFields.get(field);
            if (cm == null) {
                continue;
            }
            try {
                Class type = beanMap.getType(field);
                Object value = beanMap.get(field);
                map.put(field, prepareValue(sessionContext, beanMap, value, (String) cm.get("datatype")));
            } catch (Exception e) {
                m_logger.error("getPropertyMap.field:" + field + "," + e);
                e.printStackTrace();
            }
        }
    } else {
        Iterator itk = beanMap.keyIterator();
        while (itk.hasNext()) {
            String field = (String) itk.next();
            Map cm = (Map) permittedFields.get(field);
            if (cm == null) {
                continue;
            }

            if (STATE_FIELD.equals(cm.get("id")) && !m_permissionService.hasAdminRole()) {
                continue;
            }
            try {
                Class type = beanMap.getType(field);
                debug("Type:" + type + "/" + cm.get("datatype") + "/field:" + field);
                Object value = beanMap.get(field);
                if ("binary".equals(cm.get("datatype"))) {
                    continue;
                }
                if ("fulltext".equals(cm.get("datatype"))) {
                    continue;
                }
                if ("set".equals(cm.get("datatype"))) {
                    continue;
                }
                if (type.equals(java.util.List.class) || type.equals(java.util.Set.class)) {
                    continue;
                }
                map.put(field, prepareValue(sessionContext, beanMap, value, (String) cm.get("datatype")));
            } catch (Exception e) {
                m_logger.error("getPropertyMap.field:" + field + "," + e);
                e.printStackTrace();
            }
        }
    }
    return map;
}

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

private void setRelatedToFields(Map targetMap, String[] colNames, BeanMap beanMap, Object value) {
    BeanMap relatedTo = new BeanMap(value);
    Iterator<String> it = relatedTo.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();/*from  w w  w.j a v a  2s  .  c  om*/
        if (key.startsWith("_"))
            continue;
        if (key.equals("class"))
            continue;
        if (key.equals("id"))
            continue;
        if (key.equals("name"))
            continue;
        if (colNames != null && !arrayContains(colNames, key))
            continue;
        if (beanMap != null && !beanMap.containsKey(key))
            continue;
        Class type = relatedTo.getType(key);
        if (type.equals(List.class) || type.equals(Set.class))
            continue;
        debug("\tsetRelatedToFields.key:" + key + "=" + relatedTo.get(key) + "/" + relatedTo.getType(key));
        targetMap.put(key, relatedTo.get(key));
    }
}

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

private Object prepareValue(SessionContext sc, BeanMap beanMap, Object value, String dt) throws Exception {
    if (value == null) {
        if (dt.startsWith("array/string")) {
            return new ArrayList();
        } else {/*w w  w .  j a v a  2 s  . co m*/
            return null;
        }
    }
    if (value instanceof java.util.Date) {
        return String.valueOf(((Date) value).getTime());
    } else if (value instanceof java.lang.Boolean) {
        return value;
    } else if (value instanceof java.lang.Double) {
        return value;
    } else if (value instanceof java.lang.Integer) {
        return value;
    } else if (dt.startsWith("related")) {
        Object ret = "";
        try {
            Object id = (Object) PropertyUtils.getProperty(value, "id");
            ret = id;
            String name = getRecordTitle(value);
            ret = id + "/" + name;
            ret = getTitle(sc, m_inflector.getEntityName(value.getClass().getSimpleName()), new BeanMap(value),
                    id, (String) ret);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    } else if (dt.startsWith("array/string")) {
        List arr = new ArrayList();
        String[] vals = String.valueOf(value).split(",");
        for (int i = 0; i < vals.length; i++) {
            String v = vals[i];
            arr.add(v);
        }
        return arr;
    } else if (dt.startsWith("map_")) {
        return value;
    } else if (dt.startsWith("list_")) {
        return value;
    } else if (dt.startsWith("array/")) {
        String t = dt.substring(dt.indexOf("/") + 1);
        if ("team".equals(t)) {
            t = "_team_list";
        }
        List arr = new ArrayList();
        Collection<Object> _teams = (Collection) beanMap.get(t);
        for (Object team : _teams) {
            BeanMap bm = new BeanMap(team);
            Iterator itk = bm.keyIterator();
            Map map = new HashMap();
            while (itk.hasNext()) {
                String field = (String) itk.next();
                if ("class".equals(field)) {
                    continue;
                }
                Object val = bm.get(field);
                map.put(field, prepareValue(sc, bm, val, ""));
            }
            arr.add(map);
        }
        return arr;
    } else {
        return String.valueOf(value);
    }
}

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

private Object copyObject(Object o) throws Exception {
    Map n = new HashMap();
    BeanMap beanMap = new BeanMap(o);
    Iterator itv = beanMap.keyIterator();
    while (itv.hasNext()) {
        String prop = (String) itv.next();
        if ("class".equals(prop)) {
            continue;
        }/*from ww  w .  j av  a  2s . c  om*/
        Object value = beanMap.get(prop);
        if ("_team_list".equals(prop)) {
            Set teamSet = new HashSet();
            Set teams = (Set) beanMap.get(prop);
            for (Object team : teams) {
                Map t = new HashMap(new BeanMap(team));
                t.remove("teamintern");
                teamSet.add(t);
            }
            value = teamSet;
        } else if (value instanceof Collection) {
            continue;
        } else {
            java.lang.reflect.Field field = o.getClass().getDeclaredField(prop);
            if (field != null) {
                if (field.isAnnotationPresent(Element.class) || field.isAnnotationPresent(Persistent.class)) {
                    continue;
                }
            }
        }
        n.put(prop, value);
    }
    return n;
}

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

public static void populate(SessionContext sessionContext, Map sourceMap, Object destinationObj, Map hintsMap) {
    PersistenceManager pm = sessionContext.getPM();
    if (hintsMap == null) {
        hintsMap = new HashMap();
    }// w  ww .  j  a va2 s.c o m
    boolean noUpdate = Utils.getBoolean(hintsMap, "noUpdate", false);
    BeanMap destinationMap = new BeanMap(destinationObj);
    String entityName = m_inflector.getEntityName(destinationObj.getClass().getSimpleName());
    debug("populate.sourceMap:" + sourceMap + ",destinationObj:" + destinationObj + ",destinationMap:"
            + destinationMap + "/hintsMap:" + hintsMap + "/entityName:" + entityName);
    if (sourceMap == null) {
        return;
    }
    debug("populate(" + entityName + ") is a persistObject:" + javax.jdo.JDOHelper.isPersistent(destinationObj)
            + "/" + javax.jdo.JDOHelper.isNew(destinationObj));
    if (sourceMap.get("id") != null) {
        debug("populate(" + entityName + ") has id:" + sourceMap.get("id"));
        return;
    }
    Map permittedFields = sessionContext.getPermittedFields(entityName, "write");
    Iterator<String> it = sourceMap.keySet().iterator();
    while (it.hasNext()) {
        String propertyName = it.next();
        boolean permitted = sessionContext.getPermissionService().hasAdminRole() || "team".equals(entityName)
                || sessionContext.isFieldPermitted(propertyName, entityName, "write");
        if (!propertyName.startsWith("_") && !permitted) {
            debug("---->populate:field(" + propertyName + ") no write permission");
            continue;
        } else {
            debug("++++>populate:field(" + propertyName + ") write permitted");
        }
        String datatype = null;
        String edittype = null;
        if (!propertyName.startsWith("_")) {
            Map config = (Map) permittedFields.get(propertyName);
            if (config != null) {
                datatype = (String) config.get("datatype");
                edittype = (String) config.get("edittype");
            }
        }
        if (propertyName.equals(STATE_FIELD) && !sessionContext.getPermissionService().hasAdminRole()) {
            continue;
        }
        if ("auto".equals(edittype))
            continue;

        String mode = null;
        Map hm = (Map) hintsMap.get(propertyName);
        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 propertyClass = destinationMap.getType(propertyName);
        debug("\ttype:" + propertyClass + "(" + propertyName + "=" + sourceMap.get(propertyName) + ")");
        if ("_ignore_".equals(sourceMap.get(propertyName))) {
            continue;
        }
        if (propertyClass == null) {
            debug("\t--- Warning property not found:" + propertyName);
        } else if (propertyClass.equals(java.util.Date.class)) {
            String value = Utils.getString(sourceMap.get(propertyName), destinationMap.get(propertyName), mode);
            debug("\tDate found:" + propertyName + "=>" + 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);
            destinationMap.put(propertyName, date);
        } else if (propertyClass.equals(java.util.Map.class)) {
            info("!!!!!!!!!!!!!!!!!!!Map not implemented");
        } else if (propertyClass.equals(java.util.List.class) || propertyClass.equals(java.util.Set.class)) {
            boolean isList = propertyClass.equals(java.util.List.class);
            boolean isSimple = false;
            if (datatype != null && datatype.startsWith("list_")) {
                isSimple = true;
            }
            try {
                Class propertyType = TypeUtils.getTypeForField(destinationObj, propertyName);
                debug("propertyType:" + propertyType + " fill with: " + sourceMap.get(propertyName) + ",list:"
                        + destinationMap.get(propertyName) + "/mode:" + mode);
                Collection sourceList = isList ? new ArrayList() : new HashSet();

                Object fromVal = sourceMap.get(propertyName);
                if (fromVal instanceof String && ((String) fromVal).length() > 0) {
                    info("FromVal is StringSchrott, ignore");
                    continue;
                }

                if (sourceMap.get(propertyName) instanceof Collection) {
                    sourceList = (Collection) sourceMap.get(propertyName);
                }
                if (sourceList == null) {
                    sourceList = isList ? new ArrayList() : new HashSet();
                }
                Collection destinationList = (Collection) PropertyUtils.getProperty(destinationObj,
                        propertyName);
                debug("destinationList:" + destinationList);
                debug("sourceList:" + sourceList);
                if (destinationList == null) {
                    destinationList = isList ? new ArrayList() : new HashSet();
                    PropertyUtils.setProperty(destinationObj, propertyName, destinationList);
                }
                if ("replace".equals(mode)) {
                    boolean isEqual = false;
                    if (isSimple) {
                        isEqual = Utils.isCollectionEqual(destinationList, sourceList);
                        if (!isEqual) {
                            destinationList.clear();
                        }
                        debug("\tisEqual:" + isEqual);
                    } else {
                        List deleteList = new ArrayList();
                        String namespace = sessionContext.getStoreDesc().getNamespace();
                        for (Object o : destinationList) {
                            if (propertyType.getName().endsWith(".Team")) {
                                int status = sessionContext.getTeamService().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) {
                            destinationList.remove(o);
                        }
                    }
                    debug("populate.replace.destinationList:" + destinationList + "/" + propertyType.getName());
                    if (isSimple) {
                        if (!isEqual) {
                            for (Object o : sourceList) {
                                destinationList.add(o);
                            }
                        }
                    } else {
                        for (Object o : sourceList) {
                            Map childSourceMap = (Map) o;
                            Object childDestinationObj = propertyType.newInstance();
                            if (propertyType.getName().endsWith(".Team")) {
                                childSourceMap.remove("id");
                                Object desc = childSourceMap.get("description");
                                Object name = childSourceMap.get("name");
                                Object dis = childSourceMap.get("disabled");
                                String teamid = (String) childSourceMap.get("teamid");
                                Object ti = Utils.getTeamintern(sessionContext, teamid);
                                if (desc == null) {
                                    childSourceMap.put("description",
                                            PropertyUtils.getProperty(ti, "description"));
                                }
                                if (name == null) {
                                    childSourceMap.put("name", PropertyUtils.getProperty(ti, "name"));
                                }
                                if (dis == null) {
                                    childSourceMap.put("disabled", false);
                                }
                                pm.makePersistent(childDestinationObj);
                                populate(sessionContext, childSourceMap, childDestinationObj, hintsMap);
                                PropertyUtils.setProperty(childDestinationObj, "teamintern", ti);
                            } else {
                                pm.makePersistent(childDestinationObj);
                                populate(sessionContext, childSourceMap, childDestinationObj, hintsMap);
                            }
                            debug("populated.add:" + new HashMap(new BeanMap(childDestinationObj)));
                            destinationList.add(childDestinationObj);
                        }
                    }
                } else if ("remove".equals(mode)) {
                    if (isSimple) {
                        for (Object o : sourceList) {
                            if (destinationList.contains(o)) {
                                destinationList.remove(o);
                            }
                        }
                    } else {
                        for (Object ol : sourceList) {
                            Map childSourceMap = (Map) ol;
                            Object o = Utils.listContainsId(destinationList, childSourceMap, "teamid");
                            if (o != null) {
                                destinationList.remove(o);
                                pm.deletePersistent(o);
                            }
                        }
                    }
                } else if ("add".equals(mode)) {
                    if (isSimple) {
                        for (Object o : sourceList) {
                            destinationList.add(o);
                        }
                    } else {
                        for (Object ol : sourceList) {
                            Map childSourceMap = (Map) ol;
                            Object childDestinationObj = Utils.listContainsId(destinationList, childSourceMap,
                                    "teamid");
                            if (childDestinationObj != null) {
                                populate(sessionContext, childSourceMap, childDestinationObj, hintsMap);
                            } else {
                                childDestinationObj = propertyType.newInstance();
                                if (propertyType.getName().endsWith(".Team")) {
                                    Object desc = childSourceMap.get("description");
                                    Object name = childSourceMap.get("name");
                                    Object dis = childSourceMap.get("disabled");
                                    String teamid = (String) childSourceMap.get("teamid");
                                    Object ti = Utils.getTeamintern(sessionContext, teamid);
                                    if (desc == null) {
                                        childSourceMap.put("description",
                                                PropertyUtils.getProperty(ti, "description"));
                                    }
                                    if (name == null) {
                                        childSourceMap.put("name", PropertyUtils.getProperty(ti, "name"));
                                    }
                                    if (dis == null) {
                                        childSourceMap.put("disabled", false);
                                    }
                                    pm.makePersistent(childDestinationObj);
                                    populate(sessionContext, childSourceMap, childDestinationObj, hintsMap);
                                    PropertyUtils.setProperty(childDestinationObj, "teamintern", ti);
                                } else {
                                    pm.makePersistent(childDestinationObj);
                                    populate(sessionContext, childSourceMap, childDestinationObj, hintsMap);
                                }
                                destinationList.add(childDestinationObj);
                            }
                        }
                    }
                } else if ("assign".equals(mode)) {
                    if (!isSimple) {
                        for (Object ol : sourceList) {
                            Map childSourceMap = (Map) ol;
                            Object childDestinationObj = Utils.listContainsId(destinationList, childSourceMap);
                            if (childDestinationObj != null) {
                                debug("id:" + childSourceMap + " already assigned");
                            } else {
                                Object id = childSourceMap.get("id");
                                Boolean assign = Utils.getBoolean(childSourceMap.get("assign"));
                                Object obj = pm.getObjectById(propertyType, id);
                                if (assign) {
                                    destinationList.add(obj);
                                } else {
                                    destinationList.remove(obj);
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                debug("populate.list.failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e);
            }
        } else if (propertyClass.equals(java.lang.Boolean.class)) {
            try {
                destinationMap.put(propertyName,
                        ConvertUtils.convert(sourceMap.get(propertyName), Boolean.class));
            } catch (Exception e) {
                debug("populate.boolean.failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e);
            }
        } else if (propertyClass.equals(java.lang.Double.class)) {
            String value = Utils.getString(sourceMap.get(propertyName), destinationMap.get(propertyName), mode);
            try {
                destinationMap.put(propertyName, Double.valueOf(value));
            } catch (Exception e) {
                debug("populate.double.failed:" + propertyName + "=>" + value + ";" + e);
            }
        } else if (propertyClass.equals(java.lang.Long.class)) {
            try {
                destinationMap.put(propertyName, ConvertUtils.convert(sourceMap.get(propertyName), Long.class));
            } catch (Exception e) {
                debug("populate.long.failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e);
            }
        } else if (propertyClass.equals(java.lang.Integer.class)) {
            debug("Integer:" + ConvertUtils.convert(sourceMap.get(propertyName), Integer.class));
            try {
                destinationMap.put(propertyName,
                        ConvertUtils.convert(sourceMap.get(propertyName), Integer.class));
            } catch (Exception e) {
                debug("populate.integer.failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e);
            }
        } else if ("binary".equals(datatype) || propertyClass.equals(byte[].class)) {
            InputStream is = null;
            InputStream is2 = null;
            try {
                if (sourceMap.get(propertyName) instanceof FileItem) {
                    FileItem fi = (FileItem) sourceMap.get(propertyName);
                    String name = fi.getName();
                    byte[] bytes = IOUtils.toByteArray(fi.getInputStream());
                    if (bytes != null) {
                        debug("bytes:" + bytes.length);
                    }
                    destinationMap.put(propertyName, bytes);
                    is = fi.getInputStream();
                    is2 = fi.getInputStream();
                } else if (sourceMap.get(propertyName) instanceof Map) {
                    Map map = (Map) sourceMap.get(propertyName);
                    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();
                    destinationMap.put(propertyName, bytes);
                    is = new FileInputStream(new File(storeLocation));
                } else if (sourceMap.get(propertyName) instanceof String) {
                    String value = (String) sourceMap.get(propertyName);
                    if (value.startsWith("data:")) {
                        int ind = value.indexOf(";base64,");
                        byte b[] = Base64.decode(value.substring(ind + 8));
                        destinationMap.put(propertyName, b);
                        is = new ByteArrayInputStream(b);
                        is2 = new ByteArrayInputStream(b);
                    } else {
                    }
                } else {
                    debug("populate.byte[].no a FileItem:" + propertyName + "=>" + sourceMap.get(propertyName));
                    continue;
                }
                Tika tika = new Tika();
                TikaInputStream stream = TikaInputStream.get(is);
                TikaInputStream stream2 = TikaInputStream.get(is2);
                String text = tika.parseToString(is);
                debug("Text:" + text);
                try {
                    destinationMap.put("text", text);
                } catch (Exception e) {
                    destinationMap.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());
                    destinationMap.put("type", mime.toString());
                    sourceMap.put("type", mime.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
                e.printStackTrace();
                debug("populate.byte[].failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e);
            } finally {
                try {
                    is.close();
                    is2.close();
                } catch (Exception e) {
                }
            }
        } else {
            boolean ok = false;
            try {
                Class propertyType = TypeUtils.getTypeForField(destinationObj, propertyName);
                debug("propertyType:" + propertyType + "/" + propertyName);
                if (propertyType != null) {
                    boolean hasAnn = propertyType.isAnnotationPresent(PersistenceCapable.class);
                    debug("hasAnnotation:" + hasAnn);
                    if (propertyType.newInstance() instanceof javax.jdo.spi.PersistenceCapable || hasAnn) {
                        handleRelatedTo(sessionContext, sourceMap, propertyName, destinationMap, destinationObj,
                                propertyType);
                        Object obj = sourceMap.get(propertyName);
                        if (obj != null && obj instanceof Map) {
                            Map childSourceMap = (Map) obj;
                            Object childDestinationObj = destinationMap.get(propertyName);
                            if (childDestinationObj == null) {
                                childDestinationObj = propertyType.newInstance();
                                destinationMap.put(propertyName, childDestinationObj);
                            }
                            populate(sessionContext, childSourceMap, childDestinationObj, hintsMap);
                        } else {
                            if (obj == null) {
                                destinationMap.put(propertyName, null);
                            }
                        }
                        ok = true;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (!ok) {
                String value = Utils.getString(sourceMap.get(propertyName), destinationMap.get(propertyName),
                        mode);
                try {
                    if (noUpdate) {
                        if (Utils.isEmptyObj(destinationMap.get(propertyName))) {
                            destinationMap.put(propertyName, value);
                        }
                    } else {
                        destinationMap.put(propertyName, value);
                    }
                } catch (Exception e) {
                    debug("populate.failed:" + propertyName + "=>" + value + ";" + e);
                }
            }
        }
    }
}

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);/*from w w w. j a v a2 s.co  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.ms123.common.libhelper.Utils.java

public static Map copyObject(Object o) throws Exception {
    Map n = new HashMap();
    BeanMap beanMap = new BeanMap(o);
    Iterator itv = beanMap.keyIterator();
    while (itv.hasNext()) {
        String prop = (String) itv.next();
        if ("class".equals(prop)) {
            continue;
        }/*www .  java2  s. c o m*/
        Object value = beanMap.get(prop);
        if ("_team_list".equals(prop)) {
            Set teamSet = new HashSet();
            Set teams = (Set) beanMap.get(prop);
            if (teams != null) {
                for (Object team : teams) {
                    Map t = new HashMap(new BeanMap(team));
                    t.remove("teamintern");
                    teamSet.add(t);
                }
            }
            value = teamSet;
        } else if (value instanceof Collection) {
            continue;
        } else {
            java.lang.reflect.Field field = o.getClass().getDeclaredField(prop);
            if (field != null) {
                if (!field.isAnnotationPresent(PrimaryKey.class) && (field.isAnnotationPresent(Element.class)
                        || field.isAnnotationPresent(Persistent.class))) {
                    continue;
                }
            }
        }
        n.put(prop, value);
    }
    return n;
}

From source file:org.ms123.common.utils.TypeUtils.java

public static List<Collection> getCandidateLists(Object related, Object to, String parentName) {
    List<Collection> list = new ArrayList<Collection>();
    Object o = null;//from   w w  w. j  a  v a 2 s.com
    try {
        BeanMap beanMap = new BeanMap(related);
        Iterator itv = beanMap.keyIterator();
        while (itv.hasNext()) {
            String prop = (String) itv.next();
            if (List.class.equals(beanMap.getType(prop)) || Set.class.equals(beanMap.getType(prop))) {
                Class lt = TypeUtils.getTypeForField(related, prop);
                if (lt.equals(to.getClass())) {
                    list.add((Collection) beanMap.get(prop));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list;
}

From source file:org.mule.modules.clarizen.DefaultClarizenClient.java

/**
 * Extracts the attributes from a bean/*w  ww . j a  v  a  2 s.c  o  m*/
 * 
 * @param entity
 * @return a list of FieldValue objects 
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private List<FieldValue> getFieldValuesFromBean(Object entity) {
    List<FieldValue> fields = new ArrayList<FieldValue>();

    //Gets the Bean properties
    BeanMap beanMap = new BeanMap(entity);
    String propertyName;
    Object fieldValue;
    Iterator keyIterator = beanMap.keySet().iterator();

    while (keyIterator.hasNext()) {
        propertyName = (String) keyIterator.next();
        fieldValue = beanMap.get(propertyName);

        if (fieldValue == null) {
            continue;
        }

        //adds customFields
        if (propertyName.equalsIgnoreCase("customFields")) {
            fields.addAll((List<FieldValue>) fieldValue);
            continue;
        }

        //Convert attributes into GenericEntity
        if (isAttributeAnEntity(fieldValue.getClass()) || isAnEntityId(fieldValue.getClass(), propertyName)) {
            fieldValue = toGenericEntity(fieldValue);
        }

        if (!propertyName.equalsIgnoreCase("class") && !propertyName.equalsIgnoreCase("id")) {
            fields.add(helper.createFieldValue(propertyName, fieldValue));
        }
    }

    return fields;
}