diff --git a/src/main/org/atriasoft/aknot/pojo/IntrospectionModelComplex.java b/src/main/org/atriasoft/aknot/pojo/IntrospectionModelComplex.java index d999383..a678cc6 100644 --- a/src/main/org/atriasoft/aknot/pojo/IntrospectionModelComplex.java +++ b/src/main/org/atriasoft/aknot/pojo/IntrospectionModelComplex.java @@ -45,7 +45,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (className != null) { this.names = className; } - + if (classType.getNestHost() == classType) { this.isSubClass = false; } else if (!Modifier.isStatic(classType.getModifiers())) { @@ -57,7 +57,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (classType.isPrimitive()) { 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 // ------------------------------------------------------------------------ @@ -93,21 +94,23 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (namesBeans == null) { namesBeans = new String[elem.getParameterCount() - 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[] isCaseSensitives = new Boolean[elem.getParameterCount() - offsetSubClass]; final Boolean[] isOptionals = new Boolean[elem.getParameterCount() - offsetSubClass]; final Boolean[] isManageds = new Boolean[elem.getParameterCount() - offsetSubClass]; - + final Class[][] clazz = new Class[elem.getParameterCount() - offsetSubClass][]; final String[][] names = new String[elem.getParameterCount() - offsetSubClass][]; - + final Parameter[] params = elem.getParameters(); for (int iii = offsetSubClass; iii < params.length; iii++) { final Parameter paramElem = params[iii]; 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); isManageds[iii - offsetSubClass] = ReflectTools.getIsManaged(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... boolean managedParameters = true; - for (int iii = 0; iii < isManageds.length; iii++) { - if (isManageds[iii] != null && !isManageds[iii]) { + for (final Boolean isManaged : isManageds) { + if (isManaged != null && !isManaged) { managedParameters = false; break; } @@ -132,7 +135,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { } if (checkIfOneIsNull(namesBeans, 0)) { LOGGER.trace(" - " + elem.toGenericString()); - LOGGER.trace(" ==> unmanaged (missing names description: " + Arrays.toString(namesBeans) + ")"); + LOGGER.trace(" ==> unmanaged (missing names description: " + + Arrays.toString(namesBeans) + ")"); } else { // 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++) { @@ -144,15 +148,18 @@ public class IntrospectionModelComplex extends IntrospectionModel { final Class curentType = prop.getType(); final Class curentSubType = prop.getSubType(); if (curentType != clazz[iii][0] && curentSubType != clazz[iii][1]) { - throw new AknotException("Set 'return type' with a different value previous=" + curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() - + " ==> new=" + clazz[iii][0] + " / " + clazz[iii][1] + " in " + elem.toGenericString()); + throw new AknotException("Set 'return type' with a different value previous=" + + curentType.getCanonicalName() + " / " + + curentSubType.getCanonicalName() + " ==> new=" + clazz[iii][0] + " / " + + clazz[iii][1] + " in " + elem.toGenericString()); } final String[] names1 = names[iii]; if (names1 != null) { final String[] curentValue = prop.getNames(); if (curentValue != null) { // 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); } @@ -163,7 +170,9 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isAttribute != null) { final Boolean curentValue = prop.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); } @@ -171,8 +180,9 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isCaseSensitive != null) { final Boolean curentValue = prop.isCaseSensitive(); if (curentValue != null && curentValue != isCaseSensitive) { - throw new AknotException( - "Set 'caseSensitive' with a different value previous=" + curentValue + " ==> new=" + isCaseSensitive + " in " + elem.toGenericString()); + throw new AknotException("Set 'caseSensitive' with a different value previous=" + + curentValue + " ==> new=" + isCaseSensitive + " in " + + elem.toGenericString()); } prop.setCaseSensitive(isCaseSensitive); } @@ -180,7 +190,9 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isOptional != null) { final Boolean curentValue = prop.isOptionnal(); 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); } @@ -188,7 +200,9 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isManaged != null) { final Boolean curentValue = prop.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); } @@ -218,7 +232,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { LOGGER.trace(tmpPrint.toString()); } final List recordAllPossibleValues = new ArrayList<>(); - + if (this.isRecord) { for (final ConstructorModel elem : this.constructors) { 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 Class[] types = ReflectTools.getTypeField(elem); - + IntrospectionProperty prop = findElement(elem.getName()); if (prop == null) { prop = new IntrospectionProperty(elem.getName(), types, names); @@ -255,7 +269,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { final Class curentType = prop.getType(); final Class curentSubType = prop.getSubType(); 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()); } final String[] names1 = names; @@ -268,7 +283,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { prop.setNames(names1); } } - + final String description = ReflectTools.getDescription(elem, null); if (description != null) { prop.setDescription(description); @@ -306,7 +321,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { prop.setFactory(factory); } // generate getter and setter with field. - + final IntrospectionPropertyField modifier = new IntrospectionPropertyField(elem); // if the field is final ==> we can not set the value... if (Modifier.isFinal(elem.getModifiers())) { @@ -317,21 +332,22 @@ public class IntrospectionModelComplex extends IntrospectionModel { } LOGGER.trace(" - " + elem.toGenericString()); } - - final List methods = ReflectClass.getFilterGenericFucntion(this.classType, recordAllPossibleValues, true, true, true); - + + final List methods = ReflectClass.getFilterGenericFucntion(this.classType, recordAllPossibleValues, + true, true, true); + LOGGER.trace(" Methods: (" + methods.size() + ")"); for (final Method elem : methods) { LOGGER.trace(" - " + elem.toGenericString()); } - + // Separate the methods and filer as: // - XXX GetXxx(); & XXX != boolean // - void setXxx(XXX elem); // - [bB]oolean isXxx(); // for records: // - xxx(); - + final List methodsGet = ReflectClass.extractGetMethod(classType, methods, recordAllPossibleValues); final List methodsSet = ReflectClass.extractSetMethod(classType, methods); final List methodsIs = ReflectClass.extractIsMethod(classType, methods); @@ -339,8 +355,10 @@ public class IntrospectionModelComplex extends IntrospectionModel { this.tostring = ReflectClass.extractToString(methods); // associate methods by pair. for (final Method method : methodsGet) { - final String name = Tools.decapitalizeFirst(this.isRecord ? method.getName() : method.getName().substring(3)); - final IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method)); + final String name = Tools + .decapitalizeFirst(this.isRecord ? method.getName() : method.getName().substring(3)); + final IntrospectionProperty prop = updateForMethod(name, method, + ReflectTools.getTypeReturnFunction(method)); // generate getter and setter with field. final IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method); prop.setGetter(modifier); @@ -348,25 +366,29 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (!this.isRecord) { for (final Method method : methodsIs) { 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. final IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method); prop.setGetter(modifier); } for (final Method method : methodsSet) { 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. final IntrospectionPropertyMethodSetter modifier = new IntrospectionPropertyMethodSetter(method); prop.setSetter(modifier); } } 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... - final Boolean isDefaultAttribute = ReflectTools.getIsDefaultAttribute(classType, IntrospectionModel.DEFAULT_ATTRIBUTE); + final Boolean isDefaultAttribute = ReflectTools.getIsDefaultAttribute(classType, + IntrospectionModel.DEFAULT_ATTRIBUTE); for (final IntrospectionProperty prop : this.elements) { if (prop.isAttribute() == null) { prop.setAttribute(isDefaultAttribute); @@ -377,13 +399,15 @@ public class IntrospectionModelComplex extends IntrospectionModel { 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) { if (prop.isOptionnal() == null) { 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) { if (prop.isCaseSensitive() == null) { prop.setCaseSensitive(isDefaultCaseSensitive); @@ -395,7 +419,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { prop.setNames(new String[] { prop.getBeanName() }); } } - + } catch (final Exception ex) { ex.printStackTrace(); 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])); // separate managed and unmanaged to optimize performances... 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(); } - + @SuppressWarnings("unchecked") private T[] autoCast(final Class clazz, final List data) { final T[] out = (T[]) java.lang.reflect.Array.newInstance(clazz, data.size());// T[data.size()]; - + for (int iii = 0; iii < data.size(); iii++) { out[iii] = (T) data.get(iii); } return out; //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) { if (valA == valB) { return true; @@ -433,7 +457,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return true; } - + // private boolean checkIfOneIsNull(Boolean[] values, int offset) { // for (int iii=offset; iii properties, final Map> nodes, final boolean attributeIndependent) throws AknotException { + public Object createObject( + final Map properties, + final Map> nodes, + final boolean attributeIndependent) throws AknotException { Object tmp = null; // STEP 1: try to create the object with provided parameter (if a constructor exist....) if (!this.constructors.isEmpty()) { @@ -470,7 +497,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (valueToInject == null) { final List tmppp = nodes.get(elem.values()[iii]); if (tmppp != null) { - if (List.class == findBeanNodeDescription(elem.values()[iii], attributeIndependent).getType()) { + if (List.class == findBeanNodeDescription(elem.values()[iii], attributeIndependent) + .getType()) { valueToInject = tmppp; } else if (tmppp.size() >= 1) { valueToInject = tmppp.get(0); @@ -502,39 +530,63 @@ public class IntrospectionModelComplex extends IntrospectionModel { case 2 -> elem.constructor().newInstance(inputs[0], inputs[1]); 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 5 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4]); - case 6 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5]); - case 7 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4], inputs[5], inputs[6]); - case 8 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], 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], + case 5 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], + inputs[4]); + case 6 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], + inputs[4], inputs[5]); + case 7 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], + inputs[4], inputs[5], inputs[6]); + case 8 -> elem.constructor().newInstance(inputs[0], inputs[1], inputs[2], inputs[3], + 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]); - 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]); - 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]); - 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]); - 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]); - 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]); - 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], - inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16], inputs[17]); - 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[17], inputs[18]); - 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); + 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], + inputs[11], inputs[12], inputs[13], inputs[14], inputs[15], inputs[16], + inputs[17]); + 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[17], inputs[18]); + 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 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 for (int iii = 0; iii < elem.values().length; iii++) { @@ -559,7 +611,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { } else { tmp = this.constructorEmpty.newInstance(); } - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | SecurityException e) { e.printStackTrace(); return null; } @@ -573,7 +626,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return tmp; } - + public void display() { LOGGER.info("Class: {} nbProperty:{}", this.classType.getCanonicalName(), this.elements.size()); 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); for (final IntrospectionProperty prop : this.elements) { LOGGER.debug(" ==> {} => {}", prop.getBeanName(), prop.isAttribute()); @@ -629,7 +684,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + protected IntrospectionProperty findBeanPropertyDescription(final String propertyBeanName) throws AknotException { for (final IntrospectionProperty prop : this.elements) { if (!prop.isAttribute()) { @@ -641,7 +696,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + protected IntrospectionProperty findElement(final String beanName) { for (final IntrospectionProperty elem : this.elements) { if (elem.getBeanName().equals(beanName)) { @@ -650,7 +705,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + protected IntrospectionProperty findNodeDescription(final String propertyName) throws AknotException { for (final IntrospectionProperty prop : this.elements) { if (prop.isAttribute()) { @@ -662,7 +717,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + protected IntrospectionProperty findPropertyDescription(final String propertyName) throws AknotException { for (final IntrospectionProperty prop : this.elements) { if (!prop.isAttribute()) { @@ -674,7 +729,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + @Override public List getAttributes() { final List out = new ArrayList<>(); @@ -685,7 +740,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return out; } - + @Override public String getBeanName(final String nodeName) { for (final IntrospectionProperty elem : this.elements) { @@ -695,7 +750,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + @Override public String getBeanNameModel(final String nodeName) { for (final IntrospectionProperty elem : this.elements) { @@ -708,7 +763,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + @Override public List getNodeAvaillable() { final List out = new ArrayList<>(); @@ -720,7 +775,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return out; } - + @Override public List getNodes() { final List out = new ArrayList<>(); @@ -731,7 +786,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return out; } - + @Override public List getSignals() { final List out = new ArrayList<>(); @@ -743,7 +798,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return out; } - + @Override public String getTextBeanName() { for (final IntrospectionProperty prop : this.elements) { @@ -754,9 +809,10 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + @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 + "'"); final IntrospectionProperty propMethode = findBeanNodeDescription(nodeBeanName, attributeIndependent); if (propMethode != null && propMethode.canSetValue()) { @@ -765,7 +821,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } throw new AknotException("can not find the field '" + nodeBeanName + "'"); } - + @Override public Class getTypeOfProperty(final String nodeName) throws AknotException { LOGGER.debug("nodeType='" + nodeName + "'"); @@ -774,17 +830,18 @@ public class IntrospectionModelComplex extends IntrospectionModel { LOGGER.debug(" ==> find '" + propField.getNames()); return propField.getType(); } - + 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 * @param nodeBeanName Name of the node (bean name access ==> not the XML name) * @return Class of the node to create */ @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 nodeBeanName = elemstNames[0]; LOGGER.debug("NodeType='" + nodeBeanName + "'"); @@ -799,9 +856,10 @@ public class IntrospectionModelComplex extends IntrospectionModel { } throw new AknotException("can not find the field '" + nodeBeanName + "' available: " + getNodeAvaillable()); } - + @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 nodeBeanName = elemstNames[0]; LOGGER.debug(" nodeType='" + nodeBeanName + "'"); @@ -816,7 +874,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } throw new AknotException("can not find the field '" + nodeBeanName + "' available: " + getNodeAvaillable()); } - + @Override public Class getTypeOfSubProperty(final String nodeName) throws AknotException { LOGGER.debug(" nodeType='" + nodeName + "'"); @@ -827,7 +885,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } throw new AknotException("can not find the field '" + nodeName + "' available: " + getNodeAvaillable()); } - + @Override public Class getTypeOfText() { for (final IntrospectionProperty prop : this.elements) { @@ -838,7 +896,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return null; } - + @Override public Object getValue(final String propertyName, final String propertyValue) throws AknotException { LOGGER.debug(" propertyName='" + propertyName + "' propertyValue='" + propertyValue + "' "); @@ -856,7 +914,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } throw new AknotException("can not find the field '" + propertyName + "'"); } - + @Override 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... @@ -889,10 +947,11 @@ public class IntrospectionModelComplex extends IntrospectionModel { // } } LOGGER.debug("======>>>>>>> subElement input type : " + classTypeLocal.getCanonicalName()); - + if (this.valueof == null) { 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); } @@ -900,19 +959,22 @@ public class IntrospectionModelComplex extends IntrospectionModel { return this.valueof.invoke(null, text); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { if (Enum.class.isAssignableFrom(this.classType)) { - throw new AknotException("Error in call 'valueOf(String ...)' for enum '" + classTypeLocal.getCanonicalName() + "' ==> '" + text + "' ... availlable list: " - + Arrays.asList(this.classType.getEnumConstants())); + throw new AknotException( + "Error in call 'valueOf(String ...)' for enum '" + classTypeLocal.getCanonicalName() + "' ==> '" + + text + "' ... availlable list: " + Arrays.asList(this.classType.getEnumConstants())); } 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 public boolean hasTextModel() { LOGGER.warn("in {}", this.classType.getCanonicalName()); 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(); if (isText != null && isText) { return true; @@ -920,19 +982,25 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return false; } - + @Override public boolean isNative() { return false; } - - private void setValue(final Object data, final String beanName, final Object value, final boolean attributeIndependent) throws AknotException { - LOGGER.trace(" Set value ='" + beanName + "' propertyValue='" + value + "' " + value.getClass().getCanonicalName()); + + private void setValue( + 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 final IntrospectionProperty propMethode = findBeanNodeDescription(beanName, attributeIndependent); 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())) { propMethode.setExistingValue(data, value); } else if (value instanceof List) { @@ -940,10 +1008,12 @@ public class IntrospectionModelComplex extends IntrospectionModel { final List tmpp = (List) value; if (propMethode.getType().isArray()) { 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); } 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()); propMethode.setExistingValue(data, autoCast(propMethode.getType().componentType(), tmpp)); } @@ -974,7 +1044,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { final double dataPrimitive = (Double) value; propMethode.setExistingValue(data, dataPrimitive); } else { - + } return; } @@ -983,7 +1053,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { { final IntrospectionProperty propField = findBeanPropertyDescription(beanName); 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())) { propField.setExistingValue(data, value); // Some specific case for primitives values @@ -1034,7 +1105,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { final double[] datas = ArraysTools.listDoubleToPrimitive(tmpp); propField.setExistingValue(data, datas); } 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()); 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 + "'"); } - + @Override public String toString(final Object data) throws AknotException { if (this.tostring == null) { 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); } @@ -1062,15 +1135,17 @@ public class IntrospectionModelComplex extends IntrospectionModel { return (String) this.tostring.invoke(data); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { if (Enum.class.isAssignableFrom(this.classType)) { - throw new AknotException( - "Error in call 'toString()' for '" + this.classType.getCanonicalName() + "' ==> '????' ... availlable list: " + Arrays.asList(this.classType.getEnumConstants())); + throw new AknotException("Error in call 'toString()' for '" + this.classType.getCanonicalName() + + "' ==> '????' ... availlable list: " + Arrays.asList(this.classType.getEnumConstants())); } 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); if (prop == null) { final String[] names = ReflectTools.getNames(method, null); @@ -1080,8 +1155,9 @@ public class IntrospectionModelComplex extends IntrospectionModel { final Class curentType = prop.getType(); final Class curentSubType = prop.getSubType(); 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] - + " / " + types[1] + " in " + method.toGenericString()); + throw new AknotException("Set 'return type' with a different value previous=" + + curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() + " ==> new=" + + types[0] + " / " + types[1] + " in " + method.toGenericString()); } final String[] names = ReflectTools.getNames(method, null); if (names != null) { @@ -1097,7 +1173,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (description != null) { final String curentValue = prop.getListName(); 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); } @@ -1105,7 +1182,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (listName != null) { final String curentValue = prop.getListName(); 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); } @@ -1113,7 +1191,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isAttribute != null) { final Boolean curentValue = prop.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); } @@ -1121,7 +1200,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isManaged != null) { final Boolean curentValue = prop.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); } @@ -1129,7 +1209,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isOptionnal != null) { final Boolean curentValue = prop.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); } @@ -1137,7 +1218,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isCaseSensitive != null) { final Boolean curentValue = prop.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); } @@ -1145,7 +1227,8 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (isText != null) { final Boolean curentValue = prop.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); } @@ -1155,4 +1238,5 @@ public class IntrospectionModelComplex extends IntrospectionModel { } return prop; } + }