Package dk.brics.xmlgraph

Examples of dk.brics.xmlgraph.SequenceNode


    final Collection<String> agaps = new ArrayList<String>();
    final Map<String,String> gap_types = new HashMap<String,String>();
    final Map<Element,List<Integer>> contents = new HashMap<Element,List<Integer>>();
    final Stack<PendingNode> pending = new Stack<PendingNode>();
    List<Integer> top_contents = new ArrayList<Integer>();
    SequenceNode top = new SequenceNode(top_contents, x.getOrigin());
    xg.addNode(top);
    pending.add(new PendingNode(x, top));
    while (!pending.isEmpty()) {
      final PendingNode m = pending.pop();
      m.node.visitBy(new NodeVisitor() {

        private void push(Node n, SequenceNode parent) {
          if (n != null)
            pending.push(new PendingNode(n, parent));
        }

        private dk.brics.xmlgraph.Node wrapChoice(dk.brics.xmlgraph.Node n) {
          if (!(n instanceof ChoiceNode)) {
            Collection<Integer> cs = new ArrayList<Integer>();
            cs.add(n.getIndex());
            n = new ChoiceNode(cs, n.getOrigin());
            xg.addNode(n);
          }
          return n;
       
       
        @Override
        public void visit(Text n) {
          dk.brics.xmlgraph.Node tn = new TextNode(Automaton.makeString(n.getString()), n.getOrigin());
          xg.addNode(tn);
          if (wrapchoices)
            tn = wrapChoice(tn);
          m.parent.addContent(tn.getIndex());
          push(n.getNextSibling(), m.parent);
        }
       
        @Override
        public void visit(Element n) {
          List<Integer> cs = new ArrayList<Integer>();
          contents.put(n, cs); // contents added later
          SequenceNode content = new SequenceNode(cs, n.getOrigin());
          xg.addNode(content);
          dk.brics.xmlgraph.Node sn = content;
          if (wrapchoices)
            sn = wrapChoice(sn);
          dk.brics.xmlgraph.Node en = new ElementNode(Automaton.makeString(n.getExpandedName()),
View Full Code Here


    //new dk.brics.xmlgraph.converter.XMLGraph2Dot(System.out).print(xg);
    XMLGraph t = null;
    int i = 0;
    String expanded = expandQName(type, origin);
    for (ConvertedSchema s : schemas) {
      SequenceNode n = s.types.get(expanded);
      if (n != null) {
        t = s.xg;
        i = n.getIndex();
        break;
      }
    }
    if (t == null)
      throw new XMLValidationException("No schema found for type " + type, origin);
View Full Code Here

                TemplateConstant t = s.getConst();
                if (t.getFragment() != null)
                    return;
                // handle empty XML specially to avoid "" text nodes
                if (t.getXML().isText() && t.getXML().asText().getString().isEmpty()) {
                    SequenceNode n = new SequenceNode(Collections.<Integer>emptyList(), s.getOrigin());
                    xg.addNode(n);
                    XMLGraphFragment f = new XMLGraphFragment(n, null, null, null);
                    t.setFragment(f);
                } else {
                    XMLGraphFragment f = XMLGraphConverter.extend(xg, t.getXML(), XMLGraphConverter.GapConversion.CLOSED, true);
                    for (Map.Entry<String,String> en : f.getGapTypeMap().entrySet()) {
                        String gaptype = en.getValue();
                        // add gap types to the xml graph, and ensure that they are valid
                        resolveTypename(gaptype);
                    }
                    t.setFragment(f);
                }
            }
            void linkSchemaType(Statement s, SchemaType type) {
                type.setTypeNode(resolveTypename(type.getType()));
                for (Map.Entry<String,String> gap : type.getGapTypes().entrySet()) {
                    String gapname = gap.getKey();
                    String gaptype = gap.getValue();
                    type.getGapTypeNodes().put(gapname, resolveTypename(gaptype));
                }
            }
            Node resolveTypename(String name) {
                if (g.getTypemap().containsKey(name)) {
                    return g.getTypemap().get(name);
                }
               
                String schemaName;
                Quantifier quantifier;
                if (name.endsWith("?")) {
                    schemaName = name.substring(0, name.length() - 1);
                    quantifier = Quantifier.ZeroOrOne;
                } else if (name.endsWith("+")) {
                    schemaName = name.substring(0, name.length() - 1);
                    quantifier = Quantifier.OneOrMore;
                } else if (name.endsWith("*")) {
                    schemaName = name.substring(0, name.length() - 1);
                    quantifier = Quantifier.ZeroOrMore;
                } else {
                    schemaName = name;
                    quantifier = Quantifier.One;
                }
               
                Node base = g.getTypemap().get(schemaName);
               
                // add datatypes on-the-fly when needed
                if (base == null) {
                    if (XMLSchemaDatatypes.isDatatype(schemaName)) {
                        base = new TextNode(XMLSchemaDatatypes.getDatatype(schemaName, origin), new Origin("", -1, -1));
                        xg.addNode(base);
                        g.getTypemap().put(schemaName, base);
                    }
                }
               
                // if still not found, it does not exist
                if (base == null) {
                    throw new XMLException("Could not find schema for type " + schemaName + " referred to at " + origin, origin);
                }
               
                Node result;
                OneOrMoreNode on;
                SequenceNode empty;
                switch (quantifier) {
                case One:
                    result = base;
                    break;
                case OneOrMore:
                    result = new OneOrMoreNode(base.getIndex(), origin);
                    xg.addNode(result);
                    break;
                case ZeroOrMore:
                    empty = new SequenceNode(Collections.<Integer>emptyList(), origin);
                    on = new OneOrMoreNode(base.getIndex(), origin);
                    xg.addNode(empty);
                    xg.addNode(on);
                    result = new ChoiceNode(set(empty.getIndex(), on.getIndex()), origin);
                    xg.addNode(result);
                    break;
                case ZeroOrOne:
                default:
                    empty = new SequenceNode(Collections.<Integer>emptyList(), origin);
                    xg.addNode(empty);
                    result = new ChoiceNode(set(base.getIndex(), empty.getIndex()), origin);
                    xg.addNode(result);
                    break;
                }
               
                g.getTypemap().put(name, result);
View Full Code Here

                TemplateConstant t = s.getConst();
                if (t.getFragment() != null)
                    return;
                // handle empty XML specially to avoid "" text nodes
                if (t.getXML().isText() && t.getXML().asText().getString().isEmpty()) {
                    SequenceNode n = new SequenceNode(Collections.<Integer>emptyList(), s.getOrigin());
                    xg.addNode(n);
                    XMLGraphFragment f = new XMLGraphFragment(n, null, null, null);
                    t.setFragment(f);
                } else {
                    XMLGraphFragment f = XMLGraphConverter.extend(xg, t.getXML(), XMLGraphConverter.GapConversion.CLOSED, true);
View Full Code Here

                    throw new XMLException("Could not find schema for type " + schemaName + " referred to at " + origin, origin);
                }
               
                Node result;
                OneOrMoreNode on;
                SequenceNode empty;
                switch (quantifier) {
                case One:
                    result = base;
                    break;
                case OneOrMore:
                    result = new OneOrMoreNode(base.getIndex(), origin);
                    xg.addNode(result);
                    break;
                case ZeroOrMore:
                    empty = new SequenceNode(Collections.<Integer>emptyList(), origin);
                    on = new OneOrMoreNode(base.getIndex(), origin);
                    xg.addNode(empty);
                    xg.addNode(on);
                    result = new ChoiceNode(set(empty.getIndex(), on.getIndex()), origin);
                    xg.addNode(result);
                    break;
                case ZeroOrOne:
                default:
                    empty = new SequenceNode(Collections.<Integer>emptyList(), origin);
                    xg.addNode(empty);
                    result = new ChoiceNode(set(base.getIndex(), empty.getIndex()), origin);
                    xg.addNode(result);
                    break;
                }
               
                g.getTypemap().put(name, result);
View Full Code Here

    //new dk.brics.xmlgraph.converter.XMLGraph2Dot(System.out).print(xg);
    XMLGraph t = null;
    int i = 0;
    String expanded = expandQName(type, origin);
    for (ConvertedSchema s : schemas) {
      SequenceNode n = s.types.get(expanded);
      if (n != null) {
        t = s.xg;
        i = n.getIndex();
        break;
      }
    }
    if (t == null)
      throw new XMLValidationException("No schema found for type " + type, origin);
View Full Code Here

                return EPresence.EMPTY;
            if (tn.getText().run(""))
                return EPresence.UNKNOWN;
            return EPresence.NONEMPTY;
        } else if (node instanceof SequenceNode) {
            SequenceNode sn = (SequenceNode)node;
            if (sn.getContents().size() == 0)
                return EPresence.EMPTY;
            else
                return null;
        } else if (node instanceof ChoiceNode) {
            ChoiceNode cn = (ChoiceNode)node;
View Full Code Here

      // and replace empty-string text nodes with empty sequence nodes
        xg.processReachableNodes(new NodeProcessor<Object>() {
            @Override
            public Object process(TextNode n) {
                if (n.getText().isEmptyString()) {
                    xg.setNode(n.getIndex(), new SequenceNode(new ArrayList<Integer>(), n.getOrigin()));
                }
                return this;
            }
            @Override
      public Object process(ChoiceNode n) {
View Full Code Here

    final StatementNodes stm_nodes = new StatementNodes();
    ChoiceNode dummy_root_content = new ChoiceNode(new ArrayList<Integer>(), null);
    global_xg.addNode(dummy_root_content);
    ElementNode dummy_root = new ElementNode(Automaton.makeEmpty(), dummy_root_content.getIndex(), false, null);
    global_xg.addNode(dummy_root);
    emptySequence = new SequenceNode(new ArrayList<Integer>(), null);
    global_xg.addNode(emptySequence);
    stm_nodes.setEmptySequenceNode(emptySequence);
    for (Statement s : fg.getNodes()) {
      s.visitBy(new BasicStatementVisitor() {
        @Override
        public void visitSetStm(SetStm s) {
          TextNode tn = new TextNode(Automaton.makeEmpty(), s.getOrigin());
          global_xg.addNode(tn);
          stm_nodes.setSetTextNode(s, tn);
        }
       
        @Override
        public void visitInsertStm(InsertStm s) {
          SequenceNode seq = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
          ChoiceNode left = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
          ChoiceNode right = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
          TextNode tn = new TextNode(Automaton.makeEmpty(), s.getOrigin());
         
          global_xg.addNode(seq);
          global_xg.addNode(left);
          global_xg.addNode(right);
          global_xg.addNode(tn);
         
          seq.addContent(left.getIndex());
          seq.addContent(right.getIndex());
         
          stm_nodes.setInsertLeftSide(s, left);
          stm_nodes.setInsertRightSide(s, right);
          stm_nodes.setInsertSequenceNode(s, seq);
          stm_nodes.setInsertTextNode(s, tn);
        }
       
        @Override
        public void visitConcatStm(ConcatStm s) {
          ChoiceNode cn = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
          SequenceNode sn = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
          OneOrMoreNode on = new OneOrMoreNode(cn.getIndex(), s.getOrigin());
          TextNode tn = new TextNode(Automaton.makeEmpty(), s.getOrigin());
         
          global_xg.addNode(cn);
          global_xg.addNode(sn);
          global_xg.addNode(on);
          global_xg.addNode(tn);
         
          on.setContent(cn.getIndex());
         
          stm_nodes.setConcatOneOrMoreNode(s, on);
          stm_nodes.setConcatTextNode(s, tn);
          stm_nodes.setConcatChoiceNode(s, cn);
          stm_nodes.setConcatSequenceNode(s, sn);
        }
       
        @Override
        public void visitConstStm(ConstStm s) {
          TemplateConstant t = s.getConst();
          try {
            stm_nodes.setTemplateConstantXMLFragment(t, t.getFragment());
          } catch (XMLTemplateException e) {
            Throwable tr = e;
            if (tr.getCause() != null)
              tr = tr.getCause();
            String msg = tr.getMessage();
            if (msg.endsWith("."))
              msg = msg.substring(0, msg.length() - 1);
           
            if (System.getProperty("dk.brics.xact.analysis.tolerate-errors") != null) {
              // error recovery if enabled
              System.err.println("Error: " + msg + " at " + s.getOrigin());
              Node empty = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(empty);
              stm_nodes.setTemplateConstantXMLFragment(t, new XMLGraphFragment(empty, new HashSet<String>(), new HashSet<String>(), new HashMap<String,String>()));
            } else {
              throw new XMLAnalysisException(msg, s.getOrigin());
            }
          }
        }

        @Override
        public void visitGetStm(GetStm s) {
          ChoiceNode cn = new ChoiceNode(new HashSet<Integer>(), s.getOrigin());
          global_xg.addNode(cn);
          stm_nodes.setGetChoiceNode(s, cn);
          switch (s.getKind()) {
          case GETNEXTATTR:
          case GETNEXTATTRIBUTE:
          case GETNEXTSIBLING:
          case GETFIRSTELEMENT:
              SequenceNode sq = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
              global_xg.addNode(sq);
              stm_nodes.setGetEmptySequence(s, sq);
//            OneOrMoreNode on = new OneOrMoreNode(cn.getIndex(), s.getOrigin());
//            global_xg.addNode(on);
//            stm_nodes.setGetOneOrMoreNode(s, on);
            break;
          }
        }
       
        @Override
        public void visitGapifyStm(GapifyStm s) {
          ChoiceNode cn = new ChoiceNode(s.getGapName(), false, false, new HashSet<Integer>(), s.getOrigin());
          global_xg.addNode(cn);
          stm_nodes.setGapifyChoiceNode(s, cn);
        }

        @Override
        public void visitPlugStm(PlugStm s) {
          switch (s.getKind()) {
          case CLOSE:
            SequenceNode sn = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
            global_xg.addNode(sn);
            stm_nodes.setPlugSequenceNode(s, sn);
            break;
           
          case PLUGMULTI:
          case PLUG: {
            TextNode tn = new TextNode(Automaton.makeEmpty(), s.getOrigin());
            global_xg.addNode(tn);
            stm_nodes.setPlugTextNode(s, tn);
            break;
          }
           
          case PLUGWRAP: {
            ChoiceNode top = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
            SequenceNode empty = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
            OneOrMoreNode on = new OneOrMoreNode(-1, s.getOrigin());
            ChoiceNode content = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
            TextNode tn = new TextNode(Automaton.makeEmpty(), s.getOrigin());
           
            global_xg.addNode(top);
            global_xg.addNode(empty);
            global_xg.addNode(on);
            global_xg.addNode(content);
            global_xg.addNode(tn);
           
            top.getContents().add(empty.getIndex());
            top.getContents().add(on.getIndex());
            on.setContent(content.getIndex());
            content.getContents().add(tn.getIndex());
           
            stm_nodes.setPlugWrapTopNode(s, top);
            stm_nodes.setPlugWrapContentNode(s, content);
            stm_nodes.setPlugTextNode(s, tn);
            break;
          }
          }
        }
       
        @Override
        public void visitRemoveStm(RemoveStm s) {
          SequenceNode sn = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
          global_xg.addNode(sn);
          stm_nodes.setRemoveSequenceNode(s, sn);
        }
       
        @Override
        public void visitNodeStm(NodeStm s) {
          switch (s.getKind()) {
          case ATTRIBUTE: {
            SequenceNode seq = new SequenceNode(new LinkedList<Integer>(), s.getOrigin());
            ChoiceNode left = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
            AttributeNode attr = new AttributeNode(s.getName(), 0, s.getOrigin());
            TextNode text = new TextNode(s.getValue(), s.getOrigin());

            global_xg.addNode(seq);
            global_xg.addNode(left);
            global_xg.addNode(text);
            global_xg.addNode(attr);
           
            seq.addContent(left.getIndex());
            left.getContents().add(attr.getIndex());
            attr.setContent(text.getIndex());
           
            stm_nodes.setStmNode(s, seq);
           
            if (s.getNextNode() != null) {
              ChoiceNode next = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(next);
              seq.addContent(next.getIndex());
              stm_nodes.setStmNextNode(s, next);
            }
            break;
          }
          case ELEMENT: {
            SequenceNode seq = new SequenceNode(new LinkedList<Integer>(), s.getOrigin());
            ChoiceNode left1 = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
            ChoiceNode left2 = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
            SequenceNode left3 = new SequenceNode(new LinkedList<Integer>(), s.getOrigin());
            ElementNode element = new ElementNode(s.getName(), 0, false, s.getOrigin());
           
            global_xg.addNode(seq);
            global_xg.addNode(left1);
            global_xg.addNode(left2);
            global_xg.addNode(left3);
            global_xg.addNode(element);
           
            seq.getContents().add(left1.getIndex());
            left1.getContents().add(element.getIndex());
            element.setContent(left2.getIndex());
            left2.getContents().add(left3.getIndex());
           
            stm_nodes.setStmNode(s, seq);
            if (s.getNextNode() != null) {
              ChoiceNode next = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(next);
              seq.addContent(next.getIndex());
              stm_nodes.setStmNextNode(s, next);
            }
            if (s.getFirstAttr() != null) {
              ChoiceNode attr = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(attr);
              left3.addContent(attr.getIndex());
              stm_nodes.setStmFirstAttribute(s, attr);
            }
            if (s.getFirstChild() != null) {
              ChoiceNode child = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(child);
              left3.addContent(child.getIndex());
              stm_nodes.setStmFirstChild(s, child);
            }
            break;
          }
          case TEXT: {
            SequenceNode seq = new SequenceNode(new ArrayList<Integer>(), s.getOrigin());
            TextNode tn = new TextNode(s.getValue(), s.getOrigin());
           
            global_xg.addNode(seq);
            global_xg.addNode(tn);
           
            seq.addContent(tn.getIndex());
            stm_nodes.setStmNode(s, seq);
           
            if (s.getNextNode() != null) {
              ChoiceNode next = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(next);
              seq.addContent(next.getIndex());
              stm_nodes.setStmNextNode(s, next);
            }
            break;
          }
          case TEMPLATEGAP:
          case ATTRIBUTEGAP: {
            SequenceNode seq = new SequenceNode(new LinkedList<Integer>(), s.getOrigin());
            ChoiceNode cn = new ChoiceNode(s.getGap(), false, false, new LinkedHashSet<Integer>(), s.getOrigin());

            global_xg.addNode(seq);
            global_xg.addNode(cn);
           
            seq.addContent(cn.getIndex());
            stm_nodes.setStmNode(s, seq);
            stm_nodes.setStmGap(s, cn);
           
            if (s.getNextNode() != null) {
              ChoiceNode next = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(next);
              seq.addContent(next.getIndex());
              stm_nodes.setStmNextNode(s, next);
            }
            break;
          }
          case COMMENT:
          case PROCESSINGINSTRUCTION: {
            SequenceNode sn = new SequenceNode(new LinkedList<Integer>(), s.getOrigin());
            global_xg.addNode(sn);
            stm_nodes.setStmNode(s, sn);
            if (s.getNextNode() != null) {
              ChoiceNode next = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(next);
              sn.addContent(next.getIndex());
              stm_nodes.setStmNextNode(s, next);
            }
            break;
          }
          default:
            throw new RuntimeException("unknown node stm kind: " + s.getKind());
          }
        }
       
        @Override
        public void visitCopyStm(CopyStm s) {
          SequenceNode seq = new SequenceNode(new LinkedList<Integer>(), s.getOrigin());
          ChoiceNode left1 = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
          global_xg.addNode(seq);
          global_xg.addNode(left1);
          stm_nodes.setCopyTopNode(s, seq);
          stm_nodes.setCopyLeftChoice(s, left1);
          seq.addContent(left1.getIndex());
         
          if (s.getNextNode() != null) {
            ChoiceNode next = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
            global_xg.addNode(next);
            seq.addContent(next.getIndex());
            stm_nodes.setCopyNextNode(s, next);
          }
          switch (s.getKind()) {
          case ELEMENT: { // element nodes are handled specially
            ChoiceNode left2 = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
            SequenceNode left3 = new SequenceNode(new LinkedList<Integer>(), s.getOrigin());
            ElementNode element = new ElementNode(Automaton.makeEmpty(), 0, false, s.getOrigin());
           
            global_xg.addNode(left2);
            global_xg.addNode(left3);
            global_xg.addNode(element);
           
            stm_nodes.setCopyElementNode(s, element);
           
            left1.getContents().add(element.getIndex());
            element.setContent(left2.getIndex());
            left2.getContents().add(left3.getIndex());
            if (s.getFirstAttr() != null) {
              ChoiceNode attr = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(attr);
              left3.addContent(attr.getIndex());
              stm_nodes.setCopyFirstAttribute(s, attr);
            }
            if (s.getFirstChild() != null) {
              ChoiceNode child = new ChoiceNode(new LinkedHashSet<Integer>(), s.getOrigin());
              global_xg.addNode(child);
              left3.addContent(child.getIndex());
              stm_nodes.setCopyFirstChild(s, child);
            }
            break;
          }
          case ATTRIBUTE:
View Full Code Here

    final XMLGraph g = base.clone();
    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;
              }
View Full Code Here

TOP

Related Classes of dk.brics.xmlgraph.SequenceNode

Copyright © 2018 www.massapicom. 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.