예제 #1
0
  /**
   * Gets the dimension with the specified name within this cube.
   *
   * @param dimensionName name of the dimension to find
   * @return dimension within the cube if found, otherwise <code>null</code>
   */
  public DimensionHandle getDimension(String dimensionName) {
    if (StringUtil.isBlank(dimensionName)) return null;
    if (!getElement().canDynamicExtends()) {
      Dimension dimension = module.findDimension(dimensionName);
      if (dimension == null) return null;
      if (dimension.isContentOf(getElement())) return (DimensionHandle) dimension.getHandle(module);
      else {
        // check the client to find the children of the cube
        List<BackRef> clients = dimension.getClientList();
        if (clients != null) {
          for (BackRef ref : clients) {
            DesignElement client = ref.getElement();
            if (client.isContentOf(getElement())) return (DimensionHandle) client.getHandle(module);
          }
        }
      }
    } else if (getElement().getDynamicExtendsElement(getModule()) != null) {
      Cube cube = (Cube) getElement();
      DesignElement element =
          cube.findLocalElement(
              dimensionName,
              MetaDataDictionary.getInstance().getElement(ReportDesignConstants.DIMENSION_ELEMENT));
      return (DimensionHandle) (element == null ? null : element.getHandle(module));
    }

    return null;
  }
예제 #2
0
  /**
   * @param level
   * @return true if level is correctly added, otherwise false
   */
  public boolean addCachedLevel(DesignElement level) {
    if (!(level instanceof Level)) return true;
    String name = level.getName();

    if (name == null) return true;
    if (cachedLevelNames.get(name) != null && cachedLevelNames.get(name) != level) return false;
    this.cachedLevelNames.put(level.getName(), level);
    return true;
  }
예제 #3
0
  /**
   * Returns the dimension defined on the given cube.
   *
   * @param dimensionName
   * @param parent
   * @param parentModule
   * @return
   */
  protected DesignElement doGetLocalDimension(
      String dimensionName, Cube parent, Module parentModule) {
    DesignElement dimension = parentModule.findDimension(dimensionName);
    if (dimension == null) return null;

    int index = dimension.getIndex(parentModule);
    assert index != -1;

    List<DesignElement> dims =
        (List<DesignElement>) getElement().getProperty(module, DIMENSIONS_PROP);

    return dims.get(index);
  }
예제 #4
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 copyTopCompositeValue() {
    if (!(element instanceof ContentElement)) {
      return null;
    }

    DesignElement topElement = eventTarget.getElement();
    String propName = eventTarget.getPropName();
    ElementPropertyDefn prop = topElement.getPropertyDefn(propName);

    makeLocalCompositeValue(topElement, prop, null);

    return matchElement(topElement);
  }
예제 #5
0
  /**
   * Gets the dimension with the specified name within this cube. If dimension defined with the
   * given name doesn't exist, it returns the local corresponding one mapped to the parent dimension
   * that matches the given name.
   *
   * @param dimensionName name of the dimension to find
   * @return dimension within the cube if found, otherwise <code>null</code>
   */
  public DimensionHandle getLocalDimension(String dimensionName) {
    DesignElement dimension = module.findDimension(dimensionName);
    if (dimension != null && dimension.isContentOf(getElement()))
      return (DimensionHandle) dimension.getHandle(module);

    // find the dimension according to the name in the parent cube.

    CubeHandle parent = (CubeHandle) getExtends();
    if (parent == null) return null;

    dimension = doGetLocalDimension(dimensionName, (Cube) parent.element, parent.module);

    if (dimension == null) return null;

    return (DimensionHandle) dimension.getHandle(module);
  }
예제 #6
0
  /**
   * Checks whether the name is valid in the context.
   *
   * @param name the new name
   * @return <code>true</code> if the name is valid. Otherwise <code>false</code>.
   */
  private boolean isNameValidInContext(String name) {
    if (element instanceof Style) {
      DesignElement tmpContainer = element.getContainer();
      if (tmpContainer instanceof AbstractTheme) {
        List<SemanticException> errors =
            ThemeStyleNameValidator.getInstance()
                .validateForRenamingStyle(
                    (AbstractThemeHandle) tmpContainer.getHandle(module),
                    (StyleHandle) element.getHandle(module),
                    name);
        if (!errors.isEmpty()) return false;
      }
    }

    return true;
  }
