Esempio n. 1
0
  public void checkDimension() throws SemanticException {
    if (element instanceof TabularDimension) {
      Dimension sharedDimension =
          TabularDimensionPropSearchStrategy.getSharedDimension(module, element);
      if (sharedDimension != null) {
        String name = (String) element.getName();
        String sharedName = sharedDimension.getName();

        if (!sharedName.equals(name)) {
          NameExecutor nameExecutor = new NameExecutor(module, element);
          INameHelper nameHelper = nameExecutor.getNameHelper();
          NameSpace namespace = nameExecutor.getNameSpace();
          String namespaceId = nameExecutor.getNameSpaceId();
          DesignElement existedElement = namespace.getElement(name);
          if (existedElement == null) {
            // the name is not put in name space, then simply rename
            // it to the name of the shared element
            setName(sharedName);
          } else {
            if (existedElement == element) {
              // remove it from the name space and then rename it
              getActivityStack()
                  .execute(new NameSpaceRecord(nameHelper, namespaceId, element, false));
              setName(sharedName);
            } else {
              // do nothing and simply rename it to the name of
              // the shared element
              setName(sharedName);
            }
          }
        }
      }
    }
  }
Esempio n. 2
0
  /**
   * Sets the element name.
   *
   * @param name the new name.
   * @throws NameException if the element name is not allowed to change.
   */
  public void setName(String name) throws NameException {
    name = StringUtil.trimString(name);

    // Ignore change to the current name.

    String oldName = element.getName();
    if ((name == null && oldName == null)
        || (name != null && oldName != null && name.equals(oldName))) return;

    // ignore change to the dimension that refers a shared dimension
    Dimension sharedDimension =
        TabularDimensionPropSearchStrategy.getSharedDimension(module, element);
    if (sharedDimension != null && !sharedDimension.getName().equals(name)) return;

    checkName(name);

    DesignElement tmpElement = element;
    // if a contentElement is not local, need to make a local copy before changing the name
    if (tmpElement instanceof ContentElement && !((ContentElement) tmpElement).isLocal()) {
      eventTarget = ((ContentElement) tmpElement).getValueContainer();
      tmpElement = copyTopCompositeValue();
    }

    // Record the change.

    ActivityStack stack = getActivityStack();
    NameRecord rename = new NameRecord(tmpElement, name);
    stack.startTrans(rename.getLabel());

    // Drop the old name from the name space.

    // Change the name.
    stack.execute(rename);

    // Add the new name to the name space.
    renameSymbolFrom(oldName);

    // change the name of the dimension that shares this element
    if (element instanceof Dimension) {
      updateDimensions(stack);
    }

    stack.commit();
  }