예제 #1
0
  /**
   * The property is a simple value list. If property is a list property, the method will check to
   * see if the current element has the local list value, if it has, the method returns, otherwise,
   * a copy of the list value inherited from container or parent will be set locally on the element
   * itself.
   *
   * <p>This method is supposed to be used when we need to change the value of a composite property(
   * a simple list property ). These kind of property is inherited as a whole, so when the value
   * changed from a child element. This method will be called to ensure that a local copy will be
   * made, so change to the child won't affect the original value in the parent.
   *
   * @param ref a reference to a list property or member.
   */
  private DesignElement makeLocalCompositeValue(
      DesignElement topElement, ElementPropertyDefn prop, DesignElement content) {
    // Top level property is a list.

    Object localValue = topElement.getLocalProperty(module, prop);

    if (localValue != null) return content;

    // Make a local copy of the inherited list value.

    Object inherited = topElement.getProperty(module, prop);

    // if the action is add, the inherited can be null.

    if (inherited == null) return null;

    int index = -1;

    if (content != null && inherited instanceof List) index = ((List) inherited).indexOf(content);

    Object newValue = ModelUtil.copyValue(prop, inherited);
    ActivityStack activityStack = module.getActivityStack();

    ContainerContext context = new ContainerContext(topElement, prop.getName());

    if (newValue instanceof List) {
      List list = new ArrayList();
      PropertyRecord propRecord = new PropertyRecord(topElement, prop, list);
      activityStack.execute(propRecord);

      list = (List) newValue;
      for (int i = 0; i < list.size(); i++) {
        DesignElement tmpContent = (DesignElement) list.get(i);
        ContentRecord addRecord = new ContentRecord(module, context, tmpContent, i);
        activityStack.execute(addRecord);
      }
    } else {
      PropertyRecord propRecord = new PropertyRecord(topElement, prop, newValue);
      activityStack.execute(propRecord);
    }

    if (index != -1) return (DesignElement) ((List) newValue).get(index);

    return content;
  }
예제 #2
0
 @Override
 public List<SemanticException> validate(Module module, DesignElement element) {
   List<SemanticException> ret = new ArrayList<SemanticException>();
   Object obj = element.getProperty(module, IReportItemModel.BOOKMARK_PROP);
   if (obj != null && obj instanceof Expression) {
     Expression expr = (Expression) obj;
     if (ExpressionType.CONSTANT.equals(expr.getType())) {
       if (!Pattern.matches(BOOKMARK_PATTERN, expr.getStringExpression())) {
         ret.add(
             new SemanticException(
                 element,
                 "The bookmark is invalid, must begin with a letter(A-Za-z) and be followed by these chars (A-Za-z0-9-_:.)"));
       }
     }
     return ret;
   }
   return Collections.emptyList();
 }