[DEV] rework parameter management
This commit is contained in:
parent
e57b77c466
commit
77dd42e499
@ -13,10 +13,4 @@ public interface Converter {
|
||||
* @return The new data...
|
||||
*/
|
||||
String toString(final Object data);
|
||||
/**
|
||||
* Serialize in a string the require data
|
||||
* @param data Object to serialize
|
||||
* @return The new data...
|
||||
*/
|
||||
String[] toStringList(final Object data);
|
||||
}
|
@ -16,11 +16,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Byte.toString((Byte)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(Byte.class, new Converter() {
|
||||
@Override
|
||||
@ -32,11 +27,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Byte.toString((Byte)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(int.class, new Converter() {
|
||||
@Override
|
||||
@ -48,11 +38,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Integer.toString((Integer)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(Integer.class, new Converter() {
|
||||
@Override
|
||||
@ -64,11 +49,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Integer.toString((Integer)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(long.class, new Converter() {
|
||||
@Override
|
||||
@ -80,11 +60,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Long.toString((Long)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(Long.class, new Converter() {
|
||||
@Override
|
||||
@ -96,11 +71,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Long.toString((Long)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(short.class, new Converter() {
|
||||
@Override
|
||||
@ -112,11 +82,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Short.toString((Short)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(Short.class, new Converter() {
|
||||
@Override
|
||||
@ -128,11 +93,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Short.toString((Short)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(float.class, new Converter() {
|
||||
@Override
|
||||
@ -144,11 +104,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Float.toString((Float)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(Float.class, new Converter() {
|
||||
@Override
|
||||
@ -160,11 +115,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Float.toString((Float)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(double.class, new Converter() {
|
||||
@Override
|
||||
@ -176,11 +126,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Double.toString((Double)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(Double.class, new Converter() {
|
||||
@Override
|
||||
@ -192,11 +137,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Double.toString((Double)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(boolean.class, new Converter() {
|
||||
@Override
|
||||
@ -208,11 +148,6 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Boolean.toString((Boolean)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
StringSerializer.VALUES_OF.put(Boolean.class, new Converter() {
|
||||
@Override
|
||||
@ -224,306 +159,7 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return Boolean.toString((Boolean)data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { toString(data) };
|
||||
}
|
||||
});
|
||||
// StringSerializer.VALUES_OF.put(byte[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseByteStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((byte[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// byte[] dataCast = (byte[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Byte.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(Byte[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseByteClassStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((Byte[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// Byte[] dataCast = (Byte[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Byte.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(short[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseShortStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((short[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// short[] dataCast = (short[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Short.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(Short[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseShortClassStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((Short[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// Short[] dataCast = (Short[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Short.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(int[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseIntegerStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((int[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// int[] dataCast = (int[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Integer.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(Integer[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseIntegerClassStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((Integer[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// Integer[] dataCast = (Integer[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Integer.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(long[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseLongStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((long[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// long[] dataCast = (long[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Long.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(Long[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseLongClassStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((Long[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// Long[] dataCast = (Long[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Long.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(float[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseFloatStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((float[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// int[] dataCast = (int[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Float.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(Float[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseFloatClassStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((Float[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// Float[] dataCast = (Float[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Float.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(double[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseDoubleStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((double[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// int[] dataCast = (int[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Double.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(Double[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseDoubleClassStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((Double[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// Double[] dataCast = (Double[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Double.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(boolean[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseBooleanStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((boolean[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// boolean[] dataCast = (boolean[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Boolean.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
// StringSerializer.VALUES_OF.put(Boolean[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return Tools.parseBooleanClassStringList(value);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// return Tools.toString((Boolean[])data);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// Boolean[] dataCast = (Boolean[])data;
|
||||
// String[] out = new String[dataCast.length];
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// out[iii] = Boolean.toString(dataCast[iii]);
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// });
|
||||
StringSerializer.VALUES_OF.put(String.class, new Converter() {
|
||||
@Override
|
||||
public Object valueOf(final String value) {
|
||||
@ -534,36 +170,7 @@ public class StringSerializer {
|
||||
public String toString(final Object data) {
|
||||
return (String)data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toStringList(final Object data) {
|
||||
return new String[] { (String)data };
|
||||
}
|
||||
});
|
||||
// StringSerializer.VALUES_OF.put(String[].class, new Converter() {
|
||||
// @Override
|
||||
// public Object valueOf(final String value) {
|
||||
// return value.split(";");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString(final Object data) {
|
||||
// StringBuilder out = new StringBuilder();
|
||||
// String[] dataCast = (String[])data;
|
||||
// for (int iii=0; iii<dataCast.length; iii++) {
|
||||
// if (iii != 0) {
|
||||
// out.append(";");
|
||||
// }
|
||||
// out.append(dataCast[iii]);
|
||||
// }
|
||||
// return out.toString();
|
||||
// }
|
||||
// @Override
|
||||
// public String[] toStringList(final Object data) {
|
||||
// return (String[])data;
|
||||
//
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
public static boolean contains(final Class<?> clazz) {
|
||||
@ -609,14 +216,6 @@ public class StringSerializer {
|
||||
Converter conv = StringSerializer.VALUES_OF.get(clazz);
|
||||
return conv.toString(data);
|
||||
}
|
||||
@Deprecated
|
||||
public static String[] toStringList(final Object data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
Converter conv = StringSerializer.VALUES_OF.get(data.getClass());
|
||||
return conv.toStringList(data);
|
||||
}
|
||||
|
||||
private StringSerializer() {}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import java.lang.annotation.Target;
|
||||
/**
|
||||
* Marker annotation that set the Xml element seen as a property.
|
||||
*/
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD })
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ExmlAnnotation
|
||||
public @interface XmlAttribute {
|
||||
|
@ -25,6 +25,7 @@ import org.atriasoft.exml.reflect.ReflectTools;
|
||||
|
||||
|
||||
record ConstructorModel(String[] values,
|
||||
Boolean[] isAttributes,
|
||||
Constructor<?> constructor) {
|
||||
}
|
||||
|
||||
@ -49,6 +50,23 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
public List<IntrospectionProperty> getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
// private boolean checkIfOneIsNull(Boolean[] values, int offset) {
|
||||
// for (int iii=offset; iii<values.length; iii++) {
|
||||
// if (values[iii] == null) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
private boolean checkIfOneIsNull(String[] values, int offset) {
|
||||
for (int iii=offset; iii<values.length; iii++) {
|
||||
if (values[iii] == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public IntrospectionModelComplex(final Class<?> classType) throws ExmlBuilderException {
|
||||
super(classType);
|
||||
@ -86,70 +104,60 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
emptyConstructorTmp = elem;
|
||||
Log.verbose(" >>> " + elem.toGenericString());
|
||||
} else {
|
||||
// Retrieve full description in constructor properties...
|
||||
String[] names = ReflectTools.getNames(elem, null);
|
||||
if (names == null) {
|
||||
// Search in the parameters ...
|
||||
List<String> restoredElementNames = new ArrayList<>();
|
||||
Parameter[] params = elem.getParameters();
|
||||
for (int iii=1; iii<params.length; iii++) {
|
||||
Parameter paramElem = params[iii];
|
||||
String[] namesParam = ReflectTools.getNames(elem, paramElem, null);
|
||||
if (namesParam == null) {
|
||||
break;
|
||||
}
|
||||
if (namesParam.length != 1) {
|
||||
throw new ExmlBuilderException("the @XmlName in constructor parameter must not exceed 1 element");
|
||||
}
|
||||
restoredElementNames.add(namesParam[0]);
|
||||
}
|
||||
if (restoredElementNames.size() == 0) {
|
||||
Log.verbose(" - " + elem.toGenericString());
|
||||
Log.verbose(" ==> unmanaged");
|
||||
} else if (restoredElementNames.size() != params.length-1) {
|
||||
throw new ExmlBuilderException("the @XmlName in constructor parameter must set for every one");
|
||||
} else {
|
||||
this.constructors.add(new ConstructorModel(restoredElementNames.toArray(new String[restoredElementNames.size()]), elem));
|
||||
names = new String[elem.getParameterCount()];
|
||||
} else if (elem.getParameterCount() != names.length+1) {
|
||||
throw new ExmlBuilderException("Wrong number of parameter in constructor with ne number declared in the @XmlName");
|
||||
}
|
||||
Boolean[] isAttributes = new Boolean[elem.getParameterCount()-1];
|
||||
|
||||
Parameter[] params = elem.getParameters();
|
||||
for (int iii=1; iii<params.length; iii++) {
|
||||
Parameter paramElem = params[iii];
|
||||
isAttributes[iii-1] = 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-1] = namesParam[0];
|
||||
}
|
||||
}
|
||||
if (checkIfOneIsNull(names,1)) {
|
||||
Log.verbose(" - " + elem.toGenericString());
|
||||
Log.verbose(" ==> unmanaged (missing names description)");
|
||||
} else {
|
||||
if (elem.getParameterCount() != names.length+1) {
|
||||
throw new ExmlBuilderException("Wrong number of parameter in constructor with ne number declared in the @XmlName");
|
||||
}
|
||||
this.constructors.add(new ConstructorModel(names, elem));
|
||||
this.constructors.add(new ConstructorModel(names, 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) {
|
||||
// Search in the parameters ...
|
||||
List<String> restoredElementNames = new ArrayList<>();
|
||||
Parameter[] params = elem.getParameters();
|
||||
for (int iii=0; iii<params.length; iii++) {
|
||||
Parameter paramElem = params[iii];
|
||||
String[] namesParam = ReflectTools.getNames(elem, paramElem, null);
|
||||
if (namesParam == null) {
|
||||
break;
|
||||
}
|
||||
if (namesParam.length != 1) {
|
||||
throw new ExmlBuilderException("the @XmlName in constructor parameter must not exceed 1 element");
|
||||
}
|
||||
restoredElementNames.add(namesParam[0]);
|
||||
}
|
||||
if (restoredElementNames.size() == 0) {
|
||||
Log.verbose(" - " + elem.toGenericString());
|
||||
Log.verbose(" ==> unmanaged");
|
||||
} else if (restoredElementNames.size() != params.length) {
|
||||
throw new ExmlBuilderException("the @XmlName in constructor parameter must set for every one");
|
||||
} else {
|
||||
this.constructors.add(new ConstructorModel(restoredElementNames.toArray(new String[restoredElementNames.size()]), elem));
|
||||
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 {
|
||||
if (elem.getParameterCount() != names.length) {
|
||||
throw new ExmlBuilderException("Wrong number of parameter in constructor with ne number declared in the @XmlName");
|
||||
}
|
||||
this.constructors.add(new ConstructorModel(names, elem));
|
||||
this.constructors.add(new ConstructorModel(names, isAttributes, elem));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -473,6 +481,22 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
ex.printStackTrace();
|
||||
throw new ExmlBuilderException("Error in creating introspection data ... " + ex.getMessage());
|
||||
}
|
||||
|
||||
// Sort the parameters to generate all time the same XML..
|
||||
Collections.sort(this.nodes, new Comparator<IntrospectionProperty>() {
|
||||
@Override
|
||||
public
|
||||
int compare(final IntrospectionProperty a, final IntrospectionProperty b) {
|
||||
return a.getNames()[0].compareTo(b.getNames()[0]);
|
||||
}
|
||||
});
|
||||
Collections.sort(this.attributes, new Comparator<IntrospectionProperty>() {
|
||||
@Override
|
||||
public
|
||||
int compare(final IntrospectionProperty a, final IntrospectionProperty b) {
|
||||
return a.getNames()[0].compareTo(b.getNames()[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -517,7 +541,16 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
case 11: tmp = 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]); break;
|
||||
case 12: tmp = 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]); break;
|
||||
case 13: tmp = 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]); break;
|
||||
case 14: tmp = 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]); break;
|
||||
case 15: tmp = 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]); break;
|
||||
case 16: tmp = 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]); break;
|
||||
case 17: tmp = 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]); break;
|
||||
case 18: tmp = 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]); break;
|
||||
case 19: tmp = 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]); break;
|
||||
case 20: tmp = 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]); break;
|
||||
case 21: tmp = 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]); break;
|
||||
default:
|
||||
//tmp = elem.constructor().newInstance(new Object[] {inputs}); break;
|
||||
throw new ExmlBuilderException("to much parameter in the constructor... " + inputs.length);
|
||||
}
|
||||
//tmp = elem.constructor().newInstance(inputs);
|
||||
|
@ -27,7 +27,7 @@ public class ReflectTools {
|
||||
return defaultValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlCaseSensitive on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlCaseSensitive) annotation[0]).value();
|
||||
}
|
||||
@ -38,7 +38,7 @@ public class ReflectTools {
|
||||
return defaultValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlCaseSensitive on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlCaseSensitive) annotation[0]).value();
|
||||
}
|
||||
@ -49,7 +49,7 @@ public class ReflectTools {
|
||||
return defaultValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultCaseSensitive on " + classType.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlDefaultCaseSensitive) annotation[0]).value();
|
||||
}
|
||||
@ -60,7 +60,7 @@ public class ReflectTools {
|
||||
return defaultValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultAttibute on " + classType.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlDefaultAttibute) annotation[0]).value();
|
||||
}
|
||||
@ -71,7 +71,7 @@ public class ReflectTools {
|
||||
return defaultValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultManaged on " + classType.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlDefaultManaged) annotation[0]).value();
|
||||
}
|
||||
@ -82,7 +82,7 @@ public class ReflectTools {
|
||||
return defaultValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlDefaultOptional on " + classType.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlDefaultOptional) annotation[0]).value();
|
||||
}
|
||||
@ -93,18 +93,29 @@ public class ReflectTools {
|
||||
return parentValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlAttribute) annotation[0]).value();
|
||||
}
|
||||
|
||||
|
||||
public static Boolean getIsAttribute(final Method element, final Boolean parentValue) throws ExmlBuilderException {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class);
|
||||
if (annotation.length == 0) {
|
||||
return parentValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlAttribute) annotation[0]).value();
|
||||
}
|
||||
|
||||
public static Boolean getIsAttribute(final Constructor<?> constructor, final Parameter element, final Boolean parentValue) throws ExmlBuilderException {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class);
|
||||
if (annotation.length == 0) {
|
||||
return parentValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlAttribute on " + constructor.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlAttribute) annotation[0]).value();
|
||||
}
|
||||
@ -115,7 +126,7 @@ public class ReflectTools {
|
||||
return parentValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @ on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlManaged) annotation[0]).value();
|
||||
}
|
||||
@ -126,7 +137,7 @@ public class ReflectTools {
|
||||
return parentValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new ExmlBuilderException("Must not have more that ");
|
||||
throw new ExmlBuilderException("Must not have more than 1 element @XmlManaged on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlManaged) annotation[0]).value();
|
||||
}
|
||||
@ -137,7 +148,7 @@ public class ReflectTools {
|
||||
return parentValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more that ");
|
||||
throw new Exception("Must not have more than 1 element @XmlOptional on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlOptional) annotation[0]).value();
|
||||
}
|
||||
@ -148,7 +159,7 @@ public class ReflectTools {
|
||||
return parentValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more that ");
|
||||
throw new Exception("Must not have more than 1 element @XmlOptional on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((XmlOptional) annotation[0]).value();
|
||||
}
|
||||
@ -162,7 +173,7 @@ public class ReflectTools {
|
||||
return new String[] { defaultValue };
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more that ");
|
||||
throw new Exception("Must not have more than 1 element @XmlName on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
final String[] tmp = ((XmlName) annotation[0]).value();
|
||||
if (tmp == null) {
|
||||
@ -191,7 +202,7 @@ public class ReflectTools {
|
||||
return new String[] { defaultValue };
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more that ");
|
||||
throw new Exception("Must not have more than 1 element @XmlName on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
final String[] tmp = ((XmlName) annotation[0]).value();
|
||||
if (tmp == null) {
|
||||
@ -219,7 +230,7 @@ public class ReflectTools {
|
||||
return new String[] { defaultValue };
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more that ");
|
||||
throw new Exception("Must not have more than 1 element @XmlName on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
final String[] tmp = ((XmlName) annotation[0]).value();
|
||||
if (tmp == null) {
|
||||
@ -247,7 +258,7 @@ public class ReflectTools {
|
||||
return new String[] { defaultValue };
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more that ");
|
||||
throw new Exception("Must not have more than 1 element @XmlName on " + constructor.getClass().getCanonicalName());
|
||||
}
|
||||
final String[] tmp = ((XmlName) annotation[0]).value();
|
||||
if (tmp == null) {
|
||||
@ -274,7 +285,7 @@ public class ReflectTools {
|
||||
return defaultValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more that ");
|
||||
throw new Exception("Must not have more than 1 element @XmlList on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
final String tmp = ((XmlList) annotation[0]).value();
|
||||
if (tmp == null) {
|
||||
@ -288,7 +299,7 @@ public class ReflectTools {
|
||||
return defaultValue;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more that ");
|
||||
throw new Exception("Must not have more than 1 element @XmlList on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
final String tmp = ((XmlList) annotation[0]).value();
|
||||
if (tmp == null) {
|
||||
|
431
test/src/test/atriasoft/exml/ExmlTestIntrospectionDecorator.java
Normal file
431
test/src/test/atriasoft/exml/ExmlTestIntrospectionDecorator.java
Normal file
@ -0,0 +1,431 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2021, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
package test.atriasoft.exml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.atriasoft.exml.Exml;
|
||||
import org.atriasoft.exml.annotation.XmlAttribute;
|
||||
import org.atriasoft.exml.annotation.XmlDefaultAttibute;
|
||||
import org.atriasoft.exml.annotation.XmlList;
|
||||
import org.atriasoft.exml.annotation.XmlName;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ExmlTestIntrospectionDecorator {
|
||||
static final String NODE_NAME = "elem";
|
||||
@BeforeAll
|
||||
public static void beforeClass() {
|
||||
Log.warning("================================================================");
|
||||
}
|
||||
// ************************************************************
|
||||
// ** Attribute
|
||||
// ************************************************************
|
||||
|
||||
@XmlDefaultAttibute()
|
||||
public class TestNodeObject {
|
||||
|
||||
public int valueA;
|
||||
@XmlAttribute()
|
||||
public int valueB;
|
||||
@XmlAttribute(true)
|
||||
public int valueC;
|
||||
@XmlAttribute(false)
|
||||
public int valueD;
|
||||
|
||||
private int valueE;
|
||||
private int valueF;
|
||||
private int valueG;
|
||||
private int valueH;
|
||||
private int valueI;
|
||||
private int valueJ;
|
||||
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 TestNodeObject(
|
||||
int finalValueM, int finalValueN, int finalValueO, int finalValueP,
|
||||
int finalValueQ, @XmlAttribute() int finalValueR, @XmlAttribute(true) int finalValueS, @XmlAttribute(false) int finalValueT,
|
||||
int pFinalValueQ, int pFinalValueR, int pFinalValueS, 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() {
|
||||
return valueE;
|
||||
}
|
||||
public void setValueE(int valueE) {
|
||||
this.valueE = valueE;
|
||||
}
|
||||
@XmlAttribute()
|
||||
public int getValueF() {
|
||||
return valueF;
|
||||
}
|
||||
public void setValueF(int valueF) {
|
||||
this.valueF = valueF;
|
||||
}
|
||||
public int getValueG() {
|
||||
return valueG;
|
||||
}
|
||||
@XmlAttribute()
|
||||
public void setValueG(int valueG) {
|
||||
this.valueG = valueG;
|
||||
}
|
||||
@XmlAttribute(true)
|
||||
public int getValueH() {
|
||||
return valueH;
|
||||
}
|
||||
public void setValueH(int valueH) {
|
||||
this.valueH = valueH;
|
||||
}
|
||||
public int getValueI() {
|
||||
return valueI;
|
||||
}
|
||||
@XmlAttribute(true)
|
||||
public void setValueI(int valueI) {
|
||||
this.valueI = valueI;
|
||||
}
|
||||
@XmlAttribute(false)
|
||||
public int getValueJ() {
|
||||
return valueJ;
|
||||
}
|
||||
public void setValueJ(int valueJ) {
|
||||
this.valueJ = valueJ;
|
||||
}
|
||||
public int getValueK() {
|
||||
return valueK;
|
||||
}
|
||||
@XmlAttribute(false)
|
||||
public void setValueK(int valueK) {
|
||||
this.valueK = valueK;
|
||||
}
|
||||
|
||||
public int getPFinalValueQ() {
|
||||
return pFinalValueQ;
|
||||
}
|
||||
|
||||
@XmlAttribute()
|
||||
public int getPFinalValueR() {
|
||||
return pFinalValueR;
|
||||
}
|
||||
|
||||
@XmlAttribute(true)
|
||||
public int getPFinalValueS() {
|
||||
return pFinalValueS;
|
||||
}
|
||||
|
||||
@XmlAttribute(false)
|
||||
public int getPFinalValueT() {
|
||||
return pFinalValueT;
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testDefaultAttribute() {
|
||||
TestNodeObject elem = new TestNodeObject(321,654,987,159,267,264,1524,182445, -552, -965, -98885, -8754);
|
||||
elem.valueA = 55;
|
||||
elem.valueB = 78;
|
||||
elem.valueC = 51;
|
||||
elem.valueD = 24;
|
||||
elem.setValueE(651);
|
||||
elem.setValueF(654);
|
||||
elem.setValueG(8552);
|
||||
elem.setValueH(9531);
|
||||
elem.setValueI(87465);
|
||||
elem.setValueJ(8247);
|
||||
elem.setValueK(885522);
|
||||
|
||||
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 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"
|
||||
+ " <valueJ>8247</valueJ>\n"
|
||||
+ " <valueK>885522</valueK>\n"
|
||||
+ "</elem>", dataTest);
|
||||
|
||||
final TestNodeObject root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestNodeObject.class, ExmlTestIntrospectionObject.NODE_NAME));
|
||||
Assertions.assertEquals(55, root.valueA);
|
||||
Assertions.assertEquals(78, root.valueB);
|
||||
Assertions.assertEquals(51, root.valueC);
|
||||
Assertions.assertEquals(24, root.valueD);
|
||||
Assertions.assertEquals(651, root.getValueE());
|
||||
Assertions.assertEquals(654, root.getValueF());
|
||||
Assertions.assertEquals(8552, root.getValueG());
|
||||
Assertions.assertEquals(9531, root.getValueH());
|
||||
Assertions.assertEquals(87465, root.getValueI());
|
||||
Assertions.assertEquals(8247, root.getValueJ());
|
||||
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(true)
|
||||
public class TestNodeObjectTrue {
|
||||
public int valueA;
|
||||
@XmlAttribute()
|
||||
public int valueB;
|
||||
@XmlAttribute(true)
|
||||
public int valueC;
|
||||
@XmlAttribute(false)
|
||||
public int valueD;
|
||||
|
||||
private int valueE;
|
||||
private int valueF;
|
||||
private int valueG;
|
||||
private int valueH;
|
||||
private int valueI;
|
||||
private int valueJ;
|
||||
private int valueK;
|
||||
|
||||
public int getValueE() {
|
||||
return valueE;
|
||||
}
|
||||
public void setValueE(int valueE) {
|
||||
this.valueE = valueE;
|
||||
}
|
||||
@XmlAttribute()
|
||||
public int getValueF() {
|
||||
return valueF;
|
||||
}
|
||||
public void setValueF(int valueF) {
|
||||
this.valueF = valueF;
|
||||
}
|
||||
public int getValueG() {
|
||||
return valueG;
|
||||
}
|
||||
@XmlAttribute()
|
||||
public void setValueG(int valueG) {
|
||||
this.valueG = valueG;
|
||||
}
|
||||
@XmlAttribute(true)
|
||||
public int getValueH() {
|
||||
return valueH;
|
||||
}
|
||||
public void setValueH(int valueH) {
|
||||
this.valueH = valueH;
|
||||
}
|
||||
public int getValueI() {
|
||||
return valueI;
|
||||
}
|
||||
@XmlAttribute(true)
|
||||
public void setValueI(int valueI) {
|
||||
this.valueI = valueI;
|
||||
}
|
||||
@XmlAttribute(false)
|
||||
public int getValueJ() {
|
||||
return valueJ;
|
||||
}
|
||||
public void setValueJ(int valueJ) {
|
||||
this.valueJ = valueJ;
|
||||
}
|
||||
public int getValueK() {
|
||||
return valueK;
|
||||
}
|
||||
@XmlAttribute(false)
|
||||
public void setValueK(int valueK) {
|
||||
this.valueK = valueK;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testDefaultAttributeTrue() {
|
||||
TestNodeObjectTrue elem = new TestNodeObjectTrue();
|
||||
elem.valueA = 55;
|
||||
elem.valueB = 78;
|
||||
elem.valueC = 51;
|
||||
elem.valueD = 24;
|
||||
elem.setValueE(651);
|
||||
elem.setValueF(654);
|
||||
elem.setValueG(8552);
|
||||
elem.setValueH(9531);
|
||||
elem.setValueI(87465);
|
||||
elem.setValueJ(8247);
|
||||
elem.setValueK(885522);
|
||||
|
||||
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=\"55\" valueB=\"78\" valueC=\"51\" valueE=\"651\" valueF=\"654\" valueG=\"8552\" valueH=\"9531\" valueI=\"87465\">\n"
|
||||
+ " <valueD>24</valueD>\n"
|
||||
+ " <valueJ>8247</valueJ>\n"
|
||||
+ " <valueK>885522</valueK>\n"
|
||||
+ "</elem>", dataTest);
|
||||
|
||||
final TestNodeObjectTrue root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestNodeObjectTrue.class, ExmlTestIntrospectionObject.NODE_NAME));
|
||||
Assertions.assertEquals(55, root.valueA);
|
||||
Assertions.assertEquals(78, root.valueB);
|
||||
Assertions.assertEquals(51, root.valueC);
|
||||
Assertions.assertEquals(24, root.valueD);
|
||||
Assertions.assertEquals(651, root.getValueE());
|
||||
Assertions.assertEquals(654, root.getValueF());
|
||||
Assertions.assertEquals(8552, root.getValueG());
|
||||
Assertions.assertEquals(9531, root.getValueH());
|
||||
Assertions.assertEquals(87465, root.getValueI());
|
||||
Assertions.assertEquals(8247, root.getValueJ());
|
||||
Assertions.assertEquals(885522, root.getValueK());
|
||||
}
|
||||
|
||||
@XmlDefaultAttibute(false)
|
||||
public class TestNodeObjectFalse {
|
||||
public int valueA;
|
||||
@XmlAttribute()
|
||||
public int valueB;
|
||||
@XmlAttribute(true)
|
||||
public int valueC;
|
||||
@XmlAttribute(false)
|
||||
public int valueD;
|
||||
|
||||
private int valueE;
|
||||
private int valueF;
|
||||
private int valueG;
|
||||
private int valueH;
|
||||
private int valueI;
|
||||
private int valueJ;
|
||||
private int valueK;
|
||||
|
||||
public int getValueE() {
|
||||
return valueE;
|
||||
}
|
||||
public void setValueE(int valueE) {
|
||||
this.valueE = valueE;
|
||||
}
|
||||
@XmlAttribute()
|
||||
public int getValueF() {
|
||||
return valueF;
|
||||
}
|
||||
public void setValueF(int valueF) {
|
||||
this.valueF = valueF;
|
||||
}
|
||||
public int getValueG() {
|
||||
return valueG;
|
||||
}
|
||||
@XmlAttribute()
|
||||
public void setValueG(int valueG) {
|
||||
this.valueG = valueG;
|
||||
}
|
||||
@XmlAttribute(true)
|
||||
public int getValueH() {
|
||||
return valueH;
|
||||
}
|
||||
public void setValueH(int valueH) {
|
||||
this.valueH = valueH;
|
||||
}
|
||||
public int getValueI() {
|
||||
return valueI;
|
||||
}
|
||||
@XmlAttribute(true)
|
||||
public void setValueI(int valueI) {
|
||||
this.valueI = valueI;
|
||||
}
|
||||
@XmlAttribute(false)
|
||||
public int getValueJ() {
|
||||
return valueJ;
|
||||
}
|
||||
public void setValueJ(int valueJ) {
|
||||
this.valueJ = valueJ;
|
||||
}
|
||||
public int getValueK() {
|
||||
return valueK;
|
||||
}
|
||||
@XmlAttribute(false)
|
||||
public void setValueK(int valueK) {
|
||||
this.valueK = valueK;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testDefaultAttributeFalse() {
|
||||
TestNodeObjectFalse elem = new TestNodeObjectFalse();
|
||||
elem.valueA = 55;
|
||||
elem.valueB = 78;
|
||||
elem.valueC = 51;
|
||||
elem.valueD = 24;
|
||||
elem.setValueE(651);
|
||||
elem.setValueF(654);
|
||||
elem.setValueG(8552);
|
||||
elem.setValueH(9531);
|
||||
elem.setValueI(87465);
|
||||
elem.setValueJ(8247);
|
||||
elem.setValueK(885522);
|
||||
|
||||
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 valueB=\"78\" valueC=\"51\" valueF=\"654\" valueG=\"8552\" valueH=\"9531\" valueI=\"87465\">\n"
|
||||
+ " <valueA>55</valueA>\n"
|
||||
+ " <valueD>24</valueD>\n"
|
||||
+ " <valueE>651</valueE>\n"
|
||||
+ " <valueJ>8247</valueJ>\n"
|
||||
+ " <valueK>885522</valueK>\n"
|
||||
+ "</elem>", dataTest);
|
||||
|
||||
final TestNodeObjectFalse root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestNodeObjectFalse.class, ExmlTestIntrospectionObject.NODE_NAME));
|
||||
Assertions.assertEquals(55, root.valueA);
|
||||
Assertions.assertEquals(78, root.valueB);
|
||||
Assertions.assertEquals(51, root.valueC);
|
||||
Assertions.assertEquals(24, root.valueD);
|
||||
Assertions.assertEquals(651, root.getValueE());
|
||||
Assertions.assertEquals(654, root.getValueF());
|
||||
Assertions.assertEquals(8552, root.getValueG());
|
||||
Assertions.assertEquals(9531, root.getValueH());
|
||||
Assertions.assertEquals(87465, root.getValueI());
|
||||
Assertions.assertEquals(8247, root.getValueJ());
|
||||
Assertions.assertEquals(885522, root.getValueK());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user