public void setProperties(PoolProperties props) { if(null != props) { Beans.copyProperties(props, this); } }
@Override public Map<String, Object> toMap() { Map<String,Object> props = Beans.toMap(raw); if(null != map) { props.putAll(map); } return props; } }
@SuppressWarnings({ "unchecked", "rawtypes" }) public Map<String, Object> toMap(Object object) throws InvalidParametersException { if(null == object){ throw new InvalidParameterException("Cannot convert null to map"); } if(object instanceof Map){ return ((Map)object); }else if(object instanceof Params){ return ((Params)object).map(); } if(Beans.isSimpleProperty(object.getClass())){ throw new InvalidParameterException("Cannot convert value of simple type '" + object.getClass().getName() + "' to map"); } return Beans.toMap(object); }
protected static Object getNestedProperty(BeanType beanType,Object bean,BeanProperty bp,String nestedProperty){ Class<?> nestedBeanClass = bp.getType(); if(Map.class.isAssignableFrom(nestedBeanClass)){ return getNestedMapProperty(beanType, nestedBeanClass, bp, nestedProperty); } Object nestedBean = bp.getValue(bean); if(null == nestedBean){ return null; } return getNestableProperty(BeanType.of(nestedBeanClass), nestedBean, nestedProperty); }
protected static boolean isBeanParameters(Class<?> cls){ if(Iterable.class.isAssignableFrom(cls)){ return false; } if(Map.class.isAssignableFrom(cls)){ return false; } if(Beans.isSimpleProperty(cls)){ return false; } if(cls.equals(Object.class)){ return false; } return true; }
return null; }else{ return getNestableProperty(nestedBean, property.substring(dotIndex+1)); }else{ int arrayIndex = Integer.parseInt(property.substring(index1 + 1, property.length() - 2)); return getArrayProperty(nestedBean, arrayIndex);
public static Object getNestableProperty(Object bean,String property){ if(bean instanceof Map){ return getNestableProperty((Map)bean, property); }else if(bean instanceof DynaBean){ return getNestableProperty(((DynaBean) bean).getProperties(), property); }else{ return getNestableProperty(BeanType.of(bean.getClass()), bean, property); } }
return getNestedProperty(beanType, bean, bp, property.substring(dotIndex+1)); }else if(property.charAt(property.length() - 1) == ']'){ int index1 = property.indexOf('['); }else{ int arrayIndex = Integer.parseInt(property.substring(index1 + 1, property.length() - 2)); return getArrayProperty(nestedBean, arrayIndex);
private List<KV> flat(){ List<KV> flat = new ArrayList<>(); list.forEach(kv -> { String key = kv.key; Object value = kv.value; if(value == null || Beans.isSimpleProperty(value.getClass())){ flat.add(new KV(key,value)); }else { JsonObject json = JsonObject.of(JSON.decodeMap(JSON.encode(value))); addFlatList(key,json,flat); } }); return flat; }
protected static Object getNestedMapProperty(BeanType beanType,Object bean,BeanProperty bp,String nestedProperty) { Map map = (Map)bp.getValue(bean); if(null == map){ return null; } if(map.containsKey(nestedProperty)){ return map.get(nestedProperty); } return getNestableProperty(map,nestedProperty); }
public Map<String, String> hencode(Object o) { Map<String, Object> map = Beans.toMap(o); Map<String, String> hash = new LinkedHashMap<>(map.size()); map.forEach((k,v) -> { hash.put(k, encode(v)); }); return hash; }
public static <T> T copyNew(T from) { if(null == from) { return null; } T to = (T)Reflection.newInstance(from.getClass()); copyProperties(from, to); return to; }
private void addFlatList(String key, JsonObject json, List<KV> flat){ json.forEachProperty((s,o) ->{ if(null == o){ flat.add(new KV(key+"."+s,null)); return; } if(Beans.isSimpleProperty(o.getClass())){ flat.add(new KV(key+"."+s,o)); return; } if(o.getClass().isArray()){ Object[] arrays = (Object[])o; for (int i = 0; i < arrays.length; i ++){ addFlatList(key+"." + s + "["+i+"]",json.getObject(s),flat); } return; } if(o instanceof List){ List arrays = (List) o; for (int i = 0; i < arrays.size(); i ++){ addFlatList(key+"." + s + "["+i+"]",json.getObject(s),flat); } return; } addFlatList(key+"."+s,json.getObject(s),flat); }); } }
protected Object resolveVariableProperty(String key,String variable){ int dotIndex = key.indexOf('.'); if(dotIndex == Arrays2.INDEX_NOT_FOUND){ return null; } String prefix = key.substring(0,dotIndex); VariableDefinition vd = variables.get(prefix); if(null == vd){ return null; }else{ Object value = resolveVariable(vd, null); if(null == value){ return null; }else if(value instanceof PropertyGetter){ return ((PropertyGetter) value).getProperty(variable.substring(dotIndex + 1)); }else{ return Beans.getNestableProperty(value,variable.substring(dotIndex + 1)); } } }
public int update(Object record, Object id) { if(null == id) { return dao.update(em, record); }else { return dao.update(em, id, Beans.toMap(record)); } }
@Override public AuthzClient loadClient(String clientId) { AuthzClient authzClient = clients.get(clientId); SimpleAuthzClient client = new SimpleAuthzClient(); Beans.copyProperties(authzClient,client); return client; }
if(Beans.isSimpleProperty(beanType)){ return null; if(Beans.isSimpleProperty(beanType)){ return null;
@Override public int executeNamedUpdate(String sqlKey, Object bean) { return ensureGetSqlCommand(sqlKey).executeUpdate(simpleSqlContext, Beans.toMap(bean)); }
public MetaFormat copyNew() { MetaFormat n = new MetaFormat(); Beans.copyProperties(this, n); return n; }
public static Object[] getIdArgs(EntityMapping em, Object id) { if(id instanceof Object[]) { return (Object[])id; } if(id instanceof Collection) { return ((Collection)id).toArray(); } if(em.getKeyColumnNames().length > 1) { Map map; if(id instanceof Map) { map = (Map)id; }else { map = Beans.toMap(id); } List<Object> args = new ArrayList<>(); for(String name : em.getKeyFieldNames()) { args.add(map.get(name)); } return args.toArray(); }else { return new Object[]{id}; } }