[DEV] update log model
This commit is contained in:
parent
6ced097f47
commit
f0738ed05c
@ -10,14 +10,18 @@ public class ActionList {
|
|||||||
private final Map<String, Class<?>> subActions = new HashMap<>();
|
private final Map<String, Class<?>> subActions = new HashMap<>();
|
||||||
|
|
||||||
public void add(final Class<?> clazz) {
|
public void add(final Class<?> clazz) {
|
||||||
String name = PropertiesInterface.getCommand(clazz);
|
final String name = PropertiesInterface.getCommand(clazz);
|
||||||
if (name == null || name.isEmpty()) {
|
if (name == null || name.isEmpty()) {
|
||||||
Log.error("Can not add an action without name. for: " + clazz.getCanonicalName());
|
Log.error("Can not add an action without name. for: {}", clazz.getCanonicalName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.subActions.put(name, clazz);
|
this.subActions.put(name, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean exist(final String value) {
|
||||||
|
return this.subActions.get(value) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public Set<String> getActions() {
|
public Set<String> getActions() {
|
||||||
return this.subActions.keySet();
|
return this.subActions.keySet();
|
||||||
}
|
}
|
||||||
@ -26,8 +30,4 @@ public class ActionList {
|
|||||||
return this.subActions.get(action);
|
return this.subActions.get(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean exist(final String value) {
|
|
||||||
return this.subActions.get(value) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,75 +38,75 @@ public class ArgumentManager {
|
|||||||
private void configure(final Object tmp) {
|
private void configure(final Object tmp) {
|
||||||
boolean endParsing = false;
|
boolean endParsing = false;
|
||||||
for (int iii = 0; iii < this.arguments.size(); iii++) {
|
for (int iii = 0; iii < this.arguments.size(); iii++) {
|
||||||
String value = this.arguments.get(iii);
|
final String value = this.arguments.get(iii);
|
||||||
if (endParsing) {
|
if (endParsing) {
|
||||||
this.argumentResidual.add(value);
|
this.argumentResidual.add(value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (value.startsWith("--")) {
|
if (value.startsWith("--")) {
|
||||||
String[] elements = value.split("=");
|
final String[] elements = value.split("=");
|
||||||
elements[0] = elements[0].substring(2);
|
elements[0] = elements[0].substring(2);
|
||||||
Log.verbose("find element (--) : " + Arrays.toString(elements));
|
Log.verbose("find element (--) : {}", Arrays.toString(elements));
|
||||||
String parameter = elements[0];
|
final String parameter = elements[0];
|
||||||
String newValue = null;
|
String newValue = null;
|
||||||
if (!this.properties.existParameter(parameter)) {
|
if (!this.properties.existParameter(parameter)) {
|
||||||
Log.critical("Parameter Does not exist for '" + value + "'");
|
Log.critical("Parameter Does not exist for '{}'", value);
|
||||||
}
|
}
|
||||||
if (!this.properties.haveParameter(parameter)) {
|
if (!this.properties.haveParameter(parameter)) {
|
||||||
// Boolean value
|
// Boolean value
|
||||||
if (elements.length != 1) {
|
if (elements.length != 1) {
|
||||||
Log.critical("Boolean parameter can not have parameters for '" + value + "'");
|
Log.critical("Boolean parameter can not have parameters for '{}", value);
|
||||||
}
|
}
|
||||||
} else if (elements.length == 1) {
|
} else if (elements.length == 1) {
|
||||||
if (iii == this.arguments.size() - 1) {
|
if (iii == this.arguments.size() - 1) {
|
||||||
Log.critical("Missing parameters for '" + value + "' (no more arguments)");
|
Log.critical("Missing parameters for '{}' (no more arguments)", value);
|
||||||
}
|
}
|
||||||
newValue = this.arguments.get(iii + 1);
|
newValue = this.arguments.get(iii + 1);
|
||||||
if (newValue.startsWith("-")) {
|
if (newValue.startsWith("-")) {
|
||||||
Log.critical("Missing parameters for '" + value + "' (next argument is a parameter (start with '-'))");
|
Log.critical("Missing parameters for '{}' (next argument is a parameter (start with '-'))", value);
|
||||||
}
|
}
|
||||||
iii++;
|
iii++;
|
||||||
} else if (elements.length == 2) {
|
} else if (elements.length == 2) {
|
||||||
newValue = elements[1];
|
newValue = elements[1];
|
||||||
} else {
|
} else {
|
||||||
Log.critical("too much parameters for '" + value + "' (only 1 = is authorized)");
|
Log.critical("too much parameters for '{}' (only 1 = is authorized)", value);
|
||||||
}
|
}
|
||||||
this.properties.setParameter(tmp, parameter, newValue);
|
this.properties.setParameter(tmp, parameter, newValue);
|
||||||
} else if (value.startsWith("-")) {
|
} else if (value.startsWith("-")) {
|
||||||
String[] elements = value.split("=");
|
final String[] elements = value.split("=");
|
||||||
elements[0] = elements[0].substring(1);
|
elements[0] = elements[0].substring(1);
|
||||||
Log.warning("find element (-) : " + Arrays.toString(elements));
|
Log.warning("find element (-) : {}", Arrays.toString(elements));
|
||||||
if (elements[0].length() != 1) {
|
if (elements[0].length() != 1) {
|
||||||
Log.critical("Can not parse alias argument with a size != 1 for '" + value + "'");
|
Log.critical("Can not parse alias argument with a size != 1 for '{}'", value);
|
||||||
}
|
}
|
||||||
char parameter = elements[0].charAt(0);
|
final char parameter = elements[0].charAt(0);
|
||||||
String newValue = null;
|
String newValue = null;
|
||||||
if (!this.properties.existParameterAlias(parameter)) {
|
if (!this.properties.existParameterAlias(parameter)) {
|
||||||
Log.critical("Parameter Does not exist for '" + value + "'");
|
Log.critical("Parameter Does not exist for '{}'", value);
|
||||||
}
|
}
|
||||||
if (!this.properties.haveParameterAlias(parameter)) {
|
if (!this.properties.haveParameterAlias(parameter)) {
|
||||||
// Boolean value
|
// Boolean value
|
||||||
if (elements.length != 1) {
|
if (elements.length != 1) {
|
||||||
Log.critical("Boolean parameter can not have parameters for '" + value + "'");
|
Log.critical("Boolean parameter can not have parameters for '{}'", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (elements.length == 1) {
|
} else if (elements.length == 1) {
|
||||||
if (iii == this.arguments.size() - 1) {
|
if (iii == this.arguments.size() - 1) {
|
||||||
Log.critical("Missing parameters for '" + value + "' (no more arguments)");
|
Log.critical("Missing parameters for '{}' (no more arguments)", value);
|
||||||
}
|
}
|
||||||
newValue = this.arguments.get(iii + 1);
|
newValue = this.arguments.get(iii + 1);
|
||||||
if (newValue.startsWith("-")) {
|
if (newValue.startsWith("-")) {
|
||||||
Log.critical("Missing parameters for '" + value + "' (next argument is a parameter (start with '-'))");
|
Log.critical("Missing parameters for '{}' (next argument is a parameter (start with '-'))", value);
|
||||||
}
|
}
|
||||||
iii++;
|
iii++;
|
||||||
} else if (elements.length == 2) {
|
} else if (elements.length == 2) {
|
||||||
newValue = elements[1];
|
newValue = elements[1];
|
||||||
} else {
|
} else {
|
||||||
Log.critical("too much parameters for '" + value + "' (only 1 = is authorized)");
|
Log.critical("too much parameters for '{}' (only 1 = is authorized)", value);
|
||||||
}
|
}
|
||||||
this.properties.setParameterAlias(tmp, parameter, newValue);
|
this.properties.setParameterAlias(tmp, parameter, newValue);
|
||||||
} else {
|
} else {
|
||||||
Log.verbose("find element ( ) : " + value);
|
Log.verbose("find element ( ) : {}", value);
|
||||||
if (this.properties.actions != null && this.properties.actions.exist(value)) {
|
if (this.properties.actions != null && this.properties.actions.exist(value)) {
|
||||||
// Find end of parsing ...
|
// Find end of parsing ...
|
||||||
endParsing = true;
|
endParsing = true;
|
||||||
@ -123,7 +123,7 @@ public class ArgumentManager {
|
|||||||
if (this.actionDetected == null) {
|
if (this.actionDetected == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Class<?> actionClass = this.properties.getAction(this.actionDetected);
|
final Class<?> actionClass = this.properties.getAction(this.actionDetected);
|
||||||
if (actionClass == null) {
|
if (actionClass == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -135,17 +135,17 @@ public class ArgumentManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArgumentManager localManager = new ArgumentManager(this.argumentResidual.toArray(new String[0]), obj);
|
final ArgumentManager localManager = new ArgumentManager(this.argumentResidual.toArray(new String[0]), obj);
|
||||||
|
|
||||||
//localManager.showHelp();
|
//localManager.showHelp();
|
||||||
int nbParameters = localManager.argumentPostConfigure.size();
|
final int nbParameters = localManager.argumentPostConfigure.size();
|
||||||
List<Method> executor = localManager.properties.getExecutor();
|
final List<Method> executor = localManager.properties.getExecutor();
|
||||||
for (Method exec : executor) {
|
for (final Method exec : executor) {
|
||||||
if (nbParameters != exec.getParameterCount()) {
|
if (nbParameters != exec.getParameterCount()) {
|
||||||
Log.warning("Rejected executor, " + exec.getName() + " nbParameter=" + exec.getParameterCount() + " require=" + nbParameters);
|
Log.warning("Rejected executor, {} nbParameter={} require={}", exec.getName(), exec.getParameterCount(), nbParameters);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log.verbose("find executor, " + exec.getName());
|
Log.verbose("find executor, {}", exec.getName());
|
||||||
try {
|
try {
|
||||||
switch (nbParameters) {
|
switch (nbParameters) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -9,11 +9,16 @@ import org.atriasoft.death.internal.Log;
|
|||||||
|
|
||||||
public class FieldProperty {
|
public class FieldProperty {
|
||||||
|
|
||||||
|
public record ChoiceElement(
|
||||||
|
String origin,
|
||||||
|
String destination) {}
|
||||||
|
|
||||||
public Field field;
|
public Field field;
|
||||||
public String name;
|
public String name;
|
||||||
public Character alias;
|
public Character alias;
|
||||||
public String description;
|
public String description;
|
||||||
public String[] choice;
|
public String[] choice;
|
||||||
|
|
||||||
public Class<?>[] types;
|
public Class<?>[] types;
|
||||||
|
|
||||||
public FieldProperty(final Field elem) {
|
public FieldProperty(final Field elem) {
|
||||||
@ -27,12 +32,12 @@ public class FieldProperty {
|
|||||||
this.field = null;
|
this.field = null;
|
||||||
}
|
}
|
||||||
this.field = elem;
|
this.field = elem;
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
this.name = null;
|
this.name = null;
|
||||||
this.alias = null;
|
this.alias = null;
|
||||||
this.description = null;
|
this.description = null;
|
||||||
this.choice = null;
|
this.choice = null;
|
||||||
Class<?>[] types = null;
|
final Class<?>[] types = null;
|
||||||
if (this.name == null && this.alias == null) {
|
if (this.name == null && this.alias == null) {
|
||||||
this.field = null;
|
this.field = null;
|
||||||
}
|
}
|
||||||
@ -40,48 +45,13 @@ public class FieldProperty {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public boolean isValid() {
|
|
||||||
return this.field != null;
|
|
||||||
}
|
|
||||||
public void print() {
|
|
||||||
if (this.name != null) {
|
|
||||||
Log.print("Detect element: --" + this.name);
|
|
||||||
}
|
|
||||||
if (this.alias != null) {
|
|
||||||
Log.print(" alias: -" + this.alias);
|
|
||||||
}
|
|
||||||
if (this.types[1] == null) {
|
|
||||||
Log.print(" type: " + this.types[0].getCanonicalName());
|
|
||||||
} else {
|
|
||||||
Log.print(" type: " + this.types[0].getCanonicalName() + " / " + this.types[1].getCanonicalName());
|
|
||||||
}
|
|
||||||
Log.print(" description: " + this.description);
|
|
||||||
if (this.choice != null) {
|
|
||||||
Log.print(" choice: " + Arrays.toString(this.choice));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public record ChoiceElement(String origin, String destination) {}
|
|
||||||
|
|
||||||
List<ChoiceElement> getChoiceList() {
|
|
||||||
List<ChoiceElement> out = new ArrayList<>();
|
|
||||||
for (String value : this.choice) {
|
|
||||||
String[] split = value.split(">>");
|
|
||||||
if (split.length == 1) {
|
|
||||||
out.add(new ChoiceElement(split[0], null));
|
|
||||||
} else {
|
|
||||||
out.add(new ChoiceElement(split[0], split[1]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String convertChoice(final String newValue) {
|
public String convertChoice(final String newValue) {
|
||||||
if (this.choice == null) {
|
if (this.choice == null) {
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
List<ChoiceElement> available = getChoiceList();
|
final List<ChoiceElement> available = getChoiceList();
|
||||||
for (ChoiceElement elem : available) {
|
for (final ChoiceElement elem : available) {
|
||||||
if (elem.destination == null) {
|
if (elem.destination == null) {
|
||||||
if (elem.origin.contentEquals(newValue)) {
|
if (elem.origin.contentEquals(newValue)) {
|
||||||
return newValue;
|
return newValue;
|
||||||
@ -96,7 +66,7 @@ public class FieldProperty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String list = null;
|
String list = null;
|
||||||
for (ChoiceElement elem : available) {
|
for (final ChoiceElement elem : available) {
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = "[";
|
list = "[";
|
||||||
} else {
|
} else {
|
||||||
@ -105,7 +75,42 @@ public class FieldProperty {
|
|||||||
list += elem;
|
list += elem;
|
||||||
}
|
}
|
||||||
list += "]";
|
list += "]";
|
||||||
Log.critical("Can not find property '" + newValue + "'in the choice values : " + list);
|
Log.critical("Can not find property '{}'in the choice values : {}", newValue, list);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ChoiceElement> getChoiceList() {
|
||||||
|
final List<ChoiceElement> out = new ArrayList<>();
|
||||||
|
for (final String value : this.choice) {
|
||||||
|
final String[] split = value.split(">>");
|
||||||
|
if (split.length == 1) {
|
||||||
|
out.add(new ChoiceElement(split[0], null));
|
||||||
|
} else {
|
||||||
|
out.add(new ChoiceElement(split[0], split[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
return this.field != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void print() {
|
||||||
|
if (this.name != null) {
|
||||||
|
Log.print("Detect element: --{}", this.name);
|
||||||
|
}
|
||||||
|
if (this.alias != null) {
|
||||||
|
Log.print(" alias: -{}", this.alias);
|
||||||
|
}
|
||||||
|
if (this.types[1] == null) {
|
||||||
|
Log.print(" type: {}", this.types[0].getCanonicalName());
|
||||||
|
} else {
|
||||||
|
Log.print(" type: {} / {}", this.types[0].getCanonicalName(), this.types[1].getCanonicalName());
|
||||||
|
}
|
||||||
|
Log.print(" description: {}", this.description);
|
||||||
|
if (this.choice != null) {
|
||||||
|
Log.print(" choice: {}", Arrays.toString(this.choice));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,45 +11,34 @@ import org.atriasoft.death.FieldProperty.ChoiceElement;
|
|||||||
import org.atriasoft.death.internal.Log;
|
import org.atriasoft.death.internal.Log;
|
||||||
|
|
||||||
public class PropertiesInterface {
|
public class PropertiesInterface {
|
||||||
final List<FieldProperty> properties = new ArrayList<>();
|
|
||||||
ActionList actions = null;
|
|
||||||
final String classDescription;
|
|
||||||
final String classCommand;
|
|
||||||
final List<Method> executes = new ArrayList<>();
|
|
||||||
|
|
||||||
public List<Method> getExecutor() {
|
|
||||||
return this.executes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<?> getAction(final String action) {
|
|
||||||
if (this.actions == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return this.actions.getInterface(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FieldProperty> parseFields() {
|
|
||||||
return this.properties;
|
|
||||||
}
|
|
||||||
public static String getCommand(final Class<?> clazz) {
|
public static String getCommand(final Class<?> clazz) {
|
||||||
try {
|
try {
|
||||||
return ReflectTools.getCommand(clazz);
|
return ReflectTools.getCommand(clazz);
|
||||||
} catch (Exception ex) {
|
} catch (final Exception ex) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDescription(final Class<?> clazz) {
|
public static String getDescription(final Class<?> clazz) {
|
||||||
try {
|
try {
|
||||||
return ReflectTools.getDescription(clazz);
|
return ReflectTools.getDescription(clazz);
|
||||||
} catch (Exception ex) {
|
} catch (final Exception ex) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final List<FieldProperty> properties = new ArrayList<>();
|
||||||
|
ActionList actions = null;
|
||||||
|
final String classDescription;
|
||||||
|
|
||||||
|
final String classCommand;
|
||||||
|
|
||||||
|
final List<Method> executes = new ArrayList<>();
|
||||||
|
|
||||||
public PropertiesInterface(final Class<?> clazz) {
|
public PropertiesInterface(final Class<?> clazz) {
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// -- Find class description
|
// -- Find class description
|
||||||
@ -60,25 +49,25 @@ public class PropertiesInterface {
|
|||||||
// -- Find property Field
|
// -- Find property Field
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
final Field[] fields = clazz.getFields();
|
final Field[] fields = clazz.getFields();
|
||||||
Log.verbose(" Fields: (" + fields.length + ")");
|
Log.verbose(" Fields: ({})", fields.length);
|
||||||
for (final Field elem : fields) {
|
for (final Field elem : fields) {
|
||||||
// we does not manage static field
|
// we does not manage static field
|
||||||
if (Modifier.isStatic(elem.getModifiers())) {
|
if (Modifier.isStatic(elem.getModifiers())) {
|
||||||
try {
|
try {
|
||||||
boolean subAction = ReflectTools.isSubAction(elem);
|
final boolean subAction = ReflectTools.isSubAction(elem);
|
||||||
if (!subAction) {
|
if (!subAction) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Class<?>[] type = ReflectTools.getTypeField(elem);
|
final Class<?>[] type = ReflectTools.getTypeField(elem);
|
||||||
if (type[0] == ActionList.class) {
|
if (type[0] == ActionList.class) {
|
||||||
Object data = elem.get(null);
|
final Object data = elem.get(null);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
Log.error("set a @ArgSubActions on a wrong field");
|
Log.error("set a @ArgSubActions on a wrong field");
|
||||||
} else if (data instanceof ActionList tmp) {
|
} else if (data instanceof final ActionList tmp) {
|
||||||
this.actions = tmp;
|
this.actions = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
Log.error("get error on @ArgSubActions !!!");
|
Log.error("get error on @ArgSubActions !!!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -93,19 +82,9 @@ public class PropertiesInterface {
|
|||||||
if (!element.isValid()) {
|
if (!element.isValid()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (element.types[0] == boolean.class
|
if (element.types[0] == boolean.class || element.types[0] == Boolean.class || element.types[0] == int.class || element.types[0] == Integer.class || element.types[0] == short.class
|
||||||
|| element.types[0] == Boolean.class
|
|| element.types[0] == Short.class || element.types[0] == long.class || element.types[0] == Long.class || element.types[0] == float.class || element.types[0] == Float.class
|
||||||
|| element.types[0] == int.class
|
|| element.types[0] == double.class || element.types[0] == Double.class || element.types[0] == String.class) {
|
||||||
|| element.types[0] == Integer.class
|
|
||||||
|| element.types[0] == short.class
|
|
||||||
|| element.types[0] == Short.class
|
|
||||||
|| element.types[0] == long.class
|
|
||||||
|| element.types[0] == Long.class
|
|
||||||
|| element.types[0] == float.class
|
|
||||||
|| element.types[0] == Float.class
|
|
||||||
|| element.types[0] == double.class
|
|
||||||
|| element.types[0] == Double.class
|
|
||||||
|| element.types[0] == String.class) {
|
|
||||||
// all is good
|
// all is good
|
||||||
} else {
|
} else {
|
||||||
Log.error("Can not manage other type than: [boolean,Boolean,String,int,Integer,long,Long,short,Short,float,Float,double,Double]");
|
Log.error("Can not manage other type than: [boolean,Boolean,String,int,Integer,long,Long,short,Short,float,Float,double,Double]");
|
||||||
@ -118,7 +97,7 @@ public class PropertiesInterface {
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
final Method[] methods = clazz.getMethods();
|
final Method[] methods = clazz.getMethods();
|
||||||
for (final Method elem : methods) {
|
for (final Method elem : methods) {
|
||||||
Log.verbose("Detect function : " + elem.getName());
|
Log.verbose("Detect function : {}", elem.getName());
|
||||||
// we does not manage static field
|
// we does not manage static field
|
||||||
if (Modifier.isStatic(elem.getModifiers())) {
|
if (Modifier.isStatic(elem.getModifiers())) {
|
||||||
continue;
|
continue;
|
||||||
@ -132,28 +111,106 @@ public class PropertiesInterface {
|
|||||||
if (ReflectTools.isExecutable(elem)) {
|
if (ReflectTools.isExecutable(elem)) {
|
||||||
this.executes.add(elem);
|
this.executes.add(elem);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void displayHelp() {
|
||||||
|
Log.print("Usage:");
|
||||||
|
final StringBuilder applicationLine = new StringBuilder(" ");
|
||||||
|
if (this.classCommand != null) {
|
||||||
|
applicationLine.append(this.classCommand).append(" ");
|
||||||
|
} else {
|
||||||
|
applicationLine.append("XXX ");
|
||||||
|
}
|
||||||
|
if (this.properties.size() != 0) {
|
||||||
|
applicationLine.append("[options] ");
|
||||||
|
}
|
||||||
|
if (this.actions != null && this.actions.getActions().size() != 0) {
|
||||||
|
applicationLine.append("[actions] ...");
|
||||||
|
}
|
||||||
|
Log.print(applicationLine.toString());
|
||||||
|
if (this.classDescription != null) {
|
||||||
|
Log.print("{}", this.classDescription);
|
||||||
|
}
|
||||||
|
if (this.properties.size() != 0) {
|
||||||
|
Log.print(" [options]");
|
||||||
|
for (final FieldProperty prop : this.properties) {
|
||||||
|
final String parameterExpect = haveParameter(prop) ? " [PARAMETER]" : "";
|
||||||
|
if (prop.alias != null && prop.name != null) {
|
||||||
|
Log.print(" -{} / --{}{}", prop.alias, prop.name, parameterExpect);
|
||||||
|
} else if (prop.alias != null) {
|
||||||
|
Log.print(" -{}{}", prop.alias, parameterExpect);
|
||||||
|
} else if (prop.name != null) {
|
||||||
|
Log.print(" --{}{}", prop.name, parameterExpect);
|
||||||
|
}
|
||||||
|
if (prop.description != null) {
|
||||||
|
Log.print(" {}", prop.description);
|
||||||
|
}
|
||||||
|
if (prop.choice != null) {
|
||||||
|
for (final ChoiceElement elem : prop.getChoiceList()) {
|
||||||
|
if (elem.destination() == null) {
|
||||||
|
Log.print(" - {}", elem.origin());
|
||||||
|
} else {
|
||||||
|
Log.print(" - {} ==> {}", elem.origin(), elem.destination());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.actions != null && this.actions.getActions().size() != 0) {
|
||||||
|
Log.print(" [actions]");
|
||||||
|
final Set<String> actions = this.actions.getActions();
|
||||||
|
for (final String action : actions) {
|
||||||
|
final Class<?> clazz = this.actions.getInterface(action);
|
||||||
|
final String description = PropertiesInterface.getDescription(clazz);
|
||||||
|
if (description == null || description.isEmpty()) {
|
||||||
|
Log.print(" {}", action);
|
||||||
|
} else {
|
||||||
|
Log.print(" {}: {}", action, description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean existParameter(final String parameterName) {
|
||||||
|
return findField(parameterName) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean existParameterAlias(final char parameterName) {
|
||||||
|
return findFieldAlias(parameterName) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldProperty findField(final String parameterName) {
|
||||||
|
for (final FieldProperty elem : this.properties) {
|
||||||
|
if (elem.name != null && elem.name.contentEquals(parameterName)) {
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public FieldProperty findFieldAlias(final char parameterName) {
|
public FieldProperty findFieldAlias(final char parameterName) {
|
||||||
for (FieldProperty elem : this.properties) {
|
for (final FieldProperty elem : this.properties) {
|
||||||
if (elem.alias != null && elem.alias == parameterName) {
|
if (elem.alias != null && elem.alias == parameterName) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public FieldProperty findField(final String parameterName) {
|
|
||||||
for (FieldProperty elem : this.properties) {
|
public Class<?> getAction(final String action) {
|
||||||
if (elem.name != null && elem.name.contentEquals(parameterName)) {
|
if (this.actions == null) {
|
||||||
return elem;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return this.actions.getInterface(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Method> getExecutor() {
|
||||||
|
return this.executes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean haveParameter(final FieldProperty field) {
|
public boolean haveParameter(final FieldProperty field) {
|
||||||
@ -162,43 +219,43 @@ public class PropertiesInterface {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean haveParameter(final String parameterName) {
|
public boolean haveParameter(final String parameterName) {
|
||||||
FieldProperty field = findField(parameterName);
|
final FieldProperty field = findField(parameterName);
|
||||||
return haveParameter(field);
|
return haveParameter(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean haveParameterAlias(final char parameterName) {
|
public boolean haveParameterAlias(final char parameterName) {
|
||||||
FieldProperty field = findFieldAlias(parameterName);
|
final FieldProperty field = findFieldAlias(parameterName);
|
||||||
return haveParameter(field);
|
return haveParameter(field);
|
||||||
}
|
}
|
||||||
public boolean existParameter(final String parameterName) {
|
|
||||||
return findField(parameterName) != null;
|
public List<FieldProperty> parseFields() {
|
||||||
}
|
return this.properties;
|
||||||
public boolean existParameterAlias(final char parameterName) {
|
|
||||||
return findFieldAlias(parameterName) != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParameter(final Object tmp, final String parameter, String newValue) {
|
public void setParameter(final Object tmp, final String parameter, String newValue) {
|
||||||
try {
|
try {
|
||||||
FieldProperty property = findField(parameter);
|
final FieldProperty property = findField(parameter);
|
||||||
newValue = property.convertChoice(newValue);
|
newValue = property.convertChoice(newValue);
|
||||||
if (property.types[0] == boolean.class || property.types[0] == Boolean.class) {
|
if (property.types[0] == boolean.class || property.types[0] == Boolean.class) {
|
||||||
//Boolean value = Boolean.valueOf(newValue);
|
//Boolean value = Boolean.valueOf(newValue);
|
||||||
//property.field.setBoolean(tmp, value);
|
//property.field.setBoolean(tmp, value);
|
||||||
property.field.setBoolean(tmp, true);
|
property.field.setBoolean(tmp, true);
|
||||||
} else if (property.types[0] == int.class || property.types[0] == Integer.class) {
|
} else if (property.types[0] == int.class || property.types[0] == Integer.class) {
|
||||||
Integer value = Integer.valueOf(newValue);
|
final Integer value = Integer.valueOf(newValue);
|
||||||
property.field.setInt(tmp, value);
|
property.field.setInt(tmp, value);
|
||||||
} else if (property.types[0] == short.class || property.types[0] == Short.class) {
|
} else if (property.types[0] == short.class || property.types[0] == Short.class) {
|
||||||
Short value = Short.valueOf(newValue);
|
final Short value = Short.valueOf(newValue);
|
||||||
property.field.setShort(tmp, value);
|
property.field.setShort(tmp, value);
|
||||||
} else if (property.types[0] == long.class || property.types[0] == Long.class) {
|
} else if (property.types[0] == long.class || property.types[0] == Long.class) {
|
||||||
Long value = Long.valueOf(newValue);
|
final Long value = Long.valueOf(newValue);
|
||||||
property.field.setLong(tmp, value);
|
property.field.setLong(tmp, value);
|
||||||
} else if (property.types[0] == float.class || property.types[0] == Float.class) {
|
} else if (property.types[0] == float.class || property.types[0] == Float.class) {
|
||||||
Float value = Float.valueOf(newValue);
|
final Float value = Float.valueOf(newValue);
|
||||||
property.field.setFloat(tmp, value);
|
property.field.setFloat(tmp, value);
|
||||||
} else if (property.types[0] == double.class || property.types[0] == Double.class) {
|
} else if (property.types[0] == double.class || property.types[0] == Double.class) {
|
||||||
Double value = Double.valueOf(newValue);
|
final Double value = Double.valueOf(newValue);
|
||||||
property.field.setDouble(tmp, value);
|
property.field.setDouble(tmp, value);
|
||||||
} else if (property.types[0] == String.class) {
|
} else if (property.types[0] == String.class) {
|
||||||
property.field.set(tmp, newValue);
|
property.field.set(tmp, newValue);
|
||||||
@ -208,70 +265,13 @@ public class PropertiesInterface {
|
|||||||
}
|
}
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
Log.critical("Can not SET the value : " + parameter + " : " + newValue);
|
Log.critical("Can not SET the value : {}: {}", parameter, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParameterAlias(final Object tmp, final char parameter, final String newValue) {
|
public void setParameterAlias(final Object tmp, final char parameter, final String newValue) {
|
||||||
FieldProperty property = findFieldAlias(parameter);
|
final FieldProperty property = findFieldAlias(parameter);
|
||||||
setParameter(tmp, property.name, newValue);
|
setParameter(tmp, property.name, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayHelp() {
|
|
||||||
Log.print("Usage:");
|
|
||||||
String applicationLine = " ";
|
|
||||||
if (this.classCommand != null) {
|
|
||||||
applicationLine += this.classCommand + " ";
|
|
||||||
} else {
|
|
||||||
applicationLine += "XXX ";
|
|
||||||
}
|
|
||||||
if (this.properties.size() != 0) {
|
|
||||||
applicationLine += "[options] ";
|
|
||||||
}
|
|
||||||
if (this.actions != null && this.actions.getActions().size() != 0) {
|
|
||||||
applicationLine += "[actions] ...";
|
|
||||||
}
|
|
||||||
Log.print(applicationLine);
|
|
||||||
if (this.classDescription != null) {
|
|
||||||
Log.print("" + this.classDescription);
|
|
||||||
}
|
|
||||||
if (this.properties.size() != 0) {
|
|
||||||
Log.print(" [options]");
|
|
||||||
for (FieldProperty prop : this.properties) {
|
|
||||||
String parameterExpect = haveParameter(prop) ? " [PARAMETER]" : "";
|
|
||||||
if (prop.alias != null && prop.name != null) {
|
|
||||||
Log.print(" -" + prop.alias + " / --" + prop.name + parameterExpect);
|
|
||||||
} else if (prop.alias != null) {
|
|
||||||
Log.print(" -" + prop.alias + parameterExpect);
|
|
||||||
} else if (prop.name != null) {
|
|
||||||
Log.print(" --" + prop.name + parameterExpect);
|
|
||||||
}
|
|
||||||
if (prop.description != null) {
|
|
||||||
Log.print(" " + prop.description);
|
|
||||||
}
|
|
||||||
if (prop.choice != null) {
|
|
||||||
for (ChoiceElement elem: prop.getChoiceList()) {
|
|
||||||
if (elem.destination() == null) {
|
|
||||||
Log.print(" - " + elem.origin());
|
|
||||||
} else {
|
|
||||||
Log.print(" - " + elem.origin() + " ==> " + elem.destination());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.actions != null && this.actions.getActions().size() != 0) {
|
|
||||||
Log.print(" [actions]");
|
|
||||||
Set<String> actions = this.actions.getActions();
|
|
||||||
for (String action : actions) {
|
|
||||||
Class<?> clazz = this.actions.getInterface(action);
|
|
||||||
String description = PropertiesInterface.getDescription(clazz);
|
|
||||||
if (description == null || description.isEmpty()) {
|
|
||||||
Log.print(" " + action);
|
|
||||||
} else {
|
|
||||||
Log.print(" " + action + ": " + description );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,88 +20,6 @@ import org.atriasoft.death.annotation.ArgSubActions;
|
|||||||
import org.atriasoft.death.internal.Log;
|
import org.atriasoft.death.internal.Log;
|
||||||
|
|
||||||
public class ReflectTools {
|
public class ReflectTools {
|
||||||
private ReflectTools() {}
|
|
||||||
|
|
||||||
public static Class<?>[] getTypeField(final Field fieldDescription) {
|
|
||||||
Class<?> type = fieldDescription.getType();
|
|
||||||
Class<?> subType = null;
|
|
||||||
Type empppe = fieldDescription.getGenericType();
|
|
||||||
if (empppe instanceof ParameterizedType plopppppp) {
|
|
||||||
Type[] realType = plopppppp.getActualTypeArguments();
|
|
||||||
if (realType.length > 0) {
|
|
||||||
try {
|
|
||||||
subType = Class.forName(realType[0].getTypeName());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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(final Constructor<?> elem, final 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 > paramId) {
|
|
||||||
if (empppe[paramId] instanceof ParameterizedType plopppppp) {
|
|
||||||
Type[] realType = plopppppp.getActualTypeArguments();
|
|
||||||
//Log.info("ppplllppp: " + realType.length);
|
|
||||||
if (realType.length > 0) {
|
|
||||||
Log.warning(" -->> " + realType[0]);
|
|
||||||
internalModelClass = Class.forName(realType[0].getTypeName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
subType = internalModelClass;
|
|
||||||
}
|
|
||||||
return new Class<?>[] {type, subType};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Character getAlias(final Field element) throws Exception {
|
public static Character getAlias(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgAlias.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgAlias.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@ -123,36 +41,7 @@ public class ReflectTools {
|
|||||||
}
|
}
|
||||||
return ((ArgChoice) annotation[0]).value();
|
return ((ArgChoice) annotation[0]).value();
|
||||||
}
|
}
|
||||||
public static String getDescription(final Field element) throws Exception {
|
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgDescription.class);
|
|
||||||
if (annotation.length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (annotation.length > 1) {
|
|
||||||
throw new Exception("Must not have more than 1 element @ArgDescription on " + element.getClass().getCanonicalName());
|
|
||||||
}
|
|
||||||
return ((ArgDescription) annotation[0]).value();
|
|
||||||
}
|
|
||||||
public static String getDescription(final Class<?> clazz) throws Exception {
|
|
||||||
final Annotation[] annotation = clazz.getDeclaredAnnotationsByType(ArgDescription.class);
|
|
||||||
if (annotation.length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (annotation.length > 1) {
|
|
||||||
throw new Exception("Must not have more than 1 element @ArgDescription on " + clazz.getCanonicalName());
|
|
||||||
}
|
|
||||||
return ((ArgDescription) annotation[0]).value();
|
|
||||||
}
|
|
||||||
public static String getName(final Field element) throws Exception {
|
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgName.class);
|
|
||||||
if (annotation.length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (annotation.length > 1) {
|
|
||||||
throw new Exception("Must not have more than 1 element @ArgName on " + element.getClass().getCanonicalName());
|
|
||||||
}
|
|
||||||
return ((ArgName) annotation[0]).value();
|
|
||||||
}
|
|
||||||
public static String getCommand(final Class<?> clazz) throws Exception {
|
public static String getCommand(final Class<?> clazz) throws Exception {
|
||||||
final Annotation[] annotation = clazz.getDeclaredAnnotationsByType(ArgCommand.class);
|
final Annotation[] annotation = clazz.getDeclaredAnnotationsByType(ArgCommand.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@ -163,6 +52,40 @@ public class ReflectTools {
|
|||||||
}
|
}
|
||||||
return ((ArgCommand) annotation[0]).value();
|
return ((ArgCommand) annotation[0]).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getDescription(final Class<?> clazz) throws Exception {
|
||||||
|
final Annotation[] annotation = clazz.getDeclaredAnnotationsByType(ArgDescription.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (annotation.length > 1) {
|
||||||
|
throw new Exception("Must not have more than 1 element @ArgDescription on " + clazz.getCanonicalName());
|
||||||
|
}
|
||||||
|
return ((ArgDescription) annotation[0]).value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDescription(final Field element) throws Exception {
|
||||||
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgDescription.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (annotation.length > 1) {
|
||||||
|
throw new Exception("Must not have more than 1 element @ArgDescription on " + element.getClass().getCanonicalName());
|
||||||
|
}
|
||||||
|
return ((ArgDescription) annotation[0]).value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getName(final Field element) throws Exception {
|
||||||
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgName.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (annotation.length > 1) {
|
||||||
|
throw new Exception("Must not have more than 1 element @ArgName on " + element.getClass().getCanonicalName());
|
||||||
|
}
|
||||||
|
return ((ArgName) annotation[0]).value();
|
||||||
|
}
|
||||||
|
|
||||||
public static String[] getParams(final Field element) throws Exception {
|
public static String[] getParams(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgParams.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgParams.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@ -173,6 +96,7 @@ public class ReflectTools {
|
|||||||
}
|
}
|
||||||
return ((ArgParams) annotation[0]).value();
|
return ((ArgParams) annotation[0]).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getSample(final Field element) throws Exception {
|
public static String[] getSample(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgSample.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgSample.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@ -183,13 +107,86 @@ public class ReflectTools {
|
|||||||
}
|
}
|
||||||
return ((ArgSample) annotation[0]).value();
|
return ((ArgSample) annotation[0]).value();
|
||||||
}
|
}
|
||||||
public static boolean isSubAction(final Field element) throws Exception {
|
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgSubActions.class);
|
public static Class<?>[] getTypeField(final Field fieldDescription) {
|
||||||
if (annotation.length == 0) {
|
final Class<?> type = fieldDescription.getType();
|
||||||
return false;
|
Class<?> subType = null;
|
||||||
|
final Type empppe = fieldDescription.getGenericType();
|
||||||
|
if (empppe instanceof final ParameterizedType plopppppp) {
|
||||||
|
final Type[] realType = plopppppp.getActualTypeArguments();
|
||||||
|
if (realType.length > 0) {
|
||||||
|
try {
|
||||||
|
subType = Class.forName(realType[0].getTypeName());
|
||||||
|
} catch (final ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return new Class<?>[] { type, subType };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Class<?>[] getTypeParameterfunction(final Constructor<?> elem, final int paramId) throws ClassNotFoundException {
|
||||||
|
Class<?> type = null;
|
||||||
|
Class<?> subType = null;
|
||||||
|
|
||||||
|
type = elem.getParameters()[paramId].getType();
|
||||||
|
if (List.class.isAssignableFrom(type)) {
|
||||||
|
Class<?> internalModelClass = null;
|
||||||
|
final Type[] empppe = elem.getGenericParameterTypes();
|
||||||
|
if (empppe.length > paramId) {
|
||||||
|
if (empppe[paramId] instanceof final ParameterizedType plopppppp) {
|
||||||
|
final Type[] realType = plopppppp.getActualTypeArguments();
|
||||||
|
//Log.info("ppplllppp: {}", realType.length);
|
||||||
|
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(final Method setter) throws Exception {
|
||||||
|
Class<?> type = null;
|
||||||
|
Class<?> subType = null;
|
||||||
|
|
||||||
|
type = setter.getParameters()[0].getType();
|
||||||
|
if (List.class.isAssignableFrom(type)) {
|
||||||
|
Class<?> internalModelClass = null;
|
||||||
|
final Type[] empppe = setter.getGenericParameterTypes();
|
||||||
|
if (empppe.length > 0) {
|
||||||
|
if (empppe[0] instanceof final ParameterizedType plopppppp) {
|
||||||
|
final 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<?>[] getTypeReturnFunction(/*@NotNull*/ final Method getter) throws Exception {
|
||||||
|
Class<?> type = null;
|
||||||
|
Class<?> subType = null;
|
||||||
|
type = getter.getReturnType();
|
||||||
|
if (!Enum.class.isAssignableFrom(type)) {
|
||||||
|
final Type empppe = getter.getGenericReturnType();
|
||||||
|
if (empppe instanceof final ParameterizedType plopppppp) {
|
||||||
|
final Type[] realType = plopppppp.getActualTypeArguments();
|
||||||
|
if (realType.length > 0) {
|
||||||
|
subType = Class.forName(realType[0].getTypeName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Class<?>[] { type, subType };
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isExecutable(final Method element) throws Exception {
|
public static boolean isExecutable(final Method element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgExecute.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgExecute.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@ -197,4 +194,14 @@ public class ReflectTools {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isSubAction(final Field element) throws Exception {
|
||||||
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgSubActions.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReflectTools() {}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,6 @@ public class Log {
|
|||||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||||
|
|
||||||
public static void critical(final String data) {
|
|
||||||
if (PRINT_CRITICAL) {
|
|
||||||
Logger.critical(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void critical(final String data, final Exception e) {
|
public static void critical(final String data, final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (PRINT_CRITICAL) {
|
if (PRINT_CRITICAL) {
|
||||||
@ -28,45 +22,51 @@ public class Log {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(final String data) {
|
public static void critical(final String data, final Object... objects) {
|
||||||
|
if (PRINT_CRITICAL) {
|
||||||
|
Logger.critical(LIB_NAME_DRAW, data, objects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug(final String data, final Object... objects) {
|
||||||
if (PRINT_DEBUG) {
|
if (PRINT_DEBUG) {
|
||||||
Logger.debug(LIB_NAME_DRAW, data);
|
Logger.debug(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(final String data) {
|
public static void error(final String data, final Object... objects) {
|
||||||
if (PRINT_ERROR) {
|
if (PRINT_ERROR) {
|
||||||
Logger.error(LIB_NAME_DRAW, data);
|
Logger.error(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(final String data) {
|
public static void info(final String data, final Object... objects) {
|
||||||
if (PRINT_INFO) {
|
if (PRINT_INFO) {
|
||||||
Logger.info(LIB_NAME_DRAW, data);
|
Logger.info(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void print(final String data) {
|
public static void print(final String data, final Object... objects) {
|
||||||
if (PRINT_PRINT) {
|
if (PRINT_PRINT) {
|
||||||
System.out.println(data);
|
Logger.print(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void todo(final String data) {
|
public static void todo(final String data, final Object... objects) {
|
||||||
if (PRINT_TODO) {
|
if (PRINT_TODO) {
|
||||||
Logger.todo(LIB_NAME_DRAW, data);
|
Logger.todo(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void verbose(final String data) {
|
public static void verbose(final String data, final Object... objects) {
|
||||||
if (PRINT_VERBOSE) {
|
if (PRINT_VERBOSE) {
|
||||||
Logger.verbose(LIB_NAME_DRAW, data);
|
Logger.verbose(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(final String data) {
|
public static void warning(final String data, final Object... objects) {
|
||||||
if (PRINT_WARNING) {
|
if (PRINT_WARNING) {
|
||||||
Logger.warning(LIB_NAME_DRAW, data);
|
Logger.warning(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user