[DEV] generalize aknot for xml and Json conplexity
This commit is contained in:
parent
d3d4c0818f
commit
b040811197
@ -9,8 +9,8 @@ import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log {
|
||||
private static final String LIB_NAME = "aknot";
|
||||
private static final boolean FORCE_ALL = false;
|
||||
private static final String LIB_NAME = "exml";
|
||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(Log.LIB_NAME);
|
||||
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL);
|
||||
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.DEBUG);
|
||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.atriasoft.aknot.exception.AknotException;
|
||||
import org.atriasoft.aknot.internal.Log;
|
||||
import org.atriasoft.aknot.pojo.IntrospectionProperty;
|
||||
|
||||
public abstract class IntrospectionModel {
|
||||
@ -27,7 +28,7 @@ public abstract class IntrospectionModel {
|
||||
this.names[0] = classType.getSimpleName();
|
||||
}
|
||||
|
||||
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes) throws AknotException {
|
||||
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes, final boolean attributeIndependent) throws AknotException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -68,7 +69,11 @@ public abstract class IntrospectionModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getTreeNameOfSubNode(final String nodeName) throws AknotException {
|
||||
public String getTokenBasicList() {
|
||||
return STUPID_TOCKEN;
|
||||
}
|
||||
|
||||
public String getTreeNameOfSubNode(final String nodeName, final boolean attributeIndependent) throws AknotException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -76,11 +81,11 @@ public abstract class IntrospectionModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class<?> getTypeOfSubNode(final String nodeName) throws AknotException {
|
||||
public Class<?> getTypeOfSubNode(final String nodeName, final boolean attributeIndependent) throws AknotException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class<?> getTypeOfSubNodeList(final String nodeName) throws AknotException {
|
||||
public Class<?> getTypeOfSubNodeList(final String nodeName, final boolean attributeIndependent) throws AknotException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -96,6 +101,106 @@ public abstract class IntrospectionModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This converter Number to the correct type ...
|
||||
*/
|
||||
public Object getValueConverted(final Object value, final Class<?> classTypeLocal) throws AknotException {
|
||||
// Note if the type is an Array<>() or a List<>() ==> we parse element by element ... then we need to keep the undertype...
|
||||
Log.debug("======>>>>>>> convert : {} ==> {} ", value.getClass().getCanonicalName(), classTypeLocal.getCanonicalName());
|
||||
if (value.getClass() == Long.class) {
|
||||
if (classTypeLocal == long.class || classTypeLocal == Long.class) {
|
||||
return value;
|
||||
}
|
||||
final Long value2 = (Long) value;
|
||||
if (classTypeLocal == byte.class || classTypeLocal == Byte.class) {
|
||||
return value2.byteValue();
|
||||
}
|
||||
if (classTypeLocal == short.class || classTypeLocal == Short.class) {
|
||||
return value2.shortValue();
|
||||
}
|
||||
if (classTypeLocal == float.class || classTypeLocal == Float.class) {
|
||||
return value2.floatValue();
|
||||
}
|
||||
if (classTypeLocal == double.class || classTypeLocal == Double.class) {
|
||||
return value2.doubleValue();
|
||||
}
|
||||
if (classTypeLocal == Integer.class || classTypeLocal == int.class) {
|
||||
return value2.intValue();
|
||||
}
|
||||
if (classTypeLocal == boolean.class || classTypeLocal == Boolean.class) {
|
||||
return value2.equals(0);
|
||||
}
|
||||
}
|
||||
if (value.getClass() == Double.class) {
|
||||
if (classTypeLocal == double.class || classTypeLocal == Double.class) {
|
||||
return value;
|
||||
}
|
||||
final Double value2 = (Double) value;
|
||||
if (classTypeLocal == byte.class || classTypeLocal == Byte.class) {
|
||||
return value2.byteValue();
|
||||
}
|
||||
if (classTypeLocal == short.class || classTypeLocal == Short.class) {
|
||||
return value2.shortValue();
|
||||
}
|
||||
if (classTypeLocal == float.class || classTypeLocal == Float.class) {
|
||||
return value2.floatValue();
|
||||
}
|
||||
if (classTypeLocal == long.class || classTypeLocal == Long.class) {
|
||||
return value2.longValue();
|
||||
}
|
||||
if (classTypeLocal == Integer.class || classTypeLocal == int.class) {
|
||||
return value2.intValue();
|
||||
}
|
||||
if (classTypeLocal == boolean.class || classTypeLocal == Boolean.class) {
|
||||
return !value2.equals(0);
|
||||
}
|
||||
}
|
||||
if (value.getClass() == Boolean.class) {
|
||||
if (classTypeLocal == boolean.class || classTypeLocal == Boolean.class) {
|
||||
return value;
|
||||
}
|
||||
final Boolean value2 = (Boolean) value;
|
||||
if (classTypeLocal == byte.class || classTypeLocal == Byte.class) {
|
||||
if (value2)
|
||||
return (byte) 1;
|
||||
else
|
||||
return (byte) 0;
|
||||
}
|
||||
if (classTypeLocal == short.class || classTypeLocal == Short.class) {
|
||||
if (value2)
|
||||
return (short) 1;
|
||||
else
|
||||
return (short) 0;
|
||||
}
|
||||
if (classTypeLocal == float.class || classTypeLocal == Float.class) {
|
||||
if (value2)
|
||||
return (float) 1;
|
||||
else
|
||||
return (float) 0;
|
||||
}
|
||||
if (classTypeLocal == long.class || classTypeLocal == Long.class) {
|
||||
if (value2)
|
||||
return (long) 1;
|
||||
else
|
||||
return (long) 0;
|
||||
}
|
||||
if (classTypeLocal == int.class || classTypeLocal == Integer.class) {
|
||||
if (value2)
|
||||
return (int) 1;
|
||||
else
|
||||
return (int) 0;
|
||||
}
|
||||
if (classTypeLocal == double.class || classTypeLocal == Double.class) {
|
||||
if (value2)
|
||||
return (double) 1;
|
||||
else
|
||||
return (double) 0;
|
||||
}
|
||||
}
|
||||
Log.error("======>>>>>>> convert : {} ==> {} Can not do it !!!", value.getClass().getCanonicalName(), classTypeLocal.getCanonicalName());
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getValueFromText(final String text) throws AknotException {
|
||||
return null;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class IntrospectionModelArray extends IntrospectionModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes) throws AknotException {
|
||||
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes, final boolean attributeIndependent) throws AknotException {
|
||||
List<Object> tmp = null;
|
||||
if (this.nodeName == null) {
|
||||
tmp = nodes.get(STUPID_TOCKEN);
|
||||
|
@ -14,7 +14,7 @@ public class IntrospectionModelBaseType extends IntrospectionModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes) throws AknotException {
|
||||
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes, final boolean attributeIndependent) throws AknotException {
|
||||
throw new AknotException("Base type model can not have properties and nodes ... ");
|
||||
}
|
||||
|
||||
|
1156
src/org/atriasoft/aknot/pojo/IntrospectionModelComplex.java
Normal file
1156
src/org/atriasoft/aknot/pojo/IntrospectionModelComplex.java
Normal file
File diff suppressed because it is too large
Load Diff
29
src/org/atriasoft/aknot/pojo/IntrospectionModelFactory.java
Normal file
29
src/org/atriasoft/aknot/pojo/IntrospectionModelFactory.java
Normal file
@ -0,0 +1,29 @@
|
||||
package org.atriasoft.aknot.pojo;
|
||||
|
||||
import org.atriasoft.aknot.StringSerializer;
|
||||
import org.atriasoft.aknot.exception.AknotException;
|
||||
import org.atriasoft.aknot.model.IntrospectionModel;
|
||||
import org.atriasoft.aknot.model.MapKey;
|
||||
|
||||
public class IntrospectionModelFactory {
|
||||
public static IntrospectionModel createModel(final MapKey modelType) throws AknotException {
|
||||
if (StringSerializer.contains(modelType.type())) {
|
||||
return new IntrospectionModelBaseType(modelType.type());
|
||||
}
|
||||
return new IntrospectionModelComplex(modelType.type());
|
||||
}
|
||||
|
||||
public static IntrospectionModel createModelArray(final String nodeName, final MapKey modelType) throws AknotException {
|
||||
return new IntrospectionModelArray(nodeName, modelType.type());
|
||||
}
|
||||
|
||||
public static IntrospectionModel createModelEnum(final MapKey modelType) throws AknotException {
|
||||
return new IntrospectionModelComplex(modelType.type());
|
||||
}
|
||||
|
||||
public static IntrospectionModel createModelList(final String nodeName, final MapKey modelType) throws AknotException {
|
||||
return new IntrospectionModelList(nodeName, modelType.type());
|
||||
}
|
||||
|
||||
private IntrospectionModelFactory() {}
|
||||
}
|
@ -17,11 +17,8 @@ public class IntrospectionModelList extends IntrospectionModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes) throws AknotException {
|
||||
if (this.nodeName == null) {
|
||||
return nodes.get(STUPID_TOCKEN);
|
||||
}
|
||||
return nodes.get(this.nodeName);
|
||||
public Object createObject(final Map<String, Object> properties, final Map<String, List<Object>> nodes, final boolean attributeIndependent) throws AknotException {
|
||||
return nodes.get(this.getTokenBasicList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -32,6 +29,14 @@ public class IntrospectionModelList extends IntrospectionModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTokenBasicList() {
|
||||
if (this.nodeName == null) {
|
||||
return STUPID_TOCKEN;
|
||||
}
|
||||
return this.nodeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(final String propertyName, final String propertyValue) throws AknotException {
|
||||
return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user