public static TypeInfo createRoot(String name, Class<?> clz) { // root is always a composite type // FIXME assert its a JAXB type XmlRootElement root = clz.getAnnotation(XmlRootElement.class); if (root == null) { throw new IllegalArgumentException("Not a JAXB type: " + clz); } if (name == null) { name = getRootName(clz); } return new TypeInfo(name, clz, null); }
/** * Set the expression and cache * @param type * @param expression */ public QueryImpl(Class<T> type, Expression expression) { this.expression = expression; this.rootType = TypeInfo.createRoot(null, type); }
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; }
public static final String getTypeName(Method m, XmlAccessType access) { // ignore static, transient and xmltransient fields if (Modifier.isStatic(m.getModifiers()) || m.getAnnotation(XmlTransient.class) != null ) { return null; } // try to read annotation String name = getTypeName(m.getAnnotations(), m.getName()); if (name != null) return name; //check acces type else if (access == XmlAccessType.NONE) { // none return name return name; } else if (access == XmlAccessType.PROPERTY) { // return bean property name if no annotation present return getBeanPropertyName(m); } else if (access == XmlAccessType.PUBLIC_MEMBER && Modifier.isPublic(m.getModifiers())) { // look for public access return getBeanPropertyName(m); } return null; }
return null; explore(); if (!target.getClass().equals(_class)) { if (_class.isAssignableFrom(target.getClass())) { TypeInfo subTypeInfo = new TypeInfo(getRootName(target.getClass()), target.getClass(), _accessor); return subTypeInfo.retrieve(target, query, index); } else { TypeInfo child = getChild(query[index]); if (child == null) { return null; target = child.getAccessor().getValue(target); if (index+1 == query.length) { return child.retrieve(target, query, index+1);
@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(); }
String tn = getTypeName(m, _accessType); if (tn != null) { if (LOGGER.isDebugEnabled()) { _class.getSimpleName(), tn, m); _types.put(tn, createTypeInfo(tn, new Accessor(m))); String tn = getTypeName(f, _accessType); if (tn != null) { if (LOGGER.isDebugEnabled()) { _class.getSimpleName(), tn, f); _types.put(tn, createTypeInfo(tn, new Accessor(f)));
public boolean visitInternal(CompareExpression ce) throws QueryException { String[] selector = ce.getSelector().split("\\."); if (!rootType.getName().equals(selector[0])) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Root name mismatch: {} != {}", rootType.getName(), selector[0]); Object value = rootType.retrieve(object, selector, 1); if(value == null){ // nothing to compare against return false;
@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; }
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); }