/** Creates the child bean. */
  @Override
  public Object create(Object parent, QName qName) throws ConfigException {
    Class<?> cl = TypeFactory.loadClass(qName);

    if (cl == null) {
      ConfigType<?> type = TypeFactory.getFactory().getEnvironmentType(qName);

      if (type != null) return type.create(parent, qName);

      throw new ConfigException(
          L.l(
              "'{0}.{1}' is an unknown class for element '{2}'",
              qName.getNamespaceURI(), qName.getLocalName(), qName));
    }

    if (Annotation.class.isAssignableFrom(cl)) {
      return new AnnotationConfig(cl);
    } else {
      XmlBeanConfig<?> config = new XmlBeanConfig(qName, cl, parent);
      config.setInlineBean(true);

      // config.setScope("singleton");

      return config;
    }
  }
  /** Returns true if the namespace decl has been printed. */
  public boolean hasNamespace(String prefix, String uri) {
    QName name = getQName();

    if (prefix == null || uri == null) return true;
    else if (prefix.equals(name.getPrefix()) && uri.equals(name.getNamespaceURI())) return true;
    else return _parent.hasNamespace(prefix, uri);
  }
  /**
   * Generates the code for the element.
   *
   * @param out the output writer for the generated java.
   */
  public void generate(JspJavaWriter out) throws Exception {
    out.addText("<");
    out.addText(getTagName());

    QName qName = getQName();

    HashSet<String> prefixes = new HashSet<String>();

    if (qName.getNamespaceURI() != null && !_parent.hasNamespace(qName)) {
      prefixes.add(qName.getPrefix());

      out.addText(" ");
      if (qName.getPrefix() == null || qName.getPrefix().equals("")) out.addText("xmlns=\"");
      else out.addText("xmlns:" + qName.getPrefix() + "=\"");
      out.addText(qName.getNamespaceURI());
      out.addText("\"");
    }

    for (int i = 0; i < _attrNames.size(); i++) {
      QName name = _attrNames.get(i);
      String value = _attrValues.get(i);

      if (name.getNamespaceURI() != null
          && !prefixes.contains(name.getPrefix())
          && !_parent.hasNamespace(name)) {
        prefixes.add(name.getPrefix());
        out.addText(" ");
        if (name.getPrefix() == null || name.getPrefix().equals("")) out.addText("xmlns=\"");
        else out.addText("xmlns:" + name.getPrefix() + "=\"");
        out.addText(name.getNamespaceURI());
        out.addText("\"");
      }

      out.addText(" ");
      out.addText(name.getName());

      if (value == null || value.equals("")) {
        // XXX: possibly differ for html/text

        out.addText("=\"\"");
      } else {
        out.addText("=\"");

        if (value.indexOf("${") < 0 && !value.startsWith("<%") && !value.startsWith("%")) {
          out.addText(value);
        } else {
          String javaValue =
              generateParameterValue(String.class, value, true, null, _parseState.isELIgnored());
          out.println("out.print(" + javaValue + ");");
        }
        out.addText("\"");
      }
    }

    if (getChildren() != null && getChildren().size() > 0) {
      out.addText(">");

      generateChildren(out);

      out.addText("</" + getTagName() + ">");
    } else out.addText(" />");
  }
Esempio n. 4
0
 /** Returns true if the name matches. */
 public boolean matches(QName name) {
   if (!_ns.equals(name.getNamespaceURI())) return false;
   else if (_except != null && _except.matches(name)) return false;
   else return true;
 }