Package dk.brics.xact

Examples of dk.brics.xact.XMLException


          if (type != null) {
            String t = gap_types.get(gap);
            if (t == null)
              gap_types.put(gap, type);
            else if (!t.equals(type))
              throw new XMLException("type mismatch for gap " + gap, origin);
          }
        }
      });
    }
    return new XMLGraphFragment(top, tgaps, agaps, gap_types);
View Full Code Here


        for (Map.Entry<String,Origin> entry : g.getSchemas().entrySet()) {
            try {
                Map<String,SequenceNode> map = XMLValidator.loadXMLSchema(new URL(entry.getKey()), xg);
                g.getTypemap().putAll(map);
            } catch (MalformedURLException ex) {
                throw new XMLException("Schema URL is malformed", ex, entry.getValue());
            } catch (ParseException ex) {
                throw new XMLException("Could not parse schema: " + ex.getMessage(), ex, entry.getValue());
            }
        }
        for (URL url : config.getAdditionalSchemas()) {
            try {
                Map<String, SequenceNode> map = XMLValidator.loadXMLSchema(url, xg);
                g.getTypemap().putAll(map);
            } catch (ParseException ex) {
                throw new XMLException("Could not parse schema: " + ex.getMessage(), ex);
            }
        }
       
        // link SchemaTypes to their nodes
        final class Visitor extends BasicStatementVisitor {
            Origin origin;
            @Override
            public void visitAnalyzeStm(AnalyzeStm s) {
              if (s.getKind() != AnalyzeStm.Kind.HOTSPOT) {
                linkSchemaType(s, s.getSchema());
              }
            }
            @Override
            public void visitValidateStm(ValidateStm s) {
                linkSchemaType(s, s.getSchema());
            }
            @Override
            public void visitGapifyStm(GapifyStm s) {
                if (s.getSchema() != null)
                    linkSchemaType(s, s.getSchema());
            }
            @Override
            public void visitConstStm(ConstStm s) {
                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;
View Full Code Here

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

                  Origin origin = new Origin(m.getDeclaringClass().getName() + "." + m.getName(), getLineNumber(u), 0);
                  String prefix = getConstantString(put.getArg(0), origin);
                  String uri = getConstantString(put.getArg(1), origin);
                  String oldUri = namespaces.put(prefix, uri);
                  if (oldUri != null && !uri.equals(oldUri)) {
                      throw new XMLException("Conflicting namespace bindings of prefix " + prefix + " at " + origin, origin);
                  }
                  Debug.println(1, true, "Detected namespace declaration: " + prefix + " -> " + uri);
                }
              }
            }
View Full Code Here

        return type.startsWith("{" + NAMESPACE + "}");
    }
   
    public static Automaton getDatatype(SchemaType schema) throws XMLException {
        if (schema.getGapTypes() != null && schema.getGapTypes().size() > 0) {
            throw new XMLException("Datatypes cannot have gap types", schema.getOrigin());
        }
        return getDatatype(schema.getType(), schema.getOrigin());
    }
View Full Code Here

    }
   
    public static Automaton getDatatype(String type, Origin origin) {
        String name = type.substring(NAMESPACE.length() + 2);
        if (!Datatypes.exists(name)) {
            throw new XMLException("No datatype is named " + name, origin);
        }
        return Datatypes.get(name);
    }
View Full Code Here

TOP

Related Classes of dk.brics.xact.XMLException

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.