public static void main(String[] args) {
    ClassicEngineBoot.getInstance().start();
    final TreeMap globalAttributes = new TreeMap();
    final ElementMetaData[] datas = ElementTypeRegistry.getInstance().getAllElementTypes();
    for (int i = 0; i < datas.length; i++) {
      final ElementMetaData data = datas[i];
      if (data instanceof AbstractMetaData == false) {
        continue;
      }
      printMetaBundle(data, globalAttributes);
    }
    System.out.println("-----------------------------------------------------");

    final Iterator iterator = globalAttributes.entrySet().iterator();
    while (iterator.hasNext()) {
      final Map.Entry o = (Map.Entry) iterator.next();

      final AttributeMetaData attribute = (AttributeMetaData) o.getValue();
      final AbstractMetaData aamd = (AbstractMetaData) attribute;
      final String akeyPrefix = aamd.getKeyPrefix();
      final String abundle = aamd.getBundleLocation();
      final String aname = attribute.getName();

      System.out.println(akeyPrefix + aname + ".display-name=" + aname);
      System.out.println(
          akeyPrefix + aname + ".grouping=" + filter(aamd.getGrouping(Locale.ENGLISH), "Group"));
      System.out.println(
          akeyPrefix + aname + ".description=" + filter(aamd.getDescription(Locale.ENGLISH), ""));
      System.out.println(
          akeyPrefix
              + aname
              + ".deprecated="
              + filter(aamd.getDeprecationMessage(Locale.ENGLISH), ""));
    }
  }
  private static void printMetaBundle(final ElementMetaData data, Map globalAttributes) {
    System.out.println("-----------------------------------------------------");
    final AbstractMetaData amd = (AbstractMetaData) data;
    final String keyPrefix = amd.getKeyPrefix();
    final String ename = amd.getName();
    final String ebundle = amd.getBundleLocation();

    System.out.println(keyPrefix + ename + ".display-name=" + ename);
    System.out.println(
        keyPrefix + ename + ".grouping=" + filter(amd.getGrouping(Locale.ENGLISH), "Group"));
    System.out.println(
        keyPrefix + ename + ".description=" + filter(amd.getDescription(Locale.ENGLISH), ""));
    System.out.println(
        keyPrefix + ename + ".deprecated=" + filter(amd.getDeprecationMessage(Locale.ENGLISH), ""));

    final AttributeMetaData[] attributes = data.getAttributeDescriptions();

    for (int j = 0; j < attributes.length; j++) {
      final AttributeMetaData attribute = attributes[j];
      final AbstractMetaData aamd = (AbstractMetaData) attribute;
      final String akeyPrefix = aamd.getKeyPrefix();
      final String abundle = aamd.getBundleLocation();
      final String aname = attribute.getName();
      if (abundle.equals(GLOBAL_BUNDLE) && akeyPrefix.startsWith("attribute.")) {
        globalAttributes.put(aname, attribute);
        continue;
      }
      System.out.println(akeyPrefix + aname + ".display-name=" + aname);
      System.out.println(
          akeyPrefix + aname + ".grouping=" + filter(aamd.getGrouping(Locale.ENGLISH), "Group"));
      System.out.println(
          akeyPrefix + aname + ".description=" + filter(aamd.getDescription(Locale.ENGLISH), ""));
      System.out.println(
          akeyPrefix
              + aname
              + ".deprecated="
              + filter(aamd.getDeprecationMessage(Locale.ENGLISH), ""));
    }

    System.out.println("-----------------------------------------------------");
  }
  private static void validateAttributeMetaData(
      final ElementMetaData metaData, final ArrayList<String> missingProperties) {
    final Locale locale = Locale.getDefault();
    final String typeName = metaData.getName();

    final AttributeMetaData[] attributeMetaDatas = metaData.getAttributeDescriptions();
    for (int j = 0; j < attributeMetaDatas.length; j++) {
      final AttributeMetaData propertyMetaData = attributeMetaDatas[j];
      final String propertyDisplayName = propertyMetaData.getDisplayName(locale);
      if (isValid(propertyDisplayName, propertyMetaData.getName(), missingProperties) == false) {
        logger.warn(
            "ElementType '"
                + typeName
                + ": Attr "
                + propertyMetaData.getName()
                + ": No DisplayName");
      }

      final String propertyGrouping = propertyMetaData.getGrouping(locale);
      if (isValid(propertyGrouping, "common", missingProperties) == false) {
        logger.warn(
            "ElementType '"
                + typeName
                + ": Attr "
                + propertyMetaData.getName()
                + ": Grouping is not valid");
      }
      if (propertyMetaData.isDeprecated()) {
        final String deprecateMessage = propertyMetaData.getDeprecationMessage(locale);
        if (isValid(deprecateMessage, "Deprecated", missingProperties) == false) {
          logger.warn(
              "ElementType '"
                  + typeName
                  + ": Attr "
                  + propertyMetaData.getName()
                  + ": No valid deprecate message");
        }
      }
    }
  }
示例#4
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);
        }
      }
    }
  }
示例#5
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);
    }
  }
示例#6
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());
    }
  }