summaryrefslogtreecommitdiffstats
path: root/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java
diff options
context:
space:
mode:
Diffstat (limited to 'dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java')
-rw-r--r--dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java60
1 files changed, 23 insertions, 37 deletions
diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java
index d368886..bdce9c3 100644
--- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java
+++ b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java
@@ -1,30 +1,14 @@
package org.onap.sdc.dcae.catalog.commons;
import java.util.List;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Collections;
-
-import java.util.stream.Collectors;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-
-import java.lang.reflect.Type;
import java.lang.reflect.Method;
-import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-
import java.lang.invoke.MethodHandles;
-import com.google.common.reflect.Invokable;
-import org.onap.sdc.dcae.catalog.commons.Proxy;
-import org.onap.sdc.dcae.catalog.commons.ProxyBuilder;
import com.google.common.reflect.AbstractInvocationHandler;
import org.apache.commons.beanutils.ConvertUtils;
@@ -37,13 +21,13 @@ public class Proxy extends AbstractInvocationHandler {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
- public static @interface DataMap {
+ public @interface DataMap {
- public String map() default "";
+ String map() default "";
- public boolean proxy() default false;
+ boolean proxy() default false;
- public Class elementType() default Void.class;
+ Class elementType() default Void.class;
}
@@ -51,12 +35,10 @@ public class Proxy extends AbstractInvocationHandler {
static {
try {
- lookupHandleConstructor =
- MethodHandles.Lookup.class.getDeclaredConstructor(Class.class,
- int.class);
+ lookupHandleConstructor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
if (!lookupHandleConstructor.isAccessible()) {
- lookupHandleConstructor.setAccessible(true);
+ lookupHandleConstructor.setAccessible(true);
}
}
catch (Exception x) {
@@ -64,7 +46,6 @@ public class Proxy extends AbstractInvocationHandler {
}
}
-
private JSONObject data;
private ProxyBuilder builder;
@@ -81,11 +62,9 @@ public class Proxy extends AbstractInvocationHandler {
return this.builder;
}
- protected Object handleInvocation(
- Object theProxy,Method theMethod,Object[] theArgs)
- throws Throwable {
+ protected Object handleInvocation(Object theProxy,Method theMethod,Object[] theArgs) throws Throwable {
if (theMethod.isDefault()) {
- final Class<?> declaringClass = theMethod.getDeclaringClass();
+ final Class<?> declaringClass = theMethod.getDeclaringClass();
return lookupHandleConstructor
.newInstance(declaringClass, MethodHandles.Lookup.PRIVATE)
@@ -96,28 +75,35 @@ public class Proxy extends AbstractInvocationHandler {
String key = theMethod.getName();
- Proxy.DataMap dataMap = (Proxy.DataMap)theMethod.getAnnotation(Proxy.DataMap.class);
+ Proxy.DataMap dataMap = theMethod.getAnnotation(Proxy.DataMap.class);
if (dataMap != null) {
String dataKey = dataMap.map();
- if (dataKey != null && !"".equals(dataKey))
+ if (!"".equals(dataKey)) {
key = dataKey;
+ }
}
//this is ugly, can this be done through an extension mechanism such as plugging in functions?
- if ( builder.hasExtension(key) )
+ if ( builder.hasExtension(key) ) {
return this.builder.extension(key).apply(this, theArgs);
+ }
//we give priority to the context (because of the 'catalog' property issue in catalog service) but
//how natural is this?
Object val = this.builder.context(key);
- if (val == null)
+ if (val == null) {
val = this.data.opt(key);
+ }
- if (val == null)
+ if (val == null) {
return null;
+ }
+ return getProxies(theMethod, dataMap, val);
+ }
-//as we create proxies here we should store them back in the 'data' so that we do not do it again
-//can we always 'recognize' them?
+ private Object getProxies(Method theMethod, DataMap dataMap, Object val) throws InstantiationException, IllegalAccessException {
+ //as we create proxies here we should store them back in the 'data' so that we do not do it again
+ //can we always 'recognize' them?
if (val instanceof String &&
String.class != theMethod.getReturnType()) {
//??This will yield a POJO ..
@@ -128,7 +114,7 @@ public class Proxy extends AbstractInvocationHandler {
return builder.build((JSONObject)val, theMethod.getReturnType());
}
}
- else if (val instanceof JSONArray&& dataMap != null &&
+ else if (val instanceof JSONArray && dataMap != null &&
dataMap.proxy() &&
List.class.isAssignableFrom(theMethod.getReturnType())) {