Package oracle.xml.parser.v2

Examples of oracle.xml.parser.v2.XMLNode


    /** Parse sig/set. */
    private Sig parseSig(String id, int depth) throws IOException, Err {
        Sig ans = id2sig.get(id);
        if (ans!=null) return ans;
        XMLNode node = nmap.get(id);
        if (node==null) throw new IOException("Unknown SigID "+id+" encountered.");
        if (!node.is("sig")) throw new IOException("ID "+id+" is not a sig.");
        String label   = label(node);
        Attr isAbstract = yes(node,"abstract") ? Attr.ABSTRACT : null;
        Attr isOne      = yes(node,"one")      ? Attr.ONE      : null;
        Attr isLone     = yes(node,"lone")     ? Attr.LONE     : null;
        Attr isSome     = yes(node,"some")     ? Attr.SOME     : null;
        Attr isPrivate  = yes(node,"private"? Attr.PRIVATE  : null;
        Attr isMeta     = yes(node,"meta")     ? Attr.META     : null;
        Attr isEnum     = yes(node,"enum")     ? Attr.ENUM     : null;
        Attr isExact    = yes(node,"exact")    ? Attr.EXACT    : null;
        if (yes(node,"builtin")) {
           if (label.equals(UNIV.label))   { id2sig.put(id, UNIV);   return UNIV;   }
           if (label.equals(SIGINT.label)) { id2sig.put(id, SIGINT); return SIGINT; }
           if (label.equals(SEQIDX.label)) { id2sig.put(id, SEQIDX); return SEQIDX; }
           if (label.equals(STRING.label)) { id2sig.put(id, STRING); return STRING; }
           throw new IOException("Unknown builtin sig: "+label+" (id="+id+")");
        }
        if (depth > nmap.size()) throw new IOException("Sig "+label+" (id="+id+") is in a cyclic inheritance relationship.");
        List<Sig> parents = null;
        TupleSet ts = factory.noneOf(1);
        for(XMLNode sub:node) {
           if (sub.is("atom")) { ts.add(factory.tuple(sub.getAttribute("label"))); continue; }
           if (!sub.is("type")) continue;
           Sig parent = parseSig(sub.getAttribute("ID"), depth+1);
           if (parents==null) parents = new ArrayList<Sig>();
           parents.add(parent);
        }
        if (parents==null) {
           String parentID = node.getAttribute("parentID");
           Sig parent = parseSig(parentID, depth+1);
           if (!(parent instanceof PrimSig)) throw new IOException("Parent of sig "+label+" (id="+id+") must not be a subset sig.");
           for(Expr choice: choices)
              if (choice instanceof PrimSig && parent==((PrimSig)choice).parent && ((Sig)choice).label.equals(label))
                 { ans=(Sig)choice; choices.remove(choice); break; }
View Full Code Here


        return expr;
    }

    /** Parse field. */
    private Field parseField(String id) throws IOException, Err {
       final XMLNode node = nmap.get(id);
       if (node==null) throw new IOException("Unknown FieldID "+id+" encountered.");
       if (!node.is("field")) throw new IOException("ID "+id+" is not a field.");
       String label  = label(node);
       Pos isPrivate = yes(node,"private") ? Pos.UNKNOWN : null;
       Pos isMeta = yes(node,"meta") ? Pos.UNKNOWN : null;
       Expr type = null;
       for(XMLNode sub:node) if (sub.is("types")) { Expr t=parseType(sub); if (type==null) type=t; else type=type.plus(t); }
       int arity;
       if (type==null || (arity=type.type().arity())<2) throw new IOException("Field "+label+" is maltyped.");
       String parentID = node.getAttribute("parentID");
       Sig parent = id2sig.get(parentID);
       if (parent==null) throw new IOException("ID "+parentID+" is not a sig.");
       Field field = null;
       for(Field f: parent.getFields())
           if (f.label.equals(label) && f.type().arity()==arity && choices.contains(f))
View Full Code Here

       return field;
    }

    /** Parse skolem. */
    private ExprVar parseSkolem(String id) throws IOException, Err {
       final XMLNode node = nmap.get(id);
       if (node==null) throw new IOException("Unknown ID "+id+" encountered.");
       if (!node.is("skolem")) throw new IOException("ID "+id+" is not a skolem.");
       String label = label(node);
       Expr type = null;
       for(XMLNode sub:node) if (sub.is("types")) { Expr t=parseType(sub); if (type==null) type=t; else type=type.plus(t); }
       int arity;
       if (type==null || (arity=type.type().arity())<1) throw new IOException("Skolem "+label+" is maltyped.");
View Full Code Here

           choices.add(s);
           for(Field f:s.getFields()) choices.add(f);
       }
       // find <instance>..</instance>
       if (!xml.is("alloy")) throw new ErrorSyntax("The XML file's root node must be <alloy> or <instance>.");
       XMLNode inst = null;
       for(XMLNode sub: xml) if (sub.is("instance")) { inst=sub; break; }
       if (inst==null) throw new ErrorSyntax("The XML file must contain an <instance> element.");
       // set up the basic values of the A4Solution object
       final int bitwidth = Integer.parseInt(inst.getAttribute("bitwidth"));
       final int maxseq = Integer.parseInt(inst.getAttribute("maxseq"));
       final int max = (1<<(bitwidth-1))-1, min = 0-(1<<(bitwidth-1));
       if (bitwidth>=1 && bitwidth<=30) for(int i=min; i<=max; i++) { atoms.add(Integer.toString(i)); }
       for(XMLNode x:inst) {
           String id=x.getAttribute("ID");
           if (id.length()>0 && (x.is("field") || x.is("skolem") || x.is("sig"))) {
              if (nmap.put(id, x)!=null) throw new IOException("ID "+id+" is repeated.");
              if (x.is("sig")) {
                  boolean isString = STRING.label.equals(label(x)) && yes(x, "builtin");
                  for(XMLNode y:x) if (y.is("atom")) {
                      String attr = y.getAttribute("label");
                      atoms.add(attr);
                      if (isString) strings.add(attr);
                  }
              }
           }
       }
       // create the A4Solution object
       A4Options opt = new A4Options();
       opt.originalFilename = inst.getAttribute("filename");
       sol = new A4Solution(inst.getAttribute("command"), bitwidth, maxseq, strings, atoms, null, opt, 1);
       factory = sol.getFactory();
       // parse all the sigs, fields, and skolems
       for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("sig")) parseSig(e.getKey(), 0);
       for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("field")) parseField(e.getKey());
       for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("skolem")) parseSkolem(e.getKey());
