Package dk.brics.xmlgraph

Examples of dk.brics.xmlgraph.Node


    g.processReachableNodes(new NodeProcessor<Object>() {
      @Override
      public Object process(ChoiceNode n) {
        boolean addempty=false;
        for (int child : n.getContents()) {
          Node node = g.getNode(child);
          if (!(node instanceof AttributeNode))
            continue;
          AttributeNode attr = (AttributeNode)node;
          if (g.getNode(attr.getContent()) instanceof TextNode)
            continue;
View Full Code Here


              final String gapType = g.getGapTypeMap().get(s.getGapName());
              if (gapType != null) {
                  XMLGraph value_xg = b.getIn(s, s.getXMLSource());
                  XMLGraph type_xg = b.getGlobalXMLGraph().clone();
//                  SequenceNode n = b.getSchemaTypes().get(gapType);
                  Node n = fg.getTypemap().get(gapType);
                  type_xg.useFragment(new XMLGraphFragment(n, null, null, null));
                  Validator validator = new Validator(new ValidationErrorHandler() {
                                public boolean error(ElementNode n, Origin origin, String msg,
                                        String example, Origin schema) {
                                    if (example == null)
                                         example = "";
                                    XMLGraphChecker.this.error(
                                            s,
                                            ErrorType.INVALID_PLUG_TYPE,
                                            "Plug statement violates the gap type %s\n" +
                                            "because of %s created at %s\n" +
                                            "%s %s",
                                            gapType,
                                            formatNode(n),
                                            origin,
                                            msg,
                                            formatExample(example));
                                    return true;
                                }
                            });
                  validator.validate(value_xg, type_xg, -1);
              }
              break;
          }
             
          case CLOSE:
              if (g.getGapTypeMap().isEmpty())
                  return;
              XMLGraph empty_xg = b.getGlobalXMLGraph().clone();
              empty_xg.useFragment(new XMLGraphFragment(b.getEmptySequence(), null, null, null));
                        XMLGraph type_xg = b.getGlobalXMLGraph().clone();
              for (final Map.Entry<String,String> gapentry : g.getGapTypeMap().entrySet()) {
                  final String gapName = gapentry.getKey();
                  final String gapType = gapentry.getValue();
                          Node n = fg.getTypemap().get(gapType);
                          type_xg.useFragment(new XMLGraphFragment(n, null, null, null));
                  Validator validator = new Validator(new ValidationErrorHandler() {
                                public boolean error(ElementNode n, Origin origin, String msg,
                                        String example, Origin schema) {
                                    if (example == null)
                                         example = "";
                                    XMLGraphChecker.this.error(
                                            s,
                                            ErrorType.INVALID_PLUG_TYPE,
                                            "Close statement violates the type of gap %s\n" +
                                            "%s does not permit an empty sequence\n" +
                                            "Perhaps add '?' or '*' quantifier?",
                                            gapName,
                                            gapType);
                                    return true;
                                }
                            });
                            validator.validate(empty_xg, type_xg, -1);
              }
              break;
          }
        }
       
        @Override
        public void visitRemoveStm(RemoveStm s) {
          printProgress(s);
          checkNonEmpty(s);
        }

        @Override
        public void visitSetStm(SetStm s) {
          printProgress(s);
          checkNonEmpty(s);
        }
      });
    }
    for (Statement s : fg.getNodes()) {
      s.visitBy(new BasicStatementVisitor() {

        @Override
        public void visitAnalyzeStm(final AnalyzeStm s) {
          if (s.getKind() == AnalyzeStm.Kind.HOTSPOT)
            return; // hotspots should not be analyzed here
          printProgress(s);
          XMLGraph value_xg = b.getIn(s, s.getBase());
          if (value_xg.isUnknown()) {
              String message;
              if (s.getKind() == AnalyzeStm.Kind.TYPEANNOTATION) {
                  message = "Non-validated XML data assigned to type-annotated variable";
              } else {
                  message = "Non-validated XML data at 'analyze' statement";
              }
            error(s, ErrorType.INVALID, message);
          } else {
            Validator validator = new Validator(new ValidationErrorHandler() {
              public boolean error(ElementNode n, Origin origin, String msg,
                  String example, Origin schema) {
                XMLGraphChecker.this.error(
                        s.getOrigin(),
                        ErrorType.INVALID,
                        "Problem in %s created at %s\n" +
                        "%s %s",
                                        formatNode(n),
                                        origin,
                        msg,
                        formatExample(example));
                return true;
              }
            });
            XMLGraph type_xg = b.getGlobalXMLGraph().clone();
            SchemaType schema = s.getSchema();
            String type = schema.getType();
            Node n = fg.getTypemap().get(type);
            if (n == null)
              throw new XMLAnalysisException("No schema definition found for " + type, s.getOrigin());
            type_xg.useFragment(new XMLGraphFragment(n, null, null, null));
            Map<String,String> gaptypes = schema.getGapTypes();
            if (gaptypes == null)
View Full Code Here

            }
            @Override
      public Object process(ChoiceNode n) {
                LinkedList<Integer> remove = new LinkedList<Integer>();
                for (int child : n.getContents()) {
                    Node node = xg.getNode(child);
                    if (node instanceof TextNode) {
                        TextNode tn = (TextNode)node;
                        if (tn.getText().isEmpty()) {
                            remove.add(child);
                        }
View Full Code Here

              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);
View Full Code Here

        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;
View Full Code Here

      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()) {
View Full Code Here

      g.processReachableNodes(new NodeProcessor<Object>() {
        @Override
        public Object process(ChoiceNode n) {
          LinkedHashSet<Integer> cs = new LinkedHashSet<Integer>(n.getContents());
          for (int child : n.getContents()) {
            Node node = g.getNode(child);
            if (node instanceof ConcreteNode) {
              switch (stm.get(child)) {
              case ALL:
              case DEFINITE:
                  if (g.getGapTypeMap().isEmpty()) {
View Full Code Here

          malformed[0] = true; // cycles require a fixpoint search
          return EPresence.UNKNOWN;
        }
        EPresence result = EPresence.EMPTY;
        for (int index : n.getContents()) {
          Node child = xg.getNode(index);
          EPresence p = child.process(this);
          if (result.maybeNonEmpty() && p.maybeNonEmpty())
            malformed[0] = true; // many roots
          result = result.concat(p);
        }
        open.remove(n);
        return result;
      }
      @Override
      public EPresence process(ChoiceNode n) {
        if (!open.add(n))
          return EPresence.UNKNOWN;
        EPresence result = EPresence.BOTTOM;
        for (int index : n.getContents()) {
          Node child = xg.getNode(index);
          EPresence p = child.process(this);
          result = result.leastUpperBound(p);
        }
        open.remove(n);
        return result;
      }
View Full Code Here

        Set<ElementNode> forms = new HashSet<ElementNode>();
        for (XMLGraph xg : ret2xg.values()) {
            NodeProcessor<Set<ElementNode>> isInFormActionChecker = new IsInFormActionChecker(
                    xg);
            Node node = xg.getNode(gap.getIndex());
            final Set<ElementNode> parentForms = node
                    .process(isInFormActionChecker);
            forms.addAll(parentForms);
        }
        return forms;
    }
View Full Code Here

TOP

Related Classes of dk.brics.xmlgraph.Node

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.