Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 235   Methods: 15
NCLOC: 137   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WsmlRdfSerializer.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3   
 4    Copyright (c) 2006, University of Innsbruck, Austria
 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 org.deri.wsmo4j.io.serializer.rdf;
 19   
 20    import java.io.*;
 21    import java.util.*;
 22   
 23    import org.openrdf.model.*;
 24    import org.openrdf.model.impl.*;
 25    import org.openrdf.rio.*;
 26    import org.openrdf.rio.n3.*;
 27    import org.openrdf.rio.ntriples.*;
 28    import org.openrdf.rio.rdfxml.*;
 29    import org.openrdf.rio.turtle.*;
 30    import org.openrdf.vocabulary.*;
 31    import org.wsmo.common.*;
 32    import org.wsmo.wsml.*;
 33   
 34    /**
 35    * XML serializer of WSMO object (check wsml-xml-syntax.xsd)
 36    *
 37    * @author not attributable
 38    */
 39    public class WsmlRdfSerializer implements Serializer {
 40   
 41    // property that defines to what RDF syntax should be serialized
 42    public final static String RDF_SERIALIZER_TYPE = "rdf_serializer";
 43    public final static Integer RDF_SERIALIZER_N3 = new Integer(1);
 44    public final static Integer RDF_SERIALIZER_NTRIPLES = new Integer(2);
 45    public final static Integer RDF_SERIALIZER_XML = new Integer(3);
 46    public final static Integer RDF_SERIALIZER_TURTLE = new Integer(4);
 47   
 48    // property that defines how WSML axioms should be serialized in RDF
 49    public final static String RDF_AXIOMS = "rdf_axioms";
 50    public final static String RDF_AXIOMS_TRIPLE = "rdf_axioms_triple";
 51    public final static String RDF_AXIOMS_PART = "rdf_axioms_part";
 52   
 53    public final static String DC_RELATION = "http://purl.org/dc/elements/1.1#relation";
 54   
 55    private ValueFactory vf = new ValueFactoryImpl();
 56    private RdfDocumentWriter rdw = null;
 57    private int writerType = 0;
 58    protected boolean axiomAsTriple = false;
 59   
 60    /**
 61    * Constructor should not be invoked directly.
 62    * Map properties = new TreeMap();
 63    * properties.put(Factory.PROVIDER_CLASS, "com.ontotext.wsmo4j.xmlparser.WsmlXmlSerializer");
 64    * serializer = Factory.createSerializer(properties);
 65    * @param map All parameters are ignored
 66    */
 67  0 public WsmlRdfSerializer(Map map) {
 68  0 if(map.get(RDF_SERIALIZER_TYPE)!=null) {
 69  0 writerType = ((Integer)map.get(RDF_SERIALIZER_TYPE)).intValue();
 70    } else {
 71    //default serialization = RDF/XML
 72  0 writerType = RDF_SERIALIZER_XML.intValue();
 73    }
 74  0 if (map.get(RDF_AXIOMS) != null) {
 75  0 String axiom_style = (String) map.get(RDF_AXIOMS);
 76  0 if (axiom_style.equals(RDF_AXIOMS_TRIPLE))
 77  0 axiomAsTriple = true;
 78  0 else if (axiom_style.equals(RDF_AXIOMS_PART))
 79  0 axiomAsTriple = false;
 80    }
 81    else {
 82  0 axiomAsTriple = false;
 83    }
 84    }
 85   
 86  0 public ValueFactory getFactory() { return vf; }
 87  0 public RdfDocumentWriter getWriter() { return rdw;}
 88   
 89  0 private RdfDocumentWriter setSerializer(Writer target) {
 90  0 switch(writerType) {
 91  0 case 1:
 92  0 return new N3Writer(target);
 93  0 case 2:
 94  0 return new NTriplesWriter(target);
 95  0 case 3:
 96  0 return new RdfXmlWriter(target);
 97  0 case 4:
 98  0 return new TurtleWriter(target);
 99  0 default:
 100  0 return null;
 101    }
 102    }
 103   
 104    /**
 105    * Serialize array of top entities to XML
 106    * @param item Entities to serialize
 107    * @param target Output
 108    */
 109  0 public void serialize(TopEntity[] item, Writer target) throws IOException {
 110  0 rdw = setSerializer(target);
 111  0 try {
 112    //rdf
 113  0 this.getWriter().setNamespace(
 114    "rdf",
 115    RDF.NAMESPACE);
 116    //rdfs
 117  0 this.getWriter().setNamespace(
 118    "rdfs",
 119    RDFS.NAMESPACE);
 120    //xsd
 121  0 this.getWriter().setNamespace(
 122    "xsd",
 123    XmlSchema.NAMESPACE);
 124    //defined namespace bindings
 125  0 for (int i = 0; i < item.length; i++) {
 126    //default namespace
 127  0 this.getWriter().setNamespace(
 128    "",
 129    item[i].getDefaultNamespace().getIRI().toString());
 130  0 if(!item[i].listNamespaces().isEmpty()) {
 131  0 Iterator iter = item[i].listNamespaces().iterator();
 132  0 while (iter.hasNext()) {
 133  0 Namespace ns = (Namespace)iter.next();
 134  0 this.getWriter().setNamespace(
 135    ns.getPrefix(),ns.getIRI().toString());
 136   
 137    }
 138    }
 139    }
 140  0 rdw.startDocument();
 141   
 142  0 NodeWsml.serializeTopEntity(item, this);
 143   
 144  0 rdw.endDocument();
 145    }
 146    catch (IOException e) {
 147  0 throw new RuntimeException(e);
 148    }
 149    }
 150   
 151    /**
 152    * Serialize array of top entities to XML
 153    * @param item Entities to serialize
 154    * @param target Output
 155    * @param options Ignored
 156    */
 157  0 public void serialize(TopEntity[] item, Writer target, Map options) throws IOException {
 158  0 serialize(item, target);
 159    }
 160   
 161    /**
 162    * Serialize array of top entities to XML
 163    * @param item Entities to serialize
 164    * @param target Output
 165    */
 166  0 public void serialize(TopEntity[] item, final StringBuffer target) {
 167  0 Writer myWriter = new Writer() {
 168   
 169  0 public void write(String arg0) throws IOException {
 170  0 target.append(arg0);
 171    }
 172   
 173  0 public void write(String arg0, int arg1, int arg2) throws IOException {
 174  0 target.append(arg0.toCharArray(), arg1, arg2);
 175    }
 176   
 177  0 public void write(int arg0) throws IOException {
 178  0 if (arg0 <= 255) {
 179  0 target.append((char) arg0);
 180    }
 181    else {
 182  0 byte[] bytes = new byte[] {(byte) (arg0 & 0x00FF), (byte) (arg0 & 0xFF00)};
 183  0 target.append(new String(bytes));
 184    }
 185    }
 186   
 187  0 public void write(char[] arg0) throws IOException {
 188  0 target.append(arg0);
 189    }
 190   
 191  0 public void write(char[] arg0, int arg1, int arg2) throws IOException {
 192  0 target.append(arg0, arg1, arg2);
 193    }
 194   
 195  0 public void flush() throws IOException {
 196  0 return;
 197    }
 198   
 199  0 public void close() throws IOException {
 200  0 return;
 201    }
 202    };
 203   
 204  0 try {
 205  0 serialize(item, myWriter);
 206    }
 207    catch (IOException e) {
 208  0 return;
 209    }
 210    }
 211   
 212    /**
 213    * Serialize array of top entities to XML
 214    * @param item Entities to serialize
 215    * @param target Output
 216    * @param options Ignored
 217    */
 218  0 public void serialize(TopEntity[] item, StringBuffer target, Map options) {
 219  0 serialize(item, target);
 220    }
 221    }
 222   
 223    /*
 224    * $Log$
 225    * Revision 1.2 2006/11/10 15:38:49 ohamano
 226    * *** empty log message ***
 227    *
 228    * Revision 1.1 2006/11/10 15:02:59 ohamano
 229    * *** empty log message ***
 230    *
 231    * Revision 1.1 2006/11/10 10:08:42 ohamano
 232    * *** empty log message ***
 233    *
 234    *
 235    */