⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functionfactory.java

📁 Java的Web报表库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    final int depLevel = ParserUtil.parseInt(attr.getValue(DEPENCY_LEVEL_ATT), 0);

    if (className == null)
    {
      throw new ParseException("Expression class not specified", getLocator());
    }

    try
    {
      final Class fnC = getClass().getClassLoader().loadClass(className);
      setCurrentExpression((Expression) fnC.newInstance());
      getCurrentExpression().setName(name);
      getCurrentExpression().setDependencyLevel(depLevel);
    }
    catch (ClassNotFoundException e)
    {
      throw new ParseException("Expression " + name + " class=" + className
          + " is not valid. ", e, getLocator());
    }
    catch (IllegalAccessException e)
    {
      throw new ParseException("Expression " + name + " class=" + className
          + " is not valid. ", e, getLocator());
    }
    catch (InstantiationException e)
    {
      throw new ParseException("Expression " + name + " class=" + className
          + " is not valid. ", e, getLocator());
    }
  }


  /**
   * Starts processing an expression element.
   *
   * @param attr  the element attributes.
   *
   * @throws SAXException if there is an error parsing the XML.
   */
  protected void startPropertyRef(final Attributes attr)
      throws SAXException
  {
    currentProperty = getNameGenerator().generateName(attr.getValue("name"));
    currentEncoding = attr.getValue(PROPERTY_ENCODING_ATT);
    if (currentEncoding == null)
    {
      currentEncoding = PROPERTY_ENCODING_TEXT;
    }
    currentText = new StringBuffer();
  }

  /**
   * starts and loads a function by instantating the functions class. The function must
   * have a default constructor defined.
   *
   * @param attr  the element attributes.
   *
   * @throws SAXException if there is an error parsing the XML.
   */
  protected void startFunction(final Attributes attr)
      throws SAXException
  {
    final String name = getNameGenerator().generateName(attr.getValue("name"));
    final String className = attr.getValue("class");
    final int depLevel = ParserUtil.parseInt(attr.getValue(DEPENCY_LEVEL_ATT), 0);

    if (className == null)
    {
      throw new ParseException("Function class not specified", getLocator());
    }

    try
    {
      final Class fnC = getClass().getClassLoader().loadClass(className);
      setCurrentFunction((Function) fnC.newInstance());
      getCurrentFunction().setName(name);
      getCurrentFunction().setDependencyLevel(depLevel);
    }
    catch (ClassNotFoundException e)
    {
      throw new ParseException("Function " + name + " class=" + className
          + " is not valid. ", e, getLocator());
    }
    catch (IllegalAccessException e)
    {
      throw new ParseException("Function " + name + " class=" + className
          + " is not valid. ", e, getLocator());
    }
    catch (InstantiationException e)
    {
      throw new ParseException("Function " + name + " class=" + className
          + " is not valid. ", e, getLocator());
    }
  }

  /**
   * Receives some (or all) of the text in the current element.
   *
   * @param ch  the character array.
   * @param start  the first character index.
   * @param length  the length (number of valid characters).
   */
  public void characters(final char[] ch, final int start, final int length)
  {
    // accumulate the characters in case the text is split into several chunks...
    if (this.currentText != null)
    {
      this.currentText.append(String.copyValueOf(ch, start, length));
    }
  }

  /**
   * Ends the current element.
   *
   * @param qName  the element name.
   *
   * @throws SAXException if there is a problem parsing the element.
   */
  public void endElement(final String qName) throws SAXException
  {
    final String elementName = qName.toLowerCase().trim();
    if (elementName.equals(FUNCTION_TAG))
    {
      endFunction();
    }
    else if (elementName.equals(FUNCTIONS_TAG))
    {
      endFunctions();
    }
    else if (elementName.equals(DATAREF_TAG))
    {
      // is no longer used
    }
    else if (elementName.equals(PROPERTIES_TAG))
    {
      endProperties();
    }
    else if (elementName.equals(PROPERTY_TAG))
    {
      endProperty();
    }
    else if (elementName.equals(EXPRESSION_TAG))
    {
      endExpression();
    }
    else if (elementName.equals(PROPERTY_REFERENCE_TAG))
    {
      endPropertyRef();
    }
    else if (elementName.equals(getFinishTag()))
    {
      getParser().popFactory().endElement(qName);
    }
    else
    {
      throw new ParseException("Expected closing function tag.", getLocator());
    }
  }

  /**
   * Ends the function. The current function is added to the report and initialized during
   * this process.
   *
   * @throws SAXException if there is a problem parsing the element.
   */
  protected void endFunction()
      throws SAXException
  {
    try
    {
      getReport().addFunction(getCurrentFunction());
    }
    catch (FunctionInitializeException fie)
    {
      throw new SAXException(fie);
    }
  }

  /**
   * Ends the expression. The current expression is added to the report and initialized during
   * this process.
   *
   * @throws SAXException if there is a problem parsing the element.
   */
  protected void endExpression()
      throws SAXException
  {
    try
    {
      getReport().addExpression(getCurrentExpression());
    }
    catch (FunctionInitializeException fie)
    {
      Log.warn("Function initialization failed", fie);
      throw new ParseException(fie);
    }
  }

  /**
   * Ends the parsing of functions.
   *
   * @throws SAXException if there is a problem parsing the element.
   */
  protected void endFunctions()
      throws SAXException
  {
    getParser().popFactory().endElement(FUNCTIONS_TAG);
  }

  /**
   * Ends the properties parsing for the current function. The properties are added to the
   * current function.
   *
   * @throws SAXException if there is a problem parsing the element.
   */
  protected void endProperties()
      throws SAXException
  {
    final Expression f = getCurrentExpression();
    if (f == null)
    {
      throw new ParseException("End properties reached without a function defined", getLocator());
    }
    f.setProperties(currentProperties);
  }

  /**
   * Ends the definition of a single property entry.
   *
   * @throws SAXException if there is a problem parsing the element.
   */
  protected void endProperty()
      throws SAXException
  {
    final Properties currentProps = getProperties();
    if (currentProps == null)
    {
      throw new ParseException("EndProperty without properties tag?", getLocator());
    }

    currentProps.setProperty(currentProperty, entityParser.decodeEntities(currentText.toString()));
    currentText = null;
  }


  /**
   * Ends the definition of a single property entry.
   *
   * @throws SAXException if there is a problem parsing the element.
   */
  protected void endPropertyRef()
      throws SAXException
  {
    getReport().getProperties().setMarked(currentProperty, true);
    if (currentText.length() != 0)
    {
      getReport().setProperty(currentProperty, entityParser.decodeEntities(currentText.toString()));
    }
    currentText = null;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -