Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 236   Methods: 10
NCLOC: 145   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ParserImpl.java 0% 0% 0% 0%
coverage
 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    /**
 20    * <p>Title: WSMO4J</p>
 21    * <p>Description: WSMO API and a Reference Implementation</p>
 22    * <p>Copyright: Copyright (c) 2004-2005</p>
 23    * <p>Company: OntoText Lab. / SIRMA </p>
 24    */
 25   
 26    package com.ontotext.wsmo4j.parser.wsml;
 27   
 28    import java.io.*;
 29    import java.util.*;
 30   
 31    import org.deri.wsmo4j.io.parser.*;
 32    import org.deri.wsmo4j.io.parser.wsml.*;
 33    import org.wsmo.common.*;
 34    import org.wsmo.common.exception.*;
 35    import org.wsmo.factory.*;
 36    import org.wsmo.validator.ValidationError;
 37    import org.wsmo.validator.ValidationWarning;
 38    import org.wsmo.wsml.*;
 39    import org.wsmo.wsml.compiler.lexer.*;
 40    import org.wsmo.wsml.compiler.node.*;
 41   
 42    public class ParserImpl implements Parser {
 43   
 44    protected WsmoFactory factory;
 45    protected LogicalExpressionFactory LEFactory;
 46    protected DataFactory dataFactory;
 47    protected boolean cleanOnParse=false;
 48    protected boolean memorizeLELook=false;
 49   
 50  0 public ParserImpl(Map map) {
 51  0 Object o = map.get(Factory.WSMO_FACTORY);
 52  0 if (o == null || !(o instanceof WsmoFactory)) {
 53  0 o = Factory.createWsmoFactory(new HashMap <String, Object> ());
 54    }
 55  0 factory = (WsmoFactory) o;
 56  0 assert (factory != null);
 57   
 58  0 o = map.get(Factory.LE_FACTORY);
 59  0 if (o == null || !(o instanceof LogicalExpressionFactory)) {
 60  0 o = Factory.createLogicalExpressionFactory(new HashMap <String, Object> ());
 61    }
 62  0 LEFactory = (LogicalExpressionFactory) o;
 63  0 assert (LEFactory != null);
 64   
 65  0 o = map.get(Factory.DATA_FACTORY);
 66  0 if (o == null || !(o instanceof DataFactory)) {
 67  0 o = Factory.createDataFactory(new HashMap <String, Object> ());
 68    }
 69  0 dataFactory = (DataFactory) o;
 70  0 assert (dataFactory != null);
 71   
 72  0 o = map.get(Parser.CLEAR_MODEL);
 73  0 if (o != null && !o.toString().equals("false")){
 74  0 cleanOnParse=true;
 75    }
 76   
 77  0 o = map.get(Parser.CACHE_LOGICALEXPRESSION_STRING);
 78  0 if (o != null && !o.toString().equals("false")){
 79  0 memorizeLELook=true;
 80    }
 81    }
 82   
 83  0 public TopEntity[] parse(Reader src) throws IOException, ParserException, InvalidModelException {
 84  0 return _parse(src);
 85    }
 86   
 87  0 public TopEntity[] parse(Reader src, Map options) throws IOException, ParserException,
 88    InvalidModelException {
 89  0 throw new UnsupportedOperationException("Use method parse(Reader) instead!");
 90    }
 91   
 92  0 public TopEntity[] parse(StringBuffer src) throws ParserException, InvalidModelException {
 93  0 try {
 94  0 return _parse(new StringReader(src.toString()));
 95    }
 96    catch (IOException e) {
 97    // should never happens
 98  0 throw new RuntimeException("I/O error occured!", e);
 99    }
 100    }
 101   
 102  0 public TopEntity[] parse(StringBuffer src, Map options) throws ParserException,
 103    InvalidModelException {
 104  0 throw new UnsupportedOperationException("Use method parse(StringBuffer) instead!");
 105    }
 106   
 107  0 protected ASTAnalysisContainer createContainer() {
 108  0 ASTAnalysisContainer container = new ASTAnalysisContainer();
 109   
 110  0 new IdentifierAnalysis(container, factory);
 111  0 new OntologyAnalysis(container, factory, dataFactory).setCleanOnParse(cleanOnParse);
 112  0 new MediatorAnalysis(container, factory).setCleanOnParse(cleanOnParse);
 113  0 new NFPAnalysis(container);
 114  0 new ValueAnalysis(container, dataFactory, LEFactory, factory);
 115  0 new TopEntityAnalysis(container, factory);
 116  0 new ServiceAnalysis(container, factory, LEFactory).setCleanOnParse(cleanOnParse);
 117  0 new AxiomAnalysis(container, factory);
 118  0 new VariableAnalysis(container, LEFactory);
 119  0 new AtomicExpressionAnalysis(container, factory,LEFactory);
 120  0 new CompoundExpressionAnalysis(container, LEFactory);
 121  0 return container;
 122    }
 123   
 124  0 private TopEntity[] _parse(Reader src) throws ParserException,
 125    InvalidModelException, IOException {
 126  0 ASTAnalysisContainer container = createContainer();
 127   
 128  0 if (memorizeLELook){
 129  0 src = LogExprParserImpl.findLogicalExpressions(
 130    src,container.getStack(String.class));
 131    }
 132   
 133  0 Lexer lexer = new Lexer(new PushbackReader(src, 16384));
 134  0 org.wsmo.wsml.compiler.parser.Parser parser =
 135    new org.wsmo.wsml.compiler.parser.Parser(lexer);
 136   
 137  0 try {
 138  0 Start head = parser.parse();
 139  0 head.apply(container);
 140  0 Stack stack = container.getStack(TopEntity.class);
 141  0 TopEntity[] topEntities = new TopEntity[stack.size()];
 142  0 for (int i = 0; i < topEntities.length; i++) {
 143  0 topEntities[i] = (TopEntity) stack.remove(0);
 144    }
 145  0 return topEntities;
 146    }
 147    catch (org.wsmo.wsml.compiler.parser.ParserException pe) {
 148  0 ParserException e = new ParserException(ParserException.NOT_VALID_PARSETREE,pe);
 149  0 Token t = pe.getToken();
 150  0 e.setErrorLine(t.getLine());
 151  0 e.setErrorPos(t.getPos());
 152  0 e.setFoundToken(t.getText());
 153  0 try{
 154  0 e.setExpectedToken(pe.getMessage().split("expecting: ")[1].trim());
 155    }
 156    catch (IndexOutOfBoundsException iobE){
 157    //if error message does not follow usual pattern
 158  0 e.setExpectedToken(pe.getMessage());
 159    }
 160  0 throw e;
 161    }
 162    catch (org.wsmo.wsml.compiler.lexer.LexerException le) {
 163  0 ParserException e = new ParserException(ParserException.NOT_VALID_PARSETREE, le);
 164  0 try{
 165  0 e.setErrorLine(Integer.parseInt(le.getMessage().split(",")[0].split("\\[")[1]));
 166    }catch (NumberFormatException nfE){
 167    //could not find line so leave default
 168    }
 169  0 try{
 170  0 e.setErrorPos(Integer.parseInt(le.getMessage().split(",")[1].split("\\]")[0]));
 171    }catch (NumberFormatException nfE){
 172    //could not find pos so leave default
 173    }
 174  0 throw e;
 175    }
 176    catch (WrappedParsingException wpe) {
 177  0 if (wpe.getWrappedException() instanceof ParserException){
 178  0 throw (ParserException) wpe.getWrappedException();
 179    }
 180  0 throw new RuntimeException(wpe);
 181    }
 182    }
 183   
 184  0 public Set <String> listKeywords() {
 185  0 String[] wsmlTokens = ASTAnalysisContainer.WSML_TOKENS;
 186  0 return new HashSet <String>(Arrays.asList(wsmlTokens));
 187    }
 188   
 189    /*
 190    * (non-Javadoc)
 191    * @see org.wsmo.wsml.Parser#getWarnings()
 192    */
 193  0 public List <Object> getWarnings() {
 194  0 throw new UnsupportedOperationException("This method is not implemented for WSML parsing");
 195    }
 196   
 197    /*
 198    * (non-Javadoc)
 199    * @see org.wsmo.wsml.Parser#getErrors()
 200    */
 201  0 public List <Object> getErrors() {
 202  0 throw new UnsupportedOperationException("This method is not implemented for WSML parsing");
 203    }
 204    }
 205   
 206    /*
 207    * $Log$
 208    * Revision 1.9 2007/04/02 12:13:28 morcen
 209    * Generics support added to wsmo-api, wsmo4j and wsmo-test
 210    *
 211    * Revision 1.8 2006/11/17 15:07:59 holgerlausen
 212    * added an option to the parser to "remember" the original format of logical expressions, added the representation of the original String to LEImpl, and added to the serializer to check for the orginal formating to not not make complex expressions unreadable when serialized.
 213    *
 214    * Revision 1.7 2006/11/10 11:08:53 nathaliest
 215    * added getWarnings() and getErrors() methods to Parser interface, implemented them in the rdf parser implementation and added UnsupportedOperationException to the other parser implementations
 216    *
 217    * Revision 1.6 2006/06/21 07:46:29 vassil_momtchev
 218    * createVariable(String) method moved from WsmoFactory to LogicalExpressionFactory interface
 219    *
 220    * Revision 1.5 2006/04/11 16:06:58 holgerlausen
 221    * addressed RFE 1468651 ( http://sourceforge.net/tracker/index.php?func=detail&aid=1468651&group_id=113501&atid=665349)
 222    * currently the default behaviour of the parser is still as before
 223    *
 224    * Revision 1.4 2006/01/11 13:03:30 marin_dimitrov
 225    * common constants moved to Factory
 226    *
 227    * Revision 1.3 2005/12/14 08:58:56 vassil_momtchev
 228    * removed hardcoded wsmo and datafactory impl
 229    *
 230    * Revision 1.2 2005/12/09 11:28:42 vassil_momtchev
 231    * listkeywords method added; returns all known tokens from the grammar
 232    *
 233    * Revision 1.1 2005/11/28 13:55:26 vassil_momtchev
 234    * AST analyses
 235    *
 236    */