Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 201   Methods: 4
NCLOC: 129   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CreateWebServiceExample.java - 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    package com.ontotext.wsmo4j.examples;
 20   
 21    import java.io.PrintWriter;
 22    import java.util.HashMap;
 23   
 24    import org.omwg.logicalexpression.*;
 25    import org.omwg.ontology.*;
 26    import org.wsmo.common.*;
 27    import org.wsmo.common.exception.*;
 28    import org.wsmo.factory.*;
 29    import org.wsmo.service.*;
 30    import org.wsmo.wsml.*;
 31   
 32    /**
 33    * <p>Title: </p>
 34    * <p>Description: </p>
 35    * <p>Copyright: Copyright (c) 2004-2005</p>
 36    * <p>Company: Ontotext Lab., Sirma AI</p>
 37    * @author not attributable
 38    * @version 1.0
 39    */
 40   
 41    public class CreateWebServiceExample {
 42   
 43    private WsmoFactory factory;
 44   
 45    private LogicalExpressionFactory leFactory;
 46   
 47    private DataFactory dataFactory;
 48   
 49    private static String SERVICE_ID = "http://www.wsmo.org/2004/d3/d3.3/v0.1/20041008/resources/ws.wsml";
 50   
 51  0 public static void main(String[] args) throws Exception{
 52  0 WebService service = showExample();
 53   
 54  0 Serializer serializer = Factory.createSerializer(new HashMap<String, Object>(0));
 55  0 serializer.serialize(new TopEntity[] {service}, new PrintWriter(System.out));
 56    }
 57   
 58  0 public static WebService showExample() throws InvalidModelException, ParserException {
 59  0 CreateWebServiceExample example = new CreateWebServiceExample();
 60  0 example.createFactory();
 61  0 return example.createWebservice();
 62    }
 63   
 64  0 private void createFactory() {
 65    // use default implementation for the factories
 66  0 factory = Factory.createWsmoFactory(null);
 67  0 leFactory = Factory.createLogicalExpressionFactory(null);
 68  0 dataFactory = Factory.createDataFactory(null);
 69    }
 70   
 71  0 private WebService createWebservice() throws InvalidModelException, ParserException {
 72  0 IRI serviceIRI = factory.createIRI(SERVICE_ID);
 73  0 WebService service = factory.createWebService(serviceIRI);
 74  0 Namespace targetNamespace = factory.createNamespace("targetnamespace",
 75    factory.createIRI("http://www.wsmo.org/2004/d3/d3.3/v0.1/20041008/resources/ws#"));
 76   
 77    // set namespaces
 78  0 service.setDefaultNamespace(factory.createNamespace("",
 79    factory.createIRI("http://www.wsmo.org/2004/d3/d3.3/v0.1/20041008/resources/ws#")));
 80  0 service.addNamespace(factory.createNamespace("dt",
 81    factory.createIRI("http:://www.wsmo.org/ontologies/dateTime#")));
 82  0 service.addNamespace(factory.createNamespace("tc",
 83    factory.createIRI("http:://www.wsmo.org/ontologies/trainConnection#")));
 84  0 service.addNamespace(factory.createNamespace("po",
 85    factory.createIRI("http://www.wsmo.org/ontologies/purchase#")));
 86  0 service.addNamespace(factory.createNamespace("loc",
 87    factory.createIRI("http:://www.wsmo.org/ontologies/location#")));
 88  0 service.addNamespace(factory.createNamespace("ucaswe",
 89    factory.createIRI("http://www.wsmo.org/2004/d3/d3.3/v0.1/20041008/resources/")));
 90  0 service.addNamespace(targetNamespace);
 91   
 92    // set NFP values
 93  0 service.addNFPValue(factory.createIRI(NFP.DC_TITLE), dataFactory
 94    .createWsmlString("OEBB Online Ticket Booking Web Service"));
 95  0 service.addNFPValue(factory.createIRI(NFP.DC_CREATOR), dataFactory
 96    .createWsmlString("DERI International"));
 97  0 service.addNFPValue(factory.createIRI(NFP.DC_DESCRIPTION), dataFactory
 98    .createWsmlString("Web service for booking online train "
 99    + " tickets for Austria and Germany"));
 100   
 101    // import used ontologies
 102  0 service.addOntology(factory.getOntology(factory
 103    .createIRI("http:://www.wsmo.org/ontologies/dateTime")));
 104  0 service.addOntology(factory.getOntology(factory
 105    .createIRI("http:://www.wsmo.org/ontologies/trainConnection")));
 106  0 service.addOntology(factory.getOntology(factory
 107    .createIRI("http:://www.wsmo.org/ontologies/purchase")));
 108  0 service.addOntology(factory.getOntology(factory
 109    .createIRI("http:://www.wsmo.org/ontologies/location")));
 110   
 111    // create capability
 112  0 Capability capability = factory.createCapability(factory.createIRI(targetNamespace, "capability"));
 113  0 Axiom axiom = null;
 114  0 LogicalExpression logExp = null;
 115   
 116    // add capability pre-condition
 117  0 axiom = factory.createAxiom(factory.createIRI(targetNamespace, "axiom1"));
 118  0 logExp = leFactory.createLogicalExpression(
 119    "?Buyer memberOf po#buyer and \n"
 120    + " ?Trip memberOf tc#trainTrip[ \n"
 121    + " tc#start hasValue ?Start, \n"
 122    + " tc#end hasValue ?End, \n"
 123    + " tc#departure hasValue ?Departure \n"
 124    + "] and \n"
 125    + "?Start[locatedIn hasValue ?StartLocation] and \n "
 126    + "(?StartLocation = austria or ?StartLocation = germany) and \n"
 127    + "?End[locatedIn hasValue ?EndLocation] and \n"
 128    + "(?EndLocation = austria or ?EndLocation = germany) and \n"
 129    + "(?Departure > currentDate()).", service);
 130  0 axiom.addDefinition(logExp);
 131  0 capability.addPreCondition(axiom);
 132   
 133    // add capability assumption
 134  0 axiom = factory.createAxiom(factory.createIRI(targetNamespace, "axiom2"));
 135  0 logExp = leFactory.createLogicalExpression(
 136    "?CreditCard memberOf creditCard[ \n"
 137    + " cardholdername hasValue ?someHolder, \n"
 138    + " creditcardidentifier hasValue ?someIdentifier, \n"
 139    + " expirydate hasValue ?someExpiration, \n"
 140    + " globalcreditcardclassificationcode hasValue \"Master Card\" \n"
 141    + "] \n"
 142    + "and ?someHolder memberOf po#cardHolderName[ \n"
 143    + " po#freeformtext hasValue \"Tim Berners-Lee\"\n "
 144    + "] \n"
 145    + "and ?someIdentifier memberOf creditCardIdentifier[ \n"
 146    + " proprietaryreferenceidentifier hasValue \"5535 4464 6686 7747\"\n"
 147    + "] \n"
 148    + "and ?someExpiration memberOf expiryDate[ \n"
 149    + " expmonth hasValue 09, \n"
 150    + " expyear hasValue 2007 \n"
 151    + "]\n", service);
 152  0 axiom.addDefinition(logExp);
 153  0 capability.addAssumption(axiom);
 154   
 155    // add capability post-condition
 156  0 axiom = factory.createAxiom(factory.createIRI(targetNamespace, "axiom3"));
 157  0 logExp = leFactory.createLogicalExpression("?Trip memberOf trainTrip[ \n"
 158    + " start hasValue ?Start, \n"
 159    + " end hasValue ?End, \n"
 160    + " departure hasValue ?Departure \n"
 161    + "] and \n"
 162    + "?Start[locatedIn hasValue ?StartLocation] and \n "
 163    + "(?StartLocation = austria or ?StartLocation = germany) and \n"
 164    + "?End[locatedIn hasValue ?EndLocation] and \n"
 165    + "(?EndLocation = austria or ?EndLocation = germany) and \n"
 166    + "(?Departure > currentDate()).", service);
 167  0 axiom.addDefinition(logExp);
 168  0 capability.addPostCondition(axiom);
 169   
 170    // add capability effect
 171  0 axiom = factory.createAxiom(factory.createIRI(targetNamespace, "axiom4"));
 172  0 logExp = leFactory.createLogicalExpression(
 173    "?someTrade memberOf trade[\n"
 174    + " items hasValue ?Trip, \n"
 175    + " payment hasValue ?acceptedPayment\n"
 176    + "]\n"
 177    + "and ?acceptedPayment memberOf creditCard .\n", service);
 178  0 axiom.addDefinition(logExp);
 179  0 capability.addEffect(axiom);
 180  0 service.setCapability(capability);
 181   
 182    // set webservice interface
 183  0 Interface i = factory.createInterface(factory.createIRI(targetNamespace, "interface"));
 184  0 service.addInterface(i);
 185   
 186  0 return service;
 187    }
 188    }
 189   
 190    /*
 191    * $Log$
 192    * Revision 1.3 2007/06/07 08:24:45 lcekov
 193    * fix examples http://jira.sirma.bg/jira/browse/WSMO4J-20
 194    *
 195    * Revision 1.2 2005/09/19 13:53:11 holgerlausen
 196    * corrected example syntactically, still need to do a more senseful
 197    *
 198    * Revision 1.1 2005/09/19 10:21:12 vassil_momtchev
 199    * inherite doc/examples/ CreateServiceExample LoadServiceExample
 200    *
 201    */