package org.onap.aai.introspection;
import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.onap.aai.schema.enums.ObjectMetadata;
import org.onap.aai.schema.enums.PropertyMetadata;
@Override
public Class<?> getGenericTypeClass(String name) {
- Object resultObject = null;
Class<?> resultClass = null;
- resultObject = this.getValue(name);
- if (resultObject.getClass().getName().equals("org.json.simple.JSONArray")) {
+ Object resultObject = this.getValue(name);
+ if (resultObject instanceof JSONArray) {
resultClass = ((List) resultObject).get(0).getClass();
}
@Override
public Object newInstanceOfProperty(String name) {
try {
- return this.getClass(name).newInstance();
- } catch (InstantiationException | IllegalAccessException e) {
+ return this.getClass(name).getDeclaredConstructor().newInstance();
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | NoSuchMethodException | SecurityException e) {
return null;
}
}
@Override
public Object newInstanceOfNestedProperty(String name) {
try {
- return this.getGenericTypeClass(name).newInstance();
- } catch (InstantiationException | IllegalAccessException e) {
+ return this.getGenericTypeClass(name).getDeclaredConstructor().newInstance();
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | NoSuchMethodException | SecurityException e) {
return null;
}
}
@Override
public boolean isComplexType(String name) {
String result = this.getType(name);
-
- if (result.contains("JSONObject")) {
- return true;
- } else {
- return false;
- }
-
+ return result.contains("JSONObject");
}
@Override
public boolean isComplexGenericType(String name) {
String result = this.getGenericType(name);
-
- if (result.contains("JSONObject")) {
- return true;
- } else {
- return false;
- }
-
+ return result.contains("JSONObject");
}
@Override
public boolean isListType(String name) {
String result = this.getType(name);
-
- if (result.contains("java.util.List")) {
- return true;
- } else {
- return false;
- }
-
+ return result.contains("java.util.List");
}
@Override
public boolean isContainer() {
Set<String> props = this.getProperties();
- boolean result = false;
- if (props.size() == 1 && this.isListType(props.iterator().next())) {
- result = true;
- }
-
- return result;
+ return props.size() == 1 && this.isListType(props.iterator().next());
}
@Override
return null;
}
- @Override
- public Object clone() {
- // TODO
- return null;
- }
-
/*
* @Override
* public String findEdgeName(String parent, String child) {
- *
+ *
* // Always has for now
* return "has";
- *
+ *
* }
*/