Esempio n. 1
0
    public Object next() {
      String pathComp = toks.nextToken();

      // see if this is an attribute
      Attribute attr = currentEnt.getAttribute(pathComp);
      if (attr != null) {
        // do a sanity check...
        if (toks.hasMoreTokens()) {
          throw new ExpressionException(
              "Attribute must be the last component of the path: '" + pathComp + "'.", path, null);
        }

        return attr;
      }

      Relationship rel = currentEnt.getRelationship(pathComp);
      if (rel != null) {
        currentEnt = rel.getTargetEntity();
        return rel;
      }

      // build error message
      StringBuffer buf = new StringBuffer();
      buf.append("Can't resolve path component: [")
          .append(currentEnt.getName())
          .append('.')
          .append(pathComp)
          .append("].");
      throw new ExpressionException(buf.toString(), path, null);
    }
Esempio n. 2
0
    public CayenneMapEntry next() {
      String pathComp = toks.nextToken();

      // see if this is an attribute
      Attribute attr = currentEnt.getAttribute(pathComp);
      if (attr != null) {
        // do a sanity check...
        if (toks.hasMoreTokens())
          throw new ExpressionException(
              "Attribute must be the last component of the path: '" + pathComp + "'.", path, null);

        return attr;
      }

      Relationship rel = currentEnt.getRelationship(pathComp);
      if (rel != null) {
        currentEnt = rel.getTargetEntity();
        if (currentEnt != null || !toks.hasMoreTokens()) { // otherwise an exception will be thrown
          return rel;
        }
      }

      String entityName = (currentEnt != null) ? currentEnt.getName() : "(?)";

      // build error message
      StringBuilder buf = new StringBuilder();
      buf.append("Can't resolve path component: [")
          .append(entityName)
          .append('.')
          .append(pathComp)
          .append("].");
      throw new ExpressionException(buf.toString(), path, null);
    }
Esempio n. 3
0
  /**
   * Returns a relationship that has a specified entity as a target. If there is more than one
   * relationship for the same target, it is unpredictable which one will be returned.
   *
   * @since 1.1
   */
  public Relationship getAnyRelationship(Entity targetEntity) {
    if (getRelationships().isEmpty()) return null;

    for (Relationship r : getRelationships()) {
      if (r.getTargetEntity() == targetEntity) return r;
    }
    return null;
  }
Esempio n. 4
0
  /**
   * Returns a relationship that has a specified entity as a target. If there is more than one
   * relationship for the same target, it is unpredictable which one will be returned.
   *
   * @since 1.1
   */
  public Relationship getAnyRelationship(Entity targetEntity) {
    Collection relationships = getRelationships();
    if (relationships.isEmpty()) {
      return null;
    }

    Iterator it = relationships.iterator();
    while (it.hasNext()) {
      Relationship r = (Relationship) it.next();
      if (r.getTargetEntity() == targetEntity) {
        return r;
      }
    }
    return null;
  }