Esempio n. 1
0
  private ArrayList<Pattern> parsePatterns(Element patternRoot) {
    try {
      NodeList patternNodes = patternRoot.getElementsByTagName("pattern");

      ArrayList<Pattern> patterns = new ArrayList<>();

      for (int i = 0; i < patternNodes.getLength(); i++) {
        Element patternElement = (Element) patternNodes.item(i);

        String name =
            ((Element) patternElement.getElementsByTagName("name").item(0)).getTextContent();
        String problem =
            ((Element) patternElement.getElementsByTagName("problem").item(0)).getTextContent();
        String solution =
            ((Element) patternElement.getElementsByTagName("solution").item(0)).getTextContent();
        String consequences =
            ((Element) patternElement.getElementsByTagName("consequences").item(0))
                .getTextContent();

        Scope scope =
            ScopeService.getScopeByName(
                ((Element) patternElement.getElementsByTagName("scope").item(0)).getTextContent());
        Purpose purpose =
            PurposeService.getPurposeByName(
                ((Element) patternElement.getElementsByTagName("purpose").item(0))
                    .getTextContent());

        CachableImage diagram =
            new ProxyImage(
                ((Element) patternElement.getElementsByTagName("diagram").item(0))
                    .getTextContent());

        Pattern pattern = new Pattern(name);
        pattern.setProblem(problem);
        pattern.setSolution(solution);
        pattern.setConsequences(consequences);

        pattern.setScope(scope);
        pattern.setPurpose(purpose);

        pattern.setDiagram(diagram);

        patterns.add(pattern);
      }

      return patterns;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }