Example #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));
    }
  }
Example #2
0
  /**
   * Returns the attributes of the element as unmodifable collection. The collection can be safely
   * stored as it is guaranteed to never change. (However, no assumptions are made about the
   * contents inside the collection.)
   *
   * @return the unmodifiable attribute collection
   */
  public ReportAttributeMap<Object> getAttributes() {
    if (cachedAttributes != null) {
      if (cachedAttributes.getChangeTracker() == attributes.getChangeTracker()) {
        return cachedAttributes;
      }
    }

    cachedAttributes = attributes.createUnmodifiableMap();
    return cachedAttributes;
  }
Example #3
0
  /**
   * Clones this Element, the datasource and the private stylesheet of this Element. The clone does
   * no longer have a parent, as the old parent would not recognize that new object anymore.
   *
   * @return a clone of this Element.
   */
  public Element clone() {
    try {
      final Element e = (Element) super.clone();
      e.style = (InternalElementStyleSheet) style.clone();
      e.datasource = datasource.clone();
      e.parent = null;
      e.style.updateElementReference(e);
      e.elementContext = null;

      if (attributeExpressions != null) {
        e.attributes = attributes.clone();
        e.attributeExpressions = attributeExpressions.clone();
        final String[] namespaces = e.attributeExpressions.getNameSpaces();
        for (int i = 0; i < namespaces.length; i++) {
          final String namespace = namespaces[i];
          final Map<String, Expression> attrsNs = attributeExpressions.getAttributes(namespace);
          for (final Map.Entry<String, Expression> entry : attrsNs.entrySet()) {
            final Expression exp = entry.getValue();
            e.attributeExpressions.setAttribute(
                namespace, entry.getKey(), (Expression) exp.clone());
          }
        }
      } else {
        if (e.cachedAttributes != null) {
          e.attributes = attributes;
          e.copyOnWrite = true;
          copyOnWrite = true;
        } else {
          e.copyOnWrite = false;
          e.attributes = attributes.clone();
        }
      }

      if (styleExpressions != null) {
        e.styleExpressions = (HashMap<StyleKey, Expression>) styleExpressions.clone();
        for (final Map.Entry<StyleKey, Expression> entry : e.styleExpressions.entrySet()) {
          final Expression exp = entry.getValue();
          entry.setValue((Expression) exp.clone());
        }
      }
      return e;
    } catch (CloneNotSupportedException cne) {
      throw new IllegalStateException(cne);
    }
  }
Example #4
0
  public void copyAttributes(final ReportAttributeMap<Object> attributes) {
    //noinspection unchecked
    this.attributes.putAll(attributes);
    this.cachedAttributes = null;

    final Object value =
        attributes.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.ELEMENT_TYPE);
    if (value instanceof ElementType) {
      this.elementType = (ElementType) value;
    } else {
      this.elementType = LegacyType.INSTANCE;
    }
  }
Example #5
0
  /**
   * A helper method that serializes the element object.
   *
   * @param stream the stream to which the element should be serialized.
   * @throws IOException if an IO error occured or a property was not serializable.
   */
  private void writeObject(final ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    final ReportAttributeMap attributes = this.attributes;
    stream.writeLong(attributes.getChangeTracker());
    final String[] nameSpaces = attributes.getNameSpaces();
    stream.writeObject(nameSpaces);
    for (int i = 0; i < nameSpaces.length; i++) {
      final String nameSpace = nameSpaces[i];
      final String[] names = attributes.getNames(nameSpace);
      stream.writeObject(names);
      for (int j = 0; j < names.length; j++) {
        final String name = names[j];
        final Object attribute = attributes.getAttribute(nameSpace, name);

        final AttributeMetaData data = getMetaData().getAttributeDescription(nameSpace, name);
        if (data != null) {
          if (data.isTransient()) {
            stream.writeByte(1);
            continue;
          }

          if (attribute instanceof ResourceKey) {
            final ResourceKey key = (ResourceKey) attribute;
            final ResourceKey parent = key.getParent();
            if (AttributeNames.Core.NAMESPACE.equals(nameSpace)
                && (AttributeNames.Core.CONTENT_BASE.equals(name)
                    || AttributeNames.Core.SOURCE.equals(name))) {
              if (parent != null) {
                // unwrap the content base attribute. After deserialization, the report assumes the
                // bundle-location
                // as content base, as the bundle will be gone.
                if (isKeySerializable(parent)) {
                  stream.writeByte(0);
                  SerializerHelper.getInstance().writeObject(parent, stream);
                } else {
                  stream.writeByte(1);
                }
              } else {
                // great, the report was never part of a bundle. That makes life easier and the key
                // should be
                // safely serializable too.

                if (isKeySerializable(key)) {
                  stream.writeByte(0);
                  SerializerHelper.getInstance().writeObject(key, stream);
                } else {
                  stream.writeByte(1);
                }
              }
            } else {
              if ("Resource".equals(data.getValueRole()) || parent != null) {
                stream.writeByte(0);
                try {
                  final ResourceKey resourceKey =
                      ResourceKeyUtils.embedResourceInKey(
                          locateResourceManager(), key, key.getFactoryParameters());
                  SerializerHelper.getInstance().writeObject(resourceKey, stream);
                } catch (ResourceException e) {
                  throw new IOException("Failed to convert resource-key into byte-array key: " + e);
                }
              } else {
                stream.writeByte(0);
                SerializerHelper.getInstance().writeObject(attribute, stream);
              }
            }
          } else if (SerializerHelper.getInstance().isSerializable(attribute)) {
            stream.writeByte(0);
            SerializerHelper.getInstance().writeObject(attribute, stream);
          } else {
            stream.writeByte(1);
          }
        } else if (attribute instanceof String) {
          stream.writeByte(0);
          SerializerHelper.getInstance().writeObject(attribute, stream);
        } else {
          stream.writeByte(1);
        }
      }
    }
  }
Example #6
0
  /**
   * Creates a deep copy of this element and regenerates all instance-ids.
   *
   * @param preserveElementInstanceIds defines whether this call generates new instance-ids for the
   *     derived elements. Instance-IDs are used by the report processor to recognize reoccurring
   *     elements and must not changed within the report run. Outside of the report processors new
   *     instance ids should be generated at all times to separate instances and to make them
   *     uniquely identifiable.
   * @return the copy of the element.
   */
  public Element derive(final boolean preserveElementInstanceIds) {
    try {
      final Element e = (Element) super.clone();
      e.elementContext = null;
      if (preserveElementInstanceIds == false) {
        e.treeLock = new InstanceID();
      }

      e.style = (InternalElementStyleSheet) style.derive(preserveElementInstanceIds);
      e.datasource = datasource.clone();
      e.parent = null;
      e.style.updateElementReference(e);
      e.attributes = attributes.clone();
      e.copyOnWrite = false;
      final ElementMetaData metaData = e.getMetaData();
      final String[] namespaces = e.attributes.getNameSpaces();
      for (int i = 0; i < namespaces.length; i++) {
        final String namespace = namespaces[i];
        final Map attrsNs = attributes.getAttributes(namespace);
        final Iterator it = attrsNs.entrySet().iterator();
        while (it.hasNext()) {
          final Map.Entry entry = (Map.Entry) it.next();
          final Object value = entry.getValue();

          final String name = (String) entry.getKey();
          final AttributeMetaData data = metaData.getAttributeDescription(namespace, name);
          if (data == null) {
            if (logger.isDebugEnabled()) {
              logger.debug(
                  getElementTypeName()
                      + ": Attribute "
                      + namespace
                      + "|"
                      + name
                      + " is not listed in the metadata.");
            }
          }
          if (value instanceof Cloneable) {
            e.attributes.setAttribute(namespace, name, ObjectUtilities.clone(value));
          } else if (data == null || data.isComputed() == false || data.isDesignTimeValue()) {
            e.attributes.setAttribute(namespace, name, value);
          } else {
            e.attributes.setAttribute(namespace, name, null);
          }
        }
      }
      if (e.cachedAttributes != null
          && e.attributes.getChangeTracker() != e.cachedAttributes.getChangeTracker()) {
        e.cachedAttributes = null;
      }

      if (attributeExpressions != null) {
        e.attributeExpressions = attributeExpressions.clone();
        final String[] attrExprNamespaces = e.attributeExpressions.getNameSpaces();
        for (int i = 0; i < attrExprNamespaces.length; i++) {
          final String namespace = attrExprNamespaces[i];
          final Map attrsNs = attributeExpressions.getAttributes(namespace);
          final Iterator it = attrsNs.entrySet().iterator();
          while (it.hasNext()) {
            final Map.Entry entry = (Map.Entry) it.next();
            final Expression exp = (Expression) entry.getValue();
            e.attributeExpressions.setAttribute(
                namespace, (String) entry.getKey(), exp.getInstance());
          }
        }
      }

      if (styleExpressions != null) {
        //noinspection unchecked
        e.styleExpressions = (HashMap<StyleKey, Expression>) styleExpressions.clone();
        final Iterator<Map.Entry<StyleKey, Expression>> styleExpressionsIt =
            e.styleExpressions.entrySet().iterator();
        while (styleExpressionsIt.hasNext()) {
          final Map.Entry<StyleKey, Expression> entry = styleExpressionsIt.next();
          final Expression exp = entry.getValue();
          entry.setValue(exp.getInstance());
        }
      }
      return e;
    } catch (CloneNotSupportedException cne) {
      throw new IllegalStateException(cne);
    }
  }
Example #7
0
 public <TS> TS getAttributeTyped(
     final String namespace, final String attribute, final Class<TS> filter) {
   return attributes.getAttributeTyped(namespace, attribute, filter);
 }
Example #8
0
 public String[] getAttributeNames(final String namespace) {
   return attributes.getNames(namespace);
 }
Example #9
0
 public String[] getAttributeNamespaces() {
   return attributes.getNameSpaces();
 }
Example #10
0
 public Object getFirstAttribute(final String localName) {
   return attributes.getFirstAttribute(localName);
 }
Example #11
0
 public Object getAttribute(final String namespace, final String name) {
   return attributes.getAttribute(namespace, name);
 }
Example #12
0
 public String[] getAttributeExpressionNames(final String name) {
   if (attributeExpressions == null) {
     return Element.EMPTY_NAMES;
   }
   return attributeExpressions.getNames(name);
 }
Example #13
0
 public String[] getAttributeExpressionNamespaces() {
   if (attributeExpressions == null) {
     return Element.EMPTY_NAMES;
   }
   return attributeExpressions.getNameSpaces();
 }
Example #14
0
 public Expression getAttributeExpression(final String namespace, final String name) {
   if (attributeExpressions == null) {
     return null;
   }
   return attributeExpressions.getAttribute(namespace, name);
 }