[DEV] lib is worling
This commit is contained in:
parent
0a0ee42b4b
commit
a2d37bb241
@ -42,7 +42,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
@Override
|
@Override
|
||||||
public List<IntrospectionProperty> getNodes() {
|
public List<IntrospectionProperty> getNodes() {
|
||||||
List<IntrospectionProperty> out = new ArrayList<>();
|
List<IntrospectionProperty> out = new ArrayList<>();
|
||||||
for (IntrospectionProperty elem : elements) {
|
for (IntrospectionProperty elem : this.elements) {
|
||||||
if (!elem.isAttribute()) {
|
if (!elem.isAttribute()) {
|
||||||
out.add(elem);
|
out.add(elem);
|
||||||
}
|
}
|
||||||
@ -52,15 +52,15 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
@Override
|
@Override
|
||||||
public List<IntrospectionProperty> getAttributes() {
|
public List<IntrospectionProperty> getAttributes() {
|
||||||
List<IntrospectionProperty> out = new ArrayList<>();
|
List<IntrospectionProperty> out = new ArrayList<>();
|
||||||
for (IntrospectionProperty elem : elements) {
|
for (IntrospectionProperty elem : this.elements) {
|
||||||
if (elem.isAttribute()) {
|
if (elem.isAttribute()) {
|
||||||
out.add(elem);
|
out.add(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
protected IntrospectionProperty findElement(String beanName) {
|
protected IntrospectionProperty findElement(final String beanName) {
|
||||||
for (IntrospectionProperty elem : elements) {
|
for (IntrospectionProperty elem : this.elements) {
|
||||||
if (elem.getBeanName().equals(beanName)) {
|
if (elem.getBeanName().equals(beanName)) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
@ -104,7 +104,9 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
if (classType.isPrimitive()) {
|
if (classType.isPrimitive()) {
|
||||||
Log.critical("Detect primitive ==> impossible case !!! ");
|
Log.critical("Detect primitive ==> impossible case !!! ");
|
||||||
}
|
}
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// -- Parse constructor
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
Log.verbose("Introspect class: '" + classType.getCanonicalName() + "'");
|
Log.verbose("Introspect class: '" + classType.getCanonicalName() + "'");
|
||||||
final Constructor<?>[] constructors = this.classType.getConstructors();
|
final Constructor<?>[] constructors = this.classType.getConstructors();
|
||||||
Log.verbose(" Constructors: (" + constructors.length + ")");
|
Log.verbose(" Constructors: (" + constructors.length + ")");
|
||||||
@ -114,7 +116,14 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
if (!Modifier.isPublic(elem.getModifiers())) {
|
if (!Modifier.isPublic(elem.getModifiers())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (elem.getParameterCount() == 0) {
|
||||||
|
emptyConstructorTmp = elem;
|
||||||
|
Log.verbose(" >>> " + elem.toGenericString());
|
||||||
|
} else {
|
||||||
|
int offsetSubClass = 0;
|
||||||
if (this.isSubClass) {
|
if (this.isSubClass) {
|
||||||
|
offsetSubClass = 1;
|
||||||
|
}
|
||||||
if (elem.getParameterCount() == 1) {
|
if (elem.getParameterCount() == 1) {
|
||||||
emptyConstructorTmp = elem;
|
emptyConstructorTmp = elem;
|
||||||
Log.verbose(" >>> " + elem.toGenericString());
|
Log.verbose(" >>> " + elem.toGenericString());
|
||||||
@ -122,26 +131,26 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
// Retrieve full description in constructor properties...
|
// Retrieve full description in constructor properties...
|
||||||
String[] namesBeans = ReflectTools.getNames(elem, null);
|
String[] namesBeans = ReflectTools.getNames(elem, null);
|
||||||
if (namesBeans == null) {
|
if (namesBeans == null) {
|
||||||
namesBeans = new String[elem.getParameterCount()-1];
|
namesBeans = new String[elem.getParameterCount() - offsetSubClass];
|
||||||
} else if (elem.getParameterCount() != namesBeans.length+1) {
|
} else if (elem.getParameterCount() != namesBeans.length+offsetSubClass) {
|
||||||
throw new ExmlBuilderException("Wrong number of parameter in constructor with ne number declared in the @XmlName (for bean name)");
|
throw new ExmlBuilderException("Wrong number of parameter in constructor with ne number declared in the @XmlName (for bean name)");
|
||||||
}
|
}
|
||||||
Boolean[] isAttributes = new Boolean[elem.getParameterCount()-1];
|
Boolean[] isAttributes = new Boolean[elem.getParameterCount()-offsetSubClass];
|
||||||
|
|
||||||
Class<?>[][] clazz = new Class<?>[elem.getParameterCount()-1][];
|
Class<?>[][] clazz = new Class<?>[elem.getParameterCount()-offsetSubClass][];
|
||||||
String[][] names = new String[elem.getParameterCount()-1][];
|
String[][] names = new String[elem.getParameterCount()-offsetSubClass][];
|
||||||
|
|
||||||
Parameter[] params = elem.getParameters();
|
Parameter[] params = elem.getParameters();
|
||||||
for (int iii=1; iii<params.length; iii++) {
|
for (int iii=offsetSubClass; iii<params.length; iii++) {
|
||||||
Parameter paramElem = params[iii];
|
Parameter paramElem = params[iii];
|
||||||
isAttributes[iii-1] = ReflectTools.getIsAttribute(elem, paramElem, null);
|
isAttributes[iii-offsetSubClass] = ReflectTools.getIsAttribute(elem, paramElem, null);
|
||||||
String[] namesParam = ReflectTools.getNames(elem, paramElem, null);
|
String[] namesParam = ReflectTools.getNames(elem, paramElem, null);
|
||||||
Class<?>[] types = ReflectTools.getTypeParameterfunction(elem, iii);
|
Class<?>[] types = ReflectTools.getTypeParameterfunction(elem, iii);
|
||||||
clazz[iii-1] = types;
|
clazz[iii-offsetSubClass] = types;
|
||||||
names[iii-1] = namesParam;
|
names[iii-offsetSubClass] = namesParam;
|
||||||
if (namesParam != null && namesParam.length != 0 ) {
|
if (namesParam != null && namesParam.length != 0 ) {
|
||||||
// TODO maybe do something id name is already set ???
|
// TODO maybe do something id name is already set ???
|
||||||
namesBeans[iii-1] = namesParam[0];
|
namesBeans[iii-offsetSubClass] = namesParam[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (checkIfOneIsNull(namesBeans,0)) {
|
if (checkIfOneIsNull(namesBeans,0)) {
|
||||||
@ -149,7 +158,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
Log.verbose(" ==> unmanaged (missing names description: " + Arrays.toString(namesBeans) + ")");
|
Log.verbose(" ==> 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=1; iii<namesBeans.length; iii++) {
|
for (int iii=0; iii<namesBeans.length; iii++) {
|
||||||
IntrospectionProperty prop = findElement(namesBeans[iii]);
|
IntrospectionProperty prop = findElement(namesBeans[iii]);
|
||||||
if (prop == null) {
|
if (prop == null) {
|
||||||
prop = new IntrospectionProperty(namesBeans[iii], clazz[iii], names[iii]);
|
prop = new IntrospectionProperty(namesBeans[iii], clazz[iii], names[iii]);
|
||||||
@ -170,6 +179,8 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
prop.setNames(names1);
|
prop.setNames(names1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Set settable by the constructor
|
||||||
|
prop.setCanBeSetByConstructor(true);
|
||||||
final Boolean isAttribute = isAttributes[iii];
|
final Boolean isAttribute = isAttributes[iii];
|
||||||
if (isAttribute != null) {
|
if (isAttribute != null) {
|
||||||
Boolean curentValue = prop.isAttribute();
|
Boolean curentValue = prop.isAttribute();
|
||||||
@ -182,35 +193,6 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
this.constructors.add(new ConstructorModel(namesBeans, isAttributes, elem));
|
this.constructors.add(new ConstructorModel(namesBeans, isAttributes, elem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (elem.getParameterCount() == 0) {
|
|
||||||
emptyConstructorTmp = elem;
|
|
||||||
Log.verbose(" >>> " + elem.toGenericString());
|
|
||||||
} else {
|
|
||||||
// Retrieve full description in constructor properties...
|
|
||||||
String[] names = ReflectTools.getNames(elem, null);
|
|
||||||
if (names == null) {
|
|
||||||
names = new String[elem.getParameterCount()];
|
|
||||||
} else if (elem.getParameterCount() != names.length) {
|
|
||||||
throw new ExmlBuilderException("Wrong number of parameter in constructor with ne number declared in the @XmlName");
|
|
||||||
}
|
|
||||||
Boolean[] isAttributes = new Boolean[elem.getParameterCount()];
|
|
||||||
|
|
||||||
Parameter[] params = elem.getParameters();
|
|
||||||
for (int iii=1; iii<params.length; iii++) {
|
|
||||||
Parameter paramElem = params[iii];
|
|
||||||
isAttributes[iii] = ReflectTools.getIsAttribute(elem, paramElem, null);
|
|
||||||
String[] namesParam = ReflectTools.getNames(elem, paramElem, null);
|
|
||||||
if (namesParam != null && namesParam.length != 0 ) {
|
|
||||||
// TODO maybe do something id name is already set ???
|
|
||||||
names[iii] = namesParam[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (checkIfOneIsNull(names,1)) {
|
|
||||||
Log.verbose(" - " + elem.toGenericString());
|
|
||||||
Log.verbose(" ==> unmanaged (missing names description)");
|
|
||||||
} else {
|
|
||||||
this.constructors.add(new ConstructorModel(names, isAttributes, elem));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.constructorEmpty = emptyConstructorTmp;
|
this.constructorEmpty = emptyConstructorTmp;
|
||||||
@ -250,6 +232,9 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// -- Parse Field
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
final Field[] fields = this.classType.getFields();
|
final Field[] fields = this.classType.getFields();
|
||||||
Log.verbose(" Fields: (" + fields.length + ")");
|
Log.verbose(" Fields: (" + fields.length + ")");
|
||||||
for (final Field elem : fields) {
|
for (final Field elem : fields) {
|
||||||
@ -264,8 +249,27 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
}
|
}
|
||||||
final String[] names = ReflectTools.getNames(elem, null);
|
final String[] names = ReflectTools.getNames(elem, null);
|
||||||
Class<?>[] types = ReflectTools.getTypeField(elem);
|
Class<?>[] types = ReflectTools.getTypeField(elem);
|
||||||
IntrospectionProperty prop = new IntrospectionProperty(Tools.decapitalizeFirst(elem.getName()), types, names);
|
|
||||||
|
IntrospectionProperty prop = findElement(elem.getName());
|
||||||
|
if (prop == null) {
|
||||||
|
prop = new IntrospectionProperty(elem.getName(), types, names);
|
||||||
this.elements.add(prop);
|
this.elements.add(prop);
|
||||||
|
} else {
|
||||||
|
Class<?> curentType = prop.getType();
|
||||||
|
Class<?> curentSubType = prop.getSubType();
|
||||||
|
if (curentType != types[0] && curentSubType != types[1]) {
|
||||||
|
throw new ExmlBuilderException("Set 'return type' with a different value previous=" + curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() + " ==> new=" + types[0] + " / " + types[1] + " in " + elem.toGenericString());
|
||||||
|
}
|
||||||
|
String[] names1 = names;
|
||||||
|
if (names1 != null) {
|
||||||
|
String[] curentValue = prop.getNames();
|
||||||
|
if (curentValue != null) {
|
||||||
|
// TODO maybe set the value permissive if no change !!! like the others...
|
||||||
|
throw new ExmlBuilderException("Set 'names' with a (already set!) " + elem.toGenericString());
|
||||||
|
}
|
||||||
|
prop.setNames(names1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final String listName = ReflectTools.getListName(elem, null);
|
final String listName = ReflectTools.getListName(elem, null);
|
||||||
if (listName != null) {
|
if (listName != null) {
|
||||||
@ -502,7 +506,22 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntrospectionProperty updateForMethod(String name, final Method method, Class<?>[] types) throws Exception {
|
private boolean checkIdenticalArray(final String[] valA, final String[] valB) {
|
||||||
|
if (valA == valB) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (valA.length != valB.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int iii=0; iii<valA.length; iii++) {
|
||||||
|
if (!valA[iii].equals(valB[iii])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
String[] names = ReflectTools.getNames(method, null);
|
String[] names = ReflectTools.getNames(method, null);
|
||||||
@ -517,7 +536,7 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
|||||||
String[] names = ReflectTools.getNames(method, null);
|
String[] names = ReflectTools.getNames(method, null);
|
||||||
if (names != null) {
|
if (names != null) {
|
||||||
String[] curentValue = prop.getNames();
|
String[] curentValue = prop.getNames();
|
||||||
if (curentValue != null) {
|
if (curentValue != null && !checkIdenticalArray(curentValue,names)) {
|
||||||
// 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 ExmlBuilderException("Set 'names' with a (already set!) " + method.toGenericString());
|
throw new ExmlBuilderException("Set 'names' with a (already set!) " + method.toGenericString());
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.atriasoft.exml.builder;
|
package org.atriasoft.exml.builder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.eStringSerialize.StringSerializer;
|
import org.atriasoft.eStringSerialize.StringSerializer;
|
||||||
@ -55,10 +54,10 @@ public final class IntrospectionProperty {
|
|||||||
this.names = names;
|
this.names = names;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSetter(IntrospectionPropertySetter setter) {
|
public void setSetter(final IntrospectionPropertySetter setter) {
|
||||||
this.setter = setter;
|
this.setter = setter;
|
||||||
}
|
}
|
||||||
public void setGetter(IntrospectionPropertyGetter getter) {
|
public void setGetter(final IntrospectionPropertyGetter getter) {
|
||||||
this.getter = getter;
|
this.getter = getter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,11 +97,11 @@ public final class IntrospectionProperty {
|
|||||||
* @return The generate value of the object
|
* @return The generate value of the object
|
||||||
* @throws ExmlBuilderException in an error occured
|
* @throws ExmlBuilderException in an error occured
|
||||||
*/
|
*/
|
||||||
public Object getValue(Object object) throws ExmlBuilderException {
|
public Object getValue(final Object object) throws ExmlBuilderException {
|
||||||
if (getter != null) {
|
if (this.getter != null) {
|
||||||
return this.getter.getValue(object);
|
return this.getter.getValue(object);
|
||||||
}
|
}
|
||||||
throw new ExmlBuilderException("Property: " + names + " have no getter");
|
throw new ExmlBuilderException("Property: " + this.names + " have no getter");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,12 +132,12 @@ public final class IntrospectionProperty {
|
|||||||
* @param value Value to set in the Object
|
* @param value Value to set in the Object
|
||||||
* @throws Exception An error occurred
|
* @throws Exception An error occurred
|
||||||
*/
|
*/
|
||||||
public void setExistingValue(Object object, Object value) throws ExmlBuilderException {
|
public void setExistingValue(final Object object, final Object value) throws ExmlBuilderException {
|
||||||
if (setter != null) {
|
if (this.setter != null) {
|
||||||
this.setter.setValue(object, value);
|
this.setter.setValue(object, value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new ExmlBuilderException("Property: " + names + " have no setter");
|
throw new ExmlBuilderException("Property: " + this.names + " have no setter");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create a value adapted to the property type.
|
* Create a value adapted to the property type.
|
||||||
@ -171,36 +170,36 @@ public final class IntrospectionProperty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isCaseSensitive() {
|
public Boolean isCaseSensitive() {
|
||||||
return caseSensitive;
|
return this.caseSensitive;
|
||||||
}
|
}
|
||||||
public void setCaseSensitive(Boolean caseSensitive) {
|
public void setCaseSensitive(final Boolean caseSensitive) {
|
||||||
this.caseSensitive = caseSensitive;
|
this.caseSensitive = caseSensitive;
|
||||||
}
|
}
|
||||||
public Boolean isOptionnal() {
|
public Boolean isOptionnal() {
|
||||||
return optionnal;
|
return this.optionnal;
|
||||||
}
|
}
|
||||||
public void setOptionnal(Boolean optionnal) {
|
public void setOptionnal(final Boolean optionnal) {
|
||||||
this.optionnal = optionnal;
|
this.optionnal = optionnal;
|
||||||
}
|
}
|
||||||
public Boolean isAttribute() {
|
public Boolean isAttribute() {
|
||||||
return attribute;
|
return this.attribute;
|
||||||
}
|
}
|
||||||
public void setAttribute(Boolean attribute) {
|
public void setAttribute(final Boolean attribute) {
|
||||||
this.attribute = attribute;
|
this.attribute = attribute;
|
||||||
}
|
}
|
||||||
public String getBeanName() {
|
public String getBeanName() {
|
||||||
return beanName;
|
return this.beanName;
|
||||||
}
|
}
|
||||||
public void setNames(String[] names) {
|
public void setNames(final String[] names) {
|
||||||
this.names = names;
|
this.names = names;
|
||||||
}
|
}
|
||||||
public void setListName(String listName) {
|
public void setListName(final String listName) {
|
||||||
this.listName = listName;
|
this.listName = listName;
|
||||||
}
|
}
|
||||||
public Boolean isManaged() {
|
public Boolean isManaged() {
|
||||||
return managed;
|
return this.managed;
|
||||||
}
|
}
|
||||||
public void setManaged(Boolean managed) {
|
public void setManaged(final Boolean managed) {
|
||||||
this.managed = managed;
|
this.managed = managed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@ package org.atriasoft.exml.builder;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
import org.atriasoft.exml.exception.ExmlBuilderException;
|
import org.atriasoft.exml.exception.ExmlBuilderException;
|
||||||
|
|
||||||
|
@ -2,12 +2,8 @@ package org.atriasoft.exml.builder;
|
|||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.atriasoft.exml.exception.ExmlBuilderException;
|
import org.atriasoft.exml.exception.ExmlBuilderException;
|
||||||
import org.atriasoft.exml.internal.Log;
|
|
||||||
|
|
||||||
public class IntrospectionPropertyMethodGetter implements IntrospectionPropertyGetter {
|
public class IntrospectionPropertyMethodGetter implements IntrospectionPropertyGetter {
|
||||||
// private static Class<?>[] getTypefunction(final Method setter, final Method getter) throws Exception {
|
// private static Class<?>[] getTypefunction(final Method setter, final Method getter) throws Exception {
|
||||||
|
@ -2,12 +2,8 @@ package org.atriasoft.exml.builder;
|
|||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.atriasoft.exml.exception.ExmlBuilderException;
|
import org.atriasoft.exml.exception.ExmlBuilderException;
|
||||||
import org.atriasoft.exml.internal.Log;
|
|
||||||
|
|
||||||
public class IntrospectionPropertyMethodSetter implements IntrospectionPropertySetter {
|
public class IntrospectionPropertyMethodSetter implements IntrospectionPropertySetter {
|
||||||
protected Method setter;
|
protected Method setter;
|
||||||
|
@ -15,7 +15,7 @@ import org.junit.jupiter.api.Assertions;
|
|||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class ExmlTestIntrospectionDecorator {
|
public class ExmlTestIntrospectionDecoratorAttribute {
|
||||||
static final String NODE_NAME = "elem";
|
static final String NODE_NAME = "elem";
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
@ -172,7 +172,7 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionObject.NODE_NAME, builder));
|
Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionObject.NODE_NAME, builder));
|
||||||
String dataTest = builder.toString();
|
String dataTest = builder.toString();
|
||||||
Log.warning("data generated: " + builder.toString());
|
Log.warning("data generated: " + dataTest);
|
||||||
Assertions.assertEquals("<elem finalValueM=\"321\" finalValueN=\"654\" finalValueO=\"987\" finalValueQ=\"267\" finalValueR=\"264\" finalValueS=\"1524\" pFinalValueQ=\"-552\" pFinalValueR=\"-965\" pFinalValueS=\"-98885\" valueA=\"55\" valueB=\"78\" valueC=\"51\" valueE=\"651\" valueF=\"654\" valueG=\"8552\" valueH=\"9531\" valueI=\"87465\">\n"
|
Assertions.assertEquals("<elem finalValueM=\"321\" finalValueN=\"654\" finalValueO=\"987\" finalValueQ=\"267\" finalValueR=\"264\" finalValueS=\"1524\" pFinalValueQ=\"-552\" pFinalValueR=\"-965\" pFinalValueS=\"-98885\" valueA=\"55\" valueB=\"78\" valueC=\"51\" valueE=\"651\" valueF=\"654\" valueG=\"8552\" valueH=\"9531\" valueI=\"87465\">\n"
|
||||||
+ " <finalValueP>159</finalValueP>\n"
|
+ " <finalValueP>159</finalValueP>\n"
|
||||||
+ " <finalValueT>182445</finalValueT>\n"
|
+ " <finalValueT>182445</finalValueT>\n"
|
||||||
@ -226,6 +226,47 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
private int valueJ;
|
private int valueJ;
|
||||||
private int valueK;
|
private int valueK;
|
||||||
|
|
||||||
|
|
||||||
|
public final int finalValueM;
|
||||||
|
@XmlAttribute
|
||||||
|
public final int finalValueN;
|
||||||
|
@XmlAttribute(true)
|
||||||
|
public final int finalValueO;
|
||||||
|
@XmlAttribute(false)
|
||||||
|
public final int finalValueP;
|
||||||
|
|
||||||
|
// special case for bijectivity with records
|
||||||
|
public final int finalValueQ;
|
||||||
|
public final int finalValueR;
|
||||||
|
public final int finalValueS;
|
||||||
|
public final int finalValueT;
|
||||||
|
|
||||||
|
private final int pFinalValueQ;
|
||||||
|
private final int pFinalValueR;
|
||||||
|
private final int pFinalValueS;
|
||||||
|
private final int pFinalValueT;
|
||||||
|
|
||||||
|
@XmlName({"finalValueM", "finalValueN", "finalValueO", "finalValueP",
|
||||||
|
"finalValueQ", "finalValueR", "finalValueS", "finalValueT",
|
||||||
|
"pFinalValueQ", "pFinalValueR", "pFinalValueS", "pFinalValueT"})
|
||||||
|
public TestNodeObjectTrue(
|
||||||
|
final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP,
|
||||||
|
final int finalValueQ, @XmlAttribute final int finalValueR, @XmlAttribute(true) final int finalValueS, @XmlAttribute(false) final int finalValueT,
|
||||||
|
final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS, final int pFinalValueT) {
|
||||||
|
this.finalValueM = finalValueM;
|
||||||
|
this.finalValueN = finalValueN;
|
||||||
|
this.finalValueO = finalValueO;
|
||||||
|
this.finalValueP = finalValueP;
|
||||||
|
this.finalValueQ = finalValueQ;
|
||||||
|
this.finalValueR = finalValueR;
|
||||||
|
this.finalValueS = finalValueS;
|
||||||
|
this.finalValueT = finalValueT;
|
||||||
|
this.pFinalValueQ = pFinalValueQ;
|
||||||
|
this.pFinalValueR = pFinalValueR;
|
||||||
|
this.pFinalValueS = pFinalValueS;
|
||||||
|
this.pFinalValueT = pFinalValueT;
|
||||||
|
}
|
||||||
|
|
||||||
public int getValueE() {
|
public int getValueE() {
|
||||||
return this.valueE;
|
return this.valueE;
|
||||||
}
|
}
|
||||||
@ -275,11 +316,30 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
this.valueK = valueK;
|
this.valueK = valueK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPFinalValueQ() {
|
||||||
|
return this.pFinalValueQ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlAttribute
|
||||||
|
public int getPFinalValueR() {
|
||||||
|
return this.pFinalValueR;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlAttribute(true)
|
||||||
|
public int getPFinalValueS() {
|
||||||
|
return this.pFinalValueS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlAttribute(false)
|
||||||
|
public int getPFinalValueT() {
|
||||||
|
return this.pFinalValueT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultAttributeTrue() {
|
public void testDefaultAttributeTrue() {
|
||||||
TestNodeObjectTrue elem = new TestNodeObjectTrue();
|
TestNodeObjectTrue elem = new TestNodeObjectTrue(321,654,987,159,267,264,1524,182445, -552, -965, -98885, -8754);
|
||||||
elem.valueA = 55;
|
elem.valueA = 55;
|
||||||
elem.valueB = 78;
|
elem.valueB = 78;
|
||||||
elem.valueC = 51;
|
elem.valueC = 51;
|
||||||
@ -296,7 +356,10 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionObject.NODE_NAME, builder));
|
Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionObject.NODE_NAME, builder));
|
||||||
String dataTest = builder.toString();
|
String dataTest = builder.toString();
|
||||||
Log.warning("data generated: " + builder.toString());
|
Log.warning("data generated: " + builder.toString());
|
||||||
Assertions.assertEquals("<elem valueA=\"55\" valueB=\"78\" valueC=\"51\" valueE=\"651\" valueF=\"654\" valueG=\"8552\" valueH=\"9531\" valueI=\"87465\">\n"
|
Assertions.assertEquals("<elem finalValueM=\"321\" finalValueN=\"654\" finalValueO=\"987\" finalValueQ=\"267\" finalValueR=\"264\" finalValueS=\"1524\" pFinalValueQ=\"-552\" pFinalValueR=\"-965\" pFinalValueS=\"-98885\" valueA=\"55\" valueB=\"78\" valueC=\"51\" valueE=\"651\" valueF=\"654\" valueG=\"8552\" valueH=\"9531\" valueI=\"87465\">\n"
|
||||||
|
+ " <finalValueP>159</finalValueP>\n"
|
||||||
|
+ " <finalValueT>182445</finalValueT>\n"
|
||||||
|
+ " <pFinalValueT>-8754</pFinalValueT>\n"
|
||||||
+ " <valueD>24</valueD>\n"
|
+ " <valueD>24</valueD>\n"
|
||||||
+ " <valueJ>8247</valueJ>\n"
|
+ " <valueJ>8247</valueJ>\n"
|
||||||
+ " <valueK>885522</valueK>\n"
|
+ " <valueK>885522</valueK>\n"
|
||||||
@ -314,6 +377,18 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
Assertions.assertEquals(87465, root.getValueI());
|
Assertions.assertEquals(87465, root.getValueI());
|
||||||
Assertions.assertEquals(8247, root.getValueJ());
|
Assertions.assertEquals(8247, root.getValueJ());
|
||||||
Assertions.assertEquals(885522, root.getValueK());
|
Assertions.assertEquals(885522, root.getValueK());
|
||||||
|
Assertions.assertEquals(321, root.finalValueM);
|
||||||
|
Assertions.assertEquals(654, root.finalValueN);
|
||||||
|
Assertions.assertEquals(987, root.finalValueO);
|
||||||
|
Assertions.assertEquals(159, root.finalValueP);
|
||||||
|
Assertions.assertEquals(267, root.finalValueQ);
|
||||||
|
Assertions.assertEquals(264, root.finalValueR);
|
||||||
|
Assertions.assertEquals(1524, root.finalValueS);
|
||||||
|
Assertions.assertEquals(182445, root.finalValueT);
|
||||||
|
Assertions.assertEquals(-552, root.getPFinalValueQ());
|
||||||
|
Assertions.assertEquals(-965, root.getPFinalValueR());
|
||||||
|
Assertions.assertEquals(-98885, root.getPFinalValueS());
|
||||||
|
Assertions.assertEquals(-8754, root.getPFinalValueT());
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlDefaultAttibute(false)
|
@XmlDefaultAttibute(false)
|
||||||
@ -334,6 +409,46 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
private int valueJ;
|
private int valueJ;
|
||||||
private int valueK;
|
private int valueK;
|
||||||
|
|
||||||
|
public final int finalValueM;
|
||||||
|
@XmlAttribute
|
||||||
|
public final int finalValueN;
|
||||||
|
@XmlAttribute(true)
|
||||||
|
public final int finalValueO;
|
||||||
|
@XmlAttribute(false)
|
||||||
|
public final int finalValueP;
|
||||||
|
|
||||||
|
// special case for bijectivity with records
|
||||||
|
public final int finalValueQ;
|
||||||
|
public final int finalValueR;
|
||||||
|
public final int finalValueS;
|
||||||
|
public final int finalValueT;
|
||||||
|
|
||||||
|
private final int pFinalValueQ;
|
||||||
|
private final int pFinalValueR;
|
||||||
|
private final int pFinalValueS;
|
||||||
|
private final int pFinalValueT;
|
||||||
|
|
||||||
|
@XmlName({"finalValueM", "finalValueN", "finalValueO", "finalValueP",
|
||||||
|
"finalValueQ", "finalValueR", "finalValueS", "finalValueT",
|
||||||
|
"pFinalValueQ", "pFinalValueR", "pFinalValueS", "pFinalValueT"})
|
||||||
|
public TestNodeObjectFalse(
|
||||||
|
final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP,
|
||||||
|
final int finalValueQ, @XmlAttribute final int finalValueR, @XmlAttribute(true) final int finalValueS, @XmlAttribute(false) final int finalValueT,
|
||||||
|
final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS, final int pFinalValueT) {
|
||||||
|
this.finalValueM = finalValueM;
|
||||||
|
this.finalValueN = finalValueN;
|
||||||
|
this.finalValueO = finalValueO;
|
||||||
|
this.finalValueP = finalValueP;
|
||||||
|
this.finalValueQ = finalValueQ;
|
||||||
|
this.finalValueR = finalValueR;
|
||||||
|
this.finalValueS = finalValueS;
|
||||||
|
this.finalValueT = finalValueT;
|
||||||
|
this.pFinalValueQ = pFinalValueQ;
|
||||||
|
this.pFinalValueR = pFinalValueR;
|
||||||
|
this.pFinalValueS = pFinalValueS;
|
||||||
|
this.pFinalValueT = pFinalValueT;
|
||||||
|
}
|
||||||
|
|
||||||
public int getValueE() {
|
public int getValueE() {
|
||||||
return this.valueE;
|
return this.valueE;
|
||||||
}
|
}
|
||||||
@ -384,10 +499,29 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getPFinalValueQ() {
|
||||||
|
return this.pFinalValueQ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlAttribute
|
||||||
|
public int getPFinalValueR() {
|
||||||
|
return this.pFinalValueR;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlAttribute(true)
|
||||||
|
public int getPFinalValueS() {
|
||||||
|
return this.pFinalValueS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlAttribute(false)
|
||||||
|
public int getPFinalValueT() {
|
||||||
|
return this.pFinalValueT;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultAttributeFalse() {
|
public void testDefaultAttributeFalse() {
|
||||||
TestNodeObjectFalse elem = new TestNodeObjectFalse();
|
TestNodeObjectFalse elem = new TestNodeObjectFalse(321,654,987,159,267,264,1524,182445, -552, -965, -98885, -8754);
|
||||||
elem.valueA = 55;
|
elem.valueA = 55;
|
||||||
elem.valueB = 78;
|
elem.valueB = 78;
|
||||||
elem.valueC = 51;
|
elem.valueC = 51;
|
||||||
@ -404,7 +538,13 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionObject.NODE_NAME, builder));
|
Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionObject.NODE_NAME, builder));
|
||||||
String dataTest = builder.toString();
|
String dataTest = builder.toString();
|
||||||
Log.warning("data generated: " + builder.toString());
|
Log.warning("data generated: " + builder.toString());
|
||||||
Assertions.assertEquals("<elem valueB=\"78\" valueC=\"51\" valueF=\"654\" valueG=\"8552\" valueH=\"9531\" valueI=\"87465\">\n"
|
Assertions.assertEquals("<elem finalValueN=\"654\" finalValueO=\"987\" finalValueR=\"264\" finalValueS=\"1524\" pFinalValueR=\"-965\" pFinalValueS=\"-98885\" valueB=\"78\" valueC=\"51\" valueF=\"654\" valueG=\"8552\" valueH=\"9531\" valueI=\"87465\">\n"
|
||||||
|
+ " <finalValueM>321</finalValueM>\n"
|
||||||
|
+ " <finalValueP>159</finalValueP>\n"
|
||||||
|
+ " <finalValueQ>267</finalValueQ>\n"
|
||||||
|
+ " <finalValueT>182445</finalValueT>\n"
|
||||||
|
+ " <pFinalValueQ>-552</pFinalValueQ>\n"
|
||||||
|
+ " <pFinalValueT>-8754</pFinalValueT>\n"
|
||||||
+ " <valueA>55</valueA>\n"
|
+ " <valueA>55</valueA>\n"
|
||||||
+ " <valueD>24</valueD>\n"
|
+ " <valueD>24</valueD>\n"
|
||||||
+ " <valueE>651</valueE>\n"
|
+ " <valueE>651</valueE>\n"
|
||||||
@ -424,6 +564,18 @@ public class ExmlTestIntrospectionDecorator {
|
|||||||
Assertions.assertEquals(87465, root.getValueI());
|
Assertions.assertEquals(87465, root.getValueI());
|
||||||
Assertions.assertEquals(8247, root.getValueJ());
|
Assertions.assertEquals(8247, root.getValueJ());
|
||||||
Assertions.assertEquals(885522, root.getValueK());
|
Assertions.assertEquals(885522, root.getValueK());
|
||||||
|
Assertions.assertEquals(321, root.finalValueM);
|
||||||
|
Assertions.assertEquals(654, root.finalValueN);
|
||||||
|
Assertions.assertEquals(987, root.finalValueO);
|
||||||
|
Assertions.assertEquals(159, root.finalValueP);
|
||||||
|
Assertions.assertEquals(267, root.finalValueQ);
|
||||||
|
Assertions.assertEquals(264, root.finalValueR);
|
||||||
|
Assertions.assertEquals(1524, root.finalValueS);
|
||||||
|
Assertions.assertEquals(182445, root.finalValueT);
|
||||||
|
Assertions.assertEquals(-552, root.getPFinalValueQ());
|
||||||
|
Assertions.assertEquals(-965, root.getPFinalValueR());
|
||||||
|
Assertions.assertEquals(-98885, root.getPFinalValueS());
|
||||||
|
Assertions.assertEquals(-8754, root.getPFinalValueT());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,6 +6,7 @@
|
|||||||
package test.atriasoft.exml;
|
package test.atriasoft.exml;
|
||||||
|
|
||||||
import org.atriasoft.exml.Exml;
|
import org.atriasoft.exml.Exml;
|
||||||
|
import org.atriasoft.exml.annotation.XmlAttribute;
|
||||||
import org.atriasoft.exml.annotation.XmlName;
|
import org.atriasoft.exml.annotation.XmlName;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
@ -18,10 +19,12 @@ public class ExmlTestIntrospectionRecord {
|
|||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
Log.warning("================================================================");
|
Log.warning("================================================================");
|
||||||
}
|
}
|
||||||
|
|
||||||
public record TestRecord(
|
public record TestRecord(
|
||||||
@XmlName("valueA") Integer valueA,
|
@XmlName("valueA") Integer valueA,
|
||||||
@XmlName("valueB") double valueB) {
|
@XmlName("valueB") double valueB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testModelRecord() {
|
public void testModelRecord() {
|
||||||
TestRecord elem = new TestRecord(66, 18523.0);
|
TestRecord elem = new TestRecord(66, 18523.0);
|
||||||
@ -40,5 +43,25 @@ public class ExmlTestIntrospectionRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public record TestRecordProperty (
|
||||||
|
@XmlName("valueA") @XmlAttribute Integer valueA,
|
||||||
|
@XmlName("valueB") @XmlAttribute double valueB) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testModelRecordProperty() {
|
||||||
|
TestRecordProperty elem = new TestRecordProperty(66, 18523.0);
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionObject.NODE_NAME, builder));
|
||||||
|
String dataTest = builder.toString();
|
||||||
|
Log.warning("data generated: " + builder.toString());
|
||||||
|
Assertions.assertEquals("<elem valueA=\"66\" valueB=\"18523.0\"/>", dataTest);
|
||||||
|
|
||||||
|
final TestRecordProperty root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestRecordProperty.class, ExmlTestIntrospectionObject.NODE_NAME));
|
||||||
|
Assertions.assertEquals(66, root.valueA);
|
||||||
|
Assertions.assertEquals(18523.0f, root.valueB);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user