Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 277   Methods: 13
NCLOC: 128   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WsmlXmlParser.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    package com.ontotext.wsmo4j.parser.xml;
 19   
 20    /**
 21    * <p>Title: WSMO4J</p>
 22    * <p>Description: WSMO API and a Reference Implementation</p>
 23    * <p>Copyright: Copyright (c) 2004-2005</p>
 24    * <p>Company: OntoText Lab. / SIRMA </p>
 25    * @author not attributable
 26    * @version 1.0
 27    *
 28    */
 29    import java.io.IOException;
 30    import java.io.Reader;
 31    import java.io.StringReader;
 32    import java.util.HashMap;
 33    import java.util.HashSet;
 34    import java.util.List;
 35    import java.util.Map;
 36    import java.util.Set;
 37    import java.util.Vector;
 38   
 39    import javax.xml.parsers.DocumentBuilder;
 40    import javax.xml.parsers.DocumentBuilderFactory;
 41    import javax.xml.parsers.ParserConfigurationException;
 42   
 43    import org.deri.wsmo4j.io.parser.xml.LogExprParserImpl;
 44    import org.w3c.dom.Document;
 45    import org.w3c.dom.Node;
 46    import org.w3c.dom.NodeList;
 47    import org.wsmo.common.TopEntity;
 48    import org.wsmo.common.exception.InvalidModelException;
 49    import org.wsmo.factory.DataFactory;
 50    import org.wsmo.factory.Factory;
 51    import org.wsmo.factory.LogicalExpressionFactory;
 52    import org.wsmo.factory.WsmoFactory;
 53    import org.wsmo.wsml.Parser;
 54    import org.wsmo.wsml.ParserException;
 55    import org.xml.sax.InputSource;
 56    import org.xml.sax.SAXException;
 57   
 58    import com.ontotext.wsmo4j.parser.WrappedInvalidModelException;
 59   
 60    /**
 61    * Parse XML file and creates WSMO obkjects (check wsml-xml-syntax.xsd)
 62    *
 63    * @author not attributable
 64    */
 65    public class WsmlXmlParser implements Parser {
 66   
 67    private static final boolean isValidating = false;
 68   
 69    private WsmoFactory wsmoFactory;
 70   
 71    private LogicalExpressionFactory leFactory;
 72   
 73    private DataFactory dataFactory;
 74   
 75    private LogExprParserImpl leParser;
 76   
 77    /**
 78    * Map properties = new TreeMap();
 79    * properties.put(Factory.PROVIDER_CLASS, "com.ontotext.wsmo4j.xmlparser.WsmlXmlParser");
 80    * properties.put(Parser.PARSER_WSMO_FACTORY, factory);
 81    * properties.put(Parser.PARSER_LE_FACTORY, leFactory);
 82    * parser = Factory.createParser(properties);
 83    *
 84    * @param map Initialization properties, requires Parser.PARSER_LE_FACTORY
 85    * and Parser.PARSER_WSMO_FACTORY
 86    */
 87  0 public WsmlXmlParser(Map map) {
 88  0 wsmoFactory = (WsmoFactory) map.get(Factory.WSMO_FACTORY);
 89  0 leFactory = (LogicalExpressionFactory) map.get(Factory.LE_FACTORY);
 90  0 dataFactory = (DataFactory) map.get(Factory.DATA_FACTORY);
 91  0 if (wsmoFactory == null) {
 92  0 wsmoFactory = Factory.createWsmoFactory(new HashMap <String, Object> ());
 93    }
 94  0 if (leFactory == null) {
 95  0 leFactory = Factory.createLogicalExpressionFactory(new HashMap <String, Object> ());
 96    }
 97  0 if (dataFactory == null) {
 98  0 dataFactory = Factory.createDataFactory(new HashMap <String, Object> ());
 99    }
 100   
 101  0 assert wsmoFactory != null;
 102  0 assert leFactory != null;
 103  0 assert dataFactory != null;
 104   
 105  0 leParser = new LogExprParserImpl(map);
 106    }
 107   
 108  0 WsmoFactory getFactory() {
 109  0 return wsmoFactory;
 110    }
 111   
 112  0 LogicalExpressionFactory getLEFactory() {
 113  0 return leFactory;
 114    }
 115   
 116  0 DataFactory getDataFactory() {
 117  0 return dataFactory;
 118    }
 119   
 120  0 LogExprParserImpl getLEParser() {
 121  0 return leParser;
 122    }
 123   
 124    /**
 125    * Parses a XML source
 126    *
 127    * @param src Reader to the xml file
 128    */
 129  0 public TopEntity[] parse(Reader src) throws IOException, ParserException {
 130  0 return parse(new InputSource(src));
 131    }
 132   
 133    /**
 134    * Parses a XML source
 135    *
 136    * @param src Reader to the xml file
 137    * @param options Ignored
 138    */
 139  0 public TopEntity[] parse(Reader src, Map options) throws IOException, ParserException {
 140  0 return parse(src);
 141    }
 142   
 143    /**
 144    * Parses a XML source
 145    *
 146    * @param src Source xml
 147    */
 148  0 public TopEntity[] parse(StringBuffer src) throws ParserException {
 149  0 try {
 150  0 return parse(new InputSource(new StringReader(src.toString())));
 151    }
 152    catch (IOException e) {
 153  0 throw new RuntimeException("IOException occured! " + e.getMessage(), e);
 154    }
 155    }
 156   
 157    /**
 158    * Parses a XML source
 159    *
 160    * @param src Source xml
 161    * @param options Ignored
 162    */
 163  0 public TopEntity[] parse(StringBuffer src, Map options) throws ParserException {
 164  0 return parse(src);
 165    }
 166   
 167  0 private TopEntity[] parse(InputSource source) throws IOException, ParserException {
 168  0 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 169   
 170  0 try {
 171  0 factory.setNamespaceAware(true);
 172   
 173  0 if (isValidating) {
 174  0 try {
 175    /*factory.setValidating(true);
 176    factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
 177    "http://www.w3.org/2001/XMLSchema");
 178    factory
 179    .setAttribute(
 180    "http://java.sun.com/xml/jaxp/properties/schemaSource",
 181    new File("URL TO THE SCHEMA"));
 182    */
 183    }
 184    catch (IllegalArgumentException e) {
 185  0 System.out.println("Schema validation is disabled!");
 186  0 System.out
 187    .println("Xml parser implementaion does not support JAXP 1.2 "
 188    + "To change the JAXP implementation with Xerces (or another alternative JAXP "
 189    + "1.2 enabled parser start with -Djavax.xml.parsers.DocumentBuilderFactory="
 190    + "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
 191    }
 192    }
 193   
 194  0 DocumentBuilder docBuilder = factory.newDocumentBuilder();
 195  0 Document document = docBuilder.parse(source);
 196  0 NodeList nodes = document.getElementsByTagName("wsml");
 197  0 Vector <TopEntity> topEntities = new Vector <TopEntity> ();
 198   
 199  0 for (int i = 0; i < nodes.getLength(); i++) {
 200  0 Node node = nodes.item(i);
 201  0 topEntities.add(NodeWsml.deserialzieTopEntity(node, this));
 202  0 assert topEntities.elementAt(i) != null;
 203    }
 204   
 205  0 return topEntities.toArray(new TopEntity[]{});
 206    }
 207    catch (InvalidModelException e) {
 208  0 throw new WrappedInvalidModelException(e);
 209    }
 210    catch (SAXException e) {
 211  0 throw new ParserException(e.getMessage(), e);
 212    }
 213    catch (ParserConfigurationException e) {
 214  0 throw new ParserException(e.getMessage(), e);
 215    }
 216    }
 217   
 218  0 public Set <String> listKeywords() {
 219  0 return new HashSet <String>();
 220    }
 221   
 222    /*
 223    * (non-Javadoc)
 224    * @see org.wsmo.wsml.Parser#getWarnings()
 225    */
 226  0 public List <Object> getWarnings() {
 227  0 throw new UnsupportedOperationException("This method is not implemented for XML parsing");
 228    }
 229   
 230    /*
 231    * (non-Javadoc)
 232    * @see org.wsmo.wsml.Parser#getErrors()
 233    */
 234  0 public List <Object> getErrors() {
 235  0 throw new UnsupportedOperationException("This method is not implemented for XML parsing");
 236    }
 237    }
 238   
 239    /*
 240    * $Log$
 241    * Revision 1.8 2007/04/02 12:19:08 morcen
 242    * Generics support added to wsmo-api, wsmo4j and wsmo-test
 243    *
 244    * Revision 1.7 2007/04/02 12:13:22 morcen
 245    * Generics support added to wsmo-api, wsmo4j and wsmo-test
 246    *
 247    * Revision 1.6 2006/11/10 11:08:53 nathaliest
 248    * added getWarnings() and getErrors() methods to Parser interface, implemented them in the rdf parser implementation and added UnsupportedOperationException to the other parser implementations
 249    *
 250    * Revision 1.5 2006/01/13 10:06:56 vassil_momtchev
 251    * removed hardcoded schema url. schema validation is still not used.
 252    *
 253    * Revision 1.4 2006/01/13 09:59:10 vassil_momtchev
 254    * exceptions handling refactored; isValidation const added
 255    *
 256    * Revision 1.3 2006/01/11 13:03:30 marin_dimitrov
 257    * common constants moved to Factory
 258    *
 259    * Revision 1.2 2005/12/09 11:29:32 vassil_momtchev
 260    * listkeywords method added; implemented to return empty set
 261    *
 262    * Revision 1.1 2005/11/28 14:03:48 vassil_momtchev
 263    * package refactored from com.ontotext.wsmo4j.xmlparser to com.ontotext.wsmo4j.parser.xml
 264    *
 265    * Revision 1.6 2005/09/21 06:28:56 holgerlausen
 266    * removing explicit factory creations and introducing parameter maps for parsers
 267    *
 268    * Revision 1.5 2005/09/17 09:02:51 vassil_momtchev
 269    * datafactory is passed with the map in constructor
 270    *
 271    * Revision 1.4 2005/09/02 09:43:32 ohamano
 272    * integrate wsmo-api and le-api on api and reference implementation level; full parser, serializer and validator integration will be next step
 273    *
 274    * Revision 1.3 2005/08/08 08:15:00 vassil_momtchev
 275    * javadoc added, implemented all parse methods, optimize xml transformation
 276    *
 277    */