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

Examples of org.pentaho.reporting.engine.classic.core.function.Expression


    final Iterator entries = styleExpressions.entrySet().iterator();
    while (entries.hasNext())
    {
      final Map.Entry entry = (Map.Entry) entries.next();
      final StyleKey key = (StyleKey) entry.getKey();
      final Expression ex = (Expression) entry.getValue();
      if (ex == null)
      {
        continue;
      }
      retval = true;
      ex.setRuntime(getRuntime());
      try
      {
        final Object value = evaluate(ex);
        if (value == null)
        {
          style.setStyleProperty(key, null);
        }
        else if (key.getValueType().isInstance(value))
        {
          style.setStyleProperty(key, value);
        }
        else if (value instanceof ErrorValue)
        {
          style.setStyleProperty(key, null);
        }
        else
        {
          final ValueConverter valueConverter = ConverterRegistry.getInstance().getValueConverter(key.getValueType());
          if (valueConverter != null)
          {
            // try to convert it ..
            final Object o = ConverterRegistry.toPropertyValue(String.valueOf(value), key.getValueType());
            style.setStyleProperty(key, o);
          }
          else
          {
            style.setStyleProperty(key, null);
          }
        }
      }
      catch (Exception exception)
      {
        // ignored, but we clear the style as we have no valid value anymore.
        style.setStyleProperty(key, null);
      }
      finally
      {
        ex.setRuntime(null);
      }
    }
    return retval;
  }
View Full Code Here


    if (expression == null)
    {
      return defaultValue;
    }

    final Expression evalExpression = expression.getInstance();

    final InlineDataRowRuntime runtime = new InlineDataRowRuntime();
    runtime.setState(this);
    final ExpressionRuntime oldRuntime = evalExpression.getRuntime();
    try
    {
      evalExpression.setRuntime(runtime);
      return evalExpression.getValue();
    }
    catch (Exception e)
    {
      logger.debug("Failed to evaluate expression " + expression);
      return defaultValue;
    }
    finally
    {
      evalExpression.setRuntime(oldRuntime);
    }
  }
View Full Code Here

    return (ReportPreProcessor[]) preProcessors.toArray(new ReportPreProcessor[preProcessors.size()]);
  }

  public boolean isSubReportExecutable()
  {
    final Expression expression =
        getReport().getAttributeExpression(AttributeNames.Core.NAMESPACE, AttributeNames.Core.SUBREPORT_ACTIVE);
    if (expression != null)
    {
      // the master-report state will only be non-null for subreports.
      final InlineDataRowRuntime dataRowRuntime = new InlineDataRowRuntime();
      dataRowRuntime.setState(this);
      expression.setRuntime(dataRowRuntime);
      try
      {
        final Object value = expression.getValue();
        // the expression has to explicitly return false as a value to disable the report processing of
        // subreports. Just returning null or a non-boolean value is not enough. This is a safety measure
        // so that if in doubt we print more data than to little.
        if (Boolean.FALSE.equals(value))
        {
          return false;
        }
        if ("false".equals(String.valueOf(value)))
        {
          return false;
        }
        return true;
      }
      finally
      {
        expression.setRuntime(null);
      }
    }
    return true;
  }
