[DEV] commit all with new insland

This commit is contained in:
Edouard DUPIN 2022-03-20 23:39:28 +01:00
parent f5f6d34135
commit 139a01063c
6 changed files with 294 additions and 280 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
/__pycache__/
/bin/ /bin/
/Operator/ /Operator/
/DrawerProperties/ /DrawerProperties/

View File

@ -21,4 +21,15 @@
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature> <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures> </natures>
<filteredResources>
<filter>
<id>1646149232194</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription> </projectDescription>

View File

@ -22,10 +22,22 @@ public class BuilderIntrospection implements Builder {
this.cacheModel.findOrCreate(model, null, classType); 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 @Override
public void newComment(final Object element, final String comment) throws ExmlException { public void newComment(final Object element, final String comment) throws ExmlException {}
}
@Override @Override
public Object newDeclaration(final Object parent, final String text) throws ExmlException { public Object newDeclaration(final Object parent, final String text) throws ExmlException {
@ -38,7 +50,7 @@ public class BuilderIntrospection implements Builder {
if (parent == null) { if (parent == null) {
return null; return null;
} }
Log.warning("new element on NodeName=" + nodeName); Log.verbose("new element on NodeName=" + nodeName);
final IntrospectionObject introspectionObject = (IntrospectionObject) parent; final IntrospectionObject introspectionObject = (IntrospectionObject) parent;
IntrospectionModel model = introspectionObject.getModelIntrospection(); IntrospectionModel model = introspectionObject.getModelIntrospection();
Class<?> typeClass = null; Class<?> typeClass = null;
@ -97,6 +109,33 @@ public class BuilderIntrospection implements Builder {
return null; 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<Object> elementsOut = (List<Object>) tmpp;
elementsOut.add(introspectionElementObject.getData());
}
}
return;
}
introspectionParentObject.addObject(tmpName, introspectionElementObject.getData());
}
@Override @Override
public void newProperty(final Object element, final String propertyName, final String propertyValue) throws ExmlException { public void newProperty(final Object element, final String propertyName, final String propertyValue) throws ExmlException {
if (element == null) { if (element == null) {
@ -125,7 +164,7 @@ public class BuilderIntrospection implements Builder {
String[] elems = propertyValue.split(";"); String[] elems = propertyValue.split(";");
Class<?> subTypeClass = typeClass.getComponentType(); Class<?> subTypeClass = typeClass.getComponentType();
IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass); IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass);
List<Object> out = new ArrayList<Object>(); List<Object> out = new ArrayList<>();
for (int iii = 0; iii < elems.length; iii++) { for (int iii = 0; iii < elems.length; iii++) {
Object tmp = inferData.getValueFromText(elems[iii]); Object tmp = inferData.getValueFromText(elems[iii]);
out.add(tmp); out.add(tmp);
@ -136,7 +175,7 @@ public class BuilderIntrospection implements Builder {
Class<?> subTypeClass = introspectionObject.getTypeOfSubProperty(propertyName); Class<?> subTypeClass = introspectionObject.getTypeOfSubProperty(propertyName);
Log.verbose("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + propertyName + "'"); Log.verbose("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + propertyName + "'");
IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass); IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass);
List<Object> out = new ArrayList<Object>(); List<Object> out = new ArrayList<>();
for (int iii = 0; iii < elems.length; iii++) { for (int iii = 0; iii < elems.length; iii++) {
Object tmp = inferData.getValueFromText(elems[iii]); Object tmp = inferData.getValueFromText(elems[iii]);
out.add(tmp); out.add(tmp);
@ -179,45 +218,4 @@ public class BuilderIntrospection implements Builder {
} }
introspectionObject.setText(text); 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<Object> elementsOut = (List<Object>)tmpp;
elementsOut.add(introspectionElementObject.getData());
}
}
return;
}
introspectionParentObject.addObject(tmpName, introspectionElementObject.getData());
}
} }

View File

@ -28,7 +28,7 @@ record ConstructorModel(
Constructor<?> constructor) {} Constructor<?> constructor) {}
public class IntrospectionModelComplex extends IntrospectionModel { public class IntrospectionModelComplex extends IntrospectionModel {
private final boolean isRecord;
// TODO Optimize this with external object for basic types.... // 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 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... 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 { } else {
this.isSubClass = false; this.isSubClass = false;
} }
final boolean isRecord = Record.class.isAssignableFrom(classType); this.isRecord = Record.class.isAssignableFrom(classType);
if (isRecord) {
Log.error("Detect record !!! ");
}
if (classType.isPrimitive()) { if (classType.isPrimitive()) {
Log.critical("Detect primitive ==> impossible case !!! "); Log.critical("Detect primitive ==> impossible case !!! ");
} }
@ -198,7 +195,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
final List<String> recordAllPossibleValues = new ArrayList<>(); final List<String> recordAllPossibleValues = new ArrayList<>();
final List<String> recordAllPossibleValuesFiltered = new ArrayList<>(); final List<String> recordAllPossibleValuesFiltered = new ArrayList<>();
if (isRecord) { if (this.isRecord) {
for (ConstructorModel elem : this.constructors) { for (ConstructorModel elem : this.constructors) {
for (int iii = 0; iii < elem.values().length; iii++) { for (int iii = 0; iii < elem.values().length; iii++) {
String tmpp = elem.values()[iii]; String tmpp = elem.values()[iii];
@ -302,7 +299,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return true; return true;
} }
if (isRecord) { if (this.isRecord) {
if (recordAllPossibleValues.contains(o.getName())) { if (recordAllPossibleValues.contains(o.getName())) {
// This list is the real list of record members // This list is the real list of record members
recordAllPossibleValuesFiltered.add(o.getName()); recordAllPossibleValuesFiltered.add(o.getName());
@ -367,7 +364,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
List<Method> methodsSet; List<Method> methodsSet;
List<Method> methodsIs; List<Method> methodsIs;
if (!Enum.class.isAssignableFrom(classType)) { if (!Enum.class.isAssignableFrom(classType)) {
if (isRecord) { if (this.isRecord) {
methodsGet = methods.stream().filter(o -> recordAllPossibleValues.contains(o.getName())).collect(Collectors.toList()); methodsGet = methods.stream().filter(o -> recordAllPossibleValues.contains(o.getName())).collect(Collectors.toList());
methodsSet = new ArrayList<>(); methodsSet = new ArrayList<>();
methodsIs = new ArrayList<>(); methodsIs = new ArrayList<>();
@ -399,13 +396,13 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
// associate methods by pair. // associate methods by pair.
for (final Method method : methodsGet) { 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)); IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method));
// generate getter and setter with field. // generate getter and setter with field.
IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method); IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method);
prop.setGetter(modifier); prop.setGetter(modifier);
} }
if (!isRecord) { if (!this.isRecord) {
for (final Method method : methodsIs) { for (final Method method : methodsIs) {
final String name = Tools.decapitalizeFirst(method.getName().substring(2)); final String name = Tools.decapitalizeFirst(method.getName().substring(2));
IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method)); IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method));
@ -561,7 +558,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
inputsTmp[iii + offset] = valueToInject; inputsTmp[iii + offset] = valueToInject;
} }
if (lastEmpty > empty) { if (lastEmpty >= empty && (inputs == null || inputs.length < inputsTmp.length)) {
inputs = inputsTmp; inputs = inputsTmp;
betterModel = elem; betterModel = elem;
lastEmpty = empty; 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 { 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 // by default use setter to set the property
final IntrospectionProperty propMethode = findBeanNodeDescription(beanName); final IntrospectionProperty propMethode = findBeanNodeDescription(beanName);

View File

@ -25,182 +25,15 @@ import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.exml.internal.Log; import org.atriasoft.exml.internal.Log;
public class ReflectTools { public class ReflectTools {
private ReflectTools() {} public static Boolean getIsAttribute(final Constructor<?> constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class);
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 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 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.warning(" -->> " + realType[0]);
internalModelClass = Class.forName(realType[0].getTypeName());
}
}
}
subType = internalModelClass;
}
return new Class<?>[] {type, subType};
}
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;
}
return new Class<?>[] {type, subType};
}
public static Boolean getIsCaseSensitive(final Field element, final Boolean defaultValue) throws ExmlBuilderException {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlCaseSensitive.class);
if (annotation.length == 0) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlCaseSensitive on " + element.getClass().getCanonicalName());
}
return ((XmlCaseSensitive) annotation[0]).value();
}
public static Boolean getIsCaseSensitive(final Method element, final Boolean defaultValue) throws ExmlBuilderException {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlCaseSensitive.class);
if (annotation.length == 0) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlCaseSensitive on " + element.getClass().getCanonicalName());
}
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);
if (annotation.length == 0) { if (annotation.length == 0) {
return parentValue; return parentValue;
} }
if (annotation.length > 1) { 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 @XmlAttribute on " + constructor.getClass().getCanonicalName());
} }
return ((XmlCaseSensitive) annotation[0]).value(); return ((XmlAttribute) annotation[0]).value();
}
public static Boolean getIsDefaultCaseSensitive(final Class<?> classType, final Boolean defaultValue) throws ExmlBuilderException {
final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultCaseSensitive.class);
if (annotation.length == 0) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultCaseSensitive on " + classType.getClass().getCanonicalName());
}
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);
if (annotation.length == 0) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultManaged on " + classType.getClass().getCanonicalName());
}
return ((XmlDefaultManaged) 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) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultOptional on " + classType.getClass().getCanonicalName());
}
return ((XmlDefaultOptional) annotation[0]).value();
} }
public static Boolean getIsAttribute(final Field element, final Boolean parentValue) throws ExmlBuilderException { public static Boolean getIsAttribute(final Field element, final Boolean parentValue) throws ExmlBuilderException {
@ -225,15 +58,114 @@ public class ReflectTools {
return ((XmlAttribute) annotation[0]).value(); return ((XmlAttribute) annotation[0]).value();
} }
public static Boolean getIsAttribute(final Constructor<?> constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { public static Boolean getIsCaseSensitive(final Constructor<?> constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlCaseSensitive.class);
if (annotation.length == 0) { if (annotation.length == 0) {
return parentValue; return parentValue;
} }
if (annotation.length > 1) { 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 @XmlCaseSensitive on " + constructor.getClass().getCanonicalName());
} }
return ((XmlAttribute) annotation[0]).value(); return ((XmlCaseSensitive) annotation[0]).value();
}
public static Boolean getIsCaseSensitive(final Field element, final Boolean defaultValue) throws ExmlBuilderException {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlCaseSensitive.class);
if (annotation.length == 0) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlCaseSensitive on " + element.getClass().getCanonicalName());
}
return ((XmlCaseSensitive) annotation[0]).value();
}
public static Boolean getIsCaseSensitive(final Method element, final Boolean defaultValue) throws ExmlBuilderException {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlCaseSensitive.class);
if (annotation.length == 0) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlCaseSensitive on " + element.getClass().getCanonicalName());
}
return ((XmlCaseSensitive) 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 getIsDefaultCaseSensitive(final Class<?> classType, final Boolean defaultValue) throws ExmlBuilderException {
final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultCaseSensitive.class);
if (annotation.length == 0) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultCaseSensitive on " + classType.getClass().getCanonicalName());
}
return ((XmlDefaultCaseSensitive) annotation[0]).value();
}
public static Boolean getIsDefaultManaged(final Class<?> classType, final Boolean defaultValue) throws ExmlBuilderException {
final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultManaged.class);
if (annotation.length == 0) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultManaged on " + classType.getClass().getCanonicalName());
}
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) {
return defaultValue;
}
if (annotation.length > 1) {
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultOptional on " + classType.getClass().getCanonicalName());
}
return ((XmlDefaultOptional) 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 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 @XmlManaged on " + constructor.getClass().getCanonicalName());
}
return ((XmlManaged) annotation[0]).value();
} }
public static Boolean getIsManaged(final Field element, final Boolean parentValue) throws ExmlBuilderException { public static Boolean getIsManaged(final Field element, final Boolean parentValue) throws ExmlBuilderException {
@ -258,15 +190,15 @@ public class ReflectTools {
return ((XmlManaged) annotation[0]).value(); return ((XmlManaged) annotation[0]).value();
} }
public static Boolean getIsManaged(final Constructor<?> constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { public static Boolean getIsOptional(final Constructor<?> constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlManaged.class); final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlOptional.class);
if (annotation.length == 0) { if (annotation.length == 0) {
return parentValue; return parentValue;
} }
if (annotation.length > 1) { 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 { public static Boolean getIsOptional(final Field element, final Boolean parentValue) throws Exception {
@ -291,15 +223,92 @@ public class ReflectTools {
return ((XmlOptional) annotation[0]).value(); return ((XmlOptional) annotation[0]).value();
} }
public static Boolean getIsOptional(final Constructor<?> constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException { public static String getListName(final Field element, final String defaultValue) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlOptional.class); final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlList.class);
if (annotation.length == 0) { if (annotation.length == 0) {
return parentValue; return defaultValue;
} }
if (annotation.length > 1) { 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 { public static String[] getNames(final Field element, final String defaultValue) throws Exception {
@ -359,91 +368,86 @@ public class ReflectTools {
} }
return tmp; return tmp;
} }
public static String[] getNames(final Constructor<?> element, final String defaultValue) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlName.class); public static Class<?>[] getTypeField(final Field fieldDescription) {
if (annotation.length == 0) { Class<?> type = fieldDescription.getType();
if (defaultValue == null) { Class<?> subType = null;
return null; Type empppe = fieldDescription.getGenericType();
} if (empppe instanceof ParameterizedType plopppppp) {
return new String[] { defaultValue }; Type[] realType = plopppppp.getActualTypeArguments();
} if (realType.length > 0) {
if (annotation.length > 1) { try {
throw new Exception("Must not have more than 1 element @XmlName on " + element.getClass().getCanonicalName()); subType = Class.forName(realType[0].getTypeName());
} } catch (ClassNotFoundException e) {
final String[] tmp = ((XmlName) annotation[0]).value(); // TODO Auto-generated catch block
if (tmp == null) { e.printStackTrace();
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 Constructor<?> constructor, final Parameter element, final String defaultValue) throws Exception { return new Class<?>[] { type, subType };
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 Class<?>[] getTypeParameterfunction(final Constructor<?> elem, final int paramId) throws ClassNotFoundException {
Class<?> type = null;
Class<?> subType = null;
public static String getListName(final Field element, final String defaultValue) throws Exception { type = elem.getParameters()[paramId].getType();
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlList.class); if (List.class.isAssignableFrom(type)) {
if (annotation.length == 0) { Class<?> internalModelClass = null;
return defaultValue; 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());
} }
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; subType = internalModelClass;
} }
public static String getListName(final Method element, final String defaultValue) throws Exception { return new Class<?>[] { type, subType };
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 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());
}
}
}
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 new Class<?>[] { type, subType };
}
private ReflectTools() {}
} }

2
test/.gitignore vendored
View File

@ -1 +1,3 @@
/__pycache__/
/bin/ /bin/