1 package org.opendaylight.controller.northbound.commons.query;
3 import java.lang.annotation.Annotation;
4 import java.lang.reflect.AccessibleObject;
5 import java.lang.reflect.Field;
6 import java.lang.reflect.Method;
7 import java.lang.reflect.Type;
9 /*package*/ class Accessor {
10 protected final AccessibleObject _accessorObj;
12 public Accessor(AccessibleObject accessor) {
13 _accessorObj = accessor;
14 _accessorObj.setAccessible(true);
17 public AccessibleObject getAccessibleObject() {
21 public Annotation[] getAnnotations() {
22 return _accessorObj.getAnnotations();
25 public Object getValue(Object parent) throws QueryException {
27 if (_accessorObj instanceof Field) {
28 return ((Field)_accessorObj).get(parent);
31 return ((Method)_accessorObj).invoke(parent);
33 } catch (Exception e) {
34 throw new QueryException("Failure in retrieving value", e);
37 public Type getGenericType() {
38 if (_accessorObj instanceof Field) {
39 return ((Field)_accessorObj).getGenericType();
42 return ((Method)_accessorObj).getGenericReturnType();
45 public Class<?> getType() {
47 if (_accessorObj instanceof Field) {
48 return ((Field)_accessorObj).getType();
51 return ((Method)_accessorObj).getReturnType();