private XmlReadHandler createReadHandler(String propertyName) throws ParseException {
   try {
     final ExpressionMetaData expressionMetaData =
         ExpressionRegistry.getInstance().getExpressionMetaData(expressionClass);
     final ExpressionPropertyMetaData propertyDescription =
         expressionMetaData.getPropertyDescription(propertyName);
     if (propertyDescription != null) {
       final Class<? extends UserDefinedExpressionPropertyReadHandler> propertyReadHandler =
           propertyDescription.getPropertyReadHandler();
       if (propertyReadHandler != null) {
         final UserDefinedExpressionPropertyReadHandler xmlReadHandler =
             propertyReadHandler.newInstance();
         xmlReadHandler.init(
             beanUtility, originalExpressionClass, expressionClass, expression.getName());
         return xmlReadHandler;
       }
     }
     return new ExpressionPropertyReadHandler(
         beanUtility, originalExpressionClass, expressionClass, expression.getName());
   } catch (MetaDataLookupException e) {
     return new ExpressionPropertyReadHandler(
         beanUtility, originalExpressionClass, expressionClass, expression.getName());
   } catch (Exception e) {
     throw new ParseException(
         "Unable to read metadata for property '" + propertyName + "'.", getLocator());
   }
 }
  private static void printMetaBundle(final ExpressionMetaData type) {
    System.out.println("# -----------------------------------------------------");
    System.out.println("# " + printBundleLocation(type));
    System.out.println("# -----------------------------------------------------");
    final String prefix = calculatePrefix(type);

    printMetadata(type, prefix, "display-name", type.getName());
    printMetadata(type, prefix, "grouping", "");
    printMetadata(type, prefix, "grouping.ordinal", "0");
    printMetadata(type, prefix, "ordinal", "0");
    printMetadata(type, prefix, "description", "");
    printMetadata(type, prefix, "deprecated", "");
    printMetadata(type, prefix, "icon", "");
    System.out.println();

    final ExpressionPropertyMetaData[] attributes = type.getPropertyDescriptions();
    Arrays.sort(attributes, GroupedMetaDataComparator.ENGLISH);

    for (int j = 0; j < attributes.length; j++) {
      final ExpressionPropertyMetaData attribute = attributes[j];
      final String propertyPrefix = calculatePrefix(attribute);

      printMetadata(attribute, propertyPrefix, "display-name", attribute.getName());
      printMetadata(attribute, propertyPrefix, "grouping", "");
      printMetadata(attribute, propertyPrefix, "grouping.ordinal", "0");
      printMetadata(attribute, propertyPrefix, "ordinal", "0");
      printMetadata(attribute, propertyPrefix, "description", "");
      printMetadata(attribute, propertyPrefix, "deprecated", "");
      System.out.println();
    }

    System.out.println("-----------------------------------------------------");
  }
  public void init() {
    if (initialized) {
      return;
    }
    initialized = true;
    final DefaultComboBoxModel<ExpressionMetaData> model =
        new DefaultComboBoxModel<ExpressionMetaData>();
    model.addElement(null);

    final ExpressionMetaData[] datas = ExpressionRegistry.getInstance().getAllExpressionMetaDatas();
    for (int i = 0; i < datas.length; i++) {
      final ExpressionMetaData expressionMetaData = datas[i];
      if (expressionMetaData.isHidden()) {
        continue;
      }
      if (WorkspaceSettings.getInstance().isShowExpertItems() == false
          && expressionMetaData.isExpert()) {
        continue;
      }
      if (WorkspaceSettings.getInstance().isShowDeprecatedItems() == false
          && expressionMetaData.isDeprecated()) {
        continue;
      }

      if (StructureFunction.class.isAssignableFrom(expressionMetaData.getExpressionType())) {
        model.addElement(expressionMetaData);
      }
    }
    expressionEditor.setModel(model);
  }
  public static void writeElementLayoutExpressions(
      final WriteableDocumentBundle bundle, final BundleWriterState state, final XmlWriter writer)
      throws IOException, BundleWriterException {
    if (state == null) {
      throw new NullPointerException();
    }
    if (writer == null) {
      throw new NullPointerException();
    }
    if (bundle == null) {
      throw new NullPointerException();
    }

    final ExpressionCollection exp = state.getReport().getExpressions();
    final ExpressionRegistry registry = ExpressionRegistry.getInstance();
    for (int i = 0; i < exp.size(); i++) {
      final Expression expression = exp.getExpression(i);
      if (registry.isExpressionRegistered(expression.getClass().getName()) == false) {
        continue;
      }

      final ExpressionMetaData emd =
          registry.getExpressionMetaData(expression.getClass().getName());
      if (emd.isElementLayoutProcessor()) {
        writeExpression(
            bundle, state, expression, writer, BundleNamespaces.LAYOUT, "expression"); // NON-NLS
      }
    }
  }
    private SelectChartExpressionAction(final Class expressionType) {
      this.expressionType = expressionType;

      final ExpressionRegistry expressionRegistry = ExpressionRegistry.getInstance();
      final ExpressionMetaData metaData =
          expressionRegistry.getExpressionMetaData(expressionType.getName());
      putValue(
          Action.NAME, metaData.getMetaAttribute("short-name", Locale.getDefault())); // NON-NLS

      final String defaultIcon = metaData.getMetaAttribute("icon", Locale.getDefault()); // NON-NLS
      if (defaultIcon != null) {
        final URL defaultIconUrl = LegacyChartEditorDialog.class.getResource(defaultIcon);
        if (defaultIconUrl != null) {
          standardIcon = new ImageIcon(defaultIconUrl);
          putValue(Action.SMALL_ICON, standardIcon);
        }
      }

      final String selectedIconProperty =
          metaData.getMetaAttribute("selected-icon", Locale.getDefault()); // NON-NLS
      if (selectedIconProperty != null) {
        final URL selectedIconUrl = LegacyChartEditorDialog.class.getResource(selectedIconProperty);
        if (selectedIconUrl != null) {
          selectedIcon = new ImageIcon(selectedIconUrl);
        }
      }
    }
 public void contentsChanged(final ListDataEvent e) {
   final ExpressionMetaData o =
       (ExpressionMetaData) editModel.getChartExpressionsModel().getSelectedItem();
   if (o != null && expressionType.equals(o.getExpressionType())) {
     putValue("selected", Boolean.TRUE); // NON-NLS
     putValue(Action.SMALL_ICON, selectedIcon);
   } else {
     putValue("selected", Boolean.FALSE); // NON-NLS
     putValue(Action.SMALL_ICON, standardIcon);
   }
 }
 private static ExpressionPropertyWriteHandler createWriteHandler(Expression e, String key) {
   try {
     final ExpressionMetaData expressionMetaData =
         ExpressionRegistry.getInstance().getExpressionMetaData(e.getClass().getName());
     final ExpressionPropertyMetaData propertyDescription =
         expressionMetaData.getPropertyDescription(key);
     final Class<? extends ExpressionPropertyWriteHandler> writeHandlerRef =
         propertyDescription.getPropertyWriteHandler();
     if (writeHandlerRef != null) {
       return writeHandlerRef.newInstance();
     }
   } catch (Exception ex) {
     logger.info("No valid property metadata defined for " + e.getClass() + " on property " + key);
   }
   return new DefaultExpressionPropertyWriteHandler();
 }
  private static String printBundleLocation(final ExpressionMetaData metaData) {
    if (metaData instanceof AbstractMetaData) {
      final AbstractMetaData metaDataImpl = (AbstractMetaData) metaData;
      return metaDataImpl.getBundleLocation().replace('.', '/') + ".properties";
    }

    return metaData.getExpressionType().getCanonicalName().replace('.', '/') + "Bundle.properties";
  }
 public Component getTreeCellRendererComponent(
     final JTree tree,
     final Object value,
     final boolean sel,
     final boolean expanded,
     final boolean leaf,
     final int row,
     final boolean hasFocus) {
   final JLabel rendererComponent =
       (JLabel)
           super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
   if (value instanceof ExpressionMetaData) {
     final ExpressionMetaData metaData = (ExpressionMetaData) value;
     rendererComponent.setText(metaData.getDisplayName(Locale.getDefault()));
     rendererComponent.setToolTipText(metaData.getDeprecationMessage(Locale.getDefault()));
   }
   return rendererComponent;
 }
    /** Invoked when an action occurs. */
    public void actionPerformed(final ActionEvent e) {
      final Window window = LibSwingUtil.getWindowAncestor(carrierPanel);
      final Object selectedItem = expressionEditor.getSelectedItem();
      if (selectedItem instanceof StructureFunction) {
        final ExpressionPropertiesDialog optionPane;
        if (window instanceof JFrame) {
          optionPane = new ExpressionPropertiesDialog((JFrame) window);
        } else if (window instanceof JDialog) {
          optionPane = new ExpressionPropertiesDialog((JDialog) window);
        } else {
          optionPane = new ExpressionPropertiesDialog();
        }
        final StructureFunction structureFunction = (StructureFunction) selectedItem;
        final StructureFunction expression =
            (StructureFunction) optionPane.editExpression(structureFunction, designerContext);
        if (expression != selectedItem) {
          expressionEditor.setSelectedItem(expression);
        }
        fireEditingStopped();
      } else if (selectedItem instanceof ExpressionMetaData) {
        try {
          final ExpressionMetaData emd = (ExpressionMetaData) selectedItem;
          final Expression expression = (Expression) emd.getExpressionType().newInstance();

          final ExpressionPropertiesDialog optionPane;
          if (window instanceof JFrame) {
            optionPane = new ExpressionPropertiesDialog((JFrame) window);
          } else if (window instanceof JDialog) {
            optionPane = new ExpressionPropertiesDialog((JDialog) window);
          } else {
            optionPane = new ExpressionPropertiesDialog();
          }

          final Expression resultexpression =
              optionPane.editExpression(expression, designerContext);
          if (resultexpression != expression) {
            expressionEditor.setSelectedItem(resultexpression);
          }
          fireEditingStopped();
        } catch (Throwable e1) {
          UncaughtExceptionsModel.getInstance().addException(e1);
        }
      }
    }
 /**
  * Returns the value contained in the editor.
  *
  * @return the value contained in the editor
  */
 public Object getCellEditorValue() {
   final Object o = this.expressionEditor.getSelectedItem();
   if (o instanceof ExpressionMetaData) {
     try {
       final ExpressionMetaData emd = (ExpressionMetaData) o;
       if (StructureFunction.class.isAssignableFrom(emd.getExpressionType())) {
         return emd.getExpressionType().newInstance();
       } else {
         return null;
       }
     } catch (Throwable t) {
       UncaughtExceptionsModel.getInstance().addException(t);
       return null;
     }
   } else if (o instanceof StructureFunction) {
     return o;
   } else {
     return null;
   }
 }
  public static boolean isElementLayoutExpressionActive(final BundleWriterState state) {
    if (state == null) {
      throw new NullPointerException();
    }

    final ExpressionCollection exp = state.getReport().getExpressions();
    final ExpressionRegistry registry = ExpressionRegistry.getInstance();
    for (int i = 0; i < exp.size(); i++) {
      final Expression expression = exp.getExpression(i);
      if (registry.isExpressionRegistered(expression.getClass().getName()) == false) {
        continue;
      }

      final ExpressionMetaData emd =
          registry.getExpressionMetaData(expression.getClass().getName());
      if (emd.isElementLayoutProcessor()) {
        return true;
      }
    }
    return false;
  }
  public static void writeExpressionCore(
      final WriteableDocumentBundle bundle,
      final BundleWriterState state,
      final Expression expression,
      final XmlWriter writer,
      final String namespaceUri,
      final String expressionTag,
      final AttributeList expressionAttrList)
      throws IOException, BundleWriterException {
    if (bundle == null) {
      throw new NullPointerException();
    }
    if (state == null) {
      throw new NullPointerException();
    }
    if (expression == null) {
      throw new NullPointerException();
    }
    if (writer == null) {
      throw new NullPointerException();
    }
    if (namespaceUri == null) {
      throw new NullPointerException();
    }
    if (expressionTag == null) {
      throw new NullPointerException();
    }
    if (expressionAttrList == null) {
      throw new NullPointerException();
    }

    if (expression instanceof FormulaExpression) {
      final FormulaExpression fe = (FormulaExpression) expression;
      if (StringUtils.isEmpty(fe.getFormula())) {
        return;
      }
      expressionAttrList.setAttribute(namespaceUri, "formula", fe.getFormula()); // NON-NLS
      writer.writeTag(namespaceUri, expressionTag, expressionAttrList, XmlWriterSupport.CLOSE);
      return;
    }

    if (expression instanceof FormulaFunction) {
      final FormulaFunction fe = (FormulaFunction) expression;
      if (StringUtils.isEmpty(fe.getFormula())) {
        return;
      }
      expressionAttrList.setAttribute(namespaceUri, "formula", fe.getFormula()); // NON-NLS
      expressionAttrList.setAttribute(namespaceUri, "initial", fe.getInitial()); // NON-NLS
      writer.writeTag(namespaceUri, expressionTag, expressionAttrList, XmlWriterSupport.CLOSE);
      return;
    }

    try {

      final String expressionId = expression.getClass().getName();
      expressionAttrList.setAttribute(namespaceUri, "class", expressionId);

      final ExpressionMetaData emd;
      if (ExpressionRegistry.getInstance().isExpressionRegistered(expressionId)) {
        emd = ExpressionRegistry.getInstance().getExpressionMetaData(expressionId);
      } else {
        emd = null;
      }

      if (emd != null) {
        final BeanUtility bu = new BeanUtility(expression);
        final ExpressionPropertyMetaData[] expressionProperties = emd.getPropertyDescriptions();
        boolean propertiesOpen = false;
        for (int i = 0; i < expressionProperties.length; i++) {
          final ExpressionPropertyMetaData metaData = expressionProperties[i];
          final String propertyName = metaData.getName();
          if (isFilteredProperty(propertyName)) {
            continue;
          }
          if (metaData.isComputed()) {
            continue;
          }
          if (propertiesOpen == false) {
            writer.writeTag(namespaceUri, expressionTag, expressionAttrList, XmlWriterSupport.OPEN);
            writer.writeTag(namespaceUri, "properties", XmlWriterSupport.OPEN); // NON-NLS
            propertiesOpen = true;
          }

          copyStaticResources(bundle, state, expression, bu, expressionProperties);
          writeExpressionParameter(
              bundle, state, writer, expression, bu, propertyName, namespaceUri);
        }

        if (propertiesOpen) {
          writer.writeCloseTag();
          writer.writeCloseTag();
        } else {
          writer.writeTag(namespaceUri, expressionTag, expressionAttrList, XmlWriterSupport.CLOSE);
        }
      } else {
        // the classic way, in case the expression does not provide any meta-data. This is
        // in the code for legacy reasons, as there are many expression implementations out there
        // that do not yet provide meta-data descriptions ..

        final BeanUtility beanUtility = new BeanUtility(expression);
        final String[] propertyNames = beanUtility.getProperties();

        for (int i = 0; i < propertyNames.length; i++) {
          final String key = propertyNames[i];
          // filter some of the standard properties. These are system-properties
          // and are set elsewhere
          if (isFilteredProperty(key)) {
            continue;
          }

          writeExpressionParameter(
              bundle, state, writer, expression, beanUtility, key, namespaceUri);
        }
      }
    } catch (IOException ioe) {
      throw ioe;
    } catch (Exception e) {
      throw new BundleWriterException("Unable to extract or write properties.", e);
    }
  }
  protected void inspectExpression(
      final ReportDesignerContext designerContext,
      final ReportRenderContext reportRenderContext,
      final InspectionResultListener resultHandler,
      final String[] columnNames,
      final Expression expression,
      final ExpressionMetaData expressionMetaData) {
    if (expressionMetaData == null) {
      return;
    }

    try {
      final BeanUtility utility = new BeanUtility(expression);
      final ExpressionPropertyMetaData[] datas = expressionMetaData.getPropertyDescriptions();
      for (int i = 0; i < datas.length; i++) {
        final ExpressionPropertyMetaData metaData = datas[i];
        if (metaData.isHidden()) {
          continue;
        }
        if (WorkspaceSettings.getInstance().isShowExpertItems() == false && metaData.isExpert()) {
          continue;
        }
        if (WorkspaceSettings.getInstance().isShowDeprecatedItems() == false
            && metaData.isDeprecated()) {
          continue;
        }

        if (!"ElementName".equals(metaData.getPropertyRole())) // NON-NLS
        {
          continue;
        }

        final Object o = utility.getProperty(metaData.getName());
        final String[] elements = metaData.getReferencedElements(expression, o);
        for (int j = 0; j < elements.length; j++) {
          final String element = elements[j];
          final AbstractReportDefinition reportDefinition =
              reportRenderContext.getReportDefinition();
          final ReportElement e =
              FunctionUtilities.findElementByAttribute(
                  reportDefinition,
                  AttributeNames.Core.NAMESPACE,
                  AttributeNames.Core.NAME,
                  element);
          if (e == null) {
            resultHandler.notifyInspectionResult(
                new InspectionResult(
                    this,
                    InspectionResult.Severity.WARNING,
                    Messages.getString(
                        "InvalidElementReferenceInspection.ExpressionReferencesInvalidName",
                        expression.getName(),
                        metaData.getDisplayName(Locale.getDefault())),
                    new PropertyLocationInfo(expression, metaData.getName())));
          }
        }
      }
    } catch (Exception e) {
      resultHandler.notifyInspectionResult(
          new InspectionResult(
              this,
              InspectionResult.Severity.WARNING,
              e.getMessage(),
              new LocationInfo(expression)));
    }
  }