Examples of ChoiceNode


Examples of dk.brics.xmlgraph.ChoiceNode

  public XMLGraph transferGapify(final GapifyStm s, final XMLGraph base) {
    final XMLGraph g = base.clone();
    if (g.isUnknown()) {
      return g;
    }
    final ChoiceNode gap_node = stm_nodes.getGapifyChoiceNode(s,g);
    StatusMap smt;
    //try {
      //smt = evaluator.evaluate(base, s.getXPath(), dummy_root, dummy_root_content);
    smt = evaluateXPathOrRoot(s.getXPath(), base);
    //} catch (XPathException e) {
    //  throw new XMLXPathException(e);
    //}
    final StatusMap sm = smt;
    checkXPathEmpty(s, base, sm);
    g.processRoots(new ReachableNodesProcessor(g) { 
      @Override
      public Object process(ChoiceNode n) { // all concrete nodes have a choice node parent
        Collection<Integer> cs = new LinkedHashSet<Integer>();
        boolean modified = false;
        boolean add_gap = false;
        for (int i : n.getContents()) {
          boolean keep = true;
          boolean hit = false;
          Node c = g.getNode(i);
          if (c instanceof ConcreteNode) {
            switch (sm.get(i)) {
            case ALL:
            case DEFINITE:
              hit = true;
              keep = false;
              break;
            case SOME:
            case DONTKNOW:
              hit = true;
              break;
            case NEVER:
            case NONE:
              break;
            }
          }
          if (keep)
            cs.add(i);
          else
            modified = true;
          if (hit) {
            add_gap = true;
            boolean tgap = false;
            boolean agap = false;
            if (c instanceof ElementNode)
              tgap = true;
            else if (c instanceof AttributeNode)
              agap = true;
            else if (c instanceof TextNode) { // TODO: determine whether this is TextNode a tgap or an agap (or both)
              tgap = true;
              agap = true;
            }
            String gapname = s.getGapName();
            if (tgap)
              g.addOpenTemplateGap(gapname);
            if (agap)
              g.addOpenAttributeGap(gapname);
            if (s.getSchema() != null) {
              if (g.getGapTypeMap().get(gapname) != null &&
                  !g.getGapTypeMap().get(gapname).equals(s.getSchema().getType()))
                throw new XMLAnalysisException("Different types of gap '" + gapname + "'", s.getOrigin());
              g.getGapTypeMap().put(gapname, s.getSchema().getType());
            }
          }
        }
        if (add_gap) {
          cs.add(gap_node.getIndex());
          modified = true;
        }
        if (modified) {
          n.setContent(cs, g);
          gap_node.setContentAndStatus(true, gap_node.isRemoved(), gap_node.getContents(), g);
        }
        return null;
      }
    });
    g.sharpen();
View Full Code Here

Examples of dk.brics.xmlgraph.ChoiceNode

  public XMLGraph transferGet(final GetStm s, final XMLGraph base) {
    final XMLGraph g = base.clone();
    if (g.isUnknown()) {
      return g;
    }
    ChoiceNode cn = stm_nodes.getGetChoiceNode(s, g);
    final LinkedHashSet<Integer> c = new LinkedHashSet<Integer>();
    cn.setContent(c, g);
    switch (s.getKind()) {
    case GET:
    case GETELEMENT: // TODO: to improve analysis precision, only select the *first* element for getElement
    case GETELEMENTS: {
      StatusMap sm;
//      try {
//        sm = evaluator.evaluate(base, s.getXPath(), dummy_root, dummy_root_content);
//      } catch (XPathException e) {
//        throw new XMLXPathException(e);
//      }
      sm = evaluateXPathOrRoot(s.getXPath(), base);
      checkXPathEmpty(s, base, sm);
      for (int i : sm.getNodes()) {
        if (g.getNode(i) instanceof ConcreteNode) {
          StatusMap.Status status = sm.get(i);
          if (status!=StatusMap.Status.NONE && status!=StatusMap.Status.NEVER)
            c.add(i);
        }
      }
      c.addAll(cn.getContents());
      g.getRoots().clear();
      g.addRoot(cn);
      // TODO: could improve precision by considering simple XPath *predicates*
      break;
    }
 
View Full Code Here

Examples of dk.brics.xmlgraph.ChoiceNode

    if (g.isUnknown() || xmlsrc.isUnknown()) {
      g.setUnknown();
      return g;
    }
    final SequenceNode seq = stm_nodes.getInsertSequenceNode(s, g);
    final ChoiceNode left;
    final ChoiceNode right;
    final TextNode text = stm_nodes.getInsertTextNode(s, g);
   
    switch (s.getKind()) {
    case APPEND:
    case APPENDCONTENT:
    case INSERTAFTER:
    case SETATTRIBUTE:
      left = makePrivate(stm_nodes.getInsertLeftSide(s, g), g);
      right = makePrivate(stm_nodes.getInsertRightSide(s, g), g);
      break;
    case PREPEND:
    case PREPENDCONTENT:
    case INSERTBEFORE:
      // SWAP left and right if prepending
      left =  makePrivate(stm_nodes.getInsertRightSide(s, g), g);
      right = makePrivate(stm_nodes.getInsertLeftSide(s, g), g);
      break;
    default:
      throw new RuntimeException("unknown insert kind");
    }
    text.replaceText(s.getStringSource(), g);
    right.getContents().addAll(xmlsrc.getRoots());
    right.getContents().add(text.getIndex());

    switch (s.getKind()) {
    case APPEND:
    case PREPEND:
      g.merge(xmlsrc);
      left.getContents().addAll(base.getRoots());
      g.getRoots().clear();
      g.getRoots().add(seq.getIndex());
      return g;

    case SETATTRIBUTE:
    case APPENDCONTENT: // this is both appendContent(XML) and appendContent(XPath,XML)
    case PREPENDCONTENT:{
      final StatusMap stm = evaluateXPathOrRoot(s.getXPath(), g);
      boolean empty = checkXPathEmpty(s, g, stm);
      if (empty)
        return g;
      g.merge(xmlsrc);
      g.getRoots().retainAll(base.getRoots());
      // TODO can we append as root here???
      g.processReachableNodes(new NodeProcessor<Object>() {
        @Override
        public Object process(ElementNode n) {
          ChoiceNode ch = (ChoiceNode)g.getNode(n.getContent());
          switch (stm.get(n.getIndex())) {
          case DEFINITE:
          case ALL:
            left.getContents().addAll(ch.getContents());
            ch = makePrivate(ch, g);
            if (g.getGapTypeMap().isEmpty()) {
                ch.getContents().clear();
            }
            ch.getContents().add(seq.getIndex());
            break;
          case SOME:
          case DONTKNOW:
            ch = makePrivate(ch, g);
            left.getContents().addAll(ch.getContents());
            ch.getContents().add(seq.getIndex());
            break;
          case NONE:
          case NEVER:
            break;
          }
          return null;
        }
      });
      g.sharpen();
      return g;
    }
    case INSERTAFTER:
    case INSERTBEFORE: {
      final StatusMap stm = evaluateXPathOrRoot(s.getXPath(), g);
      boolean empty = checkXPathEmpty(s, g, stm);
      if (empty)
        return g;
      g.merge(xmlsrc);
      g.getRoots().retainAll(base.getRoots());
      g.processReachableNodes(new NodeProcessor<Object>() {
        @Override
        public Object process(ChoiceNode ch) {
          LinkedHashSet<Integer> cs = new LinkedHashSet<Integer>(ch.getContents());
          for (int child : ch.getContents()) {
            Node node = g.getNode(child);
            if (node instanceof ConcreteNode) {
              switch (stm.get(child)) {
              case ALL:
              case DEFINITE:
                  if (g.getGapTypeMap().isEmpty()) {
                      cs.remove(child);
                  }
                left.getContents().add(child);
                cs.add(seq.getIndex());
                break;
              case SOME:
              case DONTKNOW:
                left.getContents().add(child);
                cs.add(seq.getIndex());
                break;
              case NONE:
              case NEVER:
                break;
              }
            }
          }
          ch.setContent(cs, g);
          return null;
        }
      });
      g.sharpen();
      return g;
View Full Code Here

Examples of dk.brics.xmlgraph.ChoiceNode

    case SETCONTENT:
      g.processReachableNodes(new NodeProcessor<Object>() {
        @Override
        public Object process(ElementNode n) {
          ChoiceNode ch = (ChoiceNode)g.getNode(n.getContent());
          LinkedHashSet<Integer> c = new LinkedHashSet<Integer>(ch.getContents());
          switch (stm.get(n.getIndex())) {
          case ALL:
          case DEFINITE:
              if (g.getGapTypeMap().isEmpty()) {
                  c.clear();
              }
            c.addAll(xmlsrc.getRoots());
            c.add(text.getIndex());
            break;

          case SOME:
          case DONTKNOW:
            c.addAll(xmlsrc.getRoots());
            c.add(text.getIndex());
            break;

          case NONE:
          case NEVER:
            break;
          }
          ch.setContent(c, g);
          return null;
        }
      });
      break;
View Full Code Here

Examples of dk.brics.xmlgraph.ChoiceNode

            Map<ChoiceNode, Set<Plugging>> gap2plug,
            Map<ReturnStmt, XMLGraph> ret2xg) {
        // find submithandler pluggings forms (<form action=SH>...)
        Map<ChoiceNode, Set<ElementNode>> shGap2form = new HashMap<ChoiceNode, Set<ElementNode>>();
        for (Entry<ChoiceNode, Set<Plugging>> entry : gap2plug.entrySet()) {
            ChoiceNode gap = entry.getKey();
            Set<Plugging> plugValues = entry.getValue();
            // only check possible submithandlers
            if (couldBeSubmitHandler(plugValues)) {
                for (Plugging plugging : plugValues) {
                    Set<ElementNode> forms = getEnclosingForms(gap, plugging,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.