Beispiel #1
0
  /**
   * Returns the number value of the first item selected by applying the wrapped XPath expression to
   * the given context.
   *
   * @param context the element to use as context for evaluating the XPath expression.
   * @return the number value of the first item selected by applying the wrapped XPath expression to
   *     the given context, <code>null</code> if no node was selected or the special value {@link
   *     java.lang.Double#NaN} (Not-a-Number) if the selected value can not be converted into a
   *     number value.
   * @throws JDOMException if the XPath expression is invalid or its evaluation on the specified
   *     context failed.
   */
  @Override
  public Number numberValueOf(Object context) throws JDOMException {
    try {
      navigator.setContext(context);

      return xPath.numberValueOf(context);
    } catch (JaxenException ex1) {
      throw new JDOMException(
          "XPath error while evaluating \"" + xPath.toString() + "\": " + ex1.getMessage(), ex1);
    } finally {
      navigator.reset();
    }
  }
Beispiel #2
0
  /**
   * Evaluates the wrapped XPath expression and returns the first entry in the list of selected
   * nodes (or atomics).
   *
   * @param context the node to use as context for evaluating the XPath expression.
   * @return the first selected item, which may be of types: {@link Element}, {@link Attribute},
   *     {@link Text}, {@link CDATA}, {@link Comment}, {@link ProcessingInstruction}, Boolean,
   *     Double, String, or <code>null</code> if no item was selected.
   * @throws JDOMException if the evaluation of the XPath expression on the specified context
   *     failed.
   */
  @Override
  public Object selectSingleNode(Object context) throws JDOMException {
    try {
      navigator.setContext(context);

      return unWrapNS(xPath.selectSingleNode(context));
    } catch (JaxenException ex1) {
      throw new JDOMException(
          "XPath error while evaluating \"" + xPath.toString() + "\": " + ex1.getMessage(), ex1);
    } finally {
      navigator.reset();
    }
  }
    @Override
    public void run() {

      // url connection to LTA datamall for incident
      try {
        System.out.println("Retrieving incident dataset...");

        final HashMap<String, String> map = new HashMap<String, String>();
        map.put("lta", "http://www.w3.org/2005/Atom");
        map.put("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
        map.put("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");

        final XPath xPath = new Dom4jXPath("//m:properties");
        xPath.setNamespaceContext(new SimpleNamespaceContext(map));

        final URL url = new URL("http://datamall.mytransport.sg/ltaodataservice.svc/IncidentSet");
        final URLConnection urlConn = url.openConnection();

        urlConn.setRequestProperty("accept", "*/*");
        urlConn.addRequestProperty("AccountKey", accountKey);
        urlConn.addRequestProperty("UniqueUserID", uniqueId);

        final SAXReader reader = new SAXReader();
        final Document document = reader.read(urlConn.getInputStream());

        // System.out.println("inputstream: " + urlConn.getInputStream());
        // System.out.println("document: " + document.asXML());

        final List<Node> nodes = xPath.selectNodes(document);

        System.out.println("m:properties list size: " + nodes.size());

        final ArrayList<Incident> incidentList = new ArrayList<Incident>();

        for (final Node node : nodes) {
          // extract valuable information
          incidentList.add(parseIncidentEntry(node, map));
        }

        filterIncidents(incidentList);

      } catch (final MalformedURLException e) {
        e.printStackTrace();
      } catch (final IOException e) {
        e.printStackTrace();
      } catch (final DocumentException e) {
        e.printStackTrace();
      } catch (final JaxenException e) {
        e.printStackTrace();
      }
    }
Beispiel #4
0
 @SuppressWarnings("unchecked")
 private List<? extends Node> findViolations(
     ASTCompilationUnit unit, String logLevel, String guard, String xpathExpression) {
   try {
     return unit.findChildNodesWithXPath(
         xpathExpression
             .replaceAll("LOG_LEVEL_UPPERCASE", logLevel.toUpperCase())
             .replaceAll("LOG_LEVEL", logLevel)
             .replaceAll("GUARD", guard));
   } catch (JaxenException e) {
     e.printStackTrace();
   }
   return Collections.EMPTY_LIST;
 }
Beispiel #5
0
  public ItTreeNode buildProblemNode(Element problem, ItTreeNode treeProject) {
    ItTreeNode treeProblem = new ItTreeNode(problem.getChildText("name"), problem, null, null);
    treeProblem.setIcon(new ImageIcon("resources/images/planningProblem.png"));
    treeModel.insertNodeInto(treeProblem, treeProject, treeProject.getChildCount());

    // Build each Object Diagram under the Problem Node
    Iterator objectDiagrams =
        problem.getChild("objectDiagrams").getChildren("objectDiagram").iterator();
    while (objectDiagrams.hasNext()) {
      Element objectDiagram = (Element) objectDiagrams.next();
      ItTreeNode treeDiagram =
          new ItTreeNode(
              objectDiagram.getChildText("name")
                  + " - "
                  + objectDiagram.getChildText("sequenceReference"),
              objectDiagram,
              null,
              null);
      treeDiagram.setIcon(new ImageIcon("resources/images/objectDiagram.png"));
      treeProblem.add(treeDiagram);

      Iterator objects = objectDiagram.getChild("objects").getChildren("object").iterator();
      while (objects.hasNext()) {
        Element objectReference = (Element) objects.next();
        Element object =
            getElement(
                problem.getParentElement().getParentElement(),
                "objects",
                objectReference.getAttributeValue("id"));
        if (object != null) {
          Element itsClass = null;
          try {
            XPath path =
                new JDOMXPath(
                    "project/elements/classes/class[@id=" + object.getChildText("class") + "]");
            itsClass = (Element) path.selectSingleNode(problem.getDocument());
          } catch (JaxenException e2) {
            e2.printStackTrace();
          }
          // Element itsClass = getElement(xmlProject, "classes", object.getChildText("class"));
          ItTreeNode treeObject =
              new ItTreeNode(object.getChildText("name"), object, objectReference, itsClass);
          treeObject.setIcon(new ImageIcon("resources/images/object.png"));
          treeDiagram.add(treeObject);
        }
      }
    }

    return treeProblem;
  }
Beispiel #6
0
  public void buildDiagramNode(Element xmlProject, ItTreeNode treeProject) {
    Iterator diagramsIterator = xmlProject.getChild("diagrams").getChildren().iterator();
    while (diagramsIterator.hasNext()) {
      Element diagrams = (Element) diagramsIterator.next();

      // chevere KaosDiagram
      if (diagrams.getName().equals("KaosDiagrams")) {

        Element kaosDiagram = diagrams.getChild("name");
        Element goalDiagram = diagrams.getChild("GoalDiagram");
        Element operDiagram = diagrams.getChild("OperDiagram");
        Element objectDiagram = diagrams.getChild("ObjectDiagram");
        Element agentDiagram = diagrams.getChild("AgentDiagram");
        ItTreeNode treeKAOS = new ItTreeNode(kaosDiagram.getText(), kaosDiagram, null, null);

        ItTreeNode treeGoal =
            new ItTreeNode(goalDiagram.getChild("name").getText(), goalDiagram, null, null);
        // treeGoal.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));
        treeGoal.setIcon(new ImageIcon("resources/images/goal_icono.png"));

        // Insering all goals expectation for a goal diagram
        Iterator list_goals_expectation =
            goalDiagram
                .getChild("goalsExpe")
                .getChildren("goal")
                .iterator(); // (Element)goalDiagram.getChildren("goals");

        while (list_goals_expectation.hasNext()) {
          Element goal = (Element) list_goals_expectation.next();
          ItTreeNode treeDiagram = new ItTreeNode(goal.getChildText("name"), goal, null, null);
          treeDiagram.setIcon(new ImageIcon("resources/images/expetativa.png"));
          treeModel.insertNodeInto(treeDiagram, treeGoal, treeGoal.getChildCount());
        }
        // Insering all goals expectation for a goal diagram
        Iterator list_goals_requi =
            goalDiagram
                .getChild("goalsReq")
                .getChildren("goal")
                .iterator(); // (Element)goalDiagram.getChildren("goals");

        while (list_goals_requi.hasNext()) {
          Element goal = (Element) list_goals_requi.next();
          ItTreeNode treeDiagram = new ItTreeNode(goal.getChildText("name"), goal, null, null);
          treeDiagram.setIcon(new ImageIcon("resources/images/requirement.png"));
          treeModel.insertNodeInto(treeDiagram, treeGoal, treeGoal.getChildCount());
        }

        // Insering all agents for agoal diagram.
        Iterator list_agents =
            goalDiagram
                .getChild("agents")
                .getChildren("agent")
                .iterator(); // (Element)goalDiagram.getChildren("goals");

        while (list_agents.hasNext()) {
          Element agent = (Element) list_agents.next();
          ItTreeNode treeDiagram = new ItTreeNode(agent.getChildText("name"), agent, null, null);
          treeDiagram.setIcon(new ImageIcon("resources/images/agent1.png"));
          treeModel.insertNodeInto(treeDiagram, treeGoal, treeGoal.getChildCount());
        }

        ItTreeNode treeOp =
            new ItTreeNode(operDiagram.getChild("name").getText(), operDiagram, null, null);
        treeOp.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));

        ItTreeNode treeObj =
            new ItTreeNode(objectDiagram.getChild("name").getText(), objectDiagram, null, null);
        treeObj.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));

        ItTreeNode treeAg =
            new ItTreeNode(agentDiagram.getChild("name").getText(), agentDiagram, null, null);
        treeAg.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));

        treeModel.insertNodeInto(treeGoal, treeKAOS, treeKAOS.getChildCount());
        treeModel.insertNodeInto(treeOp, treeKAOS, treeKAOS.getChildCount());
        treeModel.insertNodeInto(treeObj, treeKAOS, treeKAOS.getChildCount());
        treeModel.insertNodeInto(treeAg, treeKAOS, treeKAOS.getChildCount());

        treeKAOS.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));
        treeModel.insertNodeInto(treeKAOS, treeProject, treeProject.getChildCount());

        /* Element kaosDiagram = diagrams.getChild("name");
                                    ItTreeNode name = new ItTreeNode(kaosDiagram.getText(), kaosDiagram, null, null);




                                    Element goalDiagram1 = diagrams.getChild("GoalDiagram");


                                    name.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));
                                    treeModel.insertNodeInto(name, treeProject, treeProject.getChildCount());

        Iterator goalDiagrams = diagrams.getChildren("GoalDiagram").iterator();
        while (goalDiagrams.hasNext()){

        	Element goalDiagram = (Element)goalDiagrams.next();
        	ItTreeNode treeDiagram = new ItTreeNode(goalDiagram.getChildText("name"),
        			                                goalDiagram, null, null);
        	treeDiagram.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));
        	treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount());

        	Iterator agents = goalDiagram.getChild("agents").getChildren("agent").iterator();
        	while (agents.hasNext()){
        		Element actor = (Element) agents.next();
        		ItTreeNode treeActor = new ItTreeNode(actor.getChildText("name"), actor, null, null);
        		treeActor.setIcon(new ImageIcon("resources/images/agent1.png"));
        		treeDiagram.add(treeActor);
        	}

        	Iterator useCases = goalDiagram.getChild("goals").getChildren("goal").iterator();
        	while (useCases.hasNext()){
        		Element useCase = (Element) useCases.next();
        		ItTreeNode treeUseCase = new ItTreeNode(useCase.getChildText("name"), useCase, null, null);
        		treeUseCase.setIcon(new ImageIcon("resources/images/goal1.png"));
        		treeDiagram.add(treeUseCase);
        	}
        }*/
        /*
                                    Iterator agentDiagram = diagrams.getChildren("AgentDiagram").iterator();
        while (goalDiagrams.hasNext()){
        	Element useCaseDiagram = (Element)goalDiagrams.next();
        	ItTreeNode treeDiagram = new ItTreeNode(useCaseDiagram.getChildText("name"),
        			                                useCaseDiagram, null, null);
        	treeDiagram.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));
        	treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount());

        	Iterator agents = useCaseDiagram.getChild("agents").getChildren("agent").iterator();
        	while (agents.hasNext()){
        		Element actor = (Element) agents.next();
        		ItTreeNode treeActor = new ItTreeNode(actor.getChildText("name"), actor, null, null);
        		treeActor.setIcon(new ImageIcon("resources/images/agent1.png"));
        		treeDiagram.add(treeActor);
        	}

        	Iterator useCases = useCaseDiagram.getChild("goals").getChildren("goal").iterator();
        	while (useCases.hasNext()){
        		Element useCase = (Element) useCases.next();
        		ItTreeNode treeUseCase = new ItTreeNode(useCase.getChildText("name"), useCase, null, null);
        		treeUseCase.setIcon(new ImageIcon("resources/images/goal1.png"));
        		treeDiagram.add(treeUseCase);
        	}
        }*/
      }
      // chevere

      // Use Case Diagrams
      if (diagrams.getName().equals("useCaseDiagrams")) {
        Iterator useCaseDiagrams = diagrams.getChildren("useCaseDiagram").iterator();
        while (useCaseDiagrams.hasNext()) {
          Element useCaseDiagram = (Element) useCaseDiagrams.next();
          ItTreeNode treeDiagram =
              new ItTreeNode(useCaseDiagram.getChildText("name"), useCaseDiagram, null, null);
          treeDiagram.setIcon(new ImageIcon("resources/images/useCaseDiagram.png"));
          treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount());

          Iterator actors = useCaseDiagram.getChild("actors").getChildren("actor").iterator();
          while (actors.hasNext()) {
            Element actor = (Element) actors.next();
            ItTreeNode treeActor = new ItTreeNode(actor.getChildText("name"), actor, null, null);
            treeActor.setIcon(new ImageIcon("resources/images/actor.png"));
            treeDiagram.add(treeActor);
          }

          Iterator useCases = useCaseDiagram.getChild("useCases").getChildren("useCase").iterator();
          while (useCases.hasNext()) {
            Element useCase = (Element) useCases.next();
            ItTreeNode treeUseCase =
                new ItTreeNode(useCase.getChildText("name"), useCase, null, null);
            treeUseCase.setIcon(new ImageIcon("resources/images/useCase.png"));
            treeDiagram.add(treeUseCase);
          }
        }
      }

      // Class Diagrams
      else if (diagrams.getName().equals("classDiagrams")) {
        Iterator classDiagrams = diagrams.getChildren("classDiagram").iterator();
        while (classDiagrams.hasNext()) {
          Element classDiagram = (Element) classDiagrams.next();
          ItTreeNode treeDiagram =
              new ItTreeNode(classDiagram.getChildText("name"), classDiagram, null, null);
          treeDiagram.setIcon(new ImageIcon("resources/images/classDiagram.png"));
          treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount());

          Iterator classes = classDiagram.getChild("classes").getChildren("class").iterator();
          while (classes.hasNext()) {
            Element classReference = (Element) classes.next();
            Element Class =
                getElement(xmlProject, "classes", classReference.getAttributeValue("id"));
            if (Class != null) {
              ItTreeNode treeClass =
                  new ItTreeNode(Class.getChildText("name"), Class, classReference, null);
              treeClass.setIcon(new ImageIcon("resources/images/class.png"));
              treeDiagram.add(treeClass);

              Iterator attributes =
                  Class.getChild("attributes").getChildren("attribute").iterator();
              for (int i = 0; attributes.hasNext(); i++) {
                Element attribute = (Element) attributes.next();
                ItTreeNode treeAttribute =
                    new ItTreeNode(attribute.getChildText("name"), attribute, null, null);
                treeAttribute.setIcon(new ImageIcon("resources/images/attribute.png"));
                treeClass.add(treeAttribute);
              }

              Iterator operators = Class.getChild("operators").getChildren("operator").iterator();
              while (operators.hasNext()) {
                Element operator = (Element) operators.next();
                ItTreeNode treeOperator =
                    new ItTreeNode(operator.getChildText("name"), operator, null, null);
                treeOperator.setIcon(new ImageIcon("resources/images/operator.png"));
                treeClass.add(treeOperator);
              }
            }
          }
        }
      }

      // State Chart Diagrams
      else if (diagrams.getName().equals("stateMachineDiagrams")) {
        Iterator stateDiagrams = diagrams.getChildren("stateMachineDiagram").iterator();
        while (stateDiagrams.hasNext()) {
          Element stateDiagram = (Element) stateDiagrams.next();

          // Get class
          Element classReference = null;
          if (!stateDiagram.getChildText("class").equals("")) {
            try {
              XPath path =
                  new JDOMXPath(
                      "project/elements/classes/class[@id="
                          + stateDiagram.getChildText("class")
                          + "]");
              classReference = (Element) path.selectSingleNode(stateDiagram.getDocument());
            } catch (JaxenException e2) {
              e2.printStackTrace();
            }
          }

          ItTreeNode treeDiagram =
              new ItTreeNode(stateDiagram.getChildText("name"), stateDiagram, null, classReference);
          treeDiagram.setIcon(new ImageIcon("resources/images/stateMachineDiagram.png"));
          treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount());

          Iterator states = stateDiagram.getChild("states").getChildren("state").iterator();
          while (states.hasNext()) {
            Element state = (Element) states.next();
            ItTreeNode treeState = new ItTreeNode(state.getChildText("name"), state, null, null);
            treeState.setIcon(new ImageIcon("resources/images/state.png"));
            treeDiagram.add(treeState);
          }
        }
      }

      // Activity Diagrams
      else if (diagrams.getName().equals("activityDiagrams")) {
        Iterator activityDiagrams = diagrams.getChildren("activityDiagram").iterator();
        while (activityDiagrams.hasNext()) {
          Element activityDiagram = (Element) activityDiagrams.next();
          ItTreeNode treeDiagram =
              new ItTreeNode(activityDiagram.getChildText("name"), activityDiagram, null, null);
          treeDiagram.setIcon(new ImageIcon("resources/images/activityDiagram.png"));
          treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount());
        }

      }
      // Timing Diagrams
      else if (diagrams.getName().equals("timingDiagrams")) {
        Iterator timingDiagrams = diagrams.getChildren("timingDiagram").iterator();
        while (timingDiagrams.hasNext()) {
          Element timingDiagram = (Element) timingDiagrams.next();
          ItTreeNode treeDiagram =
              new ItTreeNode(timingDiagram.getChildText("name"), timingDiagram, null, null);
          treeDiagram.setIcon(new ImageIcon("resources/images/activityDiagram.png"));
          treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount());
        }

      }

      // Object Diagrams
      else if (diagrams.getName().equals("objectDiagrams")) {
        Iterator objectDiagrams = diagrams.getChildren("objectDiagram").iterator();
        while (objectDiagrams.hasNext()) {
          Element objectDiagram = (Element) objectDiagrams.next();
          ItTreeNode treeDiagram =
              new ItTreeNode(objectDiagram.getChildText("name"), objectDiagram, null, null);
          treeDiagram.setIcon(new ImageIcon("resources/images/objectDiagram.png"));
          treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount());

          Iterator objects = objectDiagram.getChild("objects").getChildren("object").iterator();
          while (objects.hasNext()) {
            Element objectReference = (Element) objects.next();
            Element object =
                getElement(xmlProject, "objects", objectReference.getAttributeValue("id"));
            if (object != null) {
              Element itsClass = getElement(xmlProject, "classes", object.getChildText("class"));
              ItTreeNode treeObject =
                  new ItTreeNode(object.getChildText("name"), object, objectReference, itsClass);
              treeObject.setIcon(new ImageIcon("resources/images/object.png"));
              treeDiagram.add(treeObject);
            }
          }
        }

      }
      // Planning domains
      else if (diagrams.getName().equals("planningDomains")) {
        Iterator domains = diagrams.getChildren("domain").iterator();
        while (domains.hasNext()) {
          Element domain = (Element) domains.next();
          buildDomainNode(domain, treeProject);
        }
      }

      // Planning Problems
      /*else if (diagrams.getName().equals("planningProblems")){
      	Iterator problems = diagrams.getChildren("problem").iterator();
      	while(problems.hasNext()){
      		Element problem = (Element)problems.next();

      		buildProblemNode(problem, treeProject);
      	}

      }*/

    }
  }
