[DEV] some updates

This commit is contained in:
Edouard DUPIN 2025-08-10 00:50:06 +02:00
parent cff3646783
commit 419983a77f

View File

@ -45,7 +45,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (className != null) { if (className != null) {
this.names = className; this.names = className;
} }
if (classType.getNestHost() == classType) { if (classType.getNestHost() == classType) {
this.isSubClass = false; this.isSubClass = false;
} else if (!Modifier.isStatic(classType.getModifiers())) { } else if (!Modifier.isStatic(classType.getModifiers())) {
@ -57,7 +57,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (classType.isPrimitive()) { if (classType.isPrimitive()) {
LOGGER.error("[CRITICAL] Detect primitive ==> impossible case !!! "); LOGGER.error("[CRITICAL] Detect primitive ==> impossible case !!! ");
} }
final Boolean isDefaultManaged = ReflectTools.getIsDefaultManaged(classType, IntrospectionModel.DEFAULT_MANAGED); final Boolean isDefaultManaged = ReflectTools.getIsDefaultManaged(classType,
IntrospectionModel.DEFAULT_MANAGED);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// -- Parse constructor // -- Parse constructor
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -93,21 +94,23 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (namesBeans == null) { if (namesBeans == null) {
namesBeans = new String[elem.getParameterCount() - offsetSubClass]; namesBeans = new String[elem.getParameterCount() - offsetSubClass];
} else if (elem.getParameterCount() != namesBeans.length + offsetSubClass) { } else if (elem.getParameterCount() != namesBeans.length + offsetSubClass) {
throw new AknotException("Wrong number of parameter in constructor with ne number declared in the @XmlName (for bean name)"); throw new AknotException(
"Wrong number of parameter in constructor with ne number declared in the @XmlName (for bean name)");
} }
final Boolean[] isAttributes = new Boolean[elem.getParameterCount() - offsetSubClass]; final Boolean[] isAttributes = new Boolean[elem.getParameterCount() - offsetSubClass];
final Boolean[] isCaseSensitives = new Boolean[elem.getParameterCount() - offsetSubClass]; final Boolean[] isCaseSensitives = new Boolean[elem.getParameterCount() - offsetSubClass];
final Boolean[] isOptionals = new Boolean[elem.getParameterCount() - offsetSubClass]; final Boolean[] isOptionals = new Boolean[elem.getParameterCount() - offsetSubClass];
final Boolean[] isManageds = new Boolean[elem.getParameterCount() - offsetSubClass]; final Boolean[] isManageds = new Boolean[elem.getParameterCount() - offsetSubClass];
final Class<?>[][] clazz = new Class<?>[elem.getParameterCount() - offsetSubClass][]; final Class<?>[][] clazz = new Class<?>[elem.getParameterCount() - offsetSubClass][];
final String[][] names = new String[elem.getParameterCount() - offsetSubClass][]; final String[][] names = new String[elem.getParameterCount() - offsetSubClass][];
final Parameter[] params = elem.getParameters(); final Parameter[] params = elem.getParameters();
for (int iii = offsetSubClass; iii < params.length; iii++) { for (int iii = offsetSubClass; iii < params.length; iii++) {
final Parameter paramElem = params[iii]; final Parameter paramElem = params[iii];
isAttributes[iii - offsetSubClass] = ReflectTools.getIsAttribute(elem, paramElem, null); isAttributes[iii - offsetSubClass] = ReflectTools.getIsAttribute(elem, paramElem, null);
isCaseSensitives[iii - offsetSubClass] = ReflectTools.getIsCaseSensitive(elem, paramElem, null); isCaseSensitives[iii - offsetSubClass] = ReflectTools.getIsCaseSensitive(elem, paramElem,
null);
isOptionals[iii - offsetSubClass] = ReflectTools.getIsOptional(elem, paramElem, null); isOptionals[iii - offsetSubClass] = ReflectTools.getIsOptional(elem, paramElem, null);
isManageds[iii - offsetSubClass] = ReflectTools.getIsManaged(elem, paramElem, null); isManageds[iii - offsetSubClass] = ReflectTools.getIsManaged(elem, paramElem, null);
final String[] namesParam = ReflectTools.getNames(elem, paramElem, null); final String[] namesParam = ReflectTools.getNames(elem, paramElem, null);
@ -121,8 +124,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
// The constructor can not be managed if One of the element is mark as unmanaged... // The constructor can not be managed if One of the element is mark as unmanaged...
boolean managedParameters = true; boolean managedParameters = true;
for (int iii = 0; iii < isManageds.length; iii++) { for (final Boolean isManaged : isManageds) {
if (isManageds[iii] != null && !isManageds[iii]) { if (isManaged != null && !isManaged) {
managedParameters = false; managedParameters = false;
break; break;
} }
@ -132,7 +135,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
if (checkIfOneIsNull(namesBeans, 0)) { if (checkIfOneIsNull(namesBeans, 0)) {
LOGGER.trace(" - " + elem.toGenericString()); LOGGER.trace(" - " + elem.toGenericString());
LOGGER.trace(" ==> unmanaged (missing names description: " + Arrays.toString(namesBeans) + ")"); LOGGER.trace(" ==> unmanaged (missing names description: "
+ Arrays.toString(namesBeans) + ")");
} else { } else {
// check default attributes in the global list ... (do it at the end to be sure the constructor is VALID ... // check default attributes in the global list ... (do it at the end to be sure the constructor is VALID ...
for (int iii = 0; iii < namesBeans.length; iii++) { for (int iii = 0; iii < namesBeans.length; iii++) {
@ -144,15 +148,18 @@ public class IntrospectionModelComplex extends IntrospectionModel {
final Class<?> curentType = prop.getType(); final Class<?> curentType = prop.getType();
final Class<?> curentSubType = prop.getSubType(); final Class<?> curentSubType = prop.getSubType();
if (curentType != clazz[iii][0] && curentSubType != clazz[iii][1]) { if (curentType != clazz[iii][0] && curentSubType != clazz[iii][1]) {
throw new AknotException("Set 'return type' with a different value previous=" + curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() throw new AknotException("Set 'return type' with a different value previous="
+ " ==> new=" + clazz[iii][0] + " / " + clazz[iii][1] + " in " + elem.toGenericString()); + curentType.getCanonicalName() + " / "
+ curentSubType.getCanonicalName() + " ==> new=" + clazz[iii][0] + " / "
+ clazz[iii][1] + " in " + elem.toGenericString());
} }
final String[] names1 = names[iii]; final String[] names1 = names[iii];
if (names1 != null) { if (names1 != null) {
final String[] curentValue = prop.getNames(); final String[] curentValue = prop.getNames();
if (curentValue != null) { if (curentValue != null) {
// TODO maybe set the value permissive if no change !!! like the others... // TODO maybe set the value permissive if no change !!! like the others...
throw new AknotException("Set 'names' with a (already set!) " + elem.toGenericString()); throw new AknotException(
"Set 'names' with a (already set!) " + elem.toGenericString());
} }
prop.setNames(names1); prop.setNames(names1);
} }
@ -163,7 +170,9 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isAttribute != null) { if (isAttribute != null) {
final Boolean curentValue = prop.isAttribute(); final Boolean curentValue = prop.isAttribute();
if (curentValue != null && curentValue != isAttribute) { if (curentValue != null && curentValue != isAttribute) {
throw new AknotException("Set 'attribute' with a different value previous=" + curentValue + " ==> new=" + isAttribute + " in " + elem.toGenericString()); throw new AknotException(
"Set 'attribute' with a different value previous=" + curentValue
+ " ==> new=" + isAttribute + " in " + elem.toGenericString());
} }
prop.setAttribute(isAttribute); prop.setAttribute(isAttribute);
} }
@ -171,8 +180,9 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isCaseSensitive != null) { if (isCaseSensitive != null) {
final Boolean curentValue = prop.isCaseSensitive(); final Boolean curentValue = prop.isCaseSensitive();
if (curentValue != null && curentValue != isCaseSensitive) { if (curentValue != null && curentValue != isCaseSensitive) {
throw new AknotException( throw new AknotException("Set 'caseSensitive' with a different value previous="
"Set 'caseSensitive' with a different value previous=" + curentValue + " ==> new=" + isCaseSensitive + " in " + elem.toGenericString()); + curentValue + " ==> new=" + isCaseSensitive + " in "
+ elem.toGenericString());
} }
prop.setCaseSensitive(isCaseSensitive); prop.setCaseSensitive(isCaseSensitive);
} }
@ -180,7 +190,9 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isOptional != null) { if (isOptional != null) {
final Boolean curentValue = prop.isOptionnal(); final Boolean curentValue = prop.isOptionnal();
if (curentValue != null && curentValue != isOptional) { if (curentValue != null && curentValue != isOptional) {
throw new AknotException("Set 'optionnal' with a different value previous=" + curentValue + " ==> new=" + isOptional + " in " + elem.toGenericString()); throw new AknotException(
"Set 'optionnal' with a different value previous=" + curentValue
+ " ==> new=" + isOptional + " in " + elem.toGenericString());
} }
prop.setOptionnal(isOptional); prop.setOptionnal(isOptional);
} }
@ -188,7 +200,9 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isManaged != null) { if (isManaged != null) {
final Boolean curentValue = prop.isManaged(); final Boolean curentValue = prop.isManaged();
if (curentValue != null && curentValue != isManaged) { if (curentValue != null && curentValue != isManaged) {
throw new AknotException("Set 'managed' with a different value previous=" + curentValue + " ==> new=" + isManaged + " in " + elem.toGenericString()); throw new AknotException(
"Set 'managed' with a different value previous=" + curentValue
+ " ==> new=" + isManaged + " in " + elem.toGenericString());
} }
prop.setManaged(isManaged); prop.setManaged(isManaged);
} }
@ -218,7 +232,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
LOGGER.trace(tmpPrint.toString()); LOGGER.trace(tmpPrint.toString());
} }
final List<String> recordAllPossibleValues = new ArrayList<>(); final List<String> recordAllPossibleValues = new ArrayList<>();
if (this.isRecord) { if (this.isRecord) {
for (final ConstructorModel elem : this.constructors) { for (final ConstructorModel elem : this.constructors) {
for (int iii = 0; iii < elem.values().length; iii++) { for (int iii = 0; iii < elem.values().length; iii++) {
@ -246,7 +260,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
final String[] names = ReflectTools.getNames(elem, null); final String[] names = ReflectTools.getNames(elem, null);
final Class<?>[] types = ReflectTools.getTypeField(elem); final Class<?>[] types = ReflectTools.getTypeField(elem);
IntrospectionProperty prop = findElement(elem.getName()); IntrospectionProperty prop = findElement(elem.getName());
if (prop == null) { if (prop == null) {
prop = new IntrospectionProperty(elem.getName(), types, names); prop = new IntrospectionProperty(elem.getName(), types, names);
@ -255,7 +269,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
final Class<?> curentType = prop.getType(); final Class<?> curentType = prop.getType();
final Class<?> curentSubType = prop.getSubType(); final Class<?> curentSubType = prop.getSubType();
if (curentType != types[0] && curentSubType != types[1]) { if (curentType != types[0] && curentSubType != types[1]) {
throw new AknotException("Set 'return type' with a different value previous=" + curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() + " ==> new=" throw new AknotException("Set 'return type' with a different value previous="
+ curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() + " ==> new="
+ types[0] + " / " + types[1] + " in " + elem.toGenericString()); + types[0] + " / " + types[1] + " in " + elem.toGenericString());
} }
final String[] names1 = names; final String[] names1 = names;
@ -268,7 +283,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
prop.setNames(names1); prop.setNames(names1);
} }
} }
final String description = ReflectTools.getDescription(elem, null); final String description = ReflectTools.getDescription(elem, null);
if (description != null) { if (description != null) {
prop.setDescription(description); prop.setDescription(description);
@ -306,7 +321,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
prop.setFactory(factory); prop.setFactory(factory);
} }
// generate getter and setter with field. // generate getter and setter with field.
final IntrospectionPropertyField modifier = new IntrospectionPropertyField(elem); final IntrospectionPropertyField modifier = new IntrospectionPropertyField(elem);
// if the field is final ==> we can not set the value... // if the field is final ==> we can not set the value...
if (Modifier.isFinal(elem.getModifiers())) { if (Modifier.isFinal(elem.getModifiers())) {
@ -317,21 +332,22 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
LOGGER.trace(" - " + elem.toGenericString()); LOGGER.trace(" - " + elem.toGenericString());
} }
final List<Method> methods = ReflectClass.getFilterGenericFucntion(this.classType, recordAllPossibleValues, true, true, true); final List<Method> methods = ReflectClass.getFilterGenericFucntion(this.classType, recordAllPossibleValues,
true, true, true);
LOGGER.trace(" Methods: (" + methods.size() + ")"); LOGGER.trace(" Methods: (" + methods.size() + ")");
for (final Method elem : methods) { for (final Method elem : methods) {
LOGGER.trace(" - " + elem.toGenericString()); LOGGER.trace(" - " + elem.toGenericString());
} }
// Separate the methods and filer as: // Separate the methods and filer as:
// - XXX GetXxx(); & XXX != boolean // - XXX GetXxx(); & XXX != boolean
// - void setXxx(XXX elem); // - void setXxx(XXX elem);
// - [bB]oolean isXxx(); // - [bB]oolean isXxx();
// for records: // for records:
// - xxx(); // - xxx();
final List<Method> methodsGet = ReflectClass.extractGetMethod(classType, methods, recordAllPossibleValues); final List<Method> methodsGet = ReflectClass.extractGetMethod(classType, methods, recordAllPossibleValues);
final List<Method> methodsSet = ReflectClass.extractSetMethod(classType, methods); final List<Method> methodsSet = ReflectClass.extractSetMethod(classType, methods);
final List<Method> methodsIs = ReflectClass.extractIsMethod(classType, methods); final List<Method> methodsIs = ReflectClass.extractIsMethod(classType, methods);
@ -339,8 +355,10 @@ public class IntrospectionModelComplex extends IntrospectionModel {
this.tostring = ReflectClass.extractToString(methods); this.tostring = ReflectClass.extractToString(methods);
// associate methods by pair. // associate methods by pair.
for (final Method method : methodsGet) { for (final Method method : methodsGet) {
final String name = Tools.decapitalizeFirst(this.isRecord ? method.getName() : method.getName().substring(3)); final String name = Tools
final IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method)); .decapitalizeFirst(this.isRecord ? method.getName() : method.getName().substring(3));
final IntrospectionProperty prop = updateForMethod(name, method,
ReflectTools.getTypeReturnFunction(method));
// generate getter and setter with field. // generate getter and setter with field.
final IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method); final IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method);
prop.setGetter(modifier); prop.setGetter(modifier);
@ -348,25 +366,29 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (!this.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));
final IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method)); final IntrospectionProperty prop = updateForMethod(name, method,
ReflectTools.getTypeReturnFunction(method));
// generate getter and setter with field. // generate getter and setter with field.
final IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method); final IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method);
prop.setGetter(modifier); prop.setGetter(modifier);
} }
for (final Method method : methodsSet) { for (final Method method : methodsSet) {
final String name = Tools.decapitalizeFirst(method.getName().substring(3)); final String name = Tools.decapitalizeFirst(method.getName().substring(3));
final IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeParameterfunction(method)); final IntrospectionProperty prop = updateForMethod(name, method,
ReflectTools.getTypeParameterfunction(method));
// generate getter and setter with field. // generate getter and setter with field.
final IntrospectionPropertyMethodSetter modifier = new IntrospectionPropertyMethodSetter(method); final IntrospectionPropertyMethodSetter modifier = new IntrospectionPropertyMethodSetter(method);
prop.setSetter(modifier); prop.setSetter(modifier);
} }
} }
this.ignoreUnknown = ReflectTools.getIsIgnoreUnknown(classType, IntrospectionModel.DEFAULT_IGNORE_UNBKNOWN); this.ignoreUnknown = ReflectTools.getIsIgnoreUnknown(classType, IntrospectionModel.DEFAULT_IGNORE_UNBKNOWN);
this.defaultNullValue = ReflectTools.getIsDefaultNullValue(classType, IntrospectionModel.DEFAULT_DEFAULT_NULL_VALUE); this.defaultNullValue = ReflectTools.getIsDefaultNullValue(classType,
IntrospectionModel.DEFAULT_DEFAULT_NULL_VALUE);
// Set only at the end ==> no need before... // Set only at the end ==> no need before...
final Boolean isDefaultAttribute = ReflectTools.getIsDefaultAttribute(classType, IntrospectionModel.DEFAULT_ATTRIBUTE); final Boolean isDefaultAttribute = ReflectTools.getIsDefaultAttribute(classType,
IntrospectionModel.DEFAULT_ATTRIBUTE);
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
if (prop.isAttribute() == null) { if (prop.isAttribute() == null) {
prop.setAttribute(isDefaultAttribute); prop.setAttribute(isDefaultAttribute);
@ -377,13 +399,15 @@ public class IntrospectionModelComplex extends IntrospectionModel {
prop.setManaged(isDefaultManaged); prop.setManaged(isDefaultManaged);
} }
} }
final Boolean isDefaultOptional = ReflectTools.getIsDefaultOptional(classType, IntrospectionModel.DEFAULT_OPTIONAL); final Boolean isDefaultOptional = ReflectTools.getIsDefaultOptional(classType,
IntrospectionModel.DEFAULT_OPTIONAL);
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
if (prop.isOptionnal() == null) { if (prop.isOptionnal() == null) {
prop.setOptionnal(isDefaultOptional); prop.setOptionnal(isDefaultOptional);
} }
} }
final Boolean isDefaultCaseSensitive = ReflectTools.getIsDefaultCaseSensitive(classType, IntrospectionModel.DEFAULT_CASE_SENSITIVE); final Boolean isDefaultCaseSensitive = ReflectTools.getIsDefaultCaseSensitive(classType,
IntrospectionModel.DEFAULT_CASE_SENSITIVE);
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
if (prop.isCaseSensitive() == null) { if (prop.isCaseSensitive() == null) {
prop.setCaseSensitive(isDefaultCaseSensitive); prop.setCaseSensitive(isDefaultCaseSensitive);
@ -395,7 +419,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
prop.setNames(new String[] { prop.getBeanName() }); prop.setNames(new String[] { prop.getBeanName() });
} }
} }
} catch (final Exception ex) { } catch (final Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
throw new AknotException("Error in creating introspection data ... " + ex.getMessage()); throw new AknotException("Error in creating introspection data ... " + ex.getMessage());
@ -404,21 +428,21 @@ public class IntrospectionModelComplex extends IntrospectionModel {
Collections.sort(this.elements, (a, b) -> a.getNames()[0].compareTo(b.getNames()[0])); Collections.sort(this.elements, (a, b) -> a.getNames()[0].compareTo(b.getNames()[0]));
// separate managed and unmanaged to optimize performances... // separate managed and unmanaged to optimize performances...
this.elementUnManaged = this.elements.stream().filter(o -> !o.isManaged()).collect(Collectors.toList()); this.elementUnManaged = this.elements.stream().filter(o -> !o.isManaged()).collect(Collectors.toList());
this.elements = this.elements.stream().filter(o -> o.isManaged()).collect(Collectors.toList()); this.elements = this.elements.stream().filter(IntrospectionProperty::isManaged).collect(Collectors.toList());
//display(); //display();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T> T[] autoCast(final Class<T> clazz, final List<Object> data) { private <T> T[] autoCast(final Class<T> clazz, final List<Object> data) {
final T[] out = (T[]) java.lang.reflect.Array.newInstance(clazz, data.size());// T[data.size()]; final T[] out = (T[]) java.lang.reflect.Array.newInstance(clazz, data.size());// T[data.size()];
for (int iii = 0; iii < data.size(); iii++) { for (int iii = 0; iii < data.size(); iii++) {
out[iii] = (T) data.get(iii); out[iii] = (T) data.get(iii);
} }
return out; return out;
//return data.stream().map(clazz::cast).toArray(new T[data.size()]);//java.lang.reflect.Array.newInstance((propMethode.getSubType(), tmpp.size())); //return data.stream().map(clazz::cast).toArray(new T[data.size()]);//java.lang.reflect.Array.newInstance((propMethode.getSubType(), tmpp.size()));
} }
private boolean checkIdenticalArray(final String[] valA, final String[] valB) { private boolean checkIdenticalArray(final String[] valA, final String[] valB) {
if (valA == valB) { if (valA == valB) {
return true; return true;
@ -433,7 +457,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return true; return true;
} }
// private boolean checkIfOneIsNull(Boolean[] values, int offset) { // private boolean checkIfOneIsNull(Boolean[] values, int offset) {
// for (int iii=offset; iii<values.length; iii++) { // for (int iii=offset; iii<values.length; iii++) {
// if (values[iii] == null) { // if (values[iii] == null) {
@ -450,9 +474,12 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return false; return false;
} }
@Override @Override
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes, final boolean attributeIndependent) throws AknotException { public Object createObject(
final Map<String, Object> properties,
final Map<String, List<Object>> nodes,
final boolean attributeIndependent) throws AknotException {
Object tmp = null; Object tmp = null;
// STEP 1: try to create the object with provided parameter (if a constructor exist....) // STEP 1: try to create the object with provided parameter (if a constructor exist....)
if (!this.constructors.isEmpty()) { if (!this.constructors.isEmpty()) {
@ -470,7 +497,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (valueToInject == null) { if (valueToInject == null) {
final List<Object> tmppp = nodes.get(elem.values()[iii]); final List<Object> tmppp = nodes.get(elem.values()[iii]);
if (tmppp != null) { if (tmppp != null) {
if (List.class == findBeanNodeDescription(elem.values()[iii], attributeIndependent).getType()) { if (List.class == findBeanNodeDescription(elem.values()[iii], attributeIndependent)
.getType()) {
valueToInject = tmppp; valueToInject = tmppp;
} else if (tmppp.size() >= 1) { } else if (tmppp.size() >= 1) {
valueToInject = tmppp.get(0); valueToInject = tmppp.get(0);
@ -502,39 +530,63 @@ public class IntrospectionModelComplex extends IntrospectionModel {
case 2 -> elem.constructor().newInstance(inputs[0], inputs[1]); case 2 -> elem.constructor().newInstance(inputs[0], inputs[1]);
case 3 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2]); case 3 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2]);
case 4 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3]); case 4 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3]);
case 5 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4]); case 5 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
case 6 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5]); inputs[4]);
case 7 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6]); case 6 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
case 8 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7]); inputs[4], inputs[5]);
case 9 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8]); case 7 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
case 10 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9]); inputs[4], inputs[5], inputs[6]);
case 11 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10]); case 8 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
case 12 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], inputs[4], inputs[5], inputs[6], inputs[7]);
case 9 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8]);
case 10 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9]);
case 11 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10]);
case 12 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
inputs[11]); inputs[11]);
case 13 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], case 13 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
inputs[11], inputs[12]); inputs[11], inputs[12]);
case 14 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], case 14 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
inputs[11], inputs[12], inputs[13]); inputs[11], inputs[12], inputs[13]);
case 15 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], case 15 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
inputs[11], inputs[12], inputs[13], inputs[14]); inputs[11], inputs[12], inputs[13], inputs[14]);
case 16 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], case 16 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
inputs[11], inputs[12], inputs[13], inputs[14], inputs[15]); inputs[11], inputs[12], inputs[13], inputs[14], inputs[15]);
case 17 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], case 17 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16]); inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16]);
case 18 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], case 18 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16], inputs[17]); inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
case 19 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16],
inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16], inputs[17], inputs[18]); inputs[17]);
case 20 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], case 19 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16], inputs[17], inputs[18], inputs[19]); inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
case 21 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10], inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16],
inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16], inputs[17], inputs[18], inputs[19], inputs[20]); inputs[17], inputs[18]);
default -> throw new AknotException("to much parameter in the constructor... " + inputs.length); case 20 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16],
inputs[17], inputs[18], inputs[19]);
case 21 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3],
inputs[4], inputs[5], inputs[6], inputs[7], inputs[8], inputs[9], inputs[10],
inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16],
inputs[17], inputs[18], inputs[19], inputs[20]);
default -> throw new AknotException(
"to much parameter in the constructor... " + inputs.length);
}; };
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
throw new AknotException("Error when creating the Object ..." + this.classType.getCanonicalName()); throw new AknotException(
"Error when creating the Object ..." + this.classType.getCanonicalName());
} }
// Remove all previously added parameters // Remove all previously added parameters
for (int iii = 0; iii < elem.values().length; iii++) { for (int iii = 0; iii < elem.values().length; iii++) {
@ -559,7 +611,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} else { } else {
tmp = this.constructorEmpty.newInstance(); tmp = this.constructorEmpty.newInstance();
} }
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) { } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | SecurityException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -573,7 +626,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return tmp; return tmp;
} }
public void display() { public void display() {
LOGGER.info("Class: {} nbProperty:{}", this.classType.getCanonicalName(), this.elements.size()); LOGGER.info("Class: {} nbProperty:{}", this.classType.getCanonicalName(), this.elements.size());
LOGGER.info("Managed:"); LOGGER.info("Managed:");
@ -615,8 +668,10 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
} }
} }
protected IntrospectionProperty findBeanNodeDescription(final String propertyBeanName, final boolean attributeIndependent) throws AknotException { protected IntrospectionProperty findBeanNodeDescription(
final String propertyBeanName,
final boolean attributeIndependent) throws AknotException {
LOGGER.debug("Find node description for element: {}", propertyBeanName); LOGGER.debug("Find node description for element: {}", propertyBeanName);
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
LOGGER.debug(" ==> {} => {}", prop.getBeanName(), prop.isAttribute()); LOGGER.debug(" ==> {} => {}", prop.getBeanName(), prop.isAttribute());
@ -629,7 +684,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
protected IntrospectionProperty findBeanPropertyDescription(final String propertyBeanName) throws AknotException { protected IntrospectionProperty findBeanPropertyDescription(final String propertyBeanName) throws AknotException {
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
if (!prop.isAttribute()) { if (!prop.isAttribute()) {
@ -641,7 +696,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
protected IntrospectionProperty findElement(final String beanName) { protected IntrospectionProperty findElement(final String beanName) {
for (final IntrospectionProperty elem : this.elements) { for (final IntrospectionProperty elem : this.elements) {
if (elem.getBeanName().equals(beanName)) { if (elem.getBeanName().equals(beanName)) {
@ -650,7 +705,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
protected IntrospectionProperty findNodeDescription(final String propertyName) throws AknotException { protected IntrospectionProperty findNodeDescription(final String propertyName) throws AknotException {
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
if (prop.isAttribute()) { if (prop.isAttribute()) {
@ -662,7 +717,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
protected IntrospectionProperty findPropertyDescription(final String propertyName) throws AknotException { protected IntrospectionProperty findPropertyDescription(final String propertyName) throws AknotException {
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
if (!prop.isAttribute()) { if (!prop.isAttribute()) {
@ -674,7 +729,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
@Override @Override
public List<IntrospectionProperty> getAttributes() { public List<IntrospectionProperty> getAttributes() {
final List<IntrospectionProperty> out = new ArrayList<>(); final List<IntrospectionProperty> out = new ArrayList<>();
@ -685,7 +740,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return out; return out;
} }
@Override @Override
public String getBeanName(final String nodeName) { public String getBeanName(final String nodeName) {
for (final IntrospectionProperty elem : this.elements) { for (final IntrospectionProperty elem : this.elements) {
@ -695,7 +750,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
@Override @Override
public String getBeanNameModel(final String nodeName) { public String getBeanNameModel(final String nodeName) {
for (final IntrospectionProperty elem : this.elements) { for (final IntrospectionProperty elem : this.elements) {
@ -708,7 +763,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
@Override @Override
public List<String> getNodeAvaillable() { public List<String> getNodeAvaillable() {
final List<String> out = new ArrayList<>(); final List<String> out = new ArrayList<>();
@ -720,7 +775,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return out; return out;
} }
@Override @Override
public List<IntrospectionProperty> getNodes() { public List<IntrospectionProperty> getNodes() {
final List<IntrospectionProperty> out = new ArrayList<>(); final List<IntrospectionProperty> out = new ArrayList<>();
@ -731,7 +786,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return out; return out;
} }
@Override @Override
public List<IntrospectionProperty> getSignals() { public List<IntrospectionProperty> getSignals() {
final List<IntrospectionProperty> out = new ArrayList<>(); final List<IntrospectionProperty> out = new ArrayList<>();
@ -743,7 +798,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return out; return out;
} }
@Override @Override
public String getTextBeanName() { public String getTextBeanName() {
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
@ -754,9 +809,10 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
@Override @Override
public String getTreeNameOfSubNode(final String nodeBeanName, final boolean attributeIndependent) throws AknotException { public String getTreeNameOfSubNode(final String nodeBeanName, final boolean attributeIndependent)
throws AknotException {
LOGGER.debug(" nodeType='" + nodeBeanName + "'"); LOGGER.debug(" nodeType='" + nodeBeanName + "'");
final IntrospectionProperty propMethode = findBeanNodeDescription(nodeBeanName, attributeIndependent); final IntrospectionProperty propMethode = findBeanNodeDescription(nodeBeanName, attributeIndependent);
if (propMethode != null && propMethode.canSetValue()) { if (propMethode != null && propMethode.canSetValue()) {
@ -765,7 +821,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
throw new AknotException("can not find the field '" + nodeBeanName + "'"); throw new AknotException("can not find the field '" + nodeBeanName + "'");
} }
@Override @Override
public Class<?> getTypeOfProperty(final String nodeName) throws AknotException { public Class<?> getTypeOfProperty(final String nodeName) throws AknotException {
LOGGER.debug("nodeType='" + nodeName + "'"); LOGGER.debug("nodeType='" + nodeName + "'");
@ -774,17 +830,18 @@ public class IntrospectionModelComplex extends IntrospectionModel {
LOGGER.debug(" ==> find '" + propField.getNames()); LOGGER.debug(" ==> find '" + propField.getNames());
return propField.getType(); return propField.getType();
} }
throw new AknotException("can not find the field '" + nodeName + "' available: " + getNodeAvaillable()); throw new AknotException("can not find the field '" + nodeName + "' available: " + getNodeAvaillable());
} }
/** /**
* Detect a subNode, and ask the type of the node at the parent Class * Detect a subNode, and ask the type of the node at the parent Class
* @param nodeBeanName Name of the node (bean name access ==> not the XML name) * @param nodeBeanName Name of the node (bean name access ==> not the XML name)
* @return Class of the node to create * @return Class of the node to create
*/ */
@Override @Override
public Class<?> getTypeOfSubNode(final String nodeBeanNames, final boolean attributeIndependent) throws AknotException { public Class<?> getTypeOfSubNode(final String nodeBeanNames, final boolean attributeIndependent)
throws AknotException {
final String[] elemstNames = nodeBeanNames.split("#"); final String[] elemstNames = nodeBeanNames.split("#");
final String nodeBeanName = elemstNames[0]; final String nodeBeanName = elemstNames[0];
LOGGER.debug("NodeType='" + nodeBeanName + "'"); LOGGER.debug("NodeType='" + nodeBeanName + "'");
@ -799,9 +856,10 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
throw new AknotException("can not find the field '" + nodeBeanName + "' available: " + getNodeAvaillable()); throw new AknotException("can not find the field '" + nodeBeanName + "' available: " + getNodeAvaillable());
} }
@Override @Override
public Class<?> getTypeOfSubNodeList(final String nodeBeanNames, final boolean attributeIndependent) throws AknotException { public Class<?> getTypeOfSubNodeList(final String nodeBeanNames, final boolean attributeIndependent)
throws AknotException {
final String[] elemstNames = nodeBeanNames.split("#"); final String[] elemstNames = nodeBeanNames.split("#");
final String nodeBeanName = elemstNames[0]; final String nodeBeanName = elemstNames[0];
LOGGER.debug(" nodeType='" + nodeBeanName + "'"); LOGGER.debug(" nodeType='" + nodeBeanName + "'");
@ -816,7 +874,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
throw new AknotException("can not find the field '" + nodeBeanName + "' available: " + getNodeAvaillable()); throw new AknotException("can not find the field '" + nodeBeanName + "' available: " + getNodeAvaillable());
} }
@Override @Override
public Class<?> getTypeOfSubProperty(final String nodeName) throws AknotException { public Class<?> getTypeOfSubProperty(final String nodeName) throws AknotException {
LOGGER.debug(" nodeType='" + nodeName + "'"); LOGGER.debug(" nodeType='" + nodeName + "'");
@ -827,7 +885,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
throw new AknotException("can not find the field '" + nodeName + "' available: " + getNodeAvaillable()); throw new AknotException("can not find the field '" + nodeName + "' available: " + getNodeAvaillable());
} }
@Override @Override
public Class<?> getTypeOfText() { public Class<?> getTypeOfText() {
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
@ -838,7 +896,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return null; return null;
} }
@Override @Override
public Object getValue(final String propertyName, final String propertyValue) throws AknotException { public Object getValue(final String propertyName, final String propertyValue) throws AknotException {
LOGGER.debug(" propertyName='" + propertyName + "' propertyValue='" + propertyValue + "' "); LOGGER.debug(" propertyName='" + propertyName + "' propertyValue='" + propertyValue + "' ");
@ -856,7 +914,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
throw new AknotException("can not find the field '" + propertyName + "'"); throw new AknotException("can not find the field '" + propertyName + "'");
} }
@Override @Override
public Object getValueFromText(final String text) throws AknotException { public Object getValueFromText(final String text) throws AknotException {
// Note if the type is an Array<>() or a List<>() ==> we parse element by element ... then we need to keep the undertype... // Note if the type is an Array<>() or a List<>() ==> we parse element by element ... then we need to keep the undertype...
@ -889,10 +947,11 @@ public class IntrospectionModelComplex extends IntrospectionModel {
// } // }
} }
LOGGER.debug("======>>>>>>> subElement input type : " + classTypeLocal.getCanonicalName()); LOGGER.debug("======>>>>>>> subElement input type : " + classTypeLocal.getCanonicalName());
if (this.valueof == null) { if (this.valueof == null) {
if (StringSerializer.contains(classTypeLocal)) { if (StringSerializer.contains(classTypeLocal)) {
throw new AknotException("function 'valueOf' for '" + classTypeLocal.getCanonicalName() + "' is not defined and not registered for specific type"); throw new AknotException("function 'valueOf' for '" + classTypeLocal.getCanonicalName()
+ "' is not defined and not registered for specific type");
} }
return StringSerializer.valueOf(classTypeLocal, text); return StringSerializer.valueOf(classTypeLocal, text);
} }
@ -900,19 +959,22 @@ public class IntrospectionModelComplex extends IntrospectionModel {
return this.valueof.invoke(null, text); return this.valueof.invoke(null, text);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
if (Enum.class.isAssignableFrom(this.classType)) { if (Enum.class.isAssignableFrom(this.classType)) {
throw new AknotException("Error in call 'valueOf(String ...)' for enum '" + classTypeLocal.getCanonicalName() + "' ==> '" + text + "' ... availlable list: " throw new AknotException(
+ Arrays.asList(this.classType.getEnumConstants())); "Error in call 'valueOf(String ...)' for enum '" + classTypeLocal.getCanonicalName() + "' ==> '"
+ text + "' ... availlable list: " + Arrays.asList(this.classType.getEnumConstants()));
} }
e.printStackTrace(); e.printStackTrace();
throw new AknotException("Error in call 'valueOf(String ...)' for '" + classTypeLocal.getCanonicalName() + "' " + e.getMessage()); throw new AknotException("Error in call 'valueOf(String ...)' for '" + classTypeLocal.getCanonicalName()
+ "' " + e.getMessage());
} }
} }
@Override @Override
public boolean hasTextModel() { public boolean hasTextModel() {
LOGGER.warn("in {}", this.classType.getCanonicalName()); LOGGER.warn("in {}", this.classType.getCanonicalName());
for (final IntrospectionProperty prop : this.elements) { for (final IntrospectionProperty prop : this.elements) {
LOGGER.warn(" check {}, manage={} cas setValue={} isText={}", prop.getBeanName(), prop.isManaged(), prop.canSetValue(), prop.isText()); LOGGER.warn(" check {}, manage={} cas setValue={} isText={}", prop.getBeanName(), prop.isManaged(),
prop.canSetValue(), prop.isText());
final Boolean isText = prop.isText(); final Boolean isText = prop.isText();
if (isText != null && isText) { if (isText != null && isText) {
return true; return true;
@ -920,19 +982,25 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return false; return false;
} }
@Override @Override
public boolean isNative() { public boolean isNative() {
return false; return false;
} }
private void setValue(final Object data, final String beanName, final Object value, final boolean attributeIndependent) throws AknotException { private void setValue(
LOGGER.trace(" Set value ='" + beanName + "' propertyValue='" + value + "' " + value.getClass().getCanonicalName()); final Object data,
final String beanName,
final Object value,
final boolean attributeIndependent) throws AknotException {
LOGGER.trace(" 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, attributeIndependent); final IntrospectionProperty propMethode = findBeanNodeDescription(beanName, attributeIndependent);
if (propMethode != null && propMethode.canSetValue()) { if (propMethode != null && propMethode.canSetValue()) {
LOGGER.trace(" ==> find '" + Arrays.toString(propMethode.getNames()) + " type=" + propMethode.getType() + " sub-type=" + propMethode.getSubType()); LOGGER.trace(" ==> find '" + Arrays.toString(propMethode.getNames()) + " type="
+ propMethode.getType() + " sub-type=" + propMethode.getSubType());
if (propMethode.getType().isAssignableFrom(value.getClass())) { if (propMethode.getType().isAssignableFrom(value.getClass())) {
propMethode.setExistingValue(data, value); propMethode.setExistingValue(data, value);
} else if (value instanceof List) { } else if (value instanceof List) {
@ -940,10 +1008,12 @@ public class IntrospectionModelComplex extends IntrospectionModel {
final List<Object> tmpp = (List<Object>) value; final List<Object> tmpp = (List<Object>) value;
if (propMethode.getType().isArray()) { if (propMethode.getType().isArray()) {
if (propMethode.getType().componentType().isPrimitive()) { if (propMethode.getType().componentType().isPrimitive()) {
final Object newData = ArraysTools.listToPrimitiveAuto(propMethode.getType().componentType(), tmpp); final Object newData = ArraysTools
.listToPrimitiveAuto(propMethode.getType().componentType(), tmpp);
propMethode.setExistingValue(data, newData); propMethode.setExistingValue(data, newData);
} else { } else {
LOGGER.trace(" datas type: " + autoCast(propMethode.getType().componentType(), tmpp).getClass().getCanonicalName()); LOGGER.trace(" datas type: " + autoCast(propMethode.getType().componentType(), tmpp)
.getClass().getCanonicalName());
LOGGER.trace(" methode type: " + propMethode.getType().getCanonicalName()); LOGGER.trace(" methode type: " + propMethode.getType().getCanonicalName());
propMethode.setExistingValue(data, autoCast(propMethode.getType().componentType(), tmpp)); propMethode.setExistingValue(data, autoCast(propMethode.getType().componentType(), tmpp));
} }
@ -974,7 +1044,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
final double dataPrimitive = (Double) value; final double dataPrimitive = (Double) value;
propMethode.setExistingValue(data, dataPrimitive); propMethode.setExistingValue(data, dataPrimitive);
} else { } else {
} }
return; return;
} }
@ -983,7 +1053,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
{ {
final IntrospectionProperty propField = findBeanPropertyDescription(beanName); final IntrospectionProperty propField = findBeanPropertyDescription(beanName);
if (propField != null && propField.canSetValue()) { if (propField != null && propField.canSetValue()) {
LOGGER.trace(" ==> find '" + Arrays.toString(propField.getNames()) + " type=" + propField.getType() + " sub-type=" + propField.getSubType()); LOGGER.trace(" ==> find '" + Arrays.toString(propField.getNames()) + " type=" + propField.getType()
+ " sub-type=" + propField.getSubType());
if (propField.getType().isAssignableFrom(value.getClass())) { if (propField.getType().isAssignableFrom(value.getClass())) {
propField.setExistingValue(data, value); propField.setExistingValue(data, value);
// Some specific case for primitives values // Some specific case for primitives values
@ -1034,7 +1105,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
final double[] datas = ArraysTools.listDoubleToPrimitive(tmpp); final double[] datas = ArraysTools.listDoubleToPrimitive(tmpp);
propField.setExistingValue(data, datas); propField.setExistingValue(data, datas);
} else { } else {
LOGGER.trace(" datas type: " + autoCast(propField.getType().componentType(), tmpp).getClass().getCanonicalName()); LOGGER.trace(" datas type: " + autoCast(propField.getType().componentType(), tmpp)
.getClass().getCanonicalName());
LOGGER.trace(" methode type: " + propField.getType().getCanonicalName()); LOGGER.trace(" methode type: " + propField.getType().getCanonicalName());
propField.setExistingValue(data, autoCast(propField.getType().componentType(), tmpp)); propField.setExistingValue(data, autoCast(propField.getType().componentType(), tmpp));
} }
@ -1049,12 +1121,13 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
throw new AknotException("can not find the field '" + beanName + "'"); throw new AknotException("can not find the field '" + beanName + "'");
} }
@Override @Override
public String toString(final Object data) throws AknotException { public String toString(final Object data) throws AknotException {
if (this.tostring == null) { if (this.tostring == null) {
if (StringSerializer.contains(this.classType)) { if (StringSerializer.contains(this.classType)) {
throw new AknotException("function 'toString' for '" + this.classType.getCanonicalName() + "' is not defined and not registered for specific type"); throw new AknotException("function 'toString' for '" + this.classType.getCanonicalName()
+ "' is not defined and not registered for specific type");
} }
return StringSerializer.toString(data); return StringSerializer.toString(data);
} }
@ -1062,15 +1135,17 @@ public class IntrospectionModelComplex extends IntrospectionModel {
return (String) this.tostring.invoke(data); return (String) this.tostring.invoke(data);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
if (Enum.class.isAssignableFrom(this.classType)) { if (Enum.class.isAssignableFrom(this.classType)) {
throw new AknotException( throw new AknotException("Error in call 'toString()' for '" + this.classType.getCanonicalName()
"Error in call 'toString()' for '" + this.classType.getCanonicalName() + "' ==> '????' ... availlable list: " + Arrays.asList(this.classType.getEnumConstants())); + "' ==> '????' ... availlable list: " + Arrays.asList(this.classType.getEnumConstants()));
} }
e.printStackTrace(); e.printStackTrace();
throw new AknotException("Error in call 'toString()' for '" + this.classType.getCanonicalName() + "' " + e.getMessage()); throw new AknotException(
"Error in call 'toString()' for '" + this.classType.getCanonicalName() + "' " + e.getMessage());
} }
} }
private IntrospectionProperty updateForMethod(final String name, final Method method, final Class<?>[] types) throws Exception { private IntrospectionProperty updateForMethod(final String name, final Method method, final Class<?>[] types)
throws Exception {
IntrospectionProperty prop = findElement(name); IntrospectionProperty prop = findElement(name);
if (prop == null) { if (prop == null) {
final String[] names = ReflectTools.getNames(method, null); final String[] names = ReflectTools.getNames(method, null);
@ -1080,8 +1155,9 @@ public class IntrospectionModelComplex extends IntrospectionModel {
final Class<?> curentType = prop.getType(); final Class<?> curentType = prop.getType();
final Class<?> curentSubType = prop.getSubType(); final Class<?> curentSubType = prop.getSubType();
if (curentType != types[0] && curentSubType != types[1]) { if (curentType != types[0] && curentSubType != types[1]) {
throw new AknotException("Set 'return type' with a different value previous=" + curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() + " ==> new=" + types[0] throw new AknotException("Set 'return type' with a different value previous="
+ " / " + types[1] + " in " + method.toGenericString()); + curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() + " ==> new="
+ types[0] + " / " + types[1] + " in " + method.toGenericString());
} }
final String[] names = ReflectTools.getNames(method, null); final String[] names = ReflectTools.getNames(method, null);
if (names != null) { if (names != null) {
@ -1097,7 +1173,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (description != null) { if (description != null) {
final String curentValue = prop.getListName(); final String curentValue = prop.getListName();
if (curentValue != null && curentValue != description) { if (curentValue != null && curentValue != description) {
throw new AknotException("Set 'description' with a different value previous=" + curentValue + " ==> new=" + description + " in " + method.toGenericString()); throw new AknotException("Set 'description' with a different value previous=" + curentValue
+ " ==> new=" + description + " in " + method.toGenericString());
} }
prop.setDescription(description); prop.setDescription(description);
} }
@ -1105,7 +1182,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (listName != null) { if (listName != null) {
final String curentValue = prop.getListName(); final String curentValue = prop.getListName();
if (curentValue != null && curentValue != listName) { if (curentValue != null && curentValue != listName) {
throw new AknotException("Set 'listNAme' with a different value previous=" + curentValue + " ==> new=" + listName + " in " + method.toGenericString()); throw new AknotException("Set 'listNAme' with a different value previous=" + curentValue + " ==> new="
+ listName + " in " + method.toGenericString());
} }
prop.setListName(listName); prop.setListName(listName);
} }
@ -1113,7 +1191,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isAttribute != null) { if (isAttribute != null) {
final Boolean curentValue = prop.isAttribute(); final Boolean curentValue = prop.isAttribute();
if (curentValue != null && curentValue != isAttribute) { if (curentValue != null && curentValue != isAttribute) {
throw new AknotException("Set 'attribute' with a different value previous=" + curentValue + " ==> new=" + isAttribute + " in " + method.toGenericString()); throw new AknotException("Set 'attribute' with a different value previous=" + curentValue + " ==> new="
+ isAttribute + " in " + method.toGenericString());
} }
prop.setAttribute(isAttribute); prop.setAttribute(isAttribute);
} }
@ -1121,7 +1200,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isManaged != null) { if (isManaged != null) {
final Boolean curentValue = prop.isManaged(); final Boolean curentValue = prop.isManaged();
if (curentValue != null && curentValue != isManaged) { if (curentValue != null && curentValue != isManaged) {
throw new AknotException("Set 'managed' with a different value previous=" + curentValue + " ==> new=" + isManaged + " in " + method.toGenericString()); throw new AknotException("Set 'managed' with a different value previous=" + curentValue + " ==> new="
+ isManaged + " in " + method.toGenericString());
} }
prop.setManaged(isManaged); prop.setManaged(isManaged);
} }
@ -1129,7 +1209,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isOptionnal != null) { if (isOptionnal != null) {
final Boolean curentValue = prop.isOptionnal(); final Boolean curentValue = prop.isOptionnal();
if (curentValue != null && curentValue != isOptionnal) { if (curentValue != null && curentValue != isOptionnal) {
throw new AknotException("Set 'optionnal' with a different value previous=" + curentValue + " ==> new=" + isOptionnal + " in " + method.toGenericString()); throw new AknotException("Set 'optionnal' with a different value previous=" + curentValue + " ==> new="
+ isOptionnal + " in " + method.toGenericString());
} }
prop.setOptionnal(isOptionnal); prop.setOptionnal(isOptionnal);
} }
@ -1137,7 +1218,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isCaseSensitive != null) { if (isCaseSensitive != null) {
final Boolean curentValue = prop.isCaseSensitive(); final Boolean curentValue = prop.isCaseSensitive();
if (curentValue != null && curentValue != isCaseSensitive) { if (curentValue != null && curentValue != isCaseSensitive) {
throw new AknotException("Set 'case sensitive' with a different value previous=" + curentValue + " ==> new=" + isCaseSensitive + " in " + method.toGenericString()); throw new AknotException("Set 'case sensitive' with a different value previous=" + curentValue
+ " ==> new=" + isCaseSensitive + " in " + method.toGenericString());
} }
prop.setCaseSensitive(isCaseSensitive); prop.setCaseSensitive(isCaseSensitive);
} }
@ -1145,7 +1227,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
if (isText != null) { if (isText != null) {
final Boolean curentValue = prop.isText(); final Boolean curentValue = prop.isText();
if (curentValue != null && curentValue != isText) { if (curentValue != null && curentValue != isText) {
throw new AknotException("Set 'case sensitive' with a different value previous=" + curentValue + " ==> new=" + isText + " in " + method.toGenericString()); throw new AknotException("Set 'case sensitive' with a different value previous=" + curentValue
+ " ==> new=" + isText + " in " + method.toGenericString());
} }
prop.setTextMode(isText); prop.setTextMode(isText);
} }
@ -1155,4 +1238,5 @@ public class IntrospectionModelComplex extends IntrospectionModel {
} }
return prop; return prop;
} }
} }