Package com.tll.util

Examples of com.tll.util.PropertyPath


   * @param entityClass
   * @param path
   * @return the clientized path
   */
  protected static final <T> String clientizePropertyPath(ISchemaInfo schemaInfo, Class<T> entityClass, String path) {
    final PropertyPath p = new PropertyPath(path);
    if(p.depth() > 2) {
      final String ppp = p.trim(1);
      final ISchemaProperty sp = schemaInfo.getSchemaProperty(entityClass, ppp);
      if(sp.getPropertyType().isNested()) {
        path = ppp + '_' + p.last();
      }
    }
    return path;
  }
View Full Code Here


    Map<String, ISchemaProperty> classMap = getSchemaProperties(entityClass);

    if(!classMap.containsKey(propertyName)) {

      final PropertyPath p = new PropertyPath(propertyName);
      if(p.depth() > 1) {
        // attempt to resolve the given path to a relational property and a
        // localized path
        ISchemaProperty sp;
        for(int i = 0; i < p.depth(); i++) {
          sp = classMap.get(p.pathAt(i));
          if(sp == null || !sp.getPropertyType().isRelational()) break;
          final RelationInfo ri = (RelationInfo) sp;
          if(!schemaMap.containsKey(ri.getRelatedType())) {
            load(ri.getRelatedType());
          }
          classMap = schemaMap.get(ri.getRelatedType());
          final String np = p.clip(i + 1);
          sp = classMap.get(np);
          if(sp != null) return sp;
        }
      }
View Full Code Here

          Query pquery;
          if(pname.indexOf('.') > 0) {
            pquery = query;
            // descend one time for each node in the pname (which may be a dot
            // notated property path)
            final PropertyPath path = new PropertyPath(pname);
            for(final String node : path.nodes()) {
              pquery = pquery.descend(node);
            }
          }
          else {
            pquery = query.descend(pname);
View Full Code Here

  private IModelProperty resolvePropertyPath(final String propPath) throws PropertyPathException {
    if(StringUtil.isEmpty(propPath)) {
      throw new MalformedPropPathException("No property path specified.");
    }

    final PropertyPath pp = new PropertyPath(propPath);
    IModelProperty prop = null;
    Model model = this;
    final int len = pp.depth();
    for(int i = 0; i < len; i++) {
      final String pname = pp.nameAt(i);
      final int index;
      try {
        index = pp.indexAt(i);
      }
      catch(final IllegalArgumentException e) {
        throw new MalformedPropPathException(e.getMessage());
      }
      final boolean indexed = (index >= 0);
      final boolean atEnd = (i == len - 1);

      // find the prop val under current model
      prop = model.get(pname);
      if(prop == null) {
        if(atEnd) {
          throw new UnsetPropertyException(pp.toString(), model, pname);
        }
        throw new NullNodeInPropPathException(pp.toString(), pname);
      }

      // get the bound prop val type for this prop path element
      final PropertyType pvType = prop.getType();

      // non-relational prop val
      if(!pvType.isRelational()) {
        if(!atEnd) {
          throw new PropPathNodeMismatchException(pp.toString(), pname, pvType.toString(), "Relational");
        }
        return prop;
      }

      // related one prop val
      else if(pvType == PropertyType.RELATED_ONE) {
        if(indexed) {
          throw new PropPathNodeMismatchException(pp.toString(), pname, pvType.toString(), PropertyType.RELATED_MANY
              .toString());
        }
        final IModelRefProperty mrp = (IModelRefProperty) prop;
        if(atEnd) {
          return mrp;
        }
        // get the nested group...
        final Model ng = mrp.getModel();
        if(ng == null) {
          throw new NullNodeInPropPathException(pp.toString(), pname);
        }
        // reset for next path
        model = ng;
      }

      // related many prop val
      else if(pvType == PropertyType.RELATED_MANY) {
        final RelatedManyProperty rmp = (RelatedManyProperty) prop;
        if(!indexed) {
          if(atEnd) {
            return rmp;
          }
          // an index is expected if we're not at the end
          throw new MalformedPropPathException(pp.toString());
        }
        else if(indexed) {
          // get the nested group prop val list...
          if(index >= rmp.size()) {
            throw new IndexOutOfRangeInPropPathException(pp.toString(), pname, index);
          }
          if(atEnd) {
            return rmp.getIndexedProperty(index);
          }
          // reset for next path
View Full Code Here

          if(mp instanceof IModelRefProperty || mp instanceof IndexedProperty) {
            nearestParentRefPath = rootRelPath;
          }
          else {
            // resolve the nearest parent (relational or indexed prop)
            final PropertyPath pp = new PropertyPath(rootRelPath);
            if(pp.depth() > 1) {
              nearestParentRefPath = pp.trim(1);
            }
            else {
              nearestParentRefPath = "";
            }
          }
View Full Code Here

    return list.iterator();
  }

  @Override
  public void setProperty(String propPath, Object value) throws PropertyPathException, IllegalArgumentException {
    final PropertyPath pp = new PropertyPath(propPath);
    if(pp.isIndexed()) {
      if(value != null && value instanceof Model == false) {
        throw new IllegalArgumentException("The value must be a Model instance");
      }

      final Model m = (Model) value;
      Model old = null;

      final int index;
      try {
        index = pp.index();
      }
      catch(final IllegalArgumentException e) {
        throw new MalformedPropPathException(e.getMessage());
      }
      final int size = size();

      if(index == size) {
        // we're appending a new index
        if(m != null) {
          // add
          if(mlist == null) {
            mlist = new ArrayList<Model>();
          }
          mlist.add(m);
          list.add(new IndexedProperty(relatedType, m, propertyName, isReference(), index));
        }
      }
      else if(index < size) {
        if(m != null) {
          // replace
          old = mlist.set(index, m);
          list.get(index).setModel(m, false);
        }
        else {
          // remove
          old = mlist.remove(index);
          list.remove(index);
        }
      }
      else {
        throw new IndexOutOfRangeInPropPathException(propPath, pp.last(), pp.index());
      }
      if(old != value) {
        getChangeSupport().fireIndexedPropertyChange(propertyName, index, old, value);
      }
    }
View Full Code Here

    }
    else {
      assert field instanceof IFieldWidget<?>;
      final IFieldWidget<?> fw = ((IFieldWidget<?>) field);
      final String pname = fw.getPropertyName();
      final PropertyPath p = new PropertyPath(pname);
      p.replace(old, repl);
      fw.setPropertyName(p.toString());
    }
  }
View Full Code Here

          Query pquery;
          if(pname.indexOf('.') > 0) {
            pquery = query;
            // descend one time for each node in the pname (which may be a dot
            // notated property path)
            final PropertyPath path = new PropertyPath(pname);
            for(final String node : path.nodes()) {
              pquery = pquery.descend(node);
            }
          }
          else {
            pquery = query.descend(pname);
View Full Code Here

    Map<String, ISchemaProperty> classMap = getSchemaProperties(entityClass);

    if(!classMap.containsKey(propertyName)) {

      final PropertyPath p = new PropertyPath(propertyName);
      if(p.depth() > 1) {
        // attempt to resolve the given path to a relational property and a
        // localized path
        ISchemaProperty sp;
        for(int i = 0; i < p.depth(); i++) {
          sp = classMap.get(p.pathAt(i));
          if(sp == null || !sp.getPropertyType().isRelational()) break;
          final RelationInfo ri = (RelationInfo) sp;
          if(!schemaMap.containsKey(ri.getRelatedType())) {
            load(ri.getRelatedType());
          }
          classMap = schemaMap.get(ri.getRelatedType());
          final String np = p.clip(i + 1);
          sp = classMap.get(np);
          if(sp != null) return sp;
        }
      }
View Full Code Here

    }
    else {
      assert field instanceof IFieldWidget<?>;
      final IFieldWidget<?> fw = ((IFieldWidget<?>) field);
      final String pname = fw.getPropertyName();
      final PropertyPath p = new PropertyPath(pname);
      p.replace(old, repl);
      fw.setPropertyName(p.toString());
    }
  }
View Full Code Here

TOP

Related Classes of com.tll.util.PropertyPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.