ParameterizedType pType = (ParameterizedType) type;
Type keyType = pType.getActualTypeArguments()[0];
Class keyClass = null;
if(keyType instanceof Class) keyClass = (Class)keyType;
if(keyType instanceof ParameterizedType) keyClass = (Class)((ParameterizedType)keyType).getRawType();
if(keyClass==null) throw new RePresentationException("Cant find key parameter for Map : " + keyType.toString());
Type valType = pType.getActualTypeArguments()[1];
Class valClass = null;
if(valType instanceof Class) valClass = (Class)valType;
if(valType instanceof ParameterizedType) valClass = (Class)((ParameterizedType)valType).getRawType();
if(valClass==null) throw new RePresentationException("Cant find value parameter for Map : " + valType.toString());
for(int i=0; i<node.getChildNodes().getLength(); i++) {
Node n = node.getChildNodes().item(i);
String id = n.getAttributes().getNamedItem("id").getNodeValue();
if(n.getNodeType()==Node.ELEMENT_NODE) map.put(getObjectSimple(id, keyClass), getObject(n, valClass, valType));
}
return map;
} else if(Set.class.isAssignableFrom(clazz) || List.class.isAssignableFrom(clazz)) {
if(type==null || !(type instanceof ParameterizedType))
throw new RePresentationException(clazz);
boolean isList = List.class.isAssignableFrom(clazz);
Collection<Object> col = isList ? new ArrayList<Object>() :
(HashSet.class.isAssignableFrom(clazz) ? new HashSet<Object>() : new TreeSet<Object>());
ParameterizedType pType = (ParameterizedType) type;
Type t = pType.getActualTypeArguments()[0];
Class c = null;
if(t instanceof Class) c = (Class)t;
if(t instanceof ParameterizedType) c = (Class)((ParameterizedType)t).getRawType();
if(c==null) throw new RePresentationException("Cant find parameter for Collection : " + t.toString());
for(int i=0; i<node.getChildNodes().getLength(); i++) {
Node n = node.getChildNodes().item(i);
if(n.getNodeType()==Node.ELEMENT_NODE) {
Node id = isList ? null : n.getAttributes().getNamedItem("id");
col.add(getObject(id!=null ? id : n, c, t));
}
}
return col;
} else if(ClassMethodsInfo.isPresentableOrEntity(clazz)) {
if(null == node.getFirstChild()) return null;
boolean isEntity = ClassMethodsInfo.isEntity(clazz);
// System.out.println("isEntity " +clazz+ " :: " + isEntity);
if(node.getFirstChild().getNodeType() == Node.TEXT_NODE) {
String text = node.getFirstChild().getNodeValue();
if("new".equals(text)) return clazz.newInstance();
if(clazz.isEnum()) {
return Enum.valueOf(clazz, text);
}
if(!isEntity) throw new RePresentationException("Cant create new instance of Presentable " + clazz.getCanonicalName()+"("+text+")");
return ef.find(clazz, getObjectSimple(text, ClassMethodsInfo.getEntityIdClass(clazz)));
}
Object result = null;
if(isEntity) {
ClassMethodsInfo.Property idInfo = ClassMethodsInfo.getEntityIdProperty(clazz);
Class idClass = ClassMethodsInfo.getEntityIdClass(clazz);
for(int i=0; i<node.getChildNodes().getLength(); i++) {
Node n = node.getChildNodes().item(i);
String id = n.getAttributes().getNamedItem("id").getNodeValue();
if(idInfo.getName().equals(id)) {
if(null == n.getFirstChild()) break;
result = ef.find(clazz, getObjectSimple(n.getFirstChild().getNodeValue(), idClass));
break;
}
}
}
if(null == result) result = clazz.newInstance();
boolean skipIncoming = ClassMethodsInfo.getSkipIncoming(clazz);
for(int i=0; i<node.getChildNodes().getLength(); i++) {
Node n = node.getChildNodes().item(i);
String mName = n.getAttributes().getNamedItem("id").getNodeValue();
ClassMethodsInfo.Property mInfo = ClassMethodsInfo.getProperty(clazz, mName);
if(mInfo == null) {
if(skipIncoming) continue;
throw new RePresentationException("Unknown property `"+mName+"` in class " + clazz);
}
if(!mInfo.canSet()) {
if(skipIncoming) continue;
throw new RePresentationException("Unknown setter property `"+mName+"` in class " + clazz);
}
Object value = getObject(n, mInfo.getReturnType(), mInfo.getGenericReturnType());
//System.out.println("CALL SETTER: " + setMethod.getName()+"("+getMethod.getGenericReturnType()+") - "+value);
if(Collection.class.isAssignableFrom(mInfo.getReturnType())) {