integration of contructor properties
This commit is contained in:
parent
095a705d4b
commit
0a0ee42b4b
@ -59,6 +59,16 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
protected IntrospectionProperty findElement(String beanName) {
|
||||
for (IntrospectionProperty elem : elements) {
|
||||
if (elem.getBeanName().equals(beanName)) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// private boolean checkIfOneIsNull(Boolean[] values, int offset) {
|
||||
// for (int iii=offset; iii<values.length; iii++) {
|
||||
@ -110,29 +120,66 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
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()-1];
|
||||
} else if (elem.getParameterCount() != names.length+1) {
|
||||
throw new ExmlBuilderException("Wrong number of parameter in constructor with ne number declared in the @XmlName");
|
||||
String[] namesBeans = ReflectTools.getNames(elem, null);
|
||||
if (namesBeans == null) {
|
||||
namesBeans = new String[elem.getParameterCount()-1];
|
||||
} else if (elem.getParameterCount() != namesBeans.length+1) {
|
||||
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];
|
||||
|
||||
Class<?>[][] clazz = new Class<?>[elem.getParameterCount()-1][];
|
||||
String[][] names = new String[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);
|
||||
Class<?>[] types = ReflectTools.getTypeParameterfunction(elem, iii);
|
||||
clazz[iii-1] = types;
|
||||
names[iii-1] = namesParam;
|
||||
if (namesParam != null && namesParam.length != 0 ) {
|
||||
// TODO maybe do something id name is already set ???
|
||||
names[iii-1] = namesParam[0];
|
||||
namesBeans[iii-1] = namesParam[0];
|
||||
}
|
||||
}
|
||||
if (checkIfOneIsNull(names,0)) {
|
||||
if (checkIfOneIsNull(namesBeans,0)) {
|
||||
Log.verbose(" - " + elem.toGenericString());
|
||||
Log.verbose(" ==> unmanaged (missing names description: " + Arrays.toString(names) + ")");
|
||||
Log.verbose(" ==> unmanaged (missing names description: " + Arrays.toString(namesBeans) + ")");
|
||||
} else {
|
||||
this.constructors.add(new ConstructorModel(names, isAttributes, elem));
|
||||
// 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++) {
|
||||
IntrospectionProperty prop = findElement(namesBeans[iii]);
|
||||
if (prop == null) {
|
||||
prop = new IntrospectionProperty(namesBeans[iii], clazz[iii], names[iii]);
|
||||
this.elements.add(prop);
|
||||
} else {
|
||||
Class<?> curentType = prop.getType();
|
||||
Class<?> curentSubType = prop.getSubType();
|
||||
if (curentType != clazz[iii][0] && curentSubType != clazz[iii][1]) {
|
||||
throw new ExmlBuilderException("Set 'return type' with a different value previous=" + curentType.getCanonicalName() + " / " + curentSubType.getCanonicalName() + " ==> new=" + clazz[iii][0] + " / " + clazz[iii][1] + " in " + elem.toGenericString());
|
||||
}
|
||||
String[] names1 = names[iii];
|
||||
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 Boolean isAttribute = isAttributes[iii];
|
||||
if (isAttribute != null) {
|
||||
Boolean curentValue = prop.isAttribute();
|
||||
if (curentValue != null && curentValue != isAttribute) {
|
||||
throw new ExmlBuilderException("Set 'attribute' with a different value previous=" + curentValue + " ==> new=" + isAttribute + " in " + elem.toGenericString());
|
||||
}
|
||||
prop.setAttribute(isAttribute);
|
||||
}
|
||||
}
|
||||
this.constructors.add(new ConstructorModel(namesBeans, isAttributes, elem));
|
||||
}
|
||||
}
|
||||
} else if (elem.getParameterCount() == 0) {
|
||||
@ -216,11 +263,14 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
continue;
|
||||
}
|
||||
final String[] names = ReflectTools.getNames(elem, null);
|
||||
final String listName = ReflectTools.getListName(elem, null);
|
||||
Class<?>[] types = ReflectTools.getTypeField(elem);
|
||||
IntrospectionProperty prop = new IntrospectionProperty(Tools.decapitalizeFirst(elem.getName()), types, names);
|
||||
this.elements.add(prop);
|
||||
|
||||
final String listName = ReflectTools.getListName(elem, null);
|
||||
if (listName != null) {
|
||||
prop.setListName(listName);
|
||||
}
|
||||
final Boolean isAttribute = ReflectTools.getIsAttribute(elem, null);
|
||||
if (isAttribute != null) {
|
||||
prop.setAttribute(isAttribute);
|
||||
@ -327,9 +377,11 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
|
||||
|
||||
// Separate the methods and filer as:
|
||||
// XXX GetXxx(); & XXX != boolean
|
||||
// void setXxx(XXX elem);
|
||||
// [bB]oolean isXxx();
|
||||
// - XXX GetXxx(); & XXX != boolean
|
||||
// - void setXxx(XXX elem);
|
||||
// - [bB]oolean isXxx();
|
||||
// for records:
|
||||
// - xxx();
|
||||
|
||||
List<Method> methodsGet;
|
||||
List<Method> methodsSet;
|
||||
@ -366,143 +418,60 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
this.tostring = null;
|
||||
}
|
||||
// associate methods by pair.
|
||||
final List<OrderData> elements = new ArrayList<>();
|
||||
for (final Method method : methodsGet) {
|
||||
final String name = isRecord?method.getName():method.getName().substring(3);
|
||||
final OrderData tmp = new OrderData(name);
|
||||
tmp.getter = method;
|
||||
elements.add(tmp);
|
||||
final String name = Tools.decapitalizeFirst(isRecord?method.getName():method.getName().substring(3));
|
||||
IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method));
|
||||
// generate getter and setter with field.
|
||||
IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method);
|
||||
prop.setGetter(modifier);
|
||||
}
|
||||
if (!isRecord) {
|
||||
for (final Method method : methodsIs) {
|
||||
final String name = method.getName().substring(2);
|
||||
for (final OrderData elem : elements) {
|
||||
if (elem.name.contentEquals(name)) {
|
||||
Log.error("Can not have a setXXX and isXXX with the same name ... " + method.getName());
|
||||
throw new Exception("lmkjlkjlk");
|
||||
}
|
||||
}
|
||||
final OrderData tmp = new OrderData(name);
|
||||
tmp.getter = method;
|
||||
elements.add(tmp);
|
||||
final String name = Tools.decapitalizeFirst(method.getName().substring(2));
|
||||
IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeReturnFunction(method));
|
||||
// generate getter and setter with field.
|
||||
IntrospectionPropertyMethodGetter modifier = new IntrospectionPropertyMethodGetter(method);
|
||||
prop.setGetter(modifier);
|
||||
}
|
||||
for (final Method method : methodsSet) {
|
||||
final String name = method.getName().substring(3);
|
||||
OrderData tmp = null;
|
||||
for (final OrderData elem : elements) {
|
||||
if (elem.name.contentEquals(name)) {
|
||||
tmp = elem;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tmp == null) {
|
||||
tmp = new OrderData(name);
|
||||
tmp.setter = method;
|
||||
elements.add(tmp);
|
||||
} else {
|
||||
tmp.setter = method;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add it in the engine
|
||||
for (final OrderData elem : elements) {
|
||||
Log.info("find methode : '" + elem.name + "' :");
|
||||
if (elem.setter != null && elem.getter != null) {
|
||||
Log.info(" setter: " + elem.setter.toGenericString());
|
||||
if (recordAllPossibleValuesFiltered.contains(elem.name)) {
|
||||
Log.info(" and by constructor");
|
||||
}
|
||||
Log.info(" getter: " + elem.getter.toGenericString());
|
||||
final Boolean isAttributeSet = ReflectTools.getIsAttribute(elem.setter, null);
|
||||
final Boolean isAttributeGet = ReflectTools.getIsAttribute(elem.getter, null);
|
||||
if (isAttributeSet != null && isAttributeGet != null && isAttributeSet != isAttributeGet) {
|
||||
throw new Exception("Can net set oposite information on getter and setter");
|
||||
}
|
||||
final Boolean isAttribute = isAttributeSet != null ? isAttributeSet : isAttributeGet != null ? isAttributeGet : isDefaultAttribute;
|
||||
|
||||
final Boolean isManagedSet = ReflectTools.getIsManaged(elem.setter, null);
|
||||
final Boolean isManagedGet = ReflectTools.getIsManaged(elem.getter, null);
|
||||
if (isManagedSet != null && isManagedGet != null && isManagedSet != isManagedGet) {
|
||||
throw new Exception("Can net set oposite information on getter and setter");
|
||||
}
|
||||
final Boolean isManaged = isManagedSet != null ? isManagedSet : isManagedGet != null ? isManagedGet : isDefaultManaged;
|
||||
|
||||
final Boolean isOptionnalSet = ReflectTools.getIsOptional(elem.setter, null);
|
||||
final Boolean isOptionnalGet = ReflectTools.getIsOptional(elem.getter, null);
|
||||
if (isOptionnalSet != null && isOptionnalGet != null && isOptionnalSet != isOptionnalGet) {
|
||||
throw new Exception("Can net set oposite information on getter and setter");
|
||||
}
|
||||
final Boolean isOptional = isOptionnalSet != null ? isOptionnalSet : isOptionnalGet != null ? isOptionnalGet : isDefaultOptional;
|
||||
|
||||
final Boolean caseSensitiveSet = ReflectTools.getIsCaseSensitive(elem.setter, null);
|
||||
final Boolean caseSensitiveGet = ReflectTools.getIsCaseSensitive(elem.getter, null);
|
||||
if (caseSensitiveSet != null && caseSensitiveGet != null && caseSensitiveSet != caseSensitiveGet) {
|
||||
throw new Exception("Can net set oposite information on getter and setter");
|
||||
}
|
||||
|
||||
final Boolean isCaseSensitive = caseSensitiveSet != null ? caseSensitiveSet : caseSensitiveGet != null ? caseSensitiveGet : isDefaultCaseSensitive;
|
||||
|
||||
final String[] namesSet = ReflectTools.getNames(elem.setter, null);
|
||||
final String[] namesGet = ReflectTools.getNames(elem.getter, null);
|
||||
if (namesSet != null && namesGet != null && namesSet.equals(namesGet)) {
|
||||
throw new Exception("Can net set oposite information on getter and setter");
|
||||
}
|
||||
final String[] names = namesSet != null ? namesSet : namesGet != null ? namesGet : new String[] { Tools.decapitalizeFirst(elem.name) };
|
||||
final String listNameSet = ReflectTools.getListName(elem.setter, null);
|
||||
final String listNameGet = ReflectTools.getListName(elem.getter, null);
|
||||
final String listName = listNameSet != null? listNameSet: listNameGet;
|
||||
if (isAttribute) {
|
||||
this.attributes.add(new IntrospectionPropertyMethodGetter(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptional));
|
||||
} else {
|
||||
this.nodes.add(new IntrospectionPropertyMethodGetter(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptional));
|
||||
}
|
||||
} else {
|
||||
Boolean isManaged = null;
|
||||
Boolean isOptionnal = null;
|
||||
String[] names = null;
|
||||
Boolean isCaseSensitive = null;
|
||||
String listName = null;
|
||||
Boolean isAttribute = isDefaultAttribute;
|
||||
if (elem.setter != null) {
|
||||
Log.info(" setter: " + elem.setter.toGenericString());
|
||||
isAttribute = ReflectTools.getIsAttribute(elem.setter, isDefaultAttribute);
|
||||
isManaged = ReflectTools.getIsManaged(elem.setter, isDefaultManaged);
|
||||
isOptionnal = ReflectTools.getIsOptional(elem.setter, isDefaultOptional);
|
||||
names = ReflectTools.getNames(elem.setter, Tools.decapitalizeFirst(elem.name));
|
||||
isCaseSensitive = ReflectTools.getIsCaseSensitive(elem.setter, isDefaultCaseSensitive);
|
||||
listName= ReflectTools.getListName(elem.setter, null);
|
||||
} else {
|
||||
Log.info(" setter: null");
|
||||
}
|
||||
if (elem.getter != null) {
|
||||
Log.info(" getter: " + elem.getter.toGenericString());
|
||||
isAttribute = ReflectTools.getIsAttribute(elem.getter, isDefaultAttribute);
|
||||
isManaged = ReflectTools.getIsManaged(elem.getter, isDefaultManaged);
|
||||
isOptionnal = ReflectTools.getIsOptional(elem.getter, isDefaultOptional);
|
||||
names = ReflectTools.getNames(elem.getter, Tools.decapitalizeFirst(elem.name));
|
||||
isCaseSensitive = ReflectTools.getIsCaseSensitive(elem.getter, isDefaultCaseSensitive);
|
||||
listName= ReflectTools.getListName(elem.getter, null);
|
||||
} else {
|
||||
Log.info(" getter: null");
|
||||
}
|
||||
if (isManaged) {
|
||||
if (isAttribute) {
|
||||
IntrospectionPropertyMethodGetter tmpp = new IntrospectionPropertyMethodGetter(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptionnal);
|
||||
tmpp.setCanBeSetByConstructor(recordAllPossibleValuesFiltered.contains(elem.name));
|
||||
this.attributes.add(tmpp);
|
||||
} else {
|
||||
IntrospectionPropertyMethodGetter tmpp = new IntrospectionPropertyMethodGetter(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptionnal);
|
||||
tmpp.setCanBeSetByConstructor(recordAllPossibleValuesFiltered.contains(elem.name));
|
||||
this.nodes.add(tmpp);
|
||||
}
|
||||
}
|
||||
final String name = Tools.decapitalizeFirst(method.getName().substring(3));
|
||||
IntrospectionProperty prop = updateForMethod(name, method, ReflectTools.getTypeParameterfunction(method));
|
||||
// generate getter and setter with field.
|
||||
IntrospectionPropertyMethodSetter modifier = new IntrospectionPropertyMethodSetter(method);
|
||||
prop.setSetter(modifier);
|
||||
}
|
||||
}
|
||||
// Set only at the end ==> no need before...
|
||||
final Boolean isDefaultAttribute = ReflectTools.getIsDefaultAttribute(classType, IntrospectionModel.DEFAULT_ATTRIBUTE);
|
||||
for (IntrospectionProperty prop : this.elements) {
|
||||
if (prop.isAttribute() == null) {
|
||||
prop.setAttribute(isDefaultAttribute);
|
||||
}
|
||||
}
|
||||
final Boolean isDefaultManaged = ReflectTools.getIsDefaultManaged(classType, IntrospectionModel.DEFAULT_MANAGED);
|
||||
for (IntrospectionProperty prop : this.elements) {
|
||||
if (prop.isManaged() == null) {
|
||||
prop.setManaged(isDefaultManaged);
|
||||
}
|
||||
}
|
||||
final Boolean isDefaultOptional = ReflectTools.getIsDefaultOptional(classType, IntrospectionModel.DEFAULT_OPTIONAL);
|
||||
for (IntrospectionProperty prop : this.elements) {
|
||||
if (prop.isOptionnal() == null) {
|
||||
prop.setOptionnal(isDefaultOptional);
|
||||
}
|
||||
}
|
||||
final Boolean isDefaultCaseSensitive = ReflectTools.getIsDefaultCaseSensitive(classType, IntrospectionModel.DEFAULT_CASE_SENSITIVE);
|
||||
for (IntrospectionProperty prop : this.elements) {
|
||||
if (prop.isCaseSensitive() == null) {
|
||||
prop.setCaseSensitive(isDefaultCaseSensitive);
|
||||
}
|
||||
}
|
||||
// set default name in the list:
|
||||
for (IntrospectionProperty prop : this.elements) {
|
||||
if (prop.getNames() == null) {
|
||||
prop.setNames(new String[] {prop.getBeanName()});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
@ -511,20 +480,91 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
}
|
||||
|
||||
// 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>() {
|
||||
Collections.sort(this.elements, new Comparator<IntrospectionProperty>() {
|
||||
@Override
|
||||
public
|
||||
int compare(final IntrospectionProperty a, final IntrospectionProperty b) {
|
||||
return a.getNames()[0].compareTo(b.getNames()[0]);
|
||||
}
|
||||
});
|
||||
|
||||
for (IntrospectionProperty prop : this.elements) {
|
||||
Log.warning("Property/node : " + prop.getBeanName());
|
||||
Log.warning(" names: " + Arrays.toString(prop.getNames()));
|
||||
Log.warning(" list: " + prop.getListName());
|
||||
Log.warning(" managed: " + prop.isManaged());
|
||||
Log.warning(" attribute: " + prop.isAttribute());
|
||||
Log.warning(" case-sensitive: " + prop.isCaseSensitive());
|
||||
Log.warning(" optionnal: " + prop.isOptionnal());
|
||||
Log.warning(" constructor: " + prop.isCanBeSetByConstructor());
|
||||
Log.warning(" get/set: " + prop.canGetValue() + " / " + prop.canSetValue());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private IntrospectionProperty updateForMethod(String name, final Method method, Class<?>[] types) throws Exception {
|
||||
IntrospectionProperty prop = findElement(name);
|
||||
if (prop == null) {
|
||||
String[] names = ReflectTools.getNames(method, null);
|
||||
prop = new IntrospectionProperty(name, types, names);
|
||||
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 " + method.toGenericString());
|
||||
}
|
||||
String[] names = ReflectTools.getNames(method, null);
|
||||
if (names != 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!) " + method.toGenericString());
|
||||
}
|
||||
prop.setNames(names);
|
||||
}
|
||||
}
|
||||
final String listName = ReflectTools.getListName(method, null);
|
||||
if (listName != null) {
|
||||
String curentValue = prop.getListName();
|
||||
if (curentValue != null && curentValue != listName) {
|
||||
throw new ExmlBuilderException("Set 'listNAme' with a different value previous=" + curentValue + " ==> new=" + listName + " in " + method.toGenericString());
|
||||
}
|
||||
prop.setListName(listName);
|
||||
}
|
||||
final Boolean isAttribute = ReflectTools.getIsAttribute(method, null);
|
||||
if (isAttribute != null) {
|
||||
Boolean curentValue = prop.isAttribute();
|
||||
if (curentValue != null && curentValue != isAttribute) {
|
||||
throw new ExmlBuilderException("Set 'attribute' with a different value previous=" + curentValue + " ==> new=" + isAttribute + " in " + method.toGenericString());
|
||||
}
|
||||
prop.setAttribute(isAttribute);
|
||||
}
|
||||
final Boolean isManaged = ReflectTools.getIsManaged(method, null);
|
||||
if (isManaged != null) {
|
||||
Boolean curentValue = prop.isManaged();
|
||||
if (curentValue != null && curentValue != isManaged) {
|
||||
throw new ExmlBuilderException("Set 'managed' with a different value previous=" + curentValue + " ==> new=" + isManaged + " in " + method.toGenericString());
|
||||
}
|
||||
prop.setManaged(isManaged);
|
||||
}
|
||||
final Boolean isOptionnal = ReflectTools.getIsOptional(method, null);
|
||||
if (isOptionnal != null) {
|
||||
Boolean curentValue = prop.isOptionnal();
|
||||
if (curentValue != null && curentValue != isOptionnal) {
|
||||
throw new ExmlBuilderException("Set 'optionnal' with a different value previous=" + curentValue + " ==> new=" + isOptionnal + " in " + method.toGenericString());
|
||||
}
|
||||
prop.setOptionnal(isOptionnal);
|
||||
}
|
||||
final Boolean isCaseSensitive = ReflectTools.getIsCaseSensitive(method, null);
|
||||
if (isCaseSensitive != null) {
|
||||
Boolean curentValue = prop.isCaseSensitive();
|
||||
if (curentValue != null && curentValue != isCaseSensitive) {
|
||||
throw new ExmlBuilderException("Set 'case sensitive' with a different value previous=" + curentValue + " ==> new=" + isCaseSensitive + " in " + method.toGenericString());
|
||||
}
|
||||
prop.setCaseSensitive(isCaseSensitive);
|
||||
}
|
||||
return prop;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -628,16 +668,19 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
@Override
|
||||
public List<String> getNodeAvaillable() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (final IntrospectionProperty prop : this.nodes) {
|
||||
for (final IntrospectionProperty prop : this.elements) {
|
||||
if (prop.isAttribute()) {
|
||||
continue;
|
||||
}
|
||||
out.add(prop.getNames()[0]);
|
||||
}
|
||||
// for (final IntrospectionProperty prop : this.attributes) {
|
||||
// out.add(prop.getNames()[0]);
|
||||
// }
|
||||
return out;
|
||||
}
|
||||
protected IntrospectionProperty findNodeDescription(final String propertyName) throws ExmlBuilderException {
|
||||
for (final IntrospectionProperty prop : this.nodes) {
|
||||
for (final IntrospectionProperty prop : this.elements) {
|
||||
if (prop.isAttribute()) {
|
||||
continue;
|
||||
}
|
||||
if (prop.isCompatible(propertyName)) {
|
||||
return prop;
|
||||
}
|
||||
@ -646,7 +689,10 @@ public class IntrospectionModelComplex extends IntrospectionModel {
|
||||
}
|
||||
|
||||
protected IntrospectionProperty findPropertyDescription(final String propertyName) throws ExmlBuilderException {
|
||||
for (final IntrospectionProperty prop : this.attributes) {
|
||||
for (final IntrospectionProperty prop : this.elements) {
|
||||
if (!prop.isAttribute()) {
|
||||
continue;
|
||||
}
|
||||
if (prop.isCompatible(propertyName)) {
|
||||
return prop;
|
||||
}
|
||||
|
@ -70,18 +70,34 @@ public final class IntrospectionProperty {
|
||||
return this.canBeSetByConstructor || this.setter != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all names of the property/node (minimal 1 name)
|
||||
* @return Array of names available
|
||||
*/
|
||||
public String[] getNames() {
|
||||
return this.names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get basic type of the property
|
||||
* @return property type detected.
|
||||
*/
|
||||
public Class<?> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the property (if list ==> need to be get on method otherwise it is an Object...)
|
||||
* @return Type of the list element.
|
||||
*/
|
||||
public Class<?> getSubType() {
|
||||
return this.subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value in the object.
|
||||
* @param object Object that is invoke to get the value.
|
||||
* @return The generate value of the object
|
||||
* @throws ExmlBuilderException in an error occured
|
||||
*/
|
||||
public Object getValue(Object object) throws ExmlBuilderException {
|
||||
if (getter != null) {
|
||||
return this.getter.getValue(object);
|
||||
@ -89,6 +105,11 @@ public final class IntrospectionProperty {
|
||||
throw new ExmlBuilderException("Property: " + names + " have no getter");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the input name is compatible win an element in the list availlable (respect case sensitive if needed)
|
||||
* @param name Name to check
|
||||
* @return true if the element is compatible, false otherwise
|
||||
*/
|
||||
public boolean isCompatible(String name) {
|
||||
if (this.caseSensitive) {
|
||||
for (final String elem : this.names) {
|
||||
@ -115,9 +136,40 @@ public final class IntrospectionProperty {
|
||||
public void setExistingValue(Object object, Object value) throws ExmlBuilderException {
|
||||
if (setter != null) {
|
||||
this.setter.setValue(object, value);
|
||||
return;
|
||||
}
|
||||
throw new ExmlBuilderException("Property: " + names + " have no setter");
|
||||
}
|
||||
/**
|
||||
* Create a value adapted to the property type.
|
||||
* @apiNote generic type is transformed byte -> Byte, int -> Integer ...
|
||||
* @param value Value to set in the Object
|
||||
* @throws Exception An error occurred
|
||||
* @return The object created
|
||||
*/
|
||||
public Object createValue(final String value) throws ExmlBuilderException {
|
||||
try {
|
||||
if (StringSerializer.contains(this.type)) {
|
||||
// TODO This might be a deprecated code ....
|
||||
return StringSerializer.valueOf(this.type, value);
|
||||
}
|
||||
if (this.type.isEnum()) {
|
||||
|
||||
} else if ((this.type != List.class) || !StringSerializer.contains(this.subType)) {
|
||||
throw new ExmlBuilderException("Can not parse the specific element ... need to introspect and find the 'xxx valueOf(String data);'");
|
||||
}
|
||||
ArrayList<Object> out = new ArrayList<>();
|
||||
for (String elem : value.split(";")) {
|
||||
out.add(StringSerializer.valueOf(this.subType, elem));
|
||||
}
|
||||
return out;
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
throw new ExmlBuilderException("Error in parsing the property value ... " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean isCaseSensitive() {
|
||||
return caseSensitive;
|
||||
}
|
||||
@ -145,7 +197,7 @@ public final class IntrospectionProperty {
|
||||
public void setListName(String listName) {
|
||||
this.listName = listName;
|
||||
}
|
||||
public Boolean getManaged() {
|
||||
public Boolean isManaged() {
|
||||
return managed;
|
||||
}
|
||||
public void setManaged(Boolean managed) {
|
||||
|
@ -7,6 +7,7 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import org.atriasoft.exml.annotation.XmlAttribute;
|
||||
import org.atriasoft.exml.annotation.XmlCaseSensitive;
|
||||
@ -19,6 +20,7 @@ import org.atriasoft.exml.annotation.XmlManaged;
|
||||
import org.atriasoft.exml.annotation.XmlName;
|
||||
import org.atriasoft.exml.annotation.XmlOptional;
|
||||
import org.atriasoft.exml.exception.ExmlBuilderException;
|
||||
import org.atriasoft.exml.internal.Log;
|
||||
|
||||
public class ReflectTools {
|
||||
private ReflectTools() {}
|
||||
@ -41,6 +43,67 @@ public class ReflectTools {
|
||||
return new Class<?>[] {type, subType};
|
||||
}
|
||||
|
||||
|
||||
public static Class<?>[] getTypeReturnFunction(/*@NotNull*/ final Method getter) throws Exception {
|
||||
Class<?> type = null;
|
||||
Class<?> subType = null;
|
||||
type = getter.getReturnType();
|
||||
if (!Enum.class.isAssignableFrom(type)) {
|
||||
Type empppe = getter.getGenericReturnType();
|
||||
if (empppe instanceof ParameterizedType plopppppp) {
|
||||
Type[] realType = plopppppp.getActualTypeArguments();
|
||||
if (realType.length > 0) {
|
||||
subType = Class.forName(realType[0].getTypeName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Class<?>[] {type, subType};
|
||||
}
|
||||
|
||||
public static Class<?>[] getTypeParameterfunction(final Method setter) throws Exception {
|
||||
Class<?> type = null;
|
||||
Class<?> subType = null;
|
||||
|
||||
type = setter.getParameters()[0].getType();
|
||||
if (List.class.isAssignableFrom(type)) {
|
||||
Class<?> internalModelClass = null;
|
||||
Type[] empppe = setter.getGenericParameterTypes();
|
||||
if (empppe.length > 0) {
|
||||
if (empppe[0] instanceof ParameterizedType plopppppp) {
|
||||
Type[] realType = plopppppp.getActualTypeArguments();
|
||||
if (realType.length > 0) {
|
||||
Log.warning(" -->> " + realType[0]);
|
||||
internalModelClass = Class.forName(realType[0].getTypeName());
|
||||
}
|
||||
}
|
||||
}
|
||||
subType = internalModelClass;
|
||||
}
|
||||
return new Class<?>[] {type, subType};
|
||||
}
|
||||
|
||||
public static Class<?>[] getTypeParameterfunction(Constructor<?> elem, int paramId) throws ClassNotFoundException {
|
||||
Class<?> type = null;
|
||||
Class<?> subType = null;
|
||||
|
||||
type = elem.getParameters()[paramId].getType();
|
||||
if (List.class.isAssignableFrom(type)) {
|
||||
Class<?> internalModelClass = null;
|
||||
Type[] empppe = elem.getGenericParameterTypes();
|
||||
if (empppe.length > 0) {
|
||||
if (empppe[0] instanceof ParameterizedType plopppppp) {
|
||||
Type[] realType = plopppppp.getActualTypeArguments();
|
||||
if (realType.length > paramId) {
|
||||
Log.warning(" -->> " + realType[paramId]);
|
||||
internalModelClass = Class.forName(realType[paramId].getTypeName());
|
||||
}
|
||||
}
|
||||
}
|
||||
subType = internalModelClass;
|
||||
}
|
||||
return new Class<?>[] {type, subType};
|
||||
}
|
||||
|
||||
public static Boolean getIsCaseSensitive(final Field element, final Boolean defaultValue) throws ExmlBuilderException {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlCaseSensitive.class);
|
||||
if (annotation.length == 0) {
|
||||
@ -327,4 +390,5 @@ public class ReflectTools {
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user