Esempio n. 1
0
  /**
   * Create or retrieve an instance of <code>IconBean</code> and push it on to the object statck.
   *
   * @param namespace the namespace URI of the matching element, or an empty string if the parser is
   *     not namespace aware or the element has no namespace
   * @param name the local name if the parser is namespace aware, or just the element name otherwise
   * @param attributes The attribute list of this element
   * @exception IllegalStateException if the parent stack element is not of type FeatureBean
   */
  public void begin(String namespace, String name, Attributes attributes) throws Exception {

    FeatureBean fb = null;
    try {
      fb = (FeatureBean) digester.peek();
    } catch (Exception e) {
      throw new IllegalStateException("No parent FeatureBean on object stack");
    }
    String lang = attributes.getValue("lang");
    if (lang == null) {
      lang = attributes.getValue("xml:lang"); // If digester not ns-aware
    }
    if (lang == null) {
      lang = ""; // Avoid NPE errors on sorted map comparisons
    }
    IconBean ib = fb.getIcon(lang);
    if (ib == null) {
      if (digester.getLogger().isDebugEnabled()) {
        digester.getLogger().debug("[IconRule]{" + digester.getMatch() + "} New (" + lang + ")");
      }
      Class clazz = digester.getClassLoader().loadClass(CLASS_NAME);
      ib = (IconBean) clazz.newInstance();
      ib.setLang(lang);
      fb.addIcon(ib);
    } else {
      if (digester.getLogger().isDebugEnabled()) {
        digester.getLogger().debug("[IconRule]{" + digester.getMatch() + "} Old (" + lang + ")");
      }
    }
    digester.push(ib);
  }
Esempio n. 2
0
  /**
   * Pop the <code>IconBean</code> off the top of the stack.
   *
   * @param namespace the namespace URI of the matching element, or an empty string if the parser is
   *     not namespace aware or the element has no namespace
   * @param name the local name if the parser is namespace aware, or just the element name otherwise
   * @exception IllegalStateException if the popped object is not of the correct type
   */
  public void end(String namespace, String name) throws Exception {

    IconBean top = null;
    try {
      top = (IconBean) digester.pop();
    } catch (Exception e) {
      throw new IllegalStateException("Popped object is not a " + CLASS_NAME + " instance");
    }
    if (digester.getLogger().isDebugEnabled()) {
      digester
          .getLogger()
          .debug("[IconRule]{" + digester.getMatch() + "} Pop (" + top.getLang() + ")");
    }
  }