View Javadoc

1   /*
2    *  Copyright 2004 University of Hannover
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package olr.vrp;
18  
19  import java.util.List;
20  
21  import VRP.Main;
22  import VRP.Model.Model;
23  import VRP.Parser.parser;
24  import VRP.Validator.RDF_Validator;
25  
26  /***
27   * @version $Id: Parser.java,v 1.1 2004/08/02 19:25:22 roku Exp $
28   */
29  public class Parser extends Main {
30      /***
31       * Initializes an instance of this class.
32       * 
33       * @param validate
34       * @param debug
35       */
36      public Parser(boolean validate, boolean debug) {
37          this.validate = false;
38          this.validate = validate;
39          setfetch_all(false);
40          setdebug(debug);
41          setonly(false);
42          setgraph(false);
43          settriples(false);
44          setstatements(true);
45          setverbose(false);
46          setGUI(new GUI());
47      }
48  
49      public Model parse(String fileURI) throws Exception {
50          initVRP();
51          Model out_model = new Model();
52          parser p = null;
53          p = new parser(fileURI);
54          setparseroptions(p);
55          Main.p_all = p;
56          Object result = p.parse().value;
57          if (result instanceof Model) {
58              out_model = (Model) result;
59              RDF_Validator v = new RDF_Validator(out_model);
60              setvalidatoroptions(v);
61              v.setfetch(validate);
62              v.validate();
63              if (Main.error_counter == 0)
64                  return out_model;
65          }
66          throw new Exception(String.valueOf(String.valueOf((new StringBuffer("The file ")).append(
67                  fileURI).append(" is not a valid RDF file."))));
68      }
69  
70      private void initVRP() {
71          Main.error_counter = 0;
72          Main.warning_counter = 0;
73          setnoerrormsg(false);
74      }
75  
76      public List getMessages() {
77          return ((GUI) Main.gui).getMessages();
78      }
79  
80      boolean validate;
81  }