Package dk.brics.xmlgraph

Examples of dk.brics.xmlgraph.XMLGraphFragment


              throw new XMLException("type mismatch for gap " + gap, origin);
          }
        }
      });
    }
    return new XMLGraphFragment(top, tgaps, agaps, gap_types);
  }
View Full Code Here


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

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

  }

  public XMLGraph transferValidate(final ValidateStm s, XMLGraph base) {
    final SchemaType schema = s.getSchema();
    final XMLGraph g = global_xg.clone();
    g.useFragment(new XMLGraphFragment(schema.getTypeNode(), schema.getTemplateGaps(), schema.getAttributeGaps(), schema.getGapTypes()));
    g.sharpen();
    return g;
  }
View Full Code Here

          if (g.getOpenTemplateGaps().remove(n.getName())) {
            g.getClosedTemplateGaps().add(n.getName());
          }
         
          XMLGraph sub = b.getGlobalXMLGraph().clone();
          sub.useFragment(new XMLGraphFragment(typeNode, null, null, null));
          g.merge(sub);
         
          n.setContentAndStatus(false, n.isRemoved(), cs, g);
         
          // get the original roots back
View Full Code Here

              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)
                gaptypes = Collections.emptyMap();
            for (Map.Entry<String,String> valueGapType : value_xg.getGapTypeMap().entrySet()) {
                String typeGapType = gaptypes.get(valueGapType.getKey());
View Full Code Here

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

TOP

Related Classes of dk.brics.xmlgraph.XMLGraphFragment

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.