List of usage examples for org.apache.commons.beanutils BeanMap keyIterator
public Iterator keyIterator()
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 w w .j a v a 2s .c o m*/ Iterator i = bm.keyIterator(); while (i.hasNext()) { key = (String) i.next(); put(prefix + "." + key, bm.get(key)); } }
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 . jav a 2s . co m*/ } 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: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 w ww. j a va 2s.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 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 . c o 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 a va2 s.co m*/ 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.query.BasicSelectBuilder.java
public List<String> getProjectionFromClass(String clazz, String alias) { clazz = m_inflector.getClassName(clazz); List<String> list = new ArrayList<String>(); Object o = null;/* w w w .j av a 2 s . c o m*/ try { Class c = m_queryBuilder.getClass(clazz); o = c.newInstance(); BeanMap beanMap = new BeanMap(o); Iterator itv = beanMap.keyIterator(); String komma = ""; while (itv.hasNext()) { String prop = (String) itv.next(); boolean isRelatedTo = false; try { Field field = o.getClass().getDeclaredField(prop); if (field != null) { isRelatedTo = field.isAnnotationPresent(RelatedTo.class); } } catch (Exception e) { } debug("\tName:" + prop + " -> " + beanMap.getType(prop) + "," + isRelatedTo); if (clazz.equals("Document") && prop.equals("text")) { continue; } if (!isAdmin() && STATE_FIELD.equals(prop)) { continue; } Class type = beanMap.getType(prop); if ((TypeUtils.isPrimitiveType(type) && !type.equals(byte[].class)) || isRelatedTo) { if (alias != null) { list.add(alias + "." + prop); } else { list.add(prop); } } } } catch (Exception e) { e.printStackTrace(); } if (alias != null && !alias.startsWith("v_")) { m_selectorList.add(alias); } debug("Projection for " + clazz + ":" + list); debug("Projection.m_selectorList:" + m_selectorList); return list; }
From source file:org.ms123.common.entity.BaseEntityServiceImpl.java
protected List<Object[]> getSubEntityFromClass(StoreDesc sdesc, Class clazz) { List<Object[]> list = new ArrayList<Object[]>(); if (clazz == null) { return list; }/*from www .j a v a 2s .co m*/ try { Object o = clazz.newInstance(); BeanMap beanMap = new BeanMap(o); Iterator itv = beanMap.keyIterator(); while (itv.hasNext()) { String prop = (String) itv.next(); if ("class".equals(prop)) { continue; } boolean isRelatedTo = false; boolean isDependent = false; try { java.lang.reflect.Field field = o.getClass().getDeclaredField(prop); if (field != null) { isRelatedTo = field.isAnnotationPresent(RelatedTo.class); if (field.isAnnotationPresent(Element.class) || field.isAnnotationPresent(Persistent.class)) { isDependent = isDependent(field); } } } catch (Exception e) { } debug("getSubEntityFromClass:" + prop); if (!TypeUtils.isPrimitiveType(beanMap.getType(prop)) && !"teamintern".equals(prop)) { Class type = TypeUtils.getTypeForField(o, prop); if (type != null && !TypeUtils.isPrimitiveType(type)) { Object[] s = new Object[4]; s[0] = type; s[1] = prop; s[2] = beanMap.getType(prop); s[3] = isDependent; list.add(s); } } } } catch (Exception e) { e.printStackTrace(); } return list; }
From source file:org.ms123.common.entity.BaseEntityServiceImpl.java
private List<Map> getAutoGenFields(StoreDesc sdesc, List<Map> metaFields, String entityName) throws Exception { String namespace = sdesc.getNamespace(); debug("getAutoGenFields:" + sdesc + "/" + entityName); Map<String, Map> fieldMap = toMap(metaFields, "name"); String clazz = m_inflector.getClassName(entityName); Class c = null;/*from w ww . j ava 2 s. c o m*/ try { c = m_nucleusService.getClass(sdesc, clazz); } catch (Exception e) { } debug("c:" + c); List<Map> retList = new ArrayList(); if (c == null) { return retList; } BeanMap beanMap = new BeanMap(c.newInstance()); Iterator itv = beanMap.keyIterator(); while (itv.hasNext()) { String prop = (String) itv.next(); if ("class".equals(prop)) { continue; } Map<String, Object> map = null; if (fieldMap.get(prop) != null) { continue; } else { // Autogen field map = getDefaultField(prop); } if (map == null) { continue; } retList.add(map); } return retList; }
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; }/*from w w w . j a v a 2 s . c om*/ 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 a2s . co m*/ 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; }