2ronwalf//The MIT License
2ronwalf//
2ronwalf// Copyright (c) 2004 Evren Sirin
2ronwalf//
2ronwalf// Permission is hereby granted, free of charge, to any person obtaining a copy
2ronwalf// of this software and associated documentation files (the "Software"), to
2ronwalf// deal in the Software without restriction, including without limitation the
2ronwalf// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2ronwalf// sell copies of the Software, and to permit persons to whom the Software is
2ronwalf// furnished to do so, subject to the following conditions:
2ronwalf//
2ronwalf// The above copyright notice and this permission notice shall be included in
2ronwalf// all copies or substantial portions of the Software.
2ronwalf//
2ronwalf// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2ronwalf// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2ronwalf// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2ronwalf// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2ronwalf// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2ronwalf// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2ronwalf// IN THE SOFTWARE.
2ronwalf
2ronwalf/*
2ronwalf * Created on Dec 27, 2003
2ronwalf *
2ronwalf */
2ronwalfpackage impl.owls;
2ronwalf
2ronwalfimport java.net.URI;
2ronwalfimport java.util.HashMap;
2ronwalfimport java.util.Iterator;
2ronwalfimport java.util.List;
2ronwalfimport java.util.Map;
2ronwalfimport java.util.Set;
2ronwalfimport java.util.Vector;
2ronwalf
2ronwalfimport org.mindswap.owl.OWLClass;
2ronwalfimport org.mindswap.owl.OWLDataProperty;
2ronwalfimport org.mindswap.owl.OWLDataValue;
2ronwalfimport org.mindswap.owl.OWLDataValueList;
2ronwalfimport org.mindswap.owl.OWLFactory;
2ronwalfimport org.mindswap.owl.OWLIndividual;
2ronwalfimport org.mindswap.owl.OWLIndividualList;
2ronwalfimport org.mindswap.owl.OWLKnowledgeBase;
2ronwalfimport org.mindswap.owl.OWLObjectProperty;
2ronwalfimport org.mindswap.owl.OWLOntology;
2ronwalfimport org.mindswap.owl.OWLProperty;
2ronwalfimport org.mindswap.owl.OWLType;
2ronwalfimport org.mindswap.owl.list.RDFList;
2ronwalfimport org.mindswap.owl.vocabulary.RDFS;
2ronwalfimport org.mindswap.owls.OWLSVersionTranslator;
2ronwalfimport org.mindswap.owls.generic.list.OWLSObjList;
2ronwalfimport org.mindswap.owls.grounding.AtomicGrounding;
2ronwalfimport org.mindswap.owls.grounding.Grounding;
2ronwalfimport org.mindswap.owls.grounding.UPnPAtomicGrounding;
2ronwalfimport org.mindswap.owls.grounding.WSDLAtomicGrounding;
2ronwalfimport org.mindswap.owls.process.AnyOrder;
2ronwalfimport org.mindswap.owls.process.AtomicProcess;
2ronwalfimport org.mindswap.owls.process.Choice;
2ronwalfimport org.mindswap.owls.process.CompositeProcess;
2ronwalfimport org.mindswap.owls.process.Condition;
2ronwalfimport org.mindswap.owls.process.Conditional;
2ronwalfimport org.mindswap.owls.process.ControlConstruct;
2ronwalfimport org.mindswap.owls.process.IfThenElse;
2ronwalfimport org.mindswap.owls.process.Input;
2ronwalfimport org.mindswap.owls.process.Iterate;
2ronwalfimport org.mindswap.owls.process.MultiConditional;
2ronwalfimport org.mindswap.owls.process.Output;
2ronwalfimport org.mindswap.owls.process.Parameter;
2ronwalfimport org.mindswap.owls.process.ParameterList;
2ronwalfimport org.mindswap.owls.process.Perform;
2ronwalfimport org.mindswap.owls.process.Process;
2ronwalfimport org.mindswap.owls.process.RepeatUntil;
2ronwalfimport org.mindswap.owls.process.RepeatWhile;
2ronwalfimport org.mindswap.owls.process.Result;
2ronwalfimport org.mindswap.owls.process.Sequence;
2ronwalfimport org.mindswap.owls.process.SimpleProcess;
2ronwalfimport org.mindswap.owls.process.Split;
2ronwalfimport org.mindswap.owls.process.SplitJoin;
2ronwalfimport org.mindswap.owls.profile.Profile;
2ronwalfimport org.mindswap.owls.service.Service;
2ronwalfimport org.mindswap.owls.vocabulary.FLAServiceOnt;
2ronwalfimport org.mindswap.owls.vocabulary.OWLS_1_0;
2ronwalfimport org.mindswap.owls.vocabulary.OWLS_1_1;
2ronwalf
2ronwalf/**
2ronwalf * @author Evren Sirin
2ronwalf *
2ronwalf */
2ronwalfpublic class OWLSTranslator_1_0 implements OWLSVersionTranslator {
2ronwalf public static boolean DEBUG = false;
2ronwalf
2ronwalf private OWLKnowledgeBase kb;
2ronwalf private OWLOntology inputOnt;
2ronwalf private OWLOntology outputOnt;
2ronwalf /*******************************************
2ronwalf ** added by guang huang @2005-4-12 **
2ronwalf ********************************************/
2ronwalf private List profileInputURIs = new Vector();
2ronwalf /*******************************************
2ronwalf ** end by guang huang **
2ronwalf ********************************************/
2ronwalf private Map translation;
2ronwalf
2ronwalf /**
2ronwalf *
2ronwalf */
2ronwalf public OWLSTranslator_1_0() {
2ronwalf }
2ronwalf
2ronwalf public String getVersion() {
2ronwalf return "1.0";
2ronwalf }
2ronwalf
2ronwalf public boolean canTranslate(OWLOntology ontology) {
2ronwalf return ontology.getInstances(OWLS_1_0.Service.Service).size() > 0;
2ronwalf }
2ronwalf
2ronwalf public OWLOntology translate(OWLOntology ont) {
2ronwalf kb = OWLFactory.createKB();
2ronwalf inputOnt = kb.load(ont);
2ronwalf outputOnt = OWLFactory.createOntology(ont.getURI());
2ronwalf
2ronwalf translation = new HashMap();
2ronwalf
2ronwalf translateServices();
2ronwalf translateProfiles();
2ronwalf translateProcesses();
2ronwalf translateGroundings();
2ronwalf translateAtomicGroundings();
2ronwalf
2ronwalf for(Iterator i = ont.getImports().iterator(); i.hasNext(); ) {
2ronwalf OWLOntology imported = (OWLOntology) i.next();
2ronwalf outputOnt.addImport(imported);
2ronwalf }
2ronwalf
2ronwalf outputOnt.setTranslationSource(inputOnt);
2ronwalf /*******************************************
2ronwalf ** added by guang huang @2005-4-8 **
2ronwalf *corrrect source version bug
2ronwalf ********************************************/
2ronwalf if (canTranslate(ont))
2ronwalf outputOnt.addType(ont.getInstances(OWLS_1_0.Service.Service).individualAt(0), OWLS_1_0.Service.Service);
2ronwalf /*******************************************
2ronwalf ** end by guang huang **
2ronwalf ********************************************/
2ronwalf return outputOnt;
2ronwalf }
2ronwalf
2ronwalf private void translateServices() {
2ronwalf OWLIndividualList list = inputOnt.getInstances(OWLS_1_0.Service.Service);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual serviceInfo = list.individualAt(i);
2ronwalf createService(serviceInfo);
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void translateProfiles() {
2ronwalf OWLIndividualList list = inputOnt.getInstances(OWLS_1_0.Profile.Profile);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual profileInfo = list.individualAt(i);
2ronwalf createProfile(profileInfo);
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void translateProcesses() {
2ronwalf // we are not using reasoning so loop through all possible process
2ronwalf // instances
2ronwalf OWLClass[] processClass = {
2ronwalf OWLS_1_0.Process.AtomicProcess,
2ronwalf OWLS_1_0.Process.CompositeProcess,
2ronwalf OWLS_1_0.Process.SimpleProcess};
2ronwalf for(int i = 0; i < processClass.length; i++) {
2ronwalf OWLIndividualList list = inputOnt.getInstances(processClass[i]);
2ronwalf for(int j = 0; j < list.size(); j++) {
2ronwalf OWLIndividual processInfo = list.individualAt(j);
2ronwalf createProcess(processInfo);
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void translateGroundings() {
2ronwalf OWLClass[] groundingClass = {
2ronwalf OWLS_1_0.Grounding.WsdlGrounding,
2ronwalf FLAServiceOnt.UPnPGrounding};
2ronwalf for(int i = 0; i < groundingClass.length; i++) {
2ronwalf OWLIndividualList list = inputOnt.getInstances(groundingClass[i]);
2ronwalf for(int j = 0; j < list.size(); j++) {
2ronwalf OWLIndividual groundingInfo = list.individualAt(j);
2ronwalf createGrounding(groundingInfo);
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void translateAtomicGroundings() {
2ronwalf OWLClass[] groundingClass = {
2ronwalf OWLS_1_0.Grounding.WsdlAtomicProcessGrounding,
2ronwalf FLAServiceOnt.UPnPAtomicProcessGrounding};
2ronwalf for(int i = 0; i < groundingClass.length; i++) {
2ronwalf OWLIndividualList list = inputOnt.getInstances(groundingClass[i]);
2ronwalf for(int j = 0; j < list.size(); j++) {
2ronwalf OWLIndividual groundingInfo = list.individualAt(j);
2ronwalf createAPGrounding(groundingInfo);
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private Perform getCachedPerform(Process process, OWLIndividual ind) {
2ronwalf List components = ((CompositeProcess)process).getComposedOf().getConstructs();
2ronwalf Iterator i = components.iterator();
2ronwalf while(i.hasNext()) {
2ronwalf ControlConstruct cc = (ControlConstruct) i.next();
2ronwalf if(cc instanceof Perform && ((Perform) cc).getProcess().equals(ind)) {
2ronwalf return (Perform) cc;
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf return null;
2ronwalf }
2ronwalf
2ronwalf private OWLIndividual translate(OWLIndividual ind, OWLClass owlClass) {
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(ind);
2ronwalf if(translated == null) {
2ronwalf if(ind.isAnon())
2ronwalf translated = outputOnt.createInstance(owlClass);
2ronwalf else
2ronwalf translated = outputOnt.createInstance(owlClass, ind.getURI());
2ronwalf if(owlClass != null)
2ronwalf translated.addType(owlClass);
2ronwalf translation.put(ind, translated);
2ronwalf }
2ronwalf
2ronwalf return translated;
2ronwalf }
2ronwalf
2ronwalf private OWLIndividual translate(OWLIndividual ind, Class javaClass, OWLClass owlClass) {
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(ind);
2ronwalf if(translated == null) {
2ronwalf OWLIndividual newInd;
2ronwalf if(ind.isAnon())
2ronwalf newInd = outputOnt.createInstance(owlClass);
2ronwalf else
2ronwalf newInd = outputOnt.createInstance(owlClass, ind.getURI());
2ronwalf translated = (OWLIndividual) newInd.castTo(javaClass);
2ronwalf translation.put(ind, translated);
2ronwalf }
2ronwalf
2ronwalf return translated;
2ronwalf }
2ronwalf
2ronwalf private Service createService(OWLIndividual serviceInfo) {
2ronwalf try{
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(serviceInfo);
2ronwalf if(translated != null) {
2ronwalf return (Service) translated.castTo(Service.class);
2ronwalf }
2ronwalf
2ronwalf Service service = (Service) translate(serviceInfo, Service.class, OWLS_1_1.Service.Service);
2ronwalf
2ronwalf OWLIndividual profileInfo = inputOnt.getProperty(serviceInfo, OWLS_1_0.Service.presents);
2ronwalf OWLIndividual processModelInfo = inputOnt.getProperty(serviceInfo, OWLS_1_0.Service.describedBy);
2ronwalf OWLIndividual groundingInfo = inputOnt.getProperty(serviceInfo, OWLS_1_0.Service.supports);
2ronwalf
2ronwalf Process process = createProcessModel(processModelInfo);
2ronwalf Profile profile = createProfile(profileInfo);
2ronwalf Grounding grounding = createGrounding(groundingInfo);
2ronwalf
2ronwalf service.setProcess(process);
2ronwalf service.setProfile(profile);
2ronwalf service.setGrounding(grounding);
2ronwalf translateAll(serviceInfo);
2ronwalf
2ronwalf return service;
2ronwalf } catch (RuntimeException e) {
2ronwalf error("Invalid service description");
2ronwalf e.printStackTrace();
2ronwalf return null;
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private Process createProcessModel(OWLIndividual processModelInfo) {
2ronwalf OWLIndividual processInfo = inputOnt.getProperty(processModelInfo, OWLS_1_0.Process.hasProcess);
2ronwalf return createProcess(processInfo);
2ronwalf }
2ronwalf
2ronwalf private Process createProcess(OWLIndividual processInfo) {
2ronwalf try {
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(processInfo);
2ronwalf if(translated != null) {
2ronwalf return (Process) translated.castTo(Process.class);
2ronwalf }
2ronwalf
2ronwalf Process process = null;
2ronwalf if(inputOnt.isType(processInfo, OWLS_1_0.Process.AtomicProcess))
2ronwalf process = createAtomicProcess(processInfo);
2ronwalf else if(inputOnt.isType(processInfo, OWLS_1_0.Process.CompositeProcess))
2ronwalf process = createCompositeProcess(processInfo);
2ronwalf else if(inputOnt.isType(processInfo, OWLS_1_0.Process.SimpleProcess))
2ronwalf process = createSimpleProcess(processInfo);
2ronwalf else {
2ronwalf error("Unknown process type " + processInfo);
2ronwalf return null;
2ronwalf }
2ronwalf
2ronwalf copyPropertyValues(processInfo, OWLS_1_0.Process.name, process, OWLS_1_1.Process.name);
2ronwalf
2ronwalf createProcessParams(process, true, processInfo);
2ronwalf createProcessParams(process, false, processInfo);
2ronwalf
2ronwalf createCondition(process, inputOnt.getProperties(processInfo, OWLS_1_0.Profile.hasPrecondition));
2ronwalf
2ronwalf createDataFlow(process, processInfo);
2ronwalf
2ronwalf return process;
2ronwalf } catch (RuntimeException e) {
2ronwalf error("Invalid process description");
2ronwalf e.printStackTrace();
2ronwalf return null;
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private AtomicProcess createAtomicProcess(OWLIndividual processInfo) {
2ronwalf AtomicProcess process = (AtomicProcess) translate(processInfo, AtomicProcess.class, OWLS_1_1.Process.AtomicProcess);
2ronwalf
2ronwalf return process;
2ronwalf }
2ronwalf
2ronwalf private SimpleProcess createSimpleProcess(OWLIndividual processInfo) {
2ronwalf SimpleProcess process = (SimpleProcess) translate(processInfo, SimpleProcess.class, OWLS_1_1.Process.SimpleProcess);
2ronwalf
2ronwalf // FIXME translate SimpleProcess properties
2ronwalf
2ronwalf return process;
2ronwalf }
2ronwalf
2ronwalf private CompositeProcess createCompositeProcess(OWLIndividual processInfo) {
2ronwalf CompositeProcess process = (CompositeProcess) translate(processInfo, CompositeProcess.class, OWLS_1_1.Process.CompositeProcess);
2ronwalf
2ronwalf OWLIndividual composedInfo = inputOnt.getProperty(processInfo, OWLS_1_0.Process.composedOf);
2ronwalf
2ronwalf if(composedInfo == null) {
2ronwalf error("Cannot find the components for composite process (" +
2ronwalf "\n process: " + processInfo + ")");
2ronwalf }
2ronwalf else {
2ronwalf ControlConstruct controlConstruct = createControlConstruct(composedInfo);
2ronwalf
2ronwalf process.setComposedOf(controlConstruct);
2ronwalf }
2ronwalf
2ronwalf return process;
2ronwalf }
2ronwalf
2ronwalf private boolean isProcess(OWLIndividual processInfo) {
2ronwalf return inputOnt.isType(processInfo, OWLS_1_0.Process.AtomicProcess) ||
2ronwalf inputOnt.isType(processInfo, OWLS_1_0.Process.CompositeProcess) ||
2ronwalf inputOnt.isType(processInfo, OWLS_1_0.Process.SimpleProcess);
2ronwalf }
2ronwalf
2ronwalf private ControlConstruct createControlConstruct(OWLIndividual ccInfo) {
2ronwalf OWLClass ccType = ccInfo.getType();
2ronwalf
2ronwalf ControlConstruct cc = null;
2ronwalf if(isProcess(ccInfo))
2ronwalf cc = createPerform(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.Sequence))
2ronwalf cc = createSequence(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.Sequence))
2ronwalf cc = createSequence(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.Split))
2ronwalf cc = createSplit(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.SplitJoin))
2ronwalf cc = createSplitJoin(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.Unordered))
2ronwalf cc = createAnyOrder(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.IfThenElse))
2ronwalf cc = createIfThenElse(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.Choice))
2ronwalf cc = createChoice(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.Iterate))
2ronwalf cc = createIterate(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.RepeatUntil))
2ronwalf cc = createRepeatUntil(ccInfo);
2ronwalf else if(inputOnt.isType(ccInfo, OWLS_1_0.Process.RepeatWhile))
2ronwalf cc = createRepeatWhile(ccInfo);
2ronwalf else
2ronwalf error("Don't know how to translate the control construct " + ccType);
2ronwalf
2ronwalf return cc;
2ronwalf }
2ronwalf
2ronwalf private Perform createPerform(OWLIndividual processInfo) {
2ronwalf Perform perform = outputOnt.createPerform();
2ronwalf
2ronwalf Process process = createProcess(processInfo);
2ronwalf perform.setProcess(process);
2ronwalf
2ronwalf return perform;
2ronwalf }
2ronwalf
2ronwalf private Sequence createSequence(OWLIndividual sequenceInfo) {
2ronwalf Sequence sequence = (Sequence) translate(sequenceInfo, Sequence.class, OWLS_1_1.Process.Sequence);
2ronwalf
2ronwalf createComponents(sequence, sequenceInfo);
2ronwalf
2ronwalf return sequence;
2ronwalf }
2ronwalf
2ronwalf private IfThenElse createIfThenElse(OWLIndividual ifThenElseInfo) {
2ronwalf IfThenElse ifThenElse = (IfThenElse) translate(ifThenElseInfo, IfThenElse.class, OWLS_1_1.Process.IfThenElse);
2ronwalf
2ronwalf if(inputOnt.hasProperty(ifThenElseInfo, OWLS_1_0.Process.ifCondition)) {
2ronwalf createCondition(ifThenElse, inputOnt.getProperties(ifThenElseInfo, OWLS_1_0.Process.ifCondition));
2ronwalf }
2ronwalf else
2ronwalf error("If-Then-Else does not have a process:ifCondition associated with it (" +
2ronwalf "\n ifThenElse: " + ifThenElseInfo + ")");
2ronwalf
2ronwalf if(inputOnt.hasProperty(ifThenElseInfo, OWLS_1_0.Process.thenP)) {
2ronwalf OWLIndividual thenComponentInfo = inputOnt.getProperty(ifThenElseInfo, OWLS_1_0.Process.thenP);
2ronwalf ControlConstruct thenComponent = createControlConstruct(thenComponentInfo);
2ronwalf if(thenComponent != null)
2ronwalf ifThenElse.setThen(thenComponent);
2ronwalf else
2ronwalf error("If-Then-Else has an invalid process:then associated with it (" +
2ronwalf "\n ifThenElse: " + ifThenElseInfo + ")");
2ronwalf }
2ronwalf else
2ronwalf error("If-Then-Else does not have a process:then associated with it (" +
2ronwalf "\n ifThenElse: " + ifThenElseInfo + ")");
2ronwalf
2ronwalf if(inputOnt.hasProperty(ifThenElseInfo, OWLS_1_0.Process.elseP)) {
2ronwalf OWLIndividual elseComponentInfo = inputOnt.getProperty(ifThenElseInfo, OWLS_1_0.Process.elseP);
2ronwalf ControlConstruct elseComponent = createControlConstruct(elseComponentInfo);
2ronwalf if(elseComponent != null)
2ronwalf ifThenElse.setThen(elseComponent);
2ronwalf else
2ronwalf error("If-Then-Else has an invalid process:else associated with it (" +
2ronwalf "\n ifThenElse: " + ifThenElseInfo + ")");
2ronwalf }
2ronwalf
2ronwalf return ifThenElse;
2ronwalf }
2ronwalf
2ronwalf private Split createSplit(OWLIndividual splitInfo) {
2ronwalf Split split = (Split) translate(splitInfo, Split.class, OWLS_1_1.Process.Split);
2ronwalf
2ronwalf createComponents(split, splitInfo);
2ronwalf
2ronwalf return split;
2ronwalf }
2ronwalf
2ronwalf private SplitJoin createSplitJoin(OWLIndividual splitInfo) {
2ronwalf SplitJoin split = (SplitJoin) translate(splitInfo, SplitJoin.class, OWLS_1_1.Process.SplitJoin);
2ronwalf
2ronwalf createComponents(split, splitInfo);
2ronwalf
2ronwalf return split;
2ronwalf }
2ronwalf
2ronwalf private AnyOrder createAnyOrder(OWLIndividual anyOrderInfo) {
2ronwalf AnyOrder unordered = (AnyOrder) translate(anyOrderInfo, AnyOrder.class, OWLS_1_1.Process.AnyOrder);
2ronwalf
2ronwalf createComponents(unordered, anyOrderInfo);
2ronwalf
2ronwalf return unordered;
2ronwalf }
2ronwalf
2ronwalf private Iterate createIterate(OWLIndividual iterateInfo) {
2ronwalf Iterate iterate = (Iterate) translate(iterateInfo, Iterate.class, OWLS_1_1.Process.Iterate);
2ronwalf
2ronwalf// createComponents(iterate, iterateInfo);
2ronwalf// if(iterate.getComponents().size() > 1)
2ronwalf// error("Iterate should have only one component " + iterateInfo);
2ronwalf
2ronwalf return iterate;
2ronwalf }
2ronwalf
2ronwalf private RepeatUntil createRepeatUntil(OWLIndividual repeatInfo) {
2ronwalf RepeatUntil repeat = (RepeatUntil) translate(repeatInfo, RepeatUntil.class, OWLS_1_1.Process.RepeatUntil);
2ronwalf
2ronwalf if(inputOnt.hasProperty(repeatInfo, OWLS_1_0.Process.untilCondition)) {
2ronwalf createCondition(repeat, inputOnt.getProperties(repeatInfo, OWLS_1_0.Process.untilCondition));
2ronwalf }
2ronwalf else
2ronwalf error("RepeatUntil does not have a process:untilCondition associated with it (" +
2ronwalf "\n RepeatUntil: " + repeat + ")");
2ronwalf
2ronwalf if(inputOnt.hasProperty(repeatInfo, OWLS_1_0.Process.components)) {
2ronwalf error("RepeatUntil cannot have a process:components property. Use process:untilProcess instead!");
2ronwalf }
2ronwalf
2ronwalf if(inputOnt.hasProperty(repeatInfo, OWLS_1_0.Process.untilProcess)) {
2ronwalf OWLIndividual untilComponentInfo = inputOnt.getProperty(repeatInfo, OWLS_1_0.Process.untilProcess);
2ronwalf ControlConstruct untilComponent = createControlConstruct(untilComponentInfo);
2ronwalf if(untilComponent != null)
2ronwalf repeat.setComponent(untilComponent);
2ronwalf else
2ronwalf error("RepeatUntil has an invalid process:untilProcess associated with it (" +
2ronwalf "\n RepeatUntil: " + repeatInfo + ")");
2ronwalf }
2ronwalf else
2ronwalf error("RepeatUntil does not have a process:untilProcess associated with it (" +
2ronwalf "\n RepeatUntil: " + repeat + ")");
2ronwalf
2ronwalf return repeat;
2ronwalf }
2ronwalf
2ronwalf private RepeatWhile createRepeatWhile(OWLIndividual repeatInfo) {
2ronwalf RepeatWhile repeat = (RepeatWhile) translate(repeatInfo, RepeatWhile.class, OWLS_1_1.Process.RepeatWhile);
2ronwalf
2ronwalf if(inputOnt.hasProperty(repeatInfo, OWLS_1_0.Process.whileCondition)) {
2ronwalf createCondition(repeat, inputOnt.getProperties(repeatInfo, OWLS_1_0.Process.whileCondition));
2ronwalf }
2ronwalf else
2ronwalf error("RepeatUntil does not have a process:ifCondition associated with it (" +
2ronwalf "\n RepeatWhile: " + repeat + ")");
2ronwalf
2ronwalf if(inputOnt.hasProperty(repeatInfo, OWLS_1_0.Process.components)) {
2ronwalf error("RepeatWhile cannot have a process:components property. Use process:untilProcess instead!");
2ronwalf }
2ronwalf
2ronwalf if(inputOnt.hasProperty(repeatInfo, OWLS_1_0.Process.whileProcess)) {
2ronwalf OWLIndividual whileComponentInfo = inputOnt.getProperty(repeatInfo, OWLS_1_0.Process.whileProcess);
2ronwalf ControlConstruct whileComponent = createControlConstruct(whileComponentInfo);
2ronwalf if(whileComponent != null)
2ronwalf repeat.setComponent(whileComponent);
2ronwalf else
2ronwalf error("RepeatWhile has an invalid process:whileProcess associated with it (" +
2ronwalf "\n RepeatWhile: " + repeatInfo + ")");
2ronwalf }
2ronwalf else
2ronwalf error("RepeatWhile does not have a process:whileProcess associated with it (" +
2ronwalf "\n RepeatWhile: " + repeat + ")");
2ronwalf
2ronwalf return repeat;
2ronwalf }
2ronwalf
2ronwalf private Choice createChoice(OWLIndividual choiceInfo) {
2ronwalf Choice choice = (Choice) translate(choiceInfo, Choice.class, OWLS_1_1.Process.Choice);
2ronwalf
2ronwalf createComponents(choice, choiceInfo);
2ronwalf
2ronwalf return choice;
2ronwalf }
2ronwalf
2ronwalf private void createComponents(ControlConstruct cc, OWLIndividual ccInfo) {
2ronwalf OWLIndividual componentsInfo = inputOnt.getProperty(ccInfo, OWLS_1_0.Process.components);
2ronwalf
2ronwalf if(componentsInfo == null) {
2ronwalf error(cc.getConstructName() + " construct does not have any components associated with it (" +
2ronwalf "\n Construct: " + ccInfo + ")");
2ronwalf return;
2ronwalf }
2ronwalf
2ronwalf OWLSObjList list = (OWLSObjList) componentsInfo.castTo(RDFList.class);
2ronwalf Iterator i = list.iterator();
2ronwalf while(i.hasNext()) {
2ronwalf OWLIndividual componentInfo = (OWLIndividual) i.next();
2ronwalf ControlConstruct component = createControlConstruct(componentInfo);
2ronwalf
2ronwalf if(component == null)
2ronwalf warning("There is an invalid component description for " + cc);
2ronwalf else if(cc instanceof Sequence)
2ronwalf ((Sequence)cc).addComponent(component);
2ronwalf else if(cc instanceof AnyOrder)
2ronwalf ((AnyOrder)cc).addComponent(component);
2ronwalf else if(cc instanceof Choice)
2ronwalf ((Choice)cc).addComponent(component);
2ronwalf else if(cc instanceof Split)
2ronwalf ((Split)cc).addComponent(component);
2ronwalf else if(cc instanceof SplitJoin)
2ronwalf ((SplitJoin)cc).addComponent(component);
2ronwalf else
2ronwalf throw new RuntimeException("Invalid control construct!");
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void createDataFlow(Process process, OWLIndividual processComponentInfo) {
2ronwalf try {
2ronwalf OWLIndividualList list = inputOnt.getProperties(processComponentInfo, OWLS_1_0.Process.sameValues);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLSObjList sameValuesList = (OWLSObjList) list.individualAt(i).castTo(RDFList.class);
2ronwalf OWLIndividual value1 = sameValuesList.get(0);
2ronwalf OWLIndividual value2 = sameValuesList.get(1);
2ronwalf
2ronwalf OWLIndividual p1 = inputOnt.getProperty(value1, OWLS_1_0.Process.theParameter);
2ronwalf OWLIndividual p2 = inputOnt.getProperty(value2, OWLS_1_0.Process.theParameter);
2ronwalf
2ronwalf Parameter param1 = (Parameter) translation.get(p1);
2ronwalf Parameter param2 = (Parameter) translation.get(p2);
2ronwalf
2ronwalf OWLIndividual process1 = inputOnt.getProperty(value1, OWLS_1_0.Process.atProcess);
2ronwalf OWLIndividual process2 = inputOnt.getProperty(value2, OWLS_1_0.Process.atProcess);
2ronwalf
2ronwalf if(process1.equals(process) && process2.equals(process)) {
2ronwalf // FIXME handle this case using ThisPerform
2ronwalf error("Same process used twice in the ValueOf!");
2ronwalf }
2ronwalf else if(process1.equals(process)) {
2ronwalf Perform perform = getCachedPerform(process, process2);
2ronwalf if(param1 instanceof Input) {
2ronwalf // add binding to the perform
2ronwalf perform.addBinding((Input) param1, Perform.TheParentPerform, (Input) param2);
2ronwalf }
2ronwalf else {
2ronwalf // add result to the process
2ronwalf Result result = process.getResult();
2ronwalf if(result == null) {
2ronwalf result = outputOnt.createResult();
2ronwalf process.setResult(result);
2ronwalf }
2ronwalf
2ronwalf result.addBinding((Output) param1, perform, (Output) param2);
2ronwalf }
2ronwalf }
2ronwalf else if(process2.equals(process)) {
2ronwalf Perform perform = getCachedPerform(process, process1);
2ronwalf if(param2 instanceof Input) {
2ronwalf // add binding to the perform
2ronwalf perform.addBinding((Input) param2, Perform.TheParentPerform, (Input) param1);
2ronwalf }
2ronwalf else {
2ronwalf // add result to the process
2ronwalf Result result = process.getResult();
2ronwalf if(result == null) {
2ronwalf result = outputOnt.createResult();
2ronwalf process.setResult(result);
2ronwalf }
2ronwalf
2ronwalf result.addBinding((Output) param2, perform, (Output) param1);
2ronwalf }
2ronwalf }
2ronwalf else {
2ronwalf Perform perform1 = getCachedPerform(process, process1);
2ronwalf Perform perform2 = getCachedPerform(process, process2);
2ronwalf if(param1 instanceof Input) {
2ronwalf // add binding to the perform1
2ronwalf perform1.addBinding((Input) param1, perform2, (Output) param2);
2ronwalf }
2ronwalf else {
2ronwalf // add binding to the perform1
2ronwalf perform2.addBinding((Input) param2, perform1, (Output) param1);
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf } catch(Exception e) {
2ronwalf error("Invalid data flow specification ");
2ronwalf e.printStackTrace();
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private Parameter createParam(OWLIndividual paramInfo) {
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(paramInfo);
2ronwalf if(translated != null) {
2ronwalf return (Parameter) translated.castTo(Parameter.class);
2ronwalf }
2ronwalf
2ronwalf Parameter param = null;
2ronwalf if(inputOnt.isType(paramInfo, OWLS_1_0.Process.Input))
2ronwalf param = (Parameter) translate(paramInfo, Input.class, OWLS_1_1.Process.Input);
2ronwalf else if(inputOnt.isType(paramInfo, OWLS_1_0.Process.Output))
2ronwalf param = (Parameter) translate(paramInfo, Output.class, OWLS_1_1.Process.Output);
2ronwalf else {
2ronwalf error("Unknown parameter type " + paramInfo);
2ronwalf return null;
2ronwalf }
2ronwalf
2ronwalf if( inputOnt.hasProperty(paramInfo, OWLS_1_0.Process.parameterType)) {
2ronwalf URI typeURI = inputOnt.getProperty(paramInfo, OWLS_1_0.Process.parameterType).getURI();
2ronwalf if(typeURI != null) {
2ronwalf OWLType type = inputOnt.getType(typeURI);
2ronwalf if(type == null)
2ronwalf type = outputOnt.createClass(typeURI);
2ronwalf
2ronwalf param.setParamType(type);
2ronwalf }
2ronwalf else {
2ronwalf // FIXME default values
2ronwalf }
2ronwalf }
2ronwalf else
2ronwalf error("Cannot find the type for the process parameter (" +
2ronwalf "\n parameter: " + param + ")");
2ronwalf /*******************************************
2ronwalf ** added by guang huang @2005-4-8 **
2ronwalf *Keep <fla:useRandomInput>true</fla:useRandomInput> in
2ronwalf *process:Input or process:Onput
2ronwalf ********************************************/
2ronwalf keepFLAProperties(paramInfo);
2ronwalf if(inputOnt.isType(paramInfo, OWLS_1_0.Process.Input)) {
2ronwalf try {
2ronwalf if ((!profileInputURIs.contains(param.getURI())) && (paramInfo.getProperties().size() <= 1)) {
2ronwalf param.addProperty(FLAServiceOnt.useRandomInput, "true");
2ronwalf }
2ronwalf } catch (Exception e) {
2ronwalf // TODO: handle exception
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf /*******************************************
2ronwalf ** end by guang huang **
2ronwalf ********************************************/
2ronwalf return param;
2ronwalf }
2ronwalf
2ronwalf private void createProcessParams(Process process, boolean isInput, OWLIndividual processInfo) {
2ronwalf OWLObjectProperty prop = isInput ? OWLS_1_0.Process.hasInput : OWLS_1_0.Process.hasOutput;
2ronwalf OWLIndividualList list = inputOnt.getProperties(processInfo, prop);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual p = list.individualAt(i);
2ronwalf
2ronwalf Parameter param = null;
2ronwalf if(isInput) {
2ronwalf param = createParam(p);
2ronwalf process.addInput((Input) param);
2ronwalf }
2ronwalf else {
2ronwalf param = createParam(p);
2ronwalf process.addOutput((Output) param);
2ronwalf }
2ronwalf
2ronwalf copyPropertyValues(p, RDFS.label, param, RDFS.label);
2ronwalf
2ronwalf if(DEBUG) {
2ronwalf System.out.println(" Process " + process.getURI() + "\n" +
2ronwalf (isInput ? " Input ":" Output " ) +
2ronwalf param.getURI() + "\n" +
2ronwalf " Type " + param.getParamType() + "\n");
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private Profile createProfile(OWLIndividual profileInfo) {
2ronwalf try {
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(profileInfo);
2ronwalf if(translated != null) {
2ronwalf return (Profile) translated.castTo(Profile.class);
2ronwalf }
2ronwalf
2ronwalf Profile profile = (Profile) translate(profileInfo, Profile.class, OWLS_1_1.Profile.Profile);
2ronwalf
2ronwalf copyPropertyValues(profileInfo, OWLS_1_0.Profile.serviceName, profile, OWLS_1_1.Profile.serviceName);
2ronwalf copyPropertyValues(profileInfo, RDFS.label, profile, RDFS.label);
2ronwalf copyPropertyValues(profileInfo, OWLS_1_0.Profile.textDescription, profile,
2ronwalf OWLS_1_1.Profile.textDescription);
2ronwalf
2ronwalf createProfileParams(profile, true, profileInfo);
2ronwalf createProfileParams(profile, false, profileInfo);
2ronwalf
2ronwalf createCondition(profile, inputOnt.getProperties(profileInfo, OWLS_1_0.Profile.hasPrecondition));
2ronwalf
2ronwalf createServiceParameters(profile, profileInfo);
2ronwalf translateAll(profileInfo);
2ronwalf /*******************************************
2ronwalf ** added by guang huang @2005-4-8 **
2ronwalf *Keep FLAServiceParameter
2ronwalf ********************************************/
2ronwalf keepFLAProperties(profileInfo);
2ronwalf /*******************************************
2ronwalf ** end by guang huang **
2ronwalf ********************************************/
2ronwalf return profile;
2ronwalf } catch (RuntimeException e) {
2ronwalf error("Invalid profile description");
2ronwalf e.printStackTrace();
2ronwalf return null;
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void createServiceParameters(Profile profile, OWLIndividual profileInfo) {
2ronwalf Set set = kb.getSubProperties(OWLS_1_0.Profile.serviceParameter);
2ronwalf for(Iterator it = set.iterator(); it.hasNext();) {
2ronwalf OWLObjectProperty prop = (OWLObjectProperty) it.next();
2ronwalf
2ronwalf OWLIndividualList list = profileInfo.getProperties(prop);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual serviceParamInfo = list.individualAt(i);
2ronwalf OWLIndividual serviceParam = translate(serviceParamInfo, serviceParamInfo.getType());
2ronwalf
2ronwalf OWLIndividual serviceParamValue = serviceParamInfo.getProperty(OWLS_1_0.Profile.sParameter);
2ronwalf serviceParamValue = translateAll(serviceParamValue);
2ronwalf
2ronwalf profile.addProperty(prop, serviceParam);
2ronwalf serviceParam.addProperty(OWLS_1_1.Profile.sParameter, serviceParamValue);
2ronwalf copyPropertyValues(serviceParamInfo, OWLS_1_0.Profile.serviceParameterName, serviceParam, OWLS_1_1.Profile.serviceParameterName);
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private OWLIndividual translateAll(OWLIndividual ind) {
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(ind);
2ronwalf if(translated == null) {
2ronwalf if(isProcess(ind))
2ronwalf return createProcess(ind);
2ronwalf
2ronwalf translated = translate(ind, ind.getType());
2ronwalf Map map = kb.getProperties(ind);
2ronwalf for(Iterator it = map.keySet().iterator(); it.hasNext();) {
2ronwalf OWLProperty prop = (OWLProperty) it.next();
2ronwalf
2ronwalf copyPropertyValues(ind, RDFS.label, translated, RDFS.label);
2ronwalf if(prop instanceof OWLDataProperty)
2ronwalf copyPropertyValues(ind, (OWLDataProperty) prop, translated, (OWLDataProperty) prop);
2ronwalf else {
2ronwalf OWLObjectProperty objProp = (OWLObjectProperty) prop;
2ronwalf OWLIndividualList list = inputOnt.getProperties(ind, objProp);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual value = list.individualAt(i);
2ronwalf value = translate(value, value.getType());
2ronwalf
2ronwalf translated.addProperty(objProp, value);
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf return translated;
2ronwalf }
2ronwalf
2ronwalf private void createProfileParams(Profile profile, boolean isInput, OWLIndividual profileInfo) {
2ronwalf OWLObjectProperty prop = isInput ? OWLS_1_0.Profile.hasInput : OWLS_1_0.Profile.hasOutput;
2ronwalf
2ronwalf OWLIndividualList list = inputOnt.getProperties(profileInfo, prop);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual p = list.individualAt(i);
2ronwalf
2ronwalf Parameter refersTo = (Parameter) translation.get(p);
2ronwalf
2ronwalf if(refersTo == null) {
2ronwalf error("The parameter defined in profile does not exist in the process model (" +
2ronwalf "\n parameter: " + p + ", " +
2ronwalf "\n in profile: " + profile.getURI() + ")");
2ronwalf }
2ronwalf else {
2ronwalf if(isInput) {
2ronwalf profile.addInput((Input) refersTo);
2ronwalf if (refersTo.getURI() != null) {
2ronwalf profileInputURIs.add(refersTo.getURI());
2ronwalf }
2ronwalf }
2ronwalf else
2ronwalf profile.addOutput((Output) refersTo);
2ronwalf
2ronwalf if(DEBUG) {
2ronwalf System.out.println(" Profile " + profile.getURI() + "\n" +
2ronwalf (isInput ? " Input ":" Output " ) +
2ronwalf p.getURI() + "\n" +
2ronwalf " Refers to " + refersTo + "\n");
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf
2ronwalf private void createCondition(Conditional conditional, OWLIndividualList list) {
2ronwalf if(list.size() == 0)
2ronwalf return;
2ronwalf
2ronwalf OWLIndividual conditionInfo = list.individualAt(0);
2ronwalf
2ronwalf Condition condition = (Condition) translate(conditionInfo, Condition.class, OWLS_1_1.Expression.Condition);
2ronwalf
2ronwalf conditional.setCondition(condition);
2ronwalf
2ronwalf if(list.size() > 1)
2ronwalf error("Multiple conditions defined for " + conditional);
2ronwalf }
2ronwalf
2ronwalf private void createCondition(MultiConditional conditional, OWLIndividualList list) {
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual conditionInfo = list.individualAt(i);
2ronwalf
2ronwalf Condition condition = (Condition) translate(conditionInfo, Condition.class, OWLS_1_1.Expression.Condition);
2ronwalf
2ronwalf conditional.addCondition(condition);
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private Grounding createGrounding(OWLIndividual groundingInfo) {
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(groundingInfo);
2ronwalf if(translated != null) {
2ronwalf return (Grounding) translated.castTo(Grounding.class);
2ronwalf }
2ronwalf
2ronwalf Grounding grounding = (Grounding) translate(groundingInfo, Grounding.class, OWLS_1_1.Grounding.WsdlGrounding);
2ronwalf
2ronwalf OWLIndividualList list = inputOnt.getProperties(groundingInfo, OWLS_1_0.Grounding.hasAtomicProcessGrounding);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual apGroundingInfo = list.individualAt(i);
2ronwalf
2ronwalf AtomicGrounding apGrounding = createAPGrounding(apGroundingInfo);
2ronwalf if(apGrounding != null)
2ronwalf grounding.addGrounding(apGrounding);
2ronwalf else
2ronwalf error("Invalid AtomicProcess grounding " + apGroundingInfo);
2ronwalf }
2ronwalf list = inputOnt.getProperties(groundingInfo, FLAServiceOnt.hasUPnPAtomicProcessGrounding);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual apGroundingInfo = list.individualAt(i);
2ronwalf
2ronwalf AtomicGrounding apGrounding = createAPGrounding(apGroundingInfo);
2ronwalf if(apGrounding != null)
2ronwalf grounding.addGrounding(apGrounding);
2ronwalf else
2ronwalf error("Invalid AtomicProcess grounding " + apGroundingInfo);
2ronwalf }
2ronwalf
2ronwalf if(grounding.getAtomicGroundings().size() == 0)
2ronwalf warning("The grounding of the service is empty (" +
2ronwalf "\n grounding " + grounding.getURI() + ")");
2ronwalf
2ronwalf return grounding;
2ronwalf }
2ronwalf
2ronwalf private AtomicGrounding createAPGrounding(OWLIndividual groundingInfo) {
2ronwalf try {
2ronwalf OWLIndividual translated = (OWLIndividual) translation.get(groundingInfo);
2ronwalf if(translated != null) {
2ronwalf return (AtomicGrounding) translated.castTo(AtomicGrounding.class);
2ronwalf }
2ronwalf
2ronwalf AtomicGrounding grounding = null;
2ronwalf
2ronwalf if(inputOnt.isType(groundingInfo, OWLS_1_0.Grounding.WsdlAtomicProcessGrounding))
2ronwalf grounding = createWSDLGrounding(groundingInfo);
2ronwalf else if(inputOnt.isType(groundingInfo, FLAServiceOnt.UPnPAtomicProcessGrounding))
2ronwalf grounding = createUPnPGrounding(groundingInfo);
2ronwalf
2ronwalf return grounding;
2ronwalf } catch (RuntimeException e) {
2ronwalf error("Invalid profile description");
2ronwalf e.printStackTrace();
2ronwalf return null;
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private URI getGroundingURI(OWLIndividual groundingInfo, OWLDataProperty p) {
2ronwalf OWLDataValue value = inputOnt.getProperty(groundingInfo, p);
2ronwalf if(value == null)
2ronwalf error(groundingInfo + " does not have a grounding:"
2ronwalf + p.getURI().getFragment() + " property");
2ronwalf
2ronwalf try {
2ronwalf return new URI(value.getLexicalValue().trim());
2ronwalf } catch(Exception e) {
2ronwalf error("The value of grounding:" + p.getURI().getFragment()
2ronwalf + " property (" + value.getLexicalValue() + ") in "
2ronwalf + groundingInfo + " is not a valid URI literal");
2ronwalf }
2ronwalf
2ronwalf return null;
2ronwalf }
2ronwalf
2ronwalf private AtomicProcess getGroundingProcess(OWLIndividual groundingInfo) {
2ronwalf OWLIndividual processInfo = inputOnt.getProperty(groundingInfo, OWLS_1_0.Grounding.owlsProcess);
2ronwalf
2ronwalf if(!inputOnt.hasProperty(groundingInfo, OWLS_1_0.Grounding.owlsProcess)) {
2ronwalf error(groundingInfo + " does not have a grounding:owlsProcess property");
2ronwalf return null;
2ronwalf }
2ronwalf
2ronwalf AtomicProcess process = (AtomicProcess) createProcess(processInfo);
2ronwalf
2ronwalf if(process == null) {
2ronwalf error("The process specified in the grounding cannot be found (" +
2ronwalf "\n grounding: " + groundingInfo + ", " +
2ronwalf "\n process: " + processInfo + ")");
2ronwalf return null;
2ronwalf }
2ronwalf
2ronwalf return process;
2ronwalf }
2ronwalf
2ronwalf private AtomicGrounding createWSDLGrounding(OWLIndividual groundingInfo) {
2ronwalf AtomicProcess process = getGroundingProcess(groundingInfo);
2ronwalf URI wsdlLoc = getGroundingURI(groundingInfo, OWLS_1_0.Grounding.wsdlDocument);
2ronwalf OWLIndividual operationInfo = inputOnt.getProperty(groundingInfo, OWLS_1_0.Grounding.wsdlOperation);
2ronwalf URI opName = getGroundingURI(operationInfo, OWLS_1_0.Grounding.operation);
2ronwalf URI portType = getGroundingURI(operationInfo, OWLS_1_0.Grounding.portType);
2ronwalf
2ronwalf WSDLAtomicGrounding g = (WSDLAtomicGrounding) translate(groundingInfo, WSDLAtomicGrounding.class, OWLS_1_1.Grounding.WsdlAtomicProcessGrounding);
2ronwalf g.setWSDL(wsdlLoc);
2ronwalf g.setOperation(opName);
2ronwalf g.setPortType(portType);
2ronwalf
2ronwalf if(inputOnt.hasProperty(groundingInfo, OWLS_1_0.Grounding.wsdlInputMessage))
2ronwalf g.setInputMessage(getGroundingURI(groundingInfo, OWLS_1_0.Grounding.wsdlInputMessage));
2ronwalf
2ronwalf if(inputOnt.hasProperty(groundingInfo, OWLS_1_0.Grounding.wsdlOutputMessage))
2ronwalf g.setOutputMessage(getGroundingURI(groundingInfo, OWLS_1_0.Grounding.wsdlOutputMessage));
2ronwalf
2ronwalf if(process != null) {
2ronwalf g.setProcess(process);
2ronwalf createMessageMapList(g, groundingInfo, true);
2ronwalf createMessageMapList(g, groundingInfo, false);
2ronwalf }
2ronwalf else
2ronwalf error("No OWL-S parameter defined for AtomicProcessGrounding " + groundingInfo);
2ronwalf
2ronwalf if(DEBUG) {
2ronwalf System.out.println(" Process " + process.getURI() + "\n" +
2ronwalf " WSDL file " + wsdlLoc + "\n" +
2ronwalf " Operation " + opName + "\n");
2ronwalf }
2ronwalf
2ronwalf return g;
2ronwalf }
2ronwalf
2ronwalf private AtomicGrounding createUPnPGrounding( OWLIndividual groundingInfo) {
2ronwalf OWLIndividual processInfo = inputOnt.getProperty(groundingInfo, OWLS_1_0.Grounding.owlsProcess);
2ronwalf String upnpDevice = inputOnt.getProperty(groundingInfo, FLAServiceOnt.upnpDeviceURL).toString();
2ronwalf String upnpService = inputOnt.getProperty(groundingInfo, FLAServiceOnt.upnpServiceID).toString();
2ronwalf String upnpAction = inputOnt.getProperty(groundingInfo, FLAServiceOnt.upnpCommand).toString();
2ronwalf
2ronwalf AtomicProcess process = (AtomicProcess) createProcess(processInfo);
2ronwalf
2ronwalf UPnPAtomicGrounding g = (UPnPAtomicGrounding) translate(groundingInfo, UPnPAtomicGrounding.class, FLAServiceOnt.UPnPAtomicProcessGrounding);
2ronwalf g.setProcess(process);
2ronwalf g.setUPnPDescription(upnpDevice);
2ronwalf g.setUPnPService(upnpService);
2ronwalf g.setUPnPAction(upnpAction);
2ronwalf
2ronwalf createMessageMapList(g, groundingInfo, true);
2ronwalf createMessageMapList(g, groundingInfo, false);
2ronwalf
2ronwalf if(DEBUG) {
2ronwalf System.out.println(" Process " + process.getURI() + "\n" +
2ronwalf " Device " + upnpDevice + "\n" +
2ronwalf " Service " + upnpService + "\n" +
2ronwalf " Action " + upnpAction + "\n");
2ronwalf }
2ronwalf
2ronwalf return g;
2ronwalf }
2ronwalf
2ronwalf private void createMessageMapList(AtomicGrounding g, OWLIndividual groundingInfo, boolean isInput) {
2ronwalf Process process = g.getProcess();
2ronwalf OWLObjectProperty messageParts = null;
2ronwalf OWLObjectProperty olderMessageParts = null;
2ronwalf OWLDataProperty messagePart = null;
2ronwalf
2ronwalf if(g instanceof UPnPAtomicGrounding) {
2ronwalf messageParts = isInput ?
2ronwalf FLAServiceOnt.upnpInputMapping:
2ronwalf FLAServiceOnt.upnpOutputMapping;
2ronwalf olderMessageParts = null;
2ronwalf messagePart = FLAServiceOnt.upnpParameter;
2ronwalf
2ronwalf }
2ronwalf else if(g instanceof WSDLAtomicGrounding) {
2ronwalf messageParts = isInput ?
2ronwalf OWLS_1_0.Grounding.wsdlInputs:
2ronwalf OWLS_1_0.Grounding.wsdlOutputs;
2ronwalf olderMessageParts = isInput ?
2ronwalf OWLS_1_0.Grounding.wsdlInputMessageParts:
2ronwalf OWLS_1_0.Grounding.wsdlOutputMessageParts;
2ronwalf messagePart = OWLS_1_0.Grounding.wsdlMessagePart;
2ronwalf }
2ronwalf
2ronwalf OWLIndividual messageMaps = inputOnt.getProperty(groundingInfo, messageParts);
2ronwalf // try older property name
2ronwalf if(messageMaps == null && olderMessageParts != null) {
2ronwalf messageMaps = inputOnt.getProperty(groundingInfo, olderMessageParts);
2ronwalf if(messageMaps != null)
2ronwalf warning("Using deprecated property " + olderMessageParts + " instead of " + messageParts);
2ronwalf }
2ronwalf
2ronwalf if(messageMaps == null) {
2ronwalf ParameterList params = isInput ? (ParameterList) process.getInputs() : process.getOutputs();
2ronwalf if(!params.isEmpty()) {
2ronwalf warning("No mapping defined for parameters (" +
2ronwalf "\n parameters: " + params +
2ronwalf "\n process: " + process + ")");
2ronwalf }
2ronwalf return;
2ronwalf }
2ronwalf /*******************************************
2ronwalf ** modified by guang huang @2005-4-14**
2ronwalf ********************************************/
2ronwalf RDFList messageMapList = (RDFList) messageMaps.castTo(RDFList.class);
2ronwalf /*******************************************
2ronwalf ** end by guang huang **
2ronwalf ********************************************/
2ronwalf Iterator i = messageMapList.iterator();
2ronwalf while(i.hasNext()) {
2ronwalf OWLIndividual messageMap = (OWLIndividual) i.next();
2ronwalf
2ronwalf URI owlsParameterInfo = inputOnt.getProperty(messageMap, OWLS_1_0.Grounding.owlsParameter).getURI();
2ronwalf Parameter owlsParameter = isInput ?
2ronwalf process.getInputs().getParameter(owlsParameterInfo):
2ronwalf process.getOutputs().getParameter(owlsParameterInfo);
2ronwalf
2ronwalf
2ronwalf String wsdlMessagePartInfo = inputOnt.getProperty(messageMap, messagePart).toString().trim();
2ronwalf
2ronwalf String transformation = null;
2ronwalf if(inputOnt.hasProperty(messageMap, OWLS_1_0.Grounding.xsltTransformation)) {
2ronwalf transformation = inputOnt.getProperty(messageMap, OWLS_1_0.Grounding.xsltTransformation).toString();
2ronwalf }
2ronwalf
2ronwalf
2ronwalf if(owlsParameter == null) {
2ronwalf error("Cannot find the target of message map for " + (isInput?"input":"output") + " parameter (" +
2ronwalf "\n wsdl parameter: " + wsdlMessagePartInfo + ", " +
2ronwalf "\n in process: " + process.getURI() + ", " +
2ronwalf "\n mapped to: " + owlsParameterInfo + ")");
2ronwalf }
2ronwalf else
2ronwalf g.addMessageMap(owlsParameter, wsdlMessagePartInfo, transformation);
2ronwalf
2ronwalf if(DEBUG) {
2ronwalf System.out.println(" Process " + process.getURI() + "\n" +
2ronwalf " Param " + owlsParameterInfo + "\n" +
2ronwalf " Grounding " + wsdlMessagePartInfo + "\n" +
2ronwalf " Transform " + transformation + "\n");
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void copyPropertyValues(OWLIndividual src, OWLDataProperty srcProp, OWLIndividual target, OWLDataProperty targetProp) {
2ronwalf OWLDataValueList list = inputOnt.getProperties(src, srcProp);
2ronwalf for(int i = 0; i < list.size(); i++)
2ronwalf target.addProperty(targetProp, list.valueAt(i));
2ronwalf }
2ronwalf
2ronwalf private void copyPropertyValues(OWLIndividual src, URI srcProp, OWLIndividual target, URI targetProp) {
2ronwalf OWLDataValueList list = src.getAnnotations(srcProp);
2ronwalf for(int i = 0; i < list.size(); i++)
2ronwalf target.addAnnotation(targetProp, list.valueAt(i));
2ronwalf }
2ronwalf
2ronwalf private void warning(String string) {
2ronwalf System.out.println("WARNING: " + string);
2ronwalf }
2ronwalf
2ronwalf private void error(String string) {
2ronwalf System.out.println("ERROR: " + string);
2ronwalf }
2ronwalf
2ronwalf /*******************************************
2ronwalf ** added by guang huang @2005-4-8 **
2ronwalf ********************************************/
2ronwalf private OWLIndividual keepFLAProperties(OWLIndividual ind) {
2ronwalf OWLIndividual translated = translateAll(ind);
2ronwalf if(translated != null) {
2ronwalf Map map = ind.getProperties();
2ronwalf for(Iterator it = map.keySet().iterator(); it.hasNext();) {
2ronwalf OWLProperty prop = (OWLProperty) it.next();
2ronwalf if(prop instanceof OWLDataProperty) {
2ronwalf if (FLAServiceOnt.flaDataProperties.contains(prop)) {
2ronwalf copyPropertyValues(ind, (OWLDataProperty) prop, translated, (OWLDataProperty) prop);
2ronwalf }
2ronwalf } else {
2ronwalf OWLObjectProperty objProp = (OWLObjectProperty) prop;
2ronwalf if (FLAServiceOnt.flaObjectPropertiesToDataProperties.containsKey(prop)) {
2ronwalf OWLIndividualList list = inputOnt.getProperties(ind, objProp);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual serviceParamInfo = list.individualAt(i);
2ronwalf translated.addProperty((OWLDataProperty)FLAServiceOnt.flaObjectPropertiesToDataProperties.get(prop), serviceParamInfo);
2ronwalf }
2ronwalf } else if (FLAServiceOnt.flaObjectProperties.containsKey(prop)) {
2ronwalf OWLIndividualList list = inputOnt.getProperties(ind, objProp);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual serviceParamInfo = list.individualAt(i);
2ronwalf OWLIndividual serviceParam = translate(serviceParamInfo, serviceParamInfo.getType());
2ronwalf
2ronwalf OWLIndividual serviceParamValue = serviceParamInfo.getProperty(OWLS_1_0.Profile.sParameter);
2ronwalf serviceParamValue = translate(serviceParamValue, (OWLClass) FLAServiceOnt.flaObjectProperties.get(objProp));
2ronwalf
2ronwalf translated.addProperty(objProp, serviceParam);
2ronwalf serviceParam.addProperty(OWLS_1_1.Profile.sParameter, serviceParamValue);
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf return translated;
2ronwalf }
2ronwalf
2ronwalf// private URI getURI(OWLDataValue value) {
2ronwalf// try {
2ronwalf// return new URI(value.getLexicalValue().trim());
2ronwalf// } catch (URISyntaxException e) {
2ronwalf// // TODO Auto-generated catch block
2ronwalf//// e.printStackTrace();
2ronwalf// try {
2ronwalf// return new URI("http://fla.flacp.fujitsu.com/" + value.getLexicalValue().trim());
2ronwalf// } catch (URISyntaxException e1) {
2ronwalf// // TODO Auto-generated catch block
2ronwalf// e1.printStackTrace();
2ronwalf// return null;
2ronwalf// }
2ronwalf// }
2ronwalf// }
2ronwalf /*******************************************
2ronwalf ** end by guang huang **
2ronwalf ********************************************/
2ronwalf}