2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.northbound.commons.query;
10 import java.lang.reflect.AccessibleObject;
11 import java.lang.reflect.Field;
12 import java.lang.reflect.Method;
14 import javax.xml.bind.annotation.XmlElement;
16 public class WrapperTypeInfo extends TypeInfo {
18 protected WrapperTypeInfo(String name, Accessor accessor) {
19 super(name, accessor.getType(), accessor);
23 public Object retrieve(Object target, String[] query, int index) throws QueryException {
24 if (LOGGER.isDebugEnabled()) {
25 LOGGER.debug("retrieve collection: {}/{}", index, query.length);
27 if (index >= query.length) return null;
29 TypeInfo child = getChild(query[index]);
30 if (child == null) return null;
31 if (query.length == index+1) { // skipping this node
33 }else { // if list of list go to next node to get value
34 return child.retrieve(target, query, index+1);
39 public synchronized void explore() {
40 if (_explored) return;
41 if (LOGGER.isDebugEnabled()) {
42 LOGGER.debug("exploring wrapper type: {} gtype: {}", _class,
43 _accessor.getGenericType());
46 AccessibleObject accessibleObject = _accessor.getAccessibleObject();
47 XmlElement xmlElement = accessibleObject.getAnnotation(XmlElement.class);
48 if (accessibleObject instanceof Field) {
49 Field f = (Field) accessibleObject;
50 tn = DEFAULT_NAME.equals(xmlElement.name())?f.getName() : xmlElement.name();
51 }else if (accessibleObject instanceof Method) {
52 Method m = (Method) accessibleObject;
53 tn = DEFAULT_NAME.equals(xmlElement.name())?m.getName() : xmlElement.name();
55 this._types.put(tn, new IteratableTypeInfo(tn, this._accessor));