Implementing Schema Management

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/information-system-model@129909 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-07-05 10:34:13 +00:00
parent 417d5fafb8
commit fb59d0970a
2 changed files with 33 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package org.gcube.informationsystem.types;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.HashSet;
import java.util.Set;
@ -132,7 +133,7 @@ public class TypeBinder {
if(propertyAnnotation.max()>=propertyAnnotation.min() && propertyAnnotation.min()>0) property.min = propertyAnnotation.min();
if(!propertyAnnotation.regexpr().isEmpty()) property.regexpr = propertyAnnotation.regexpr();
logger.trace("Looking for property type type {}", method.getReturnType());
logger.trace("Looking for property type {}", method.getReturnType());
Class<?> type = method.getReturnType();
property.type = OType.EMBEDDED.getIntValue();
@ -141,9 +142,26 @@ public class TypeBinder {
property.type = OType.EMBEDDED.getIntValue();
}else if (Type.getTypeByClass(type)!=null) {
property.type = Type.getTypeByClass(type).getIntValue();
if(property.type > 9){
// TODO
// Get List/Set/Map generic arguments can be LinkedType or LinkedClass
if(property.type > 9 && property.type <= 12){
java.lang.reflect.Type genericReturnType = method.getGenericReturnType();
logger.trace("Generic Return Type {} for method {}", genericReturnType, method);
java.lang.reflect.Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
java.lang.reflect.Type genericType = null;
for(java.lang.reflect.Type t : actualTypeArguments){
logger.trace("Generic Return Type {} for method {} - Actual Type Argument : {}", genericReturnType, method, t);
genericType = t;
}
Class<?> genericClass = (Class<?>) genericType;
OType linkedOType = Type.getTypeByClass(genericClass);
if(linkedOType!=null){
property.linkedType = linkedOType.getIntValue();
}else{
property.linkedClass = getStaticStringFieldByName(genericClass, NAME, genericClass.getSimpleName());
}
}
} else {
throw new RuntimeException("Type " + type.getSimpleName() + " not reconized");
@ -227,7 +245,8 @@ public class TypeBinder {
private boolean notnull = false;
private Integer max= null;
private Integer min= null;
private String regexpr= null;
private String regexpr= null;
private Integer linkedType = null;
private String linkedClass = null;
private Integer type=null;
@ -262,7 +281,11 @@ public class TypeBinder {
public String getRegexpr() {
return regexpr;
}
public Integer getLinkedType() {
return linkedType;
}
public String getLinkedClass() {
return linkedClass;
}
@ -276,7 +299,9 @@ public class TypeBinder {
return "Property [name=" + name + ", description=" + description
+ ", mandatory=" + mandatory + ", readonly=" + readonly
+ ", notnull=" + notnull + ", max=" + max + ", min="
+ min + ", regexpr=" + regexpr + ", linkedClass = "+linkedClass+"]";
+ min + ", regexpr=" + regexpr + ", type = " + type
+ ", linkedType = " + linkedType + ", linkedClass = "
+ linkedClass + "]";
}

View File

@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory;
public class EntitySchemaDefinition {
private static Logger logger = LoggerFactory.getLogger(EntitySchemaDefinition.class);
@Test
public void test() throws Exception {
Class<?> clz = Header.class;