예제 #7
0
  /**
   * Gets the measure with the specified name within this cube.
   *
   * @param measureName name of the measure to find
   * @return measure within the cube if found, otherwise <code>null</code>
   */
  public MeasureHandle getMeasure(String measureName) {
    if (StringUtil.isBlank(measureName)) return null;
    if (!getElement().canDynamicExtends()) {
      DesignElement measure = module.findOLAPElement(measureName);
      if (measure instanceof Measure && measure.isContentOf(getElement()))
        return (MeasureHandle) measure.getHandle(module);
    } else if (getElement().getDynamicExtendsElement(getModule()) != null) {
      Cube cube = (Cube) getElement();
      DesignElement element =
          cube.findLocalElement(
              measureName,
              MetaDataDictionary.getInstance().getElement(ReportDesignConstants.MEASURE_ELEMENT));
      return (MeasureHandle) (element == null ? null : element.getHandle(module));
    }

    return null;
  }
예제 #8
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;
  }
예제 #9
0
  private DesignElement matchElement(DesignElement topElement) {
    List<Step> steps = eventTarget.stepIterator();

    DesignElement tmpElement = topElement;
    for (int i = steps.size() - 1; i >= 0; i--) {
      Step step = steps.get(i);
      PropertyDefn stepPropDefn = step.stepPropDefn;
      int index = step.index;

      Object stepValue = tmpElement.getLocalProperty(module, (ElementPropertyDefn) stepPropDefn);

      if (stepPropDefn.isListType()) {
        tmpElement = (DesignElement) ((List) stepValue).get(index);
      } else tmpElement = (DesignElement) stepValue;
    }

    return tmpElement;
  }
예제 #10
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();
 }
예제 #11
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.birt.report.model.core.namespace.INameHelper#getUniqueName
   * (org.eclipse.birt.report.model.core.DesignElement, java.lang.String)
   */
  public String getUniqueName(int namespaceId, DesignElement element, String namePrefix) {
    if (element == null) return null;

    ElementDefn eDefn = (ElementDefn) element.getDefn();

    String name = element.getName();
    if (StringUtil.isBlank(name)) {
      // Use the given prefix if the element name is null
      name = namePrefix;
    }

    name = StringUtil.trimString(name);
    // replace all the illegal chars with '_'
    name = NamePropertyType.validateName(name);

    // Some elements can have a blank name.
    if (eDefn.getNameOption() == MetaDataConstants.NO_NAME) return null;

    if (eDefn.getNameOption() == MetaDataConstants.OPTIONAL_NAME
        && name == null
        && module instanceof ReportDesign) return null;

    if (module instanceof Library
        && element instanceof StyleElement
        && element.getContainer() == null
        && name != null) {
      return name;
    }

    // If the element already has a unique name, return it.
    NameSpace nameSpace = getCachedNameSpace(namespaceId);
    List<String> cachedContentNames = getCachedContentNames(namespaceId);
    NameSpace moduleNameSpace = nameContexts[namespaceId].getNameSpace();

    String validName = name;
    if (element instanceof StyleElement)
      validName = validName == null ? null : validName.toLowerCase();
    if (validName != null
        && isValidInNameSpace(nameSpace, element, validName)
        && isValidInNameSpace(moduleNameSpace, element, validName)
        && !cachedContentNames.contains(validName)) return name;

    // If the element has no name, create it as "New<new name>" where
    // "<new name>" is the new element display name for the element. Both
    // "New" and the new element display name are localized to the user's
    // locale.

    if (name == null) {
      // When creating a new report element which requires a name, the
      // default name will be "New" followed by the element name, such as
      // "New Label"; also, if "NewLabel" already exists, then a number
      // will be appended, such as "NewLabel1", etc.

      if (element instanceof ExtendedItem) {
        ExtensionElementDefn extDefn = ((ExtendedItem) element).getExtDefn();

        PeerExtensionElementDefn peerDefn = (PeerExtensionElementDefn) extDefn;
        IReportItemFactory peerFactory = peerDefn.getReportItemFactory();

        assert peerFactory != null;

        String extensionDefaultName = null;
        IMessages msgs = peerFactory.getMessages();
        if (msgs != null)
          extensionDefaultName =
              msgs.getMessage((String) extDefn.getDisplayNameKey(), module.getLocale());

        if (StringUtil.isBlank(extensionDefaultName)) extensionDefaultName = peerDefn.getName();

        name = ModelMessages.getMessage(MessageConstants.NAME_PREFIX_NEW_MESSAGE);

        name = name + extensionDefaultName;

      } else {
        name =
            ModelMessages.getMessage(
                "New." //$NON-NLS-1$
                    + element.getDefn().getName());
        name = name.trim();
      }
    }

    // Add a numeric suffix that makes the name unique.

    int index = 0;
    String baseName = name;
    validName = name;
    if (element instanceof StyleElement)
      validName = validName == null ? null : validName.toLowerCase();
    while (nameSpace.contains(validName)
        || moduleNameSpace.contains(validName)
        || cachedContentNames.contains(validName)) {
      name = baseName + ++index;
      validName = name;
      if (element instanceof StyleElement)
        validName = validName == null ? null : validName.toLowerCase();
    }

    return name;
  }