public IteratableTypeInfo(String name, Accessor accessor) { super(name, accessor.getType(), accessor); }
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 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; }
@Override public synchronized void explore() { if (_explored) { return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("exploring iteratable type: {} gtype: {}", _class, _accessor.getGenericType()); } Type t = _accessor.getGenericType(); if (t instanceof ParameterizedType) { Type[] pt = ((ParameterizedType) t).getActualTypeArguments(); // First type is a child, ignore rest if (pt.length > 0) { _types.put(_name, new TypeInfo(_name, (Class)pt[0], null)); } } _explored = true; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public int filter(T rootObject, Class<?> childClass) throws QueryException { // retrieve underlying collection TypeInfo childType = rootType.getCollectionChild(childClass); if (childType == null || !(childType instanceof IteratableTypeInfo)) { return 0; } Collection collection = (Collection) childType.getAccessor().getValue(rootObject); // get the child type of the collection type TypeInfo ti = childType.getCollectionChild(childClass); List matched = new ArrayList(); for (Object item : collection) { if (match(item, ti)) { matched.add(item); } } collection.clear(); collection.addAll(matched); return matched.size(); }
public TypeInfo getCollectionChild(Class<?> childType) { explore(); for (TypeInfo ti : _types.values()) { if (Collection.class.isAssignableFrom(ti.getType())) { ParameterizedType p = (ParameterizedType) ti.getAccessor().getGenericType(); Type[] pts = p.getActualTypeArguments(); if (pts.length == 1 && pts[0].equals(childType)) { return ti; } } } return null; }
return null; target = child.getAccessor().getValue(target); if (index+1 == query.length) {
protected WrapperTypeInfo(String name, Accessor accessor) { super(name, accessor.getType(), accessor); }