コード例 #1
0
  /**
   * Parseaza fisierul primit ca parametru.
   *
   * @param file Calea absoluta a fisierului de parsat.
   * @return mixed Daca in fisier a fost gasit un analizator atunci returneaza Analyzer, altfel
   *     returneaza null.
   */
  private Analyzer getAnalyzer(final String file) {
    Document dom = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);

    try {
      // Ia din factory o noua instanta de document builder.
      DocumentBuilder db = dbf.newDocumentBuilder();

      // Parseaza pentru a obtine o reprezentare DOM a fisierului.
      dom = db.parse(file);
    } catch (Exception e) {
      ErrorMessage.show("Exceptie la parsarea fisierelor XSD:" + e.getMessage());
    }

    Map<String, String> dt = new TreeMap<String, String>();

    // Ia toate tagurile simpleType.
    Match simpleType =
        $(dom).namespace("xs", "http://www.w3.org/2001/XMLSchema").xpath("//xs:simpleType");

    for (int i = 0; i < simpleType.size(); i++) {
      // Ia nume si valoare daca acestea exista.
      String name = simpleType.get(i).getAttribute("name");
      String value =
          $(simpleType.content(i))
              .namespace("xs", "http://www.w3.org/2001/XMLSchema")
              .xpath("//xs:pattern")
              .attr("value");

      // Verifica daca exista name si value.
      if (name != null && value != null) {
        dt.put(name, value);
      }
    }

    // Avem nevoie de un analizator de un anumit tip.
    if (dt.get("execType") != null && dt.get("execType").compareTo(this.type) == 0) {
      return new Analyzer(dt.get("execName"), dt.get("execDescription"), this.type);
    }

    return null;
  }
コード例 #2
0
 public static FeatureGenerator instantiateFromXML(Match conf) {
   return new ESANewClusterFeatureGenerator(
       conf.attr("name"),
       conf.xpath("./SourceFeatureGenerator").content().trim(),
       conf.xpath("./SourceFeatureSet").content().trim(),
       Integer.parseInt(conf.xpath("./NumberOfClusters").content().trim()),
       Integer.parseInt(conf.xpath("./NumberOfBestToUse").content().trim()),
       Boolean.parseBoolean(conf.xpath("./UsedForClassification").content().trim()),
       conf.xpath("./SourceFeatureSet").content().trim());
 }