Esempio n. 1
0
  /**
   * Cast the path to a subtype querytype
   *
   * @param <U>
   * @param clazz
   * @return
   */
  @SuppressWarnings("unchecked")
  public <U extends BeanPath<? extends T>> U as(Class<U> clazz) {
    try {
      if (!casts.containsKey(clazz)) {
        PathMetadata<T> metadata;
        if (pathMixin.getMetadata().getPathType() != PathType.COLLECTION_ANY) {
          metadata = PathMetadataFactory.forDelegate(pathMixin);
        } else {
          metadata = (PathMetadata) pathMixin.getMetadata();
        }
        U rv;
        // the inits for the subtype will be wider, if it's a variable path
        if (inits != null && pathMixin.getMetadata().getPathType() != PathType.VARIABLE) {
          rv =
              clazz
                  .getConstructor(PathMetadata.class, PathInits.class)
                  .newInstance(metadata, inits);
        } else {
          rv = clazz.getConstructor(PathMetadata.class).newInstance(metadata);
        }
        casts.put(clazz, rv);
        return rv;
      } else {
        return (U) casts.get(clazz);
      }

    } catch (InstantiationException e) {
      throw new ExpressionException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
      throw new ExpressionException(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      throw new ExpressionException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      throw new ExpressionException(e.getMessage(), e);
    }
  }
Esempio n. 2
0
 @Override
 public Path<?> getRoot() {
   return pathMixin.getRoot();
 }
Esempio n. 3
0
 @Override
 public AnnotatedElement getAnnotatedElement() {
   return pathMixin.getAnnotatedElement();
 }
Esempio n. 4
0
 @Override
 public PathMetadata<?> getMetadata() {
   return pathMixin.getMetadata();
 }