@Override public TypeInfo getCollectionChild(Class<?> childType) { explore(); for (TypeInfo ti : _types.values()) { if (ti.getType().equals(childType)) { return ti; } } return null; } }
@Override public synchronized void explore() { if (_explored) { return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("exploring wrapper type: {} gtype: {}", _class, _accessor.getGenericType()); } String tn = null; AccessibleObject accessibleObject = _accessor.getAccessibleObject(); XmlElement xmlElement = accessibleObject.getAnnotation(XmlElement.class); if (accessibleObject instanceof Field) { Field f = (Field) accessibleObject; tn = DEFAULT_NAME.equals(xmlElement.name())?f.getName() : xmlElement.name(); }else if (accessibleObject instanceof Method) { Method m = (Method) accessibleObject; tn = DEFAULT_NAME.equals(xmlElement.name())?m.getName() : xmlElement.name(); } this._types.put(tn, new IteratableTypeInfo(tn, this._accessor)); _explored = true; }
public static TypeInfo createTypeInfo(String name, Accessor accessor) { if (accessor.getAccessibleObject().getAnnotation(XmlElementWrapper.class) != null) { //XmlElementWrapperType return new WrapperTypeInfo(name, accessor); } else if (Collection.class.isAssignableFrom(accessor.getType())) { // collection type return new IteratableTypeInfo(name, accessor); } return new TypeInfo(name, accessor.getType(), accessor); }
@Override public Object retrieve(Object target, String[] query, int index) throws QueryException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("retrieve collection: {}/{} type:{}", index, query.length, target.getClass()); } explore(); Collection<?> c = (Collection<?>) target; Iterator<?> it = c.iterator(); List<Object> objects = new ArrayList<Object>(); while (it.hasNext()) { Object item = it.next(); for (TypeInfo child : _types.values()) { Object val = child.retrieve(item, query, index); if (val != null) { objects.add(val); } } } return objects; }