diff --git a/.gitignore b/.gitignore index d075be7..695c7ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ + +/__pycache__/ /bin/ /Operator/ /DrawerProperties/ diff --git a/.project b/.project index d5321e7..993f532 100644 --- a/.project +++ b/.project @@ -21,4 +21,15 @@ org.eclipse.jdt.core.javanature net.sf.eclipsecs.core.CheckstyleNature + + + 1646149232194 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/src/org/atriasoft/exml/builder/BuilderIntrospection.java b/src/org/atriasoft/exml/builder/BuilderIntrospection.java index ca4d03d..df02157 100644 --- a/src/org/atriasoft/exml/builder/BuilderIntrospection.java +++ b/src/org/atriasoft/exml/builder/BuilderIntrospection.java @@ -22,10 +22,22 @@ public class BuilderIntrospection implements Builder { this.cacheModel.findOrCreate(model, null, classType); } + @Override + public void endElement(final Object element) throws ExmlBuilderException { + if (element == null) { + return; + } + final IntrospectionObject introspectionObject = (IntrospectionObject) element; + if (introspectionObject.getModelIntrospection() == null) { + // property on nothing ??? + return; + } + introspectionObject.generateTheObject(); + + } @Override - public void newComment(final Object element, final String comment) throws ExmlException { - } + public void newComment(final Object element, final String comment) throws ExmlException {} @Override public Object newDeclaration(final Object parent, final String text) throws ExmlException { @@ -38,7 +50,7 @@ public class BuilderIntrospection implements Builder { if (parent == null) { return null; } - Log.warning("new element on NodeName=" + nodeName); + Log.verbose("new element on NodeName=" + nodeName); final IntrospectionObject introspectionObject = (IntrospectionObject) parent; IntrospectionModel model = introspectionObject.getModelIntrospection(); Class typeClass = null; @@ -86,7 +98,7 @@ public class BuilderIntrospection implements Builder { inferData = this.cacheModel.findOrCreate(ModelType.LIST, listTreeName, subTypeClass); } // Create the data when object is ended created... - return new IntrospectionObject(inferData); + return new IntrospectionObject(inferData); } Log.verbose("Create new class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'"); final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, listTreeName, typeClass); @@ -96,7 +108,34 @@ public class BuilderIntrospection implements Builder { } return null; } - + + @Override + public void newElementFinished(final Object parent, final String tmpName, final Object element) throws ExmlException { + Log.debug("new element fionished : ==> " + tmpName); + if (parent == null || element == null) { + return; + } + final IntrospectionObject introspectionElementObject = (IntrospectionObject) element; + if (introspectionElementObject.getModelIntrospection() == null) { + // property on nothing ??? + return; + } + final IntrospectionObject introspectionParentObject = (IntrospectionObject) parent; + if (introspectionParentObject.getModelIntrospection() == null) { + if (tmpName.equals(this.rootNodeName)) { + // this is the root node ... + Object tmpp = introspectionParentObject.getData(); + if (tmpp instanceof List) { + @SuppressWarnings("unchecked") + List elementsOut = (List) tmpp; + elementsOut.add(introspectionElementObject.getData()); + } + } + return; + } + introspectionParentObject.addObject(tmpName, introspectionElementObject.getData()); + } + @Override public void newProperty(final Object element, final String propertyName, final String propertyValue) throws ExmlException { if (element == null) { @@ -107,7 +146,7 @@ public class BuilderIntrospection implements Builder { if (model.isArray() || model.isList()) { throw new ExmlBuilderException("Model (List/Array) can not have property with name '" + propertyName + "'"); } - String beanName = model.getBeanName(propertyName); + String beanName = model.getBeanName(propertyName); if (beanName == null) { if (model.isIgnoreUnknown()) { Log.debug("Ignore node : '" + propertyName + "'"); @@ -125,8 +164,8 @@ public class BuilderIntrospection implements Builder { String[] elems = propertyValue.split(";"); Class subTypeClass = typeClass.getComponentType(); IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass); - List out = new ArrayList(); - for (int iii=0; iii out = new ArrayList<>(); + for (int iii = 0; iii < elems.length; iii++) { Object tmp = inferData.getValueFromText(elems[iii]); out.add(tmp); } @@ -136,8 +175,8 @@ public class BuilderIntrospection implements Builder { Class subTypeClass = introspectionObject.getTypeOfSubProperty(propertyName); Log.verbose("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + propertyName + "'"); IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass); - List out = new ArrayList(); - for (int iii=0; iii out = new ArrayList<>(); + for (int iii = 0; iii < elems.length; iii++) { Object tmp = inferData.getValueFromText(elems[iii]); out.add(tmp); } @@ -179,45 +218,4 @@ public class BuilderIntrospection implements Builder { } introspectionObject.setText(text); } - - @Override - public void endElement(final Object element) throws ExmlBuilderException { - if (element == null) { - return; - } - final IntrospectionObject introspectionObject = (IntrospectionObject) element; - if (introspectionObject.getModelIntrospection() == null) { - // property on nothing ??? - return; - } - introspectionObject.generateTheObject(); - - } - - @Override - public void newElementFinished(final Object parent, final String tmpName, final Object element) throws ExmlException { - Log.debug("new element fionished : ==> " + tmpName); - if (parent == null || element == null) { - return; - } - final IntrospectionObject introspectionElementObject = (IntrospectionObject) element; - if (introspectionElementObject.getModelIntrospection() == null) { - // property on nothing ??? - return; - } - final IntrospectionObject introspectionParentObject = (IntrospectionObject) parent; - if (introspectionParentObject.getModelIntrospection() == null) { - if (tmpName.equals(this.rootNodeName)) { - // this is the root node ... - Object tmpp = introspectionParentObject.getData(); - if( tmpp instanceof List) { - @SuppressWarnings("unchecked") - List elementsOut = (List)tmpp; - elementsOut.add(introspectionElementObject.getData()); - } - } - return; - } - introspectionParentObject.addObject(tmpName, introspectionElementObject.getData()); - } } diff --git a/src/org/atriasoft/exml/builder/IntrospectionModelComplex.java b/src/org/atriasoft/exml/builder/IntrospectionModelComplex.java index fba72b5..92f7cc8 100644 --- a/src/org/atriasoft/exml/builder/IntrospectionModelComplex.java +++ b/src/org/atriasoft/exml/builder/IntrospectionModelComplex.java @@ -28,7 +28,7 @@ record ConstructorModel( Constructor constructor) {} public class IntrospectionModelComplex extends IntrospectionModel { - + private final boolean isRecord; // TODO Optimize this with external object for basic types.... private final Method valueof; // used for the set Text if the object is an end point... private final Method tostring; // used for the set Text if the object is an end point... @@ -47,10 +47,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } else { this.isSubClass = false; } - final boolean isRecord = Record.class.isAssignableFrom(classType); - if (isRecord) { - Log.error("Detect record !!! "); - } + this.isRecord = Record.class.isAssignableFrom(classType); if (classType.isPrimitive()) { Log.critical("Detect primitive ==> impossible case !!! "); } @@ -198,7 +195,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } final List recordAllPossibleValues = new ArrayList<>(); final List recordAllPossibleValuesFiltered = new ArrayList<>(); - if (isRecord) { + if (this.isRecord) { for (ConstructorModel elem : this.constructors) { for (int iii = 0; iii < elem.values().length; iii++) { String tmpp = elem.values()[iii]; @@ -302,7 +299,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return true; } - if (isRecord) { + if (this.isRecord) { if (recordAllPossibleValues.contains(o.getName())) { // This list is the real list of record members recordAllPossibleValuesFiltered.add(o.getName()); @@ -367,7 +364,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { List methodsSet; List methodsIs; if (!Enum.class.isAssignableFrom(classType)) { - if (isRecord) { + if (this.isRecord) { methodsGet = methods.stream().filter(o -> recordAllPossibleValues.contains(o.getName())).collect(Collectors.toList()); methodsSet = new ArrayList<>(); methodsIs = new ArrayList<>(); @@ -399,13 +396,13 @@ public class IntrospectionModelComplex extends IntrospectionModel { } // associate methods by pair. for (final Method method : methodsGet) { - final String name = Tools.decapitalizeFirst(isRecord ? method.getName() : method.getName().substring(3)); + final String name = Tools.decapitalizeFirst(this.isRecord ? method.getName() : method.getName().substring(3)); IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method)); // generate getter and setter with field. IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method); prop.setGetter(modifier); } - if (!isRecord) { + if (!this.isRecord) { for (final Method method : methodsIs) { final String name = Tools.decapitalizeFirst(method.getName().substring(2)); IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method)); @@ -561,7 +558,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } inputsTmp[iii + offset] = valueToInject; } - if (lastEmpty > empty) { + if (lastEmpty >= empty && (inputs == null || inputs.length < inputsTmp.length)) { inputs = inputsTmp; betterModel = elem; lastEmpty = empty; @@ -887,7 +884,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } private void setValue(final Object data, final String beanName, final Object value) throws ExmlBuilderException { - Log.error(" Set value ='" + beanName + "' propertyValue='" + value + "' " + value.getClass().getCanonicalName()); + Log.verbose(" Set value ='" + beanName + "' propertyValue='" + value + "' " + value.getClass().getCanonicalName()); { // by default use setter to set the property final IntrospectionProperty propMethode = findBeanNodeDescription(beanName); diff --git a/src/org/atriasoft/exml/reflect/ReflectTools.java b/src/org/atriasoft/exml/reflect/ReflectTools.java index ef3c4b8..8be5511 100644 --- a/src/org/atriasoft/exml/reflect/ReflectTools.java +++ b/src/org/atriasoft/exml/reflect/ReflectTools.java @@ -25,86 +25,48 @@ import org.atriasoft.exml.exception.ExmlBuilderException; import org.atriasoft.exml.internal.Log; public class ReflectTools { - private ReflectTools() {} - - public static Class[] getTypeField(final Field fieldDescription) { - Class type = fieldDescription.getType(); - Class subType = null; - Type empppe = fieldDescription.getGenericType(); - if (empppe instanceof ParameterizedType plopppppp) { - Type[] realType = plopppppp.getActualTypeArguments(); - if (realType.length > 0) { - try { - subType = Class.forName(realType[0].getTypeName()); - } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public static Boolean getIsAttribute(final Constructor constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); + if (annotation.length == 0) { + return parentValue; } - return new Class[] {type, subType}; + if (annotation.length > 1) { + throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + constructor.getClass().getCanonicalName()); + } + return ((XmlAttribute) annotation[0]).value(); } - - public static Class[] getTypeReturnFunction(/*@NotNull*/ final Method getter) throws Exception { - Class type = null; - Class subType = null; - type = getter.getReturnType(); - if (!Enum.class.isAssignableFrom(type)) { - Type empppe = getter.getGenericReturnType(); - if (empppe instanceof ParameterizedType plopppppp) { - Type[] realType = plopppppp.getActualTypeArguments(); - if (realType.length > 0) { - subType = Class.forName(realType[0].getTypeName()); - } - } + public static Boolean getIsAttribute(final Field element, final Boolean parentValue) throws ExmlBuilderException { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); + if (annotation.length == 0) { + return parentValue; } - return new Class[] {type, subType}; + if (annotation.length > 1) { + throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + element.getClass().getCanonicalName()); + } + return ((XmlAttribute) annotation[0]).value(); } - - public static Class[] getTypeParameterfunction(final Method setter) throws Exception { - Class type = null; - Class subType = null; - - type = setter.getParameters()[0].getType(); - if (List.class.isAssignableFrom(type)) { - Class internalModelClass = null; - Type[] empppe = setter.getGenericParameterTypes(); - if (empppe.length > 0) { - if (empppe[0] instanceof ParameterizedType plopppppp) { - Type[] realType = plopppppp.getActualTypeArguments(); - if (realType.length > 0) { - Log.warning(" -->> " + realType[0]); - internalModelClass = Class.forName(realType[0].getTypeName()); - } - } - } - subType = internalModelClass; + + public static Boolean getIsAttribute(final Method element, final Boolean parentValue) throws ExmlBuilderException { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); + if (annotation.length == 0) { + return parentValue; } - return new Class[] {type, subType}; + if (annotation.length > 1) { + throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + element.getClass().getCanonicalName()); + } + return ((XmlAttribute) annotation[0]).value(); } - - public static Class[] getTypeParameterfunction(final Constructor elem, final int paramId) throws ClassNotFoundException { - Class type = null; - Class subType = null; - - type = elem.getParameters()[paramId].getType(); - if (List.class.isAssignableFrom(type)) { - Class internalModelClass = null; - Type[] empppe = elem.getGenericParameterTypes(); - if (empppe.length > paramId) { - if (empppe[paramId] instanceof ParameterizedType plopppppp) { - Type[] realType = plopppppp.getActualTypeArguments(); - //Log.info("ppplllppp: " + realType.length); - if (realType.length > 0) { - Log.warning(" -->> " + realType[0]); - internalModelClass = Class.forName(realType[0].getTypeName()); - } - } - } - subType = internalModelClass; + + public static Boolean getIsCaseSensitive(final Constructor constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlCaseSensitive.class); + if (annotation.length == 0) { + return parentValue; } - return new Class[] {type, subType}; + if (annotation.length > 1) { + throw new ExmlBuilderException("Must not have more than 1 element @XmlCaseSensitive on " + constructor.getClass().getCanonicalName()); + } + return ((XmlCaseSensitive) annotation[0]).value(); } public static Boolean getIsCaseSensitive(final Field element, final Boolean defaultValue) throws ExmlBuilderException { @@ -128,15 +90,16 @@ public class ReflectTools { } return ((XmlCaseSensitive) annotation[0]).value(); } - public static Boolean getIsCaseSensitive(final Constructor constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlCaseSensitive.class); + + public static Boolean getIsDefaultAttribute(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { + final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultAttibute.class); if (annotation.length == 0) { - return parentValue; + return defaultValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlCaseSensitive on " + constructor.getClass().getCanonicalName()); + throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultAttibute on " + classType.getClass().getCanonicalName()); } - return ((XmlCaseSensitive) annotation[0]).value(); + return ((XmlDefaultAttibute) annotation[0]).value(); } public static Boolean getIsDefaultCaseSensitive(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { @@ -149,37 +112,6 @@ public class ReflectTools { } return ((XmlDefaultCaseSensitive) annotation[0]).value(); } - - public static Boolean getIsDefaultAttribute(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { - final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultAttibute.class); - if (annotation.length == 0) { - return defaultValue; - } - if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultAttibute on " + classType.getClass().getCanonicalName()); - } - return ((XmlDefaultAttibute) annotation[0]).value(); - } - public static Boolean getIsIgnoreUnknown(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { - final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlIgnoreUnknow.class); - if (annotation.length == 0) { - return defaultValue; - } - if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlIgnoreUnknow on " + classType.getClass().getCanonicalName()); - } - return ((XmlIgnoreUnknow) annotation[0]).value(); - } - public static Boolean getIsDefaultNullValue(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { - final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultNullValue.class); - if (annotation.length == 0) { - return defaultValue; - } - if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultNullValue on " + classType.getClass().getCanonicalName()); - } - return ((XmlDefaultNullValue) annotation[0]).value(); - } public static Boolean getIsDefaultManaged(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultManaged.class); @@ -192,6 +124,17 @@ public class ReflectTools { return ((XmlDefaultManaged) annotation[0]).value(); } + public static Boolean getIsDefaultNullValue(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { + final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultNullValue.class); + if (annotation.length == 0) { + return defaultValue; + } + if (annotation.length > 1) { + throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultNullValue on " + classType.getClass().getCanonicalName()); + } + return ((XmlDefaultNullValue) annotation[0]).value(); + } + public static Boolean getIsDefaultOptional(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultOptional.class); if (annotation.length == 0) { @@ -203,37 +146,26 @@ public class ReflectTools { return ((XmlDefaultOptional) annotation[0]).value(); } - public static Boolean getIsAttribute(final Field element, final Boolean parentValue) throws ExmlBuilderException { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); + public static Boolean getIsIgnoreUnknown(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { + final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlIgnoreUnknow.class); if (annotation.length == 0) { - return parentValue; + return defaultValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + element.getClass().getCanonicalName()); + throw new ExmlBuilderException("Must not have more than 1 element @XmlIgnoreUnknow on " + classType.getClass().getCanonicalName()); } - return ((XmlAttribute) annotation[0]).value(); - } - - public static Boolean getIsAttribute(final Method element, final Boolean parentValue) throws ExmlBuilderException { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); - if (annotation.length == 0) { - return parentValue; - } - if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + element.getClass().getCanonicalName()); - } - return ((XmlAttribute) annotation[0]).value(); + return ((XmlIgnoreUnknow) annotation[0]).value(); } - public static Boolean getIsAttribute(final Constructor constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); + public static Boolean getIsManaged(final Constructor constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlManaged.class); if (annotation.length == 0) { return parentValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + constructor.getClass().getCanonicalName()); + throw new ExmlBuilderException("Must not have more than 1 element @XmlManaged on " + constructor.getClass().getCanonicalName()); } - return ((XmlAttribute) annotation[0]).value(); + return ((XmlManaged) annotation[0]).value(); } public static Boolean getIsManaged(final Field element, final Boolean parentValue) throws ExmlBuilderException { @@ -257,16 +189,16 @@ public class ReflectTools { } return ((XmlManaged) annotation[0]).value(); } - - public static Boolean getIsManaged(final Constructor constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlManaged.class); + + public static Boolean getIsOptional(final Constructor constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlOptional.class); if (annotation.length == 0) { return parentValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlManaged on " + constructor.getClass().getCanonicalName()); + throw new ExmlBuilderException("Must not have more than 1 element @XmlOptional on " + constructor.getClass().getCanonicalName()); } - return ((XmlManaged) annotation[0]).value(); + return ((XmlOptional) annotation[0]).value(); } public static Boolean getIsOptional(final Field element, final Boolean parentValue) throws Exception { @@ -290,16 +222,93 @@ public class ReflectTools { } return ((XmlOptional) annotation[0]).value(); } - - public static Boolean getIsOptional(final Constructor constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlOptional.class); + + public static String getListName(final Field element, final String defaultValue) throws Exception { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlList.class); if (annotation.length == 0) { - return parentValue; + return defaultValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not have more than 1 element @XmlOptional on " + constructor.getClass().getCanonicalName()); + throw new Exception("Must not have more than 1 element @XmlList on " + element.getClass().getCanonicalName()); } - return ((XmlOptional) annotation[0]).value(); + final String tmp = ((XmlList) annotation[0]).value(); + if (tmp == null) { + throw new Exception("Set null value in decorator @XmlList is not availlable on: " + element.toGenericString()); + } + return tmp; + } + + public static String getListName(final Method element, final String defaultValue) throws Exception { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlList.class); + if (annotation.length == 0) { + return defaultValue; + } + if (annotation.length > 1) { + throw new Exception("Must not have more than 1 element @XmlList on " + element.getClass().getCanonicalName()); + } + final String tmp = ((XmlList) annotation[0]).value(); + if (tmp == null) { + throw new Exception("Set null value in decorator @XmlList is not availlable on: " + element.toGenericString()); + } + return tmp; + } + + public static String[] getNames(final Constructor constructor, final Parameter element, final String defaultValue) throws Exception { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlName.class); + if (annotation.length == 0) { + if (defaultValue == null) { + return null; + } + return new String[] { defaultValue }; + } + if (annotation.length > 1) { + throw new Exception("Must not have more than 1 element @XmlName on " + constructor.getClass().getCanonicalName()); + } + final String[] tmp = ((XmlName) annotation[0]).value(); + if (tmp == null) { + throw new Exception("Set null value in decorator @XmlName is not availlable on: " + constructor.toGenericString()); + } + if (tmp.length == 0) { + throw new Exception("Set empty list value in decorator @XmlName is not availlable on: " + constructor.toGenericString()); + } + for (final String elem : tmp) { + if (elem == null) { + throw new Exception("Set null String in list of value in decorator @XmlName is not availlable on: " + constructor.toGenericString()); + } + if (elem.isEmpty()) { + throw new Exception("Set empty String in list of value in decorator @XmlName is not availlable on: " + constructor.toGenericString()); + } + } + return tmp; + } + + public static String[] getNames(final Constructor element, final String defaultValue) throws Exception { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlName.class); + if (annotation.length == 0) { + if (defaultValue == null) { + return null; + } + return new String[] { defaultValue }; + } + if (annotation.length > 1) { + throw new Exception("Must not have more than 1 element @XmlName on " + element.getClass().getCanonicalName()); + } + final String[] tmp = ((XmlName) annotation[0]).value(); + if (tmp == null) { + throw new Exception("Set null value in decorator @XmlName is not availlable on: " + element.toGenericString()); + } + if (tmp.length == 0) { + throw new Exception("Set empty list value in decorator @XmlName is not availlable on: " + element.toGenericString()); + } + for (final String elem : tmp) { + if (elem == null) { + throw new Exception("Set null String in list of value in decorator @XmlName is not availlable on: " + element.toGenericString()); + } + if (elem.isEmpty()) { + throw new Exception("Set empty String in list of value in decorator @XmlName is not availlable on: " + element.toGenericString()); + } + } + return tmp; } public static String[] getNames(final Field element, final String defaultValue) throws Exception { @@ -359,91 +368,86 @@ public class ReflectTools { } return tmp; } - public static String[] getNames(final Constructor element, final String defaultValue) throws Exception { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlName.class); - if (annotation.length == 0) { - if (defaultValue == null) { - return null; - } - return new String[] { defaultValue }; - } - if (annotation.length > 1) { - throw new Exception("Must not have more than 1 element @XmlName on " + element.getClass().getCanonicalName()); - } - final String[] tmp = ((XmlName) annotation[0]).value(); - if (tmp == null) { - throw new Exception("Set null value in decorator @XmlName is not availlable on: " + element.toGenericString()); - } - if (tmp.length == 0) { - throw new Exception("Set empty list value in decorator @XmlName is not availlable on: " + element.toGenericString()); - } - for (final String elem : tmp) { - if (elem == null) { - throw new Exception("Set null String in list of value in decorator @XmlName is not availlable on: " + element.toGenericString()); - } - if (elem.isEmpty()) { - throw new Exception("Set empty String in list of value in decorator @XmlName is not availlable on: " + element.toGenericString()); + + public static Class[] getTypeField(final Field fieldDescription) { + Class type = fieldDescription.getType(); + Class subType = null; + Type empppe = fieldDescription.getGenericType(); + if (empppe instanceof ParameterizedType plopppppp) { + Type[] realType = plopppppp.getActualTypeArguments(); + if (realType.length > 0) { + try { + subType = Class.forName(realType[0].getTypeName()); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } - return tmp; + return new Class[] { type, subType }; } - public static String[] getNames(final Constructor constructor, final Parameter element, final String defaultValue) throws Exception { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlName.class); - if (annotation.length == 0) { - if (defaultValue == null) { - return null; + + public static Class[] getTypeParameterfunction(final Constructor elem, final int paramId) throws ClassNotFoundException { + Class type = null; + Class subType = null; + + type = elem.getParameters()[paramId].getType(); + if (List.class.isAssignableFrom(type)) { + Class internalModelClass = null; + Type[] empppe = elem.getGenericParameterTypes(); + if (empppe.length > paramId) { + if (empppe[paramId] instanceof ParameterizedType plopppppp) { + Type[] realType = plopppppp.getActualTypeArguments(); + //Log.info("ppplllppp: " + realType.length); + if (realType.length > 0) { + Log.verbose(" -->> " + realType[0]); + internalModelClass = Class.forName(realType[0].getTypeName()); + } + } } - return new String[] { defaultValue }; + subType = internalModelClass; } - if (annotation.length > 1) { - throw new Exception("Must not have more than 1 element @XmlName on " + constructor.getClass().getCanonicalName()); - } - final String[] tmp = ((XmlName) annotation[0]).value(); - if (tmp == null) { - throw new Exception("Set null value in decorator @XmlName is not availlable on: " + constructor.toGenericString()); - } - if (tmp.length == 0) { - throw new Exception("Set empty list value in decorator @XmlName is not availlable on: " + constructor.toGenericString()); - } - for (final String elem : tmp) { - if (elem == null) { - throw new Exception("Set null String in list of value in decorator @XmlName is not availlable on: " + constructor.toGenericString()); + return new Class[] { type, subType }; + } + + public static Class[] getTypeParameterfunction(final Method setter) throws Exception { + Class type = null; + Class subType = null; + + type = setter.getParameters()[0].getType(); + if (List.class.isAssignableFrom(type)) { + Class internalModelClass = null; + Type[] empppe = setter.getGenericParameterTypes(); + if (empppe.length > 0) { + if (empppe[0] instanceof ParameterizedType plopppppp) { + Type[] realType = plopppppp.getActualTypeArguments(); + if (realType.length > 0) { + Log.verbose(" -->> " + realType[0]); + internalModelClass = Class.forName(realType[0].getTypeName()); + } + } } - if (elem.isEmpty()) { - throw new Exception("Set empty String in list of value in decorator @XmlName is not availlable on: " + constructor.toGenericString()); + subType = internalModelClass; + } + return new Class[] { type, subType }; + } + + public static Class[] getTypeReturnFunction(/*@NotNull*/ final Method getter) throws Exception { + Class type = null; + Class subType = null; + type = getter.getReturnType(); + if (!Enum.class.isAssignableFrom(type)) { + Type empppe = getter.getGenericReturnType(); + if (empppe instanceof ParameterizedType plopppppp) { + Type[] realType = plopppppp.getActualTypeArguments(); + if (realType.length > 0) { + subType = Class.forName(realType[0].getTypeName()); + } } } - return tmp; + return new Class[] { type, subType }; } - - - public static String getListName(final Field element, final String defaultValue) throws Exception { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlList.class); - if (annotation.length == 0) { - return defaultValue; - } - if (annotation.length > 1) { - throw new Exception("Must not have more than 1 element @XmlList on " + element.getClass().getCanonicalName()); - } - final String tmp = ((XmlList) annotation[0]).value(); - if (tmp == null) { - throw new Exception("Set null value in decorator @XmlList is not availlable on: " + element.toGenericString()); - } - return tmp; - } - public static String getListName(final Method element, final String defaultValue) throws Exception { - final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlList.class); - if (annotation.length == 0) { - return defaultValue; - } - if (annotation.length > 1) { - throw new Exception("Must not have more than 1 element @XmlList on " + element.getClass().getCanonicalName()); - } - final String tmp = ((XmlList) annotation[0]).value(); - if (tmp == null) { - throw new Exception("Set null value in decorator @XmlList is not availlable on: " + element.toGenericString()); - } - return tmp; - } - + + private ReflectTools() {} + } diff --git a/test/.gitignore b/test/.gitignore index ae3c172..f00a440 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,3 @@ + +/__pycache__/ /bin/