View Full Code Here

      final String namespace = namespaces[namespaceIdx];
      final String[] names = e.getAttributeExpressionNames(namespace);
      for (int nameIdx = 0; nameIdx < names.length; nameIdx++)
      {
        final String name = names[nameIdx];
        final Expression ex = e.getAttributeExpression(namespace, name);
        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)
            {
              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());
              }
              else
              {
                try
                {
                  final ValueConverter valueConverter = instance.getValueConverter(type);
                  if (type.isAssignableFrom(String.class))
                  {
                    // the attribute would allow raw-string values, so copy the element ..
                    e.setAttribute(namespace, name, value);
                  }
                  else if (valueConverter != null)
                  {
                    final Object o = ConverterRegistry.toPropertyValue(String.valueOf(value), type);
                    e.setAttribute(namespace, name, o);
                  }
                  else
                  {
                    // undo any previous computation
                    e.setAttribute(namespace, name, null);
                  }
                }
                catch (BeanException be)
                {
                  // ignore.
//                  AttributeExpressionsEvaluator.logger.debug("Attribute '" + namespace + '|' + name +
//                      "' is not convertible with the bean-methods for value " + value);
                  e.setAttribute(namespace, name, null);
                }
              }
            }
          }
        }
        catch (Exception exception)
        {
          // ignored .. but we unset the attribute as we have no valid value anymore ..
          e.setAttribute(namespace, name, null);
        }
        finally
        {
          ex.setRuntime(null);
        }
      }
    }
    return retval;
  }
View Full Code Here

    final ExpressionCollection expressions = reportDefinition.getExpressions();
    final Expression[] expressionsArray = expressions.getExpressions();
    for (int i = 0; i < expressionsArray.length; i++)
    {
      final Expression expression = expressionsArray[i];
      inspectExpression(designerContext, reportRenderContext, resultHandler, columnNames, expression);
    }

    inspectElement(designerContext, reportRenderContext, resultHandler, columnNames, reportDefinition);
    traverseSection(designerContext, reportRenderContext, resultHandler, columnNames, reportDefinition);
View Full Code Here

      final String attrExprNamespace = attrExprNamespaces[i];
      final String[] names = element.getAttributeExpressionNames(attrExprNamespace);
      for (int j = 0; j < names.length; j++)
      {
        final String name = names[j];
        final Expression expression = element.getAttributeExpression(attrExprNamespace, name);
        if (expression == null)
        {
          continue;
        }
        final String expressionName = expression.getClass().getName();
        if (ExpressionRegistry.getInstance().isExpressionRegistered(expressionName) == false)
        {
          inspectAttributeExpression(designerContext, reportRenderContext, resultHandler,
              columnNames, element, attrExprNamespace, name, expression, null);
        }
View Full Code Here

    final Map<StyleKey, Expression> map = element.getStyleExpressions();
    for (final Map.Entry<StyleKey, Expression> entry : map.entrySet())
    {
      final StyleKey styleKey = entry.getKey();
      final Expression expression = entry.getValue();

      if (expression == null)
      {
        continue;
      }
      final String expressionName = expression.getClass().getName();
      if (ExpressionRegistry.getInstance().isExpressionRegistered(expressionName) == false)
      {
        inspectStyleExpression(designerContext, reportRenderContext, resultHandler,
            columnNames, element, styleKey, expression, null);
      }
View Full Code Here

    }
  }

  private static Object insertExpression(final AbstractReportDefinition report, final Expression fromClipboard)
  {
    final Expression expression = (Expression) fromClipboard;
    final Expression instance = expression.getInstance();
    report.addExpression(instance);
    report.notifyNodeChildAdded(instance);
    return instance;
  }
View Full Code Here

    final AbstractReportDefinition report = context.getReportDefinition();
    final ExpressionCollection expressionCollection = report.getExpressions();
    final int count = expressionCollection.size();
    for (int i = 0; i < count; i++)
    {
      final Expression definitionEntry = expressionCollection.getExpression(i);
      if (definitionEntry == data)
      {
        expressionCollection.removeExpression(i);
        report.notifyNodeChildRemoved(definitionEntry);
        return new ExpressionRemoveUndoEntry(i, definitionEntry);
View Full Code Here

      final AbstractReportDefinition report = context.getReportDefinition();
      final ExpressionCollection expressionCollection = report.getExpressions();
      final int count = expressionCollection.size();
      for (int i = 0; i < count; i++)
      {
        final Expression definitionEntry = expressionCollection.getExpression(i);
        if (definitionEntry == data)
        {
          return definitionEntry.getInstance();
        }
      }
      return null;
    }
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.engine.classic.core.function.Expression

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.