View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3   
4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
5   
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17   */
18  
19  package com.ontotext.wsmo4j.parser.owl;
20  
21  import java.io.IOException;
22  import java.io.Reader;
23  import java.io.StringReader;
24  import java.util.HashSet;
25  import java.util.List;
26  import java.util.Map;
27  import java.util.Set;
28  
29  import org.wsmo.common.TopEntity;
30  import org.wsmo.common.exception.InvalidModelException;
31  import org.wsmo.factory.DataFactory;
32  import org.wsmo.factory.Factory;
33  import org.wsmo.factory.LogicalExpressionFactory;
34  import org.wsmo.factory.WsmoFactory;
35  import org.wsmo.wsml.Parser;
36  import org.wsmo.wsml.ParserException;
37  
38  
39  /**
40   * <p>Title: WSMO4J</p>
41   * <p>Description: WSMO API and a Reference Implementation - OWL parser implementation</p>
42   * <p>Copyright:  Copyright (c) 2004-2005</p>
43   * <p>Company: OntoText Lab. / SIRMA </p>
44   * @author not attributable
45   * @version 1.0
46   *
47   */
48  public class OWLParser implements Parser {
49  
50  	WsmoFactory _factory;
51  	LogicalExpressionFactory _leFactory;
52  	DataFactory _dataFactory;
53  
54  	public OWLParser(Map params) {
55  		if (null == (_factory = (WsmoFactory)params.get(Factory.WSMO_FACTORY)))
56  			_factory = Factory.createWsmoFactory(null);
57  
58  		if (null == (_leFactory = (LogicalExpressionFactory)params.get(Factory.LE_FACTORY)))
59  			_leFactory = Factory.createLogicalExpressionFactory(null);
60  
61  		if (null == (_dataFactory = (DataFactory)params.get(Factory.DATA_FACTORY)))
62  			_dataFactory = Factory.createDataFactory(null);
63  
64  	}
65  	/* (non-Javadoc)
66  	 * @see org.wsmo.io.parser.Parser#parse(java.io.Reader)
67  	 */
68  	public TopEntity[] parse(Reader src) throws IOException, ParserException,
69  			InvalidModelException {
70  		try {
71  			return new TopEntity[]{new WSMLFromOWL(_factory, _leFactory, _dataFactory).process(src, null)};
72  		} catch (Exception e) {
73  			throw new ParserException("on importing OWL", e);
74  		}
75  	}
76  	/* (non-Javadoc)
77  	 * @see org.wsmo.io.parser.Parser#parse(java.lang.StringBuffer)
78  	 */
79  	public TopEntity[] parse(StringBuffer src) throws ParserException,
80  			InvalidModelException {
81          StringReader r = new StringReader(src.toString());
82          try {
83              return parse(r);
84          }
85          catch (IOException e) {
86              throw new ParserException("IOException caught", e);
87          }
88  	}
89  	/* (non-Javadoc)
90  	 * @see org.wsmo.wsml.Parser#parse(java.io.Reader, java.util.Map)
91  	 */
92  	public TopEntity[] parse(Reader src, Map options) throws IOException, ParserException, InvalidModelException {
93  		// TODO Auto-generated method stub
94  		return parse(src);
95  	}
96  	/* (non-Javadoc)
97  	 * @see org.wsmo.wsml.Parser#parse(java.lang.StringBuffer, java.util.Map)
98  	 */
99  	public TopEntity[] parse(StringBuffer src, Map options) throws ParserException, InvalidModelException {
100 		// TODO Auto-generated method stub
101 		return parse(src);
102 	}
103     /* (non-Javadoc)
104      * @see org.wsmo.wsml.Parser#listKeywords())
105      */
106     public Set <String> listKeywords() {
107         return new HashSet <String>();
108     }
109 	
110     /*
111      *  (non-Javadoc)
112      * @see org.wsmo.wsml.Parser#getWarnings()
113      */
114     public List <Object> getWarnings() {
115 		throw new UnsupportedOperationException("This method is not implemented for OWL parsing");
116 	}
117     
118     /*
119      *  (non-Javadoc)
120      * @see org.wsmo.wsml.Parser#getErrors()
121      */
122 	public List <Object> getErrors() {
123 		throw new UnsupportedOperationException("This method is not implemented for OWL parsing");
124 	}
125 }
126 
127 /*
128  * $Log$
129  * Revision 1.7  2007/04/02 12:13:27  morcen
130  * Generics support added to wsmo-api, wsmo4j and wsmo-test
131  *
132  * Revision 1.6  2006/11/10 11:08:54  nathaliest
133  * added getWarnings() and getErrors() methods to Parser interface, implemented them in the rdf parser implementation and added UnsupportedOperationException to the other parser implementations
134  *
135  * Revision 1.5  2006/01/11 13:03:03  marin_dimitrov
136  * common constants moved to Factory
137  *
138 /*
139  * Revision 1.4  2005/12/14 09:54:07  vassil_momtchev
140 /*
141  * changed all const from IRIto String [Constants, OWLConstants, WSMLFromOWL] - no more wsmo4j constructors invoked!
142 /*
143  * organized imports to use com.ontotext.* instead to list all used types (see the rest of code and the code convetion)
144 /*
145  * commented all non used local variables (all warnings removed)
146 /*
147  *
148 */
149