コード例 #1
0
  /**
   * @param element -
   * @return DParameter
   * @throws ParameterException -
   */
  public static DParameter decode(Element element) throws ParameterException {

    String type = element.getAttribute("xsi:type");
    type = XMLUtils.getLocalPart(type);

    DParameter dParameter = null;

    if ("Float".equals(type)) {
      dParameter = DFloatCodec.decode(element);
    } else if ("Date".equals(type)) {
      dParameter = DDateCodec.decode(element);
    } else if ("String".equals(type)) {
      dParameter = DStringCodec.decode(element);
    } else if ("Integer".equals(type)) {
      dParameter = DIntegerCodec.decode(element);
    } else if ("Boolean".equals(type)) {
      dParameter = DBooleanCodec.decode(element);
    } else if ("FloatList".equals(type)) {
      dParameter = DFloatListCodec.decode(element);
    } else if ("DateList".equals(type)) {
      dParameter = DDateListCodec.decode(element);
    } else if ("StringList".equals(type)) {
      dParameter = DStringListCodec.decode(element);
    } else if ("IntegerList".equals(type)) {
      dParameter = DIntegerListCodec.decode(element);
    } else {
      throw new ParameterException("Unknown parameter type [" + type + "]");
    }

    dParameter.setName(element.getAttribute("Name"));
    dParameter.setType(type);

    return dParameter;
  } // End Method def.
コード例 #2
0
  /**
   * Decode XML element into DFieldTemplate.
   *
   * @param element Element to decode.
   * @return Decoded element as DFieldTemplate.
   * @throws DFieldTemplatesException Unable to decode XML element.
   */
  public static DFieldTemplate decode(final org.w3c.dom.Element element)
      throws DFieldTemplatesException {

    if (element == null) {
      throw new DFieldTemplatesException("parameter must not be null [element]");
    }

    final DFieldTemplate dFieldTemplate = new DFieldTemplate();

    // resolve custom attributes
    dFieldTemplate.setName(element.getAttribute("Name"));

    // resolve custom elements
    final org.w3c.dom.NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
      if (!(nl.item(i) instanceof org.w3c.dom.Element)) {
        continue;
      }
      final org.w3c.dom.Element el = (org.w3c.dom.Element) nl.item(i);

      if ("Description".equals(el.getLocalName())) {
        dFieldTemplate.setDescription(el.getTextContent());
      } else if ("Selector".equals(el.getLocalName())) {
        dFieldTemplate.setSelector(DSelectorCodec.decode(el));
      } else if ("Term".equals(el.getLocalName())) {
        try {
          XMLUtils.removeWhitespaceTextNodes(el);

          final Plugin plugin = PluginFactory.getPlugin();
          dFieldTemplate.setTerm(plugin.getAdvSearchAccess().decodeTerm(el));
        } catch (Throwable e) {
          throw new DFieldTemplatesException(e.getMessage());
        }
      }
    }

    return dFieldTemplate;
  }