View Full Code Here

        }
    }

    /** Validate the given filename to see if it is a valid Alloy XML instance file. */
    private static void validate(String filename) throws Exception {
        A4SolutionReader.read(new ArrayList<Sig>(), new XMLNode(new File(filename))).toString();
        StaticInstanceReader.parseInstance(new File(filename));
    }
View Full Code Here

      }
   }

   /** Parse the file into an AlloyInstance if possible. */
   private StaticInstanceReader(XMLNode root) throws Err {
      XMLNode inst = null;
      for(XMLNode sub: root) if (sub.is("instance")) { inst=sub; break; }
      if (inst==null) throw new ErrorSyntax("The XML file must contain an <instance> element.");
      boolean isMeta = "yes".equals(inst.getAttribute("metamodel"));
      A4Solution sol = A4SolutionReader.read(new ArrayList<Sig>(), root);
      for (Sig s:sol.getAllReachableSigs()) if (s instanceof PrimSig && ((PrimSig)s).parent==Sig.UNIV) toplevels.add((PrimSig)s);
      if (!isMeta) {
         sig2type.put(Sig.UNIV, AlloyType.UNIV);
         sig2type.put(Sig.SIGINT, AlloyType.INT);
View Full Code Here

   }

   /** Parse the file into an AlloyInstance if possible. */
   public static AlloyInstance parseInstance(File file) throws Err {
      try {
         return (new StaticInstanceReader(new XMLNode(file))).ans;
      } catch(IOException ex) {
         throw new ErrorFatal("Error reading the XML file: " + ex, ex);
      }
   }
View Full Code Here

   }

   /** Parse the file into an AlloyInstance if possible, then close the Reader afterwards. */
   public static AlloyInstance parseInstance(Reader reader) throws Err {
      try {
         return (new StaticInstanceReader(new XMLNode(reader))).ans;
      } catch(IOException ex) {
         throw new ErrorFatal("Error reading the XML file: " + ex, ex);
      }
   }
View Full Code Here

   /** Read the XML file and merge its settings into an existing VizState object. */
   public static void readAlloy(String filename, VizState theme) throws IOException {
      File file = new File(filename);
      try {
         XMLNode elem = new XMLNode(file);
         for(XMLNode sub: elem.getChildren("view")) parseView(sub,theme);
      } catch(Throwable e) {
         throw new IOException("The file \""+file.getPath()+"\" is not a valid XML file, or an error occurred in reading.");
      }
   }
View Full Code Here

/** XMLDocument initialisation
*/
  public XmlConfig(String configFileName){
     try {
         DOMParser parser = new DOMParser();
         URL url = createURL(configFileName);
         parser.setErrorStream(System.err);
         parser.showWarnings(true);
         parser.parse(url);
         configDoc = parser.getDocument();
         rootConfigNode = (XMLNode) configDoc;
     } catch (Exception e) {
         System.out.println(e.toString());
     }
  }
View Full Code Here

TOP

Related Classes of oracle.xml.parser.v2.XMLNode

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.