2ronwalfpackage org.mindswap.owls.validator;
2ronwalf
3daenzeroramaimport java.net.URI;
2ronwalfimport java.util.HashMap;
2ronwalfimport java.util.HashSet;
2ronwalfimport java.util.Iterator;
2ronwalfimport java.util.List;
3daenzeroramaimport java.util.Map;
3daenzeroramaimport java.util.Set;
2ronwalf
3daenzeroramaimport org.mindswap.exceptions.CastingException;
2ronwalfimport org.mindswap.exceptions.ConversionException;
3daenzeroramaimport org.mindswap.owl.OWLFactory;
2ronwalfimport org.mindswap.owl.OWLIndividualList;
2ronwalfimport org.mindswap.owl.OWLKnowledgeBase;
2ronwalfimport org.mindswap.owl.OWLOntology;
3daenzeroramaimport org.mindswap.owls.grounding.AtomicGrounding;
3daenzeroramaimport org.mindswap.owls.grounding.AtomicGroundingList;
3daenzeroramaimport org.mindswap.owls.grounding.Grounding;
3daenzeroramaimport org.mindswap.owls.grounding.JavaAtomicGrounding;
3daenzeroramaimport org.mindswap.owls.grounding.MessageMap;
3daenzeroramaimport org.mindswap.owls.grounding.MessageMapList;
3daenzeroramaimport org.mindswap.owls.grounding.WSDLAtomicGrounding;
3daenzeroramaimport org.mindswap.owls.process.AtomicProcess;
3daenzeroramaimport org.mindswap.owls.process.CompositeProcess;
3daenzeroramaimport org.mindswap.owls.process.ControlConstruct;
2ronwalfimport org.mindswap.owls.process.ControlConstructBag;
3daenzeroramaimport org.mindswap.owls.process.Input;
3daenzeroramaimport org.mindswap.owls.process.InputBinding;
3daenzeroramaimport org.mindswap.owls.process.InputBindingList;
2ronwalfimport org.mindswap.owls.process.InputList;
3daenzeroramaimport org.mindswap.owls.process.Local;
2ronwalfimport org.mindswap.owls.process.Output;
2ronwalfimport org.mindswap.owls.process.OutputBinding;
2ronwalfimport org.mindswap.owls.process.OutputBindingList;
3daenzeroramaimport org.mindswap.owls.process.OutputList;
3daenzeroramaimport org.mindswap.owls.process.Parameter;
3daenzeroramaimport org.mindswap.owls.process.ParameterList;
3daenzeroramaimport org.mindswap.owls.process.Perform;
2ronwalfimport org.mindswap.owls.process.Process;
2ronwalfimport org.mindswap.owls.process.ProcessList;
3daenzeroramaimport org.mindswap.owls.process.Result;
3daenzeroramaimport org.mindswap.owls.process.ResultList;
2ronwalfimport org.mindswap.owls.process.SplitJoin;
2ronwalfimport org.mindswap.owls.profile.Profile;
2ronwalfimport org.mindswap.owls.profile.ServiceCategory;
2ronwalfimport org.mindswap.owls.profile.ServiceParameter;
3daenzeroramaimport org.mindswap.owls.service.Service;
3daenzeroramaimport org.mindswap.owls.vocabulary.OWLS;
2ronwalf
2ronwalf/*
2ronwalf
2ronwalfwhat about validating precondtions?
2ronwalf is that neccessary?
2ronwalf
2ronwalfwarn about using deprecated terms?
2ronwalf how to find out which are deprecated heh
2ronwalf
2ronwalf--Process--
2ronwalf
2ronwalfBinding
2ronwalf 1 toParam,
2ronwalf <= 1 valueSource, valueData, valueSpecifier
2ronwalf
2ronwalfValueOf
2ronwalf 1 theVar
2ronwalf <= 1 fromProcess
2ronwalf
2ronwalfCompositeProcess
2ronwalf 1 composedOf
2ronwalf <= 1 invocable
2ronwalf <= 1 computedOutput
2ronwalf <= 1 computedInput
2ronwalf <= 1 computedEffect
2ronwalf <= 1 computedPrecondition
2ronwalf
2ronwalfeverything in a ControlConstructBag/ControlConstructList should be of type ControlConstruct
2ronwalf
2ronwalfSequence
2ronwalf 1, components -> ControlConstructList
2ronwalf
2ronwalfSplit
2ronwalf 1, components -> ControlConstructBag
2ronwalf
2ronwalfAny-Order
2ronwalf 1, components -> ControlConstructBag
2ronwalf
2ronwalfChoice
2ronwalf 1, components -> ControlConstructBag
2ronwalf
2ronwalfIf-Then-Else
2ronwalf 1, ifCondition
2ronwalf 1, then
2ronwalf <= 1, else
2ronwalf
2ronwalfRepeat-While
2ronwalf 1, whileCondition
2ronwalf 1, whileProcess -> ControlConstruct
2ronwalf
2ronwalfRepeat-Until
2ronwalf 1, untilCondition
2ronwalf 1, untilProcess -> ControlConstruct
2ronwalf
2ronwalf*/
2ronwalf
2ronwalfpublic class OWLSValidator
2ronwalf{
2ronwalf private static final int CODE_INVALID_VALUE = 0;
2ronwalf private static final int CODE_MISSING_VALUE = 1;
2ronwalf
2ronwalf private Map mMessageMap;
2ronwalf
2ronwalf public OWLSValidator()
2ronwalf {
2ronwalf mMessageMap = new HashMap();
2ronwalf }
2ronwalf
2ronwalf public OWLSValidatorReport validate(OWLOntology theOntology) throws OWLSValidationException
2ronwalf {
2ronwalf OWLKnowledgeBase aKb = OWLFactory.createKB();
2ronwalf aKb.setReasoner("Pellet");
2ronwalf //aKb.setReasoner("RDFS");
2ronwalf aKb.load(theOntology);
2ronwalf
2ronwalf return validateKb(aKb);
2ronwalf }
2ronwalf
2ronwalf public OWLSValidatorReport validate(URI theURI) throws OWLSValidationException
2ronwalf {
2ronwalf return validate(theURI.toString());
2ronwalf }
2ronwalf
2ronwalf public OWLSValidatorReport validate(String theURI) throws OWLSValidationException
2ronwalf {
2ronwalf mMessageMap = new HashMap();
2ronwalf
2ronwalf OWLKnowledgeBase aKb = OWLFactory.createKB();
2ronwalf aKb.setReasoner("Pellet");
2ronwalf //aKb.setReasoner("RDFS");
2ronwalf
2ronwalf try {
2ronwalf aKb.read(theURI);
2ronwalf }
2ronwalf catch (java.net.URISyntaxException ex) {
2ronwalf ex.printStackTrace();
2ronwalf throw OWLSValidationException.createParseException("Invalid URI ("+theURI+") specified for description");
2ronwalf }
2ronwalf catch (java.io.FileNotFoundException fnfe) {
2ronwalf throw OWLSValidationException.createFileNotFoundException("File at URI ("+theURI+") not found, cannot validate");
2ronwalf }
2ronwalf catch (Exception ex) {
2ronwalf // failed to parse?
2ronwalf throw OWLSValidationException.createParseException("Parse Exception: "+ex.getMessage());
2ronwalf }
2ronwalf
2ronwalf return validateKb(aKb);
2ronwalf }
2ronwalf
2ronwalf private OWLSValidatorReport validateKb(OWLKnowledgeBase theKb)
2ronwalf {
2ronwalf List aServiceList = theKb.getServices();
2ronwalf Iterator servIter = aServiceList.iterator();
2ronwalf while (servIter.hasNext())
2ronwalf {
2ronwalf Service aService = (Service)servIter.next();
2ronwalf validateService(aService);
2ronwalf }
2ronwalf
2ronwalf return new OWLSValidatorReport(mMessageMap);
2ronwalf }
2ronwalf
2ronwalf private void validateService(Service theService)
2ronwalf {
2ronwalf if (theService.getProperties(OWLS.Service.describedBy).size() > 1)
2ronwalf {
2ronwalf // invalid, can only have 0,1 describedBy
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"Cannot specify more than one describedBy for a service");
2ronwalf addMessage(theService,msg);
2ronwalf }
2ronwalf
2ronwalf validateProfileForService(theService);
2ronwalf
2ronwalf Process aProcess = null;
2ronwalf
2ronwalf try {
2ronwalf aProcess = theService.getProcess();
2ronwalf }
2ronwalf catch (Exception ex) {
2ronwalf // probably a cast exception, ignore for now, let the process validator handle it
2ronwalf }
2ronwalf validateProcess(theService,aProcess);
2ronwalf
2ronwalf validateGroundingForService(theService);
2ronwalf }
2ronwalf
2ronwalf private void validateProcess(Service theService, Process theProcess)
2ronwalf {
2ronwalf if (theProcess == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No process specified for service: "+theService.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf return;
2ronwalf }
2ronwalf
2ronwalf try {
2ronwalf // TODO: do processes really require profiles?, do they require to belong to a service?
2ronwalf if (theProcess.getProfile() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No profile specified for process: "+theProcess.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf }
2ronwalf catch (ConversionException ce) {
2ronwalf addMessage(theService, CODE_INVALID_VALUE, ce.getMessage());
2ronwalf }
2ronwalf catch (CastingException ex) {
2ronwalf addMessage(theService, CODE_INVALID_VALUE, ex.getMessage());
2ronwalf }
2ronwalf
2ronwalf if (theProcess.getNames().size() > 1)
2ronwalf {
2ronwalf // process must have a name
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Process '"+theProcess.getLocalName()+"' can specify at most one name");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf// ParameterList aParamList = aProcess.getParameters();
2ronwalf// for (int i = 0; i < aParamList.size(); i++)
2ronwalf// {
2ronwalf// Parameter aParam = aParamList.parameterAt(i);
2ronwalf// validateParameter(theService,aParam);
2ronwalf// }
2ronwalf
2ronwalf ResultList aResultList = theProcess.getResults();
2ronwalf for (int i = 0; i < aResultList.size(); i++)
2ronwalf {
2ronwalf Result aResult = aResultList.resultAt(i);
2ronwalf validateResult(theService,aResult);
2ronwalf }
2ronwalf
2ronwalf ParameterList aParamList = theProcess.getLocals();
2ronwalf for (int i = 0; i < aParamList.size(); i++)
2ronwalf {
2ronwalf Local aLocal = (Local)aParamList.parameterAt(i);
2ronwalf validateLocal(theService,aLocal);
2ronwalf }
2ronwalf
2ronwalf InputList aInputList = theProcess.getInputs();
2ronwalf for (int i = 0; i < aParamList.size(); i++)
2ronwalf {
2ronwalf Input aInput = aInputList.inputAt(i);
2ronwalf validateInput(theService,aInput);
2ronwalf }
2ronwalf
2ronwalf OutputList aOutputList = theProcess.getOutputs();
2ronwalf for (int i = 0; i < aOutputList.size(); i++)
2ronwalf {
2ronwalf Output aOutput = aOutputList.outputAt(i);
2ronwalf validateOutput(theService,aOutput);
2ronwalf }
2ronwalf
2ronwalf if (theProcess.canCastTo(CompositeProcess.class))
2ronwalf validateCompositeProcess((CompositeProcess)theProcess.castTo(CompositeProcess.class));
2ronwalf else if (theProcess.canCastTo(AtomicProcess.class))
2ronwalf validateAtomicProcess((AtomicProcess)theProcess.castTo(AtomicProcess.class));
2ronwalf else
2ronwalf {
2ronwalf // TODO: is this an error?
2ronwalf System.err.println("WTF!");
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void validateLocal(Service theService, Local theLocal)
2ronwalf {
2ronwalf validateParameter(theService,theLocal);
2ronwalf }
2ronwalf
2ronwalf private void validateInput(Service theService, Input theInput)
2ronwalf {
2ronwalf validateParameter(theService,theInput);
2ronwalf }
2ronwalf
2ronwalf private void validateOutput(Service theService, Output theOutput)
2ronwalf {
2ronwalf validateParameter(theService,theOutput);
2ronwalf }
2ronwalf
2ronwalf private void validateParameter(Service theService, Parameter theParam)
2ronwalf {
2ronwalf if (theParam.getParamType() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"A paramType must be specified for Parameter: "+theParam.getLocalName());
2ronwalf addMessage(theService,msg);
2ronwalf }
2ronwalf
2ronwalf if (!theParam.getParamType().isDataType())
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"The paramType for parameter: '"+theParam.getLocalName()+"' is not specified properly. It is supposed to be a datatype property, but it is specifed as an Object property. Please change the declaration.");
2ronwalf addMessage(theService,msg);
2ronwalf }
2ronwalf
2ronwalf // what about getConstantValue() ??
2ronwalf }
2ronwalf
2ronwalf private void validateAtomicProcess(AtomicProcess theAtomicProcess)
2ronwalf {
2ronwalf // TODO: is the AtomicGrounding required?
2ronwalf
2ronwalf // what else needs to be validated on an atomic process
2ronwalf }
2ronwalf
2ronwalf private void validateCompositeProcess(CompositeProcess theCompositeProcess)
2ronwalf {
2ronwalf Service aService = theCompositeProcess.getService();
2ronwalf
2ronwalf if (theCompositeProcess.getComposedOf() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"");
2ronwalf addMessage(theCompositeProcess.getService(),msg);
2ronwalf }
2ronwalf
2ronwalf ControlConstruct aCC = theCompositeProcess.getComposedOf();
2ronwalf List aList = aCC.getConstructs();
2ronwalf for (int i = 0; i < aList.size(); i++)
2ronwalf {
2ronwalf ControlConstruct tempCC = (ControlConstruct)aList.get(i);
2ronwalf validateControlConstruct(aService,tempCC);
2ronwalf }
2ronwalf
2ronwalf try {
2ronwalf ProcessList aProcessList = aCC.getAllProcesses();
2ronwalf for (int i = 0; i < aProcessList.size(); i++)
2ronwalf {
7daenzerorama // Process aProcess = aProcessList.processAt(i);
2ronwalf
2ronwalf // TODO: validate each process?
2ronwalf //System.err.println("proc: "+aProcess);
2ronwalf }
2ronwalf }
2ronwalf catch (ConversionException ce) {
2ronwalf addMessage(aService,CODE_INVALID_VALUE,ce.getMessage());
2ronwalf }
2ronwalf catch (CastingException ex) {
2ronwalf addMessage(aService, CODE_INVALID_VALUE, ex.getMessage());
2ronwalf }
2ronwalf
2ronwalf // maybe just verify that there are at least two processes for the composite
2ronwalf // and that the perform and process list match up?
2ronwalf }
2ronwalf
2ronwalf private void validateGroundingForService(Service theService)
2ronwalf {
2ronwalf Grounding aGrounding = null;
2ronwalf
2ronwalf try {
2ronwalf aGrounding = theService.getGrounding();
2ronwalf }
2ronwalf catch (Exception ex) {
2ronwalf ex.printStackTrace();
2ronwalf // likely a cast exception, we'll ignore the exception, aGrounding will be null
2ronwalf // and the below error message will be recorded.
2ronwalf }
2ronwalf
2ronwalf if (aGrounding == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No grounding specified for service: "+theService.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf return;
2ronwalf }
2ronwalf
2ronwalf if (aGrounding.getProperties(OWLS.Service.supportedBy).size() > 1)
2ronwalf {
2ronwalf // invalid, can only have 0,1 supportedBy
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"The grounding '"+aGrounding.getLocalName()+"' cannot have more than one supportedBy property");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (aGrounding.getService() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"The grounding '"+aGrounding.getLocalName()+"' does not specify a service.");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf // TODO: is at least one grounding required?
2ronwalf try {
2ronwalf AtomicGroundingList aGroundingList = aGrounding.getAtomicGroundings();
2ronwalf for (int i = 0; i < aGroundingList.size(); i++)
2ronwalf {
2ronwalf AtomicGrounding aAtomicGrounding = (AtomicGrounding)aGroundingList.groundingAt(i);
2ronwalf
2ronwalf if (aAtomicGrounding.getProcess() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"The atomic grounding '"+aAtomicGrounding.getLocalName()+"' does not specify its process.");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (aAtomicGrounding.canCastTo(JavaAtomicGrounding.class))
2ronwalf {
2ronwalf }
2ronwalf else if (aAtomicGrounding.canCastTo(WSDLAtomicGrounding.class))
2ronwalf {
2ronwalf validateWSDLAtomicGrounding(theService,(WSDLAtomicGrounding)aAtomicGrounding.castTo(WSDLAtomicGrounding.class));
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf catch (ConversionException ce) {
2ronwalf addMessage(theService, CODE_INVALID_VALUE, ce.getMessage());
2ronwalf }
2ronwalf catch (CastingException ex) {
2ronwalf addMessage(theService, CODE_INVALID_VALUE, ex.getMessage());
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void validateWSDLAtomicGrounding(Service theService, WSDLAtomicGrounding theWSDLAtomicGrounding)
2ronwalf {
2ronwalf // todo: are the wsdlInputMessage/wsdlOutputMessage required? what about getWSDL()?
2ronwalf if (theWSDLAtomicGrounding.getOperationRef() == null)
2ronwalf addMessage(theService,CODE_INVALID_VALUE,"The grounding '"+theWSDLAtomicGrounding.getLocalName()+"' has a missing, or invalid operationRef.");
2ronwalf else {
2ronwalf if (theWSDLAtomicGrounding.getOperationRef().getPortType() == null)
2ronwalf addMessage(theService, CODE_MISSING_VALUE,"The grounding '"+theWSDLAtomicGrounding.getLocalName()+"' must specify a portType for its operationRef.");
2ronwalf
2ronwalf if (theWSDLAtomicGrounding.getOperationRef().getOperation() == null)
2ronwalf addMessage(theService, CODE_MISSING_VALUE,"The grounding '"+theWSDLAtomicGrounding.getLocalName()+"' must specify an operation for its operationRef");
2ronwalf }
2ronwalf
2ronwalf // TODO: are you required to have input and output maps?
2ronwalf
2ronwalf MessageMapList inputMap = theWSDLAtomicGrounding.getInputMap();
2ronwalf for (int i = 0; i < inputMap.size(); i++)
2ronwalf {
2ronwalf MessageMap aMap = (MessageMap)inputMap.messageMapAt(i);
2ronwalf
2ronwalf if (aMap.getGroundingParameter() == null)
2ronwalf addMessage(theService,CODE_MISSING_VALUE,"The input map for grounding '"+theWSDLAtomicGrounding.getLocalName()+"' requires a grounding parameter (wsdlMessagePart).");
2ronwalf
2ronwalf if (aMap.getOWLSParameter() == null && aMap.getTransformation() == null)
2ronwalf addMessage(theService,CODE_MISSING_VALUE,"The input map for grounding '"+theWSDLAtomicGrounding.getLocalName()+"' must specify either an owlsParameter or an xlstTransformation.");
2ronwalf }
2ronwalf
2ronwalf MessageMapList outputMap = theWSDLAtomicGrounding.getOutputMap();
2ronwalf for (int i = 0; i < outputMap.size(); i++)
2ronwalf {
2ronwalf MessageMap aMap = (MessageMap)outputMap.messageMapAt(i);
2ronwalf
2ronwalf if (aMap.getOWLSParameter() == null)
2ronwalf addMessage(theService,CODE_MISSING_VALUE,"The output map for grounding '"+theWSDLAtomicGrounding.getLocalName()+"' requires an owlsParameter.");
2ronwalf
2ronwalf if (aMap.getGroundingParameter() == null && aMap.getTransformation() == null)
2ronwalf addMessage(theService,CODE_MISSING_VALUE,"The output map for grounding '"+theWSDLAtomicGrounding.getLocalName()+"' must specify either an grounding parameter (wsdlMessagePart) or an xlstTransformation.");
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void validateSplitJoin(Service theService, SplitJoin theSplitJoin)
2ronwalf {
2ronwalf ControlConstructBag ccBag = theSplitJoin.getComponents();
2ronwalf for (int i = 0; i < ccBag.size(); i++)
2ronwalf {
2ronwalf ControlConstruct aCC = ccBag.constructAt(i);
2ronwalf validateControlConstruct(theService,aCC);
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void validateControlConstruct(Service theService, ControlConstruct theControlConstruct)
2ronwalf {
2ronwalf if (theControlConstruct.canCastTo(Perform.class))
2ronwalf validatePerform(theService,(Perform)theControlConstruct.castTo(Perform.class));
2ronwalf else if (theControlConstruct.canCastTo(SplitJoin.class))
2ronwalf validateSplitJoin(theService,(SplitJoin)theControlConstruct.castTo(SplitJoin.class));
2ronwalf else
2ronwalf {
2ronwalf System.err.println("unsupported CC? "+theControlConstruct.getClass());
2ronwalf }
2ronwalf //Perform aPerform = (Perform)aList.get(i);
2ronwalf //validatePerform(aService, aPerform);
2ronwalf }
2ronwalf
2ronwalf private void validateResult(Service theService, Result theResult)
2ronwalf {
2ronwalf ParameterList aParamList = theResult.getParameters();
2ronwalf for (int i = 0; i < aParamList.size(); i++)
2ronwalf {
2ronwalf Parameter aParam = aParamList.parameterAt(i);
2ronwalf validateParameter(theService,aParam);
2ronwalf }
2ronwalf
2ronwalf OWLIndividualList aList = theResult.getEffects();
2ronwalf for (int i = 0; i < aList.size(); i++)
2ronwalf {
7daenzerorama// OWLIndividual aInd = aList.individualAt(i);
2ronwalf // are these the preconditions? or post conditions?
2ronwalf }
2ronwalf
2ronwalf OutputBindingList aBindingList = theResult.getBindings();
2ronwalf for (int i = 0; i < aBindingList.size(); i++)
2ronwalf {
2ronwalf OutputBinding aOutputBinding = aBindingList.outputBindingAt(i);
2ronwalf if (aOutputBinding.getOutput() == null)
2ronwalf addMessage(theService,CODE_MISSING_VALUE,"Result '"+theResult.getLocalName()+"' must specify an Output for its toParam property.");
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void validatePerform(Service theService, Perform thePerform)
2ronwalf {
2ronwalf try {
2ronwalf if (thePerform.getProcess() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Perform '"+thePerform.getLocalName()+"' must specify a process");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf //else validateProcess(theService, thePerform.getProcess());
2ronwalf }
2ronwalf catch (CastingException ex) {
2ronwalf addMessage(theService,CODE_INVALID_VALUE,ex.getMessage());
2ronwalf }
2ronwalf catch (ConversionException ce) {
2ronwalf addMessage(theService,CODE_INVALID_VALUE,ce.getMessage());
2ronwalf }
2ronwalf
2ronwalf InputBindingList aBindingList = thePerform.getBindings();
2ronwalf for (int i = 0; i < aBindingList.size(); i++)
2ronwalf {
2ronwalf InputBinding aInputBinding = aBindingList.inputBindingAt(i);
2ronwalf
2ronwalf try {
2ronwalf if (aInputBinding.getInput() == null)
2ronwalf addMessage(theService,CODE_MISSING_VALUE,"Perform '"+thePerform.getLocalName()+"' must specify an Input for the toParam property.");
2ronwalf }
2ronwalf catch (CastingException ex) {
2ronwalf addMessage(theService,CODE_INVALID_VALUE,ex.getMessage());
2ronwalf }
2ronwalf catch (ConversionException ex) {
2ronwalf addMessage(theService,CODE_INVALID_VALUE,ex.getMessage());
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf // TODO: is there any way to validate the valueSource for the perform?
2ronwalf }
2ronwalf
2ronwalf private void validateProfileForService(Service theService)
2ronwalf {
2ronwalf Profile aProfile = null;
2ronwalf
2ronwalf try {
2ronwalf aProfile = theService.getProfile();
2ronwalf }
2ronwalf catch (Exception ex) {
2ronwalf // cast exception most likely, let the null check below handle the error message
2ronwalf }
2ronwalf
2ronwalf if (aProfile == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No profile specified for service: "+theService.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf return;
2ronwalf }
2ronwalf
2ronwalf if (aProfile.getService() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No service specified for profile: "+aProfile.getLocalName()+"; double check the presentedBy property on the profile to make sure its correctly specified");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (aProfile.getProperties(OWLS.Profile.serviceName).size() != 1)
2ronwalf {
2ronwalf // invalid, must have a service name
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"The profile '"+aProfile.getLocalName()+"' must specify only one serviceName. ");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (aProfile.getProperties(OWLS.Profile.textDescription).size() != 1)
2ronwalf {
2ronwalf // invalid, must have a text description
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"The profile '"+aProfile.getLocalName()+"' must specify only one textDescription.");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (!aProfile.getInputs().equals(theService.getProcess().getInputs()))
2ronwalf {
2ronwalf // profile inputs should match process inputs
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"Profile inputs for service '"+theService.getLocalName()+"' do not match the process inputs!");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (!aProfile.getOutputs().equals(theService.getProcess().getOutputs()))
2ronwalf {
2ronwalf // profile outputs should match process outputs
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"Profile outputs for service '"+theService.getLocalName()+"' do not match the process outputs!");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf OWLIndividualList aList = aProfile.getServiceParameters();
2ronwalf for (int i = 0; i < aList.size(); i++)
2ronwalf {
2ronwalf // TODO, why does this give a cast exception?
2ronwalf ServiceParameter aServParam = (ServiceParameter)aList.individualAt(i);
2ronwalf validateServiceParameter(theService, aServParam);
2ronwalf }
2ronwalf
2ronwalf aList = aProfile.getCategories();
2ronwalf for (int i = 0; i < aList.size(); i++)
2ronwalf {
2ronwalf ServiceCategory aServCategory = (ServiceCategory)aList.individualAt(i);
2ronwalf validateServiceCategory(theService, aServCategory);
2ronwalf }
2ronwalf
2ronwalf try {
2ronwalf if (aProfile.getProcess() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Profile '"+aProfile.getLocalName()+"' do not specify a process!");
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf }
2ronwalf catch (ConversionException ce) {
2ronwalf addMessage(theService,CODE_INVALID_VALUE,ce.getMessage());
2ronwalf }
2ronwalf catch (CastingException ex) {
2ronwalf addMessage(theService, CODE_INVALID_VALUE, ex.getMessage());
2ronwalf }
2ronwalf catch (NullPointerException npe) {
2ronwalf // we'll do nothing in this case for now, the above check should catch this problem
2ronwalf // you'll get an NPE here if the service for this profile is not properly specified.
2ronwalf // there is a check above that will print a msg for this, so I think we can
2ronwalf // ignore it here
2ronwalf }
2ronwalf
2ronwalf ResultList aResultList = aProfile.getResults();
2ronwalf for (int i = 0; i < aResultList.size(); i++)
2ronwalf validateResult(theService,aResultList.resultAt(i));
2ronwalf
2ronwalf // what about Classification, Products??
2ronwalf }
2ronwalf
2ronwalf private void validateServiceParameter(Service theService, ServiceParameter theServiceParameter)
2ronwalf {
2ronwalf if (theServiceParameter.getName() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a name for serviceParameter: "+theServiceParameter.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (theServiceParameter.getParameter() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a parameter for serviceParameter: "+theServiceParameter.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void validateServiceCategory(Service theService, ServiceCategory theServiceCategory)
2ronwalf {
2ronwalf if (theServiceCategory.getCode() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a code for serviceCategory: "+theServiceCategory.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (theServiceCategory.getValue() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a value for serviceCategory "+theServiceCategory.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (theServiceCategory.getTaxonomy() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a taxonomy for serviceCategory: "+theServiceCategory.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf
2ronwalf if (theServiceCategory.getName() == null)
2ronwalf {
2ronwalf OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a name for serviceCategory: "+theServiceCategory.getLocalName());
2ronwalf addMessage(theService, msg);
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf private void addMessage(Service theService, int theCode, String theMsg)
2ronwalf {
2ronwalf addMessage(theService,new OWLSValidatorMessage(theCode,theMsg));
2ronwalf }
2ronwalf
2ronwalf private void addMessage(Service theService, OWLSValidatorMessage theMsg)
2ronwalf {
2ronwalf Set aSet = (Set)mMessageMap.get(theService);
2ronwalf
2ronwalf if (aSet == null)
2ronwalf aSet = new HashSet();
2ronwalf
2ronwalf aSet.add(theMsg);
2ronwalf
2ronwalf mMessageMap.put(theService,aSet);
2ronwalf }
2ronwalf
2ronwalf public static void main(String[] args)
2ronwalf {
2ronwalf System.err.println("validator main");
2ronwalf
7daenzerorama// OWLSValidator aValidator = new OWLSValidator();
2ronwalf
2ronwalf try {
2ronwalf
2ronwalf// OWLOntology theSourceOntology = OWLFactory.createOntology();
2ronwalf// OWLOntology theDestinationOntology = OWLFactory.createOntology();
2ronwalf//
2ronwalf// java.net.URI theIndToRemoveURI = java.net.URI.create("<some uri>");
2ronwalf// java.net.URI thePredicateURI = java.net.URI.create("<some property uri>");
2ronwalf//
2ronwalf// OWLIndividual aInd = theSourceOntology.getIndividual(theIndToRemoveURI);
2ronwalf// OWLObjectProperty aProp = theSourceOntology.getObjectProperty(thePredicateURI);
2ronwalf// OWLIndividual aValue = aInd.getProperty(aProp);
2ronwalf//
2ronwalf// aInd.removeProperty(aProp,aValue);
2ronwalf// aInd = theDestinationOntology.getIndividual(theIndToRemoveURI);
2ronwalf// aInd.addProperty(aProp,aValue);
2ronwalf
2ronwalf
2ronwalf// OWLKnowledgeBase kb = OWLFactory.createKB();
2ronwalf// kb.setReasoner("RDFS");
2ronwalf// Service aService = kb.readService("http://bai-hu.ethz.ch/next/ont/comp/NMRCompSampleSetup.owl");
2ronwalf// aService.removeProperty(org.mindswap.owls.vocabulary.OWLS_1_1.Service.supports,aService.getGrounding());
2ronwalf// System.err.println(aService.getProperty(org.mindswap.owls.vocabulary.OWLS_1_1.Service.supports));
2ronwalf// System.err.println(aService.getGrounding());
2ronwalf
2ronwalf //new OWLSValidator().validate("http://bai-hu.ethz.ch/next/ont/comp/NMRCompSampleSetup.owl").print(System.err);
2ronwalf
2ronwalf//org.mindswap.owl.OWLConfig.setStrictConversion(false);
2ronwalf //new OWLSValidator().validate(new java.io.File("BookPrice.owl").toURL().toExternalForm().replaceAll(" ","%20")).print(System.err);
2ronwalf //new OWLSValidator().validate("http://www.kellyjoe.com/services/commissioning/CommissioningService.owl").print(System.err);
2ronwalf new OWLSValidator().validate(new java.io.File("composite.owl").toURL().toExternalForm().replaceAll(" ","%20")).print(System.err);
2ronwalf
2ronwalf //OWLKnowledgeBase kb = OWLFactory.createKB();
2ronwalf //kb.setReasoner("Pellet");
2ronwalf //Service aService = kb.readService("http://www.kellyjoe.com/services/commissioning/CommissioningService.owl");
2ronwalf
2ronwalf // execution engine error test code
2ronwalf// OWLKnowledgeBase kb = OWLFactory.createKB();
2ronwalf// kb.setReasoner("Pellet");
2ronwalf// Service aService = kb.readService("http://bai-hu.ethz.ch/next/ont/comp/NMRCompSampleSetup.owl");
2ronwalf//
2ronwalf// Process aProcess = aService.getProcess();
2ronwalf// try {
2ronwalf// //values = exec.execute(aProcess, values);
2ronwalf// ValueMap aValueMap = new ValueMap();
2ronwalf//
2ronwalf// ProcessExecutionEngine exec = org.mindswap.owls.OWLSFactory.createExecutionEngine();
2ronwalf// impl.owls.process.execution.ProcessExecutionEngineImpl.DEBUG = true;
2ronwalf//
2ronwalf// aValueMap = exec.execute(aProcess,aValueMap);
2ronwalf// } catch (Exception e) {
2ronwalf// //System.err.println(e.getMessage());
2ronwalf// e.printStackTrace();
2ronwalf// }
2ronwalf
2ronwalf // this code illustrates the cast exception that arises when getting the service parameters for a profile
2ronwalf// String aURI = "http://www.mindswap.org/2004/owl-s/1.1/sensor/GetData2.owl";
2ronwalf// OWLKnowledgeBase kb = OWLFactory.createKB();
2ronwalf// kb.setReasoner("Pellet");
2ronwalf// Service aService = kb.readService(aURI);
2ronwalf// OWLIndividualList aList = aService.getProfile().getServiceParameters();
2ronwalf// for (int i = 0; i < aList.size(); i++)
2ronwalf// System.err.println(aList.individualAt(i));
2ronwalf
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/sensor/GetData2.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/BNPrice.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/BookPrice.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/AmazonBookPrice.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/BabelFishTranslator.owl";
2ronwalf//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/CheaperBookFinder.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/Dictionary.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/CurrencyConverter.owl";
2ronwalf//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/FindCheaperBook.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/FindLatLong.owl";
2ronwalf//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/FrenchDictionary.owl";
2ronwalf //String aURI = "http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl";
2ronwalf
2ronwalf// OWLSValidatorReport aReport = aValidator.validate(aURI);
2ronwalf// aReport.print(System.err);
2ronwalf }
2ronwalf catch (Exception ex) {
2ronwalf ex.printStackTrace();
2ronwalf }
2ronwalf }
2ronwalf}