Package org.pentaho.reporting.engine.classic.core.metadata

Examples of org.pentaho.reporting.engine.classic.core.metadata.AttributeMetaData


        if (ex == null)
        {
          continue;
        }

        final AttributeMetaData attribute = metaData.getAttributeDescription(namespace, name);
        if (attribute != null && attribute.isDesignTimeValue())
        {
          continue;
        }

        retval = true;
        ex.setRuntime(getRuntime());
        try
        {
          final Object value = evaluate(ex);
          if (attribute == null)
          {
            // Not a declared attribute, but maybe one of the output-handlers can work on this one.
            e.setAttribute(namespace, name, value);
          }
          else
          {
            final Class<?> type = attribute.getTargetType();
            if (value == null || type.isAssignableFrom(value.getClass()))
            {
              e.setAttribute(namespace, name, value);
            }
            else if (value instanceof ErrorValue)
            {
              if (failOnErrors)
              {
                throw new InvalidReportStateException(String.format
                    ("Failed to evaluate attribute-expression for attribute %s:%s on element [%s]", // NON-NLS
                        namespace, name,
                        FunctionUtilities.computeElementLocation(e)));
              }
              e.setAttribute(namespace, name, null);
            }
            else
            {

              final PropertyEditor propertyEditor = attribute.getEditor();
              if (propertyEditor != null)
              {
                propertyEditor.setAsText(String.valueOf(value));
                e.setAttribute(namespace, name, propertyEditor.getValue());
              }
View Full Code Here


        {
          continue;
        }


        final AttributeMetaData attrMeta = type.getMetaData().getAttributeDescription(namespace, name);
        if (attrMeta == null)
        {
          // if you want to use attributes in this output target, declare the attribute's metadata first.
          continue;
        }

        final AttributeList attList = new AttributeList();
        if (value instanceof String)
        {
          final String s = (String) value;
          if (StringUtils.isEmpty(s))
          {
            continue;
          }

          if (xmlWriter.isNamespaceDefined(namespace) == false &&
              attList.isNamespaceUriDefined(namespace) == false)
          {
            attList.addNamespaceDeclaration("autoGenNs", namespace);
          }

          // preserve strings, but discard anything else. Until a attribute has a definition, we cannot
          // hope to understand the attribute's value. String-attributes can be expressed in XML easily,
          // and string is also how all unknown attributes are stored by the parser.
          attList.setAttribute(namespace, name, s);
          this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList, XmlWriter.CLOSE);
          continue;
        }

        if (xmlWriter.isNamespaceDefined(namespace) == false &&
            attList.isNamespaceUriDefined(namespace) == false)
        {
          attList.addNamespaceDeclaration("autoGenNs", namespace);
        }

        try
        {
          final PropertyEditor propertyEditor = attrMeta.getEditor();
          final String textValue;
          if (propertyEditor != null)
          {
            propertyEditor.setValue(value);
            textValue = propertyEditor.getAsText();
          }
          else
          {
            textValue = ConverterRegistry.toAttributeValue(value);
          }

          if (textValue != null)
          {
            if ("".equals(textValue) == false)
            {
              attList.setAttribute(namespace, name, textValue);
              this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList, XmlWriter.CLOSE);
            }
          }
          else
          {
            if (value instanceof ResourceKey)
            {
              final ResourceKey reskey = (ResourceKey) value;
              final String identifierAsString = reskey.getIdentifierAsString();
              attList.setAttribute(namespace, name, "resource-key:" + reskey.getSchema() + ":" + identifierAsString);
              this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList, XmlWriter.CLOSE);
            }
            else
            {
              XmlDocumentWriter.logger.debug(
                  "Attribute '" + namespace + '|' + name + "' is not convertible to a text - returned null: " + value);
            }
          }
        }
        catch (BeanException e)
        {
          if (attrMeta.isTransient() == false)
          {
            XmlDocumentWriter.logger.warn(
                "Attribute '" + namespace + '|' + name + "' is not convertible with the bean-methods");
          }
          else
View Full Code Here

  private void setAttributeValue(final ReportElement element,
                                 final String namespace,
                                 final String name,
                                 final String attributeValue,
                                 final ReportAttributeMap attributes) throws ParseException {
    final AttributeMetaData attributeMetaData = metaData.getAttributeDescription(namespace, name);
    if (attributeMetaData == null || attributeValue == null) {
      element.setAttribute(namespace, name, attributeValue);
      return;
    }

    if (attributeMetaData.isTransient()) {
      return;
    }

    if (isFiltered(attributeMetaData)) {
      return;
    }

    if (ElementMetaData.VALUEROLE_RESOURCE.equals(attributeMetaData.getValueRole())) {
      try {
        final Object type = attributes.getAttribute(AttributeNames.Core.NAMESPACE, "resource-type");
        if ("url".equals(type)) {
          element.setAttribute(namespace, name, new URL(attributeValue));
          return;
        }
        if ("file".equals(type)) {
          element.setAttribute(namespace, name, new File(attributeValue));
          return;
        }
        if ("local-ref".equals(type)) {
          element.setAttribute(namespace, name, attributeValue);
          return;
        }
        if ("resource-key".equals(type)) {
          final ResourceManager resourceManager = getRootHandler().getResourceManager();
          final ResourceKey key = getRootHandler().getContext();
          final ResourceKey parent = key.getParent();
          final ResourceKey valueKey = resourceManager.deserialize(parent, attributeValue);

          // make local ..
          final ResourceKey resourceKey = localizeKey(resourceManager, valueKey);
          element.setAttribute(namespace, name, resourceKey);
          return;
        }
        element.setAttribute(namespace, name, attributeValue);
        return;
      } catch (MalformedURLException e) {
        throw new ParseException("Failed to parse URL value", e);
      } catch (ResourceKeyCreationException e) {
        throw new ParseException("Failed to parse resource-key value", e);
      }
    }

    final Class type = attributeMetaData.getTargetType();
    if (String.class.equals(type)) {
      element.setAttribute(namespace, name, attributeValue);
    } else {
      try {
        final PropertyEditor propertyEditor = attributeMetaData.getEditor();
        if (propertyEditor != null) {
          propertyEditor.setAsText(attributeValue);
          element.setAttribute(namespace, name, propertyEditor.getValue());
        } else {
          final ConverterRegistry instance = ConverterRegistry.getInstance();
View Full Code Here

            value instanceof ResourceKey)
        {
          continue;
        }

        final AttributeMetaData attrMeta = type.getMetaData().getAttributeDescription(namespace, name);
        if (attrMeta == null)
        {
          // if you want to use attributes in this output target, declare the attribute's metadata first.
          continue;
        }

        final AttributeList attList = new AttributeList();
        if (value instanceof String)
        {
          final String s = (String) value;
          if (StringUtils.isEmpty(s))
          {
            continue;
          }

          if (xmlWriter.isNamespaceDefined(namespace) == false &&
              attList.isNamespaceUriDefined(namespace) == false)
          {
            attList.addNamespaceDeclaration("autoGenNs", namespace);
          }

          // preserve strings, but discard anything else. Until a attribute has a definition, we cannot
          // hope to understand the attribute's value. String-attributes can be expressed in XML easily,
          // and string is also how all unknown attributes are stored by the parser.
          attList.setAttribute(namespace, name, String.valueOf(value));
          this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList, XmlWriter.CLOSE);
          continue;
        }

        if (xmlWriter.isNamespaceDefined(namespace) == false &&
            attList.isNamespaceUriDefined(namespace) == false)
        {
          attList.addNamespaceDeclaration("autoGenNs", namespace);
        }

        try
        {
          final PropertyEditor propertyEditor = attrMeta.getEditor();
          final String textValue;
          if (propertyEditor != null)
          {
            propertyEditor.setValue(value);
            textValue = propertyEditor.getAsText();
          }
          else
          {
            textValue = ConverterRegistry.toAttributeValue(value);
          }

          if (textValue != null)
          {
            if ("".equals(textValue) == false)
            {
              attList.setAttribute(namespace, name, textValue);
              this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList, XmlWriter.CLOSE);
            }
          }
          else
          {
            if (value instanceof ResourceKey)
            {
              final ResourceKey reskey = (ResourceKey) value;
              final String identifierAsString = reskey.getIdentifierAsString();
              attList.setAttribute(namespace, name, "resource-key:" + reskey.getSchema() + ":" + identifierAsString);
              this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList, XmlWriter.CLOSE);
            }
            else
            {
              XmlDocumentWriter.logger.debug(
                  "Attribute '" + namespace + '|' + name + "' is not convertible to a text - returned null: " + value);
            }
          }
        }
        catch (BeanException e)
        {
          if (attrMeta.isTransient() == false)
          {
            XmlDocumentWriter.logger.warn(
                "Attribute '" + namespace + '|' + name + "' is not convertible with the bean-methods");
          }
          else
View Full Code Here

    final ElementType type = element.getElementType();
    final ElementMetaData data = type.getMetaData();
    final AttributeMetaData[] datas = data.getAttributeDescriptions();
    for (int i = 0; i < datas.length; i++)
    {
      final AttributeMetaData attributeMetaData = datas[i];
      if (attributeMetaData.isTransient())
      {
        continue;
      }
      if (isFiltered(attributeMetaData))
      {
        continue;
      }

      final Object attValue = element.getAttribute(attributeMetaData.getNameSpace(), attributeMetaData.getName());
      if (attValue == null)
      {
        continue;
      }
      final ResourceReference[] referencedResources = attributeMetaData.getReferencedResources
          (element, state.getMasterReport().getResourceManager(), attValue);
      for (int j = 0; j < referencedResources.length; j++)
      {
        final ResourceReference reference = referencedResources[j];
        if (reference.isLinked())
View Full Code Here

        if (value == null)
        {
          continue;
        }

        final AttributeMetaData attrMeta = metaData.getAttributeDescription(namespace, name);
        if (attrMeta == null)
        {
          if (value instanceof String)
          {
            ensureNamespaceDefined(writer, attList, namespace);

            // preserve strings, but discard anything else. Until a attribute has a definition, we cannot
            // hope to understand the attribute's value. String-attributes can be expressed in XML easily,
            // and string is also how all unknown attributes are stored by the parser.
            attList.setAttribute(namespace, name, String.valueOf(value));
          }
          continue;
        }

        if (attrMeta.isTransient())
        {
          continue;
        }
        if (isFiltered(attrMeta))
        {
          continue;
        }
        if (attrMeta.isBulk())
        {
          continue;
        }

        ensureNamespaceDefined(writer, attList, namespace);
        try
        {
          final PropertyEditor propertyEditor = attrMeta.getEditor();
          if (propertyEditor != null)
          {
            propertyEditor.setValue(value);
            attList.setAttribute(namespace, name, propertyEditor.getAsText());
          }
View Full Code Here

        if (value == null)
        {
          continue;
        }

        final AttributeMetaData attrMeta = metaData.getAttributeDescription(namespace, name);
        if (attrMeta == null)
        {
          continue;
        }

        if (attrMeta.isTransient())
        {
          continue;
        }
        if (isFiltered(attrMeta))
        {
          continue;
        }
        if (attrMeta.isBulk() == false)
        {
          continue;
        }

        if ("Resource".equals(attrMeta.getValueRole()))
        {
          final AttributeList attList = new AttributeList();
          if (attList.isNamespaceUriDefined(namespace) == false &&
              writer.isNamespaceDefined(namespace) == false)
          {
            attList.addNamespaceDeclaration("autoGenNS", namespace);
          }

          if (value instanceof URL)
          {
            attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "url");
            writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
            writer.writeTextNormalized(String.valueOf(value), true);
            writer.writeCloseTag();
          }
          else if (value instanceof ResourceKey)
          {
            try
            {
              final ResourceKey key = (ResourceKey) value;
              final ResourceManager resourceManager = bundle.getResourceManager();
              final ResourceKey bundleKey = bundle.getBundleKey().getParent();
              final String serializedKey = resourceManager.serialize(bundleKey, key);
              attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "resource-key");
              writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
              writer.writeTextNormalized(serializedKey, true);
              writer.writeCloseTag();
            }
            catch (ResourceException re)
            {
              logger.error("Could not serialize the ResourceKey: " + re.getMessage(), re);
              throw new IOException("Could not serialize the ResourceKey: ", re);
            }
          }
          else if (value instanceof File)
          {
            attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "file");
            writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
            writer.writeTextNormalized(String.valueOf(value), true);
            writer.writeCloseTag();
          }
          else if (value instanceof String)
          {
            attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "local-ref");
            writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
            writer.writeTextNormalized(String.valueOf(value), true);
            writer.writeCloseTag();
          }
          else
          {
            logger.warn("Unknown value-type in resource-attribute " + namespace + ":" + name);
          }

          continue;
        }

        if ("Expression".equals(attrMeta.getValueRole()) && value instanceof Expression)
        {
          // write attribute-expressions.
          final AttributeList attList = new AttributeList();
          attList.setAttribute(BundleNamespaces.LAYOUT, "attribute-namespace", namespace);
          attList.setAttribute(BundleNamespaces.LAYOUT, "attribute-name", name);
          ExpressionWriterUtility.writeExpressionCore
              (bundle, state, (Expression) value, writer, BundleNamespaces.LAYOUT, "expression", attList);
          continue;
        }

        try
        {
          final PropertyEditor propertyEditor = attrMeta.getEditor();
          if (propertyEditor != null)
          {

            propertyEditor.setValue(value);
            final String text = propertyEditor.getAsText();

            final AttributeList attList = new AttributeList();
            if (attList.isNamespaceUriDefined(namespace) == false &&
                writer.isNamespaceDefined(namespace) == false)
            {
              attList.addNamespaceDeclaration("autoGenNS", namespace);
            }
            writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
            writer.writeTextNormalized(text, true);
            writer.writeCloseTag();
          }
          else
          {
            final String attrValue = ConverterRegistry.toAttributeValue(value);
            final AttributeList attList = new AttributeList();
            if (attList.isNamespaceUriDefined(namespace) == false &&
                writer.isNamespaceDefined(namespace) == false)
            {
              attList.addNamespaceDeclaration("autoGenNS", namespace);
            }
            writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
            writer.writeTextNormalized(attrValue, true);
            writer.writeCloseTag();
          }

        }
View Full Code Here

      // Process the attributes if they are a resource key
      final ElementMetaData metaData = element.getMetaData();
      final AttributeMetaData[] attributeDescriptions = metaData.getAttributeDescriptions();
      for (int j = 0; j < attributeDescriptions.length; j++)
      {
        final AttributeMetaData attributeDescription = attributeDescriptions[j];
        if ("Resource".equals(attributeDescription.getValueRole()) == false)
        {
          continue;
        }

        final Object attribute = element.getAttribute(attributeDescription.getNameSpace(), attributeDescription.getName());
        if (attribute instanceof ResourceKey == false)
        {
          continue;
        }

        final ResourceKey resourceKey = (ResourceKey) attribute;
        final ResourceKey replacementKey = processResourceKeyAttribute(documentBundle, report, resourceKey);
        if (replacementKey != null)
        {
          element.setAttribute(attributeDescription.getNameSpace(), attributeDescription.getName(), replacementKey);
        }
      }
    }
  }
View Full Code Here

    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");
        }
      }
    }
  }
View Full Code Here

  public void testRegisterAttribute ()
  {
    final ElementMetaData metaData =
        ElementTypeRegistry.getInstance().getElementType(LabelType.INSTANCE.getMetaData().getName());
    final AttributeMetaData attrMeta = metaData.getAttributeDescription("namespace", "Name");
    assertNull(attrMeta);

    final AttributeRegistry attributeRegistry =
        ElementTypeRegistry.getInstance().getAttributeRegistry(LabelType.INSTANCE);

    final DefaultAttributeMetaData m = new DefaultAttributeMetaData
        ("namespace", "Name", BUNDLE_LOCATION, "prefix",
            String.class, false, ClassicEngineBoot.computeCurrentVersionId());
    attributeRegistry.putAttributeDescription(m);

    final AttributeMetaData attributeDescription = metaData.getAttributeDescription("namespace", "Name");
    assertEquals("prefix", attributeDescription.getKeyPrefix());
    assertEquals(BUNDLE_LOCATION, attributeDescription.getBundleLocation());
  }
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.engine.classic.core.metadata.AttributeMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.