Beispiel #7
0
  public void buildPDDLNode(Element xmlProject, ItTreeNode treeProject, String path) {

    // domain files
    Iterator domainsIterator = xmlProject.getChild("pddldomains").getChildren().iterator();
    while (domainsIterator.hasNext()) {
      Element pddldomain = (Element) domainsIterator.next();
      ItTreeNode treePDDL = new ItTreeNode(pddldomain.getChildText("name"), pddldomain, null, null);
      treePDDL.setIcon(new ImageIcon("resources/images/domain.png"));
      treeModel.insertNodeInto(treePDDL, treeProject, treeProject.getChildCount());
    }

    // Problem Instance files
    Element problemInstancesRoot = xmlProject.getChild("problemInstances");
    ItTreeNode treeProblemInstPDDL =
        new ItTreeNode("Problem Instances", problemInstancesRoot, null, null);
    treeProblemInstPDDL.setIcon(new ImageIcon("resources/images/openreport.png"));
    treeModel.insertNodeInto(treeProblemInstPDDL, treeProject, treeProject.getChildCount());

    File theproject = new File(path);
    // File folder = new File(theproject.getParent());
    File folder = theproject.getParentFile();

    FilenameFilter filter =
        new FilenameFilter() {
          public boolean accept(File dir, String name) {
            if (name != null && name.toLowerCase().endsWith(".pddl")) {
              return true;
            } else {
              return false;
            }
          }
        };

    // PDDLFileFilter ff = new PDDLFileFilter();
    File[] listOfFiles = folder.listFiles(filter);

    // sorting the files (alphabetical order)
    Arrays.sort(
        listOfFiles,
        new Comparator<File>() {
          public int compare(File a, File b) {
            return a.getName().compareTo(b.getName());
          }
        });

    for (int i = 0; i < listOfFiles.length; i++) {
      File eachfile = listOfFiles[i];
      // System.out.println("File " + eachfile.getName());
      String filename = eachfile.getName();

      // check if file is a domain file
      Element pddldomainNode = null;
      try {
        XPath dpath = new JDOMXPath("pddlproject/pddldomains/pddldomain[name='" + filename + "']");
        pddldomainNode = (Element) dpath.selectSingleNode(xmlProject.getDocument());

      } catch (JaxenException e1) {
        e1.printStackTrace();
      }

      if (pddldomainNode == null) {
        Element problemInstance = new Element("pddlproblem");
        // problemInstance.setText(filename);
        problemInstance.setAttribute("filename", filename);
        problemInstance.setAttribute("file", eachfile.getAbsolutePath());
        Element thename = new Element("name");
        thename.setText(filename);
        problemInstance.addContent(thename);
        problemInstancesRoot.addContent(problemInstance);

        ItTreeNode nodeProblemInstPDDL = new ItTreeNode(filename, problemInstance, null, null);
        nodeProblemInstPDDL.setIcon(new ImageIcon("resources/images/problem.png"));
        treeModel.insertNodeInto(
            nodeProblemInstPDDL, treeProblemInstPDDL, treeProblemInstPDDL.getChildCount());
      }
    }
  }