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

Source Code of org.pentaho.reporting.engine.classic.core.metadata.parser.ReportPreProcessorPropertyReadHandler

/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors..  All rights reserved.
*/

package org.pentaho.reporting.engine.classic.core.metadata.parser;

import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;

import org.pentaho.reporting.engine.classic.core.metadata.DefaultReportPreProcessorPropertyCore;
import org.pentaho.reporting.engine.classic.core.metadata.DefaultReportPreProcessorPropertyMetaData;
import org.pentaho.reporting.engine.classic.core.metadata.ReportPreProcessorPropertyCore;
import org.pentaho.reporting.libraries.base.util.ObjectUtilities;
import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler;
import org.pentaho.reporting.libraries.xmlns.parser.ParseException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

/**
* Todo: Document Me
*
* @author Thomas Morgner
*/
public class ReportPreProcessorPropertyReadHandler extends AbstractXmlReadHandler
{
  private String name;
  private boolean preferred;
  private boolean mandatory;
  private boolean expert;
  private boolean hidden;
  private String valueRole;
  private boolean deprecated;
  private BeanInfo expression;
  private String bundleLocation;
  private String prefix;
  private PropertyDescriptor descriptor;
  private String propertyEditorClass;
  private boolean computed;
  private ReportPreProcessorPropertyCore reportPreProcessorPropertyCore;

  public ReportPreProcessorPropertyReadHandler(final BeanInfo expression,
                                               final String bundleLocation,
                                               final String prefix)
  {
    this.expression = expression;
    this.bundleLocation = bundleLocation;
    this.prefix = prefix;
  }

  /**
   * Starts parsing.
   *
   * @param attrs the attributes.
   * @throws org.xml.sax.SAXException if there is a parsing error.
   */
  protected void startParsing(final Attributes attrs) throws SAXException
  {
    name = attrs.getValue(getUri(), "name");
    if (name == null)
    {
      throw new ParseException("Attribute 'name' is undefined", getLocator());
    }

    mandatory = "true".equals(attrs.getValue(getUri(), "mandatory"));
    expert = "true".equals(attrs.getValue(getUri(), "expert"));
    hidden = "true".equals(attrs.getValue(getUri(), "hidden"));
    preferred = "true".equals(attrs.getValue(getUri(), "preferred"));
    deprecated = "true".equals(attrs.getValue(getUri(), "deprecated"));
    computed = "true".equals(attrs.getValue(getUri(), "computed"));

    valueRole = attrs.getValue(getUri(), "value-role");
    if (valueRole == null)
    {
      valueRole = "Value";
    }

    propertyEditorClass = attrs.getValue(getUri(), "propertyEditor");

    final PropertyDescriptor[] descriptors = expression.getPropertyDescriptors();
    for (int i = 0; i < descriptors.length; i++)
    {
      final PropertyDescriptor maybeDescriptor = descriptors[i];
      if (name.equals(maybeDescriptor.getName()))
      {
        descriptor = maybeDescriptor;
        break;
      }
    }

    if (descriptor == null)
    {
      throw new ParseException("Attribute 'name' with value '" + name + "' does not reference a valid property. ["
          + expression.getBeanDescriptor().getBeanClass() + "]", getLocator());
    }


    final String metaDataCoreClass = attrs.getValue(getUri(), "impl"); // NON-NLS
    if (metaDataCoreClass != null)
    {
      reportPreProcessorPropertyCore = (ReportPreProcessorPropertyCore) ObjectUtilities.loadAndInstantiate
          (metaDataCoreClass, ReportPreProcessorPropertyReadHandler.class, ReportPreProcessorPropertyCore.class);
      if (reportPreProcessorPropertyCore == null)
      {
        throw new ParseException("Attribute 'impl' references a invalid ReportPreProcessorPropertyCore implementation.", getLocator());
      }
    }
    else
    {
      reportPreProcessorPropertyCore = new DefaultReportPreProcessorPropertyCore();
    }
  }

  public String getName()
  {
    return name;
  }

  public boolean isPreferred()
  {
    return preferred;
  }

  public boolean isMandatory()
  {
    return mandatory;
  }

  public boolean isExpert()
  {
    return expert;
  }

  public boolean isDeprecated()
  {
    return deprecated;
  }

  public boolean isHidden()
  {
    return hidden;
  }

  public String getValueRole()
  {
    return valueRole;
  }

  /**
   * Returns the object for this element or null, if this element does not create an object.
   *
   * @return the object.
   * @throws org.xml.sax.SAXException if an parser error occured.
   */
  public Object getObject() throws SAXException
  {
    return new DefaultReportPreProcessorPropertyMetaData
        (name, bundleLocation, prefix, expert, preferred, hidden, deprecated, mandatory,
            computed, valueRole, descriptor, propertyEditorClass, reportPreProcessorPropertyCore);
  }
}
TOP

Related Classes of org.pentaho.reporting.engine.classic.core.metadata.parser.ReportPreProcessorPropertyReadHandler

TOP
Copyright © 2018 www.massapi.com. 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.