Ejemplo n.º 1
0
  public void setAttribute(
      final String namespace, final String name, final Object value, final boolean notifyChange) {
    if (copyOnWrite) {
      this.attributes = attributes.clone();
      this.copyOnWrite = false;
    }

    final Object oldValue = attributes.setAttribute(namespace, name, value);
    if (cachedAttributes != null) {
      if (cachedAttributes.getChangeTracker() != attributes.getChangeTracker()) {
        cachedAttributes = null;
      }
    }
    if (AttributeNames.Core.NAMESPACE.equals(namespace)
        && AttributeNames.Core.ELEMENT_TYPE.equals(name)) {
      if (value instanceof ElementType) {
        this.elementType = (ElementType) value;
      } else {
        this.elementType = LegacyType.INSTANCE;
      }
    }

    if (notifyChange) {
      notifyNodePropertiesChanged(new AttributeChange(namespace, name, oldValue, value));
    }
  }
Ejemplo n.º 2
0
  public void copyInto(final Element target) {
    final ElementMetaData metaData = getMetaData();
    final String[] attributeNamespaces = getAttributeNamespaces();
    for (int i = 0; i < attributeNamespaces.length; i++) {
      final String namespace = attributeNamespaces[i];
      final String[] attributeNames = getAttributeNames(namespace);
      for (int j = 0; j < attributeNames.length; j++) {
        final String name = attributeNames[j];
        final AttributeMetaData attributeDescription =
            metaData.getAttributeDescription(namespace, name);
        if (attributeDescription == null) {
          continue;
        }
        if (attributeDescription.isTransient()) {
          continue;
        }
        if (attributeDescription.isComputed()) {
          continue;
        }
        if (AttributeNames.Core.ELEMENT_TYPE.equals(name)
            && AttributeNames.Core.NAMESPACE.equals(namespace)) {
          continue;
        }
        target.setAttribute(namespace, name, getAttribute(namespace, name), false);
      }
    }

    final String[] attrExprNamespaces = getAttributeExpressionNamespaces();
    for (int i = 0; i < attrExprNamespaces.length; i++) {
      final String namespace = attrExprNamespaces[i];
      final String[] attributeNames = getAttributeExpressionNames(namespace);
      for (int j = 0; j < attributeNames.length; j++) {
        final String name = attributeNames[j];

        final AttributeMetaData attributeDescription =
            metaData.getAttributeDescription(namespace, name);
        if (attributeDescription == null) {
          continue;
        }
        if (attributeDescription.isTransient()) {
          continue;
        }
        target.setAttributeExpression(namespace, name, getAttributeExpression(namespace, name));
      }
    }

    final ElementStyleSheet styleSheet = getStyle();
    final StyleKey[] styleKeys = styleSheet.getDefinedPropertyNamesArray();
    for (int i = 0; i < styleKeys.length; i++) {
      final StyleKey styleKey = styleKeys[i];
      if (styleKey != null) {
        target.getStyle().setStyleProperty(styleKey, styleSheet.getStyleProperty(styleKey));
      }
    }

    final Set<Map.Entry<StyleKey, Expression>> styleExpressionEntries =
        getStyleExpressions().entrySet();
    for (final Map.Entry<StyleKey, Expression> entry : styleExpressionEntries) {
      target.setStyleExpression(entry.getKey(), entry.getValue());
    }
  }