OWLSValidator.java revision 7
/*
what about validating precondtions?
is that neccessary?
warn about using deprecated terms?
how to find out which are deprecated heh
--Process--
Binding
1 toParam,
<= 1 valueSource, valueData, valueSpecifier
ValueOf
1 theVar
<= 1 fromProcess
CompositeProcess
1 composedOf
<= 1 invocable
<= 1 computedOutput
<= 1 computedInput
<= 1 computedEffect
<= 1 computedPrecondition
everything in a ControlConstructBag/ControlConstructList should be of type ControlConstruct
Sequence
1, components -> ControlConstructList
Split
1, components -> ControlConstructBag
Any-Order
1, components -> ControlConstructBag
Choice
1, components -> ControlConstructBag
If-Then-Else
1, ifCondition
1, then
<= 1, else
Repeat-While
1, whileCondition
1, whileProcess -> ControlConstruct
Repeat-Until
1, untilCondition
1, untilProcess -> ControlConstruct
*/
public class OWLSValidator
{
private static final int CODE_INVALID_VALUE = 0;
private static final int CODE_MISSING_VALUE = 1;
private Map mMessageMap;
public OWLSValidator()
{
mMessageMap = new HashMap();
}
{
//aKb.setReasoner("RDFS");
return validateKb(aKb);
}
{
}
{
mMessageMap = new HashMap();
//aKb.setReasoner("RDFS");
try {
}
throw OWLSValidationException.createParseException("Invalid URI ("+theURI+") specified for description");
}
throw OWLSValidationException.createFileNotFoundException("File at URI ("+theURI+") not found, cannot validate");
}
// failed to parse?
}
return validateKb(aKb);
}
{
{
}
return new OWLSValidatorReport(mMessageMap);
}
{
{
// invalid, can only have 0,1 describedBy
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"Cannot specify more than one describedBy for a service");
}
try {
}
// probably a cast exception, ignore for now, let the process validator handle it
}
}
{
if (theProcess == null)
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No process specified for service: "+theService.getLocalName());
return;
}
try {
// TODO: do processes really require profiles?, do they require to belong to a service?
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No profile specified for process: "+theProcess.getLocalName());
}
}
catch (ConversionException ce) {
}
catch (CastingException ex) {
}
{
// process must have a name
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Process '"+theProcess.getLocalName()+"' can specify at most one name");
}
// ParameterList aParamList = aProcess.getParameters();
// for (int i = 0; i < aParamList.size(); i++)
// {
// Parameter aParam = aParamList.parameterAt(i);
// validateParameter(theService,aParam);
// }
{
}
{
}
{
}
{
}
else
{
// TODO: is this an error?
}
}
{
}
{
}
{
}
{
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"A paramType must be specified for Parameter: "+theParam.getLocalName());
}
{
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.");
}
// what about getConstantValue() ??
}
{
// TODO: is the AtomicGrounding required?
// what else needs to be validated on an atomic process
}
{
{
}
{
}
try {
{
// Process aProcess = aProcessList.processAt(i);
// TODO: validate each process?
//System.err.println("proc: "+aProcess);
}
}
catch (ConversionException ce) {
}
catch (CastingException ex) {
}
// maybe just verify that there are at least two processes for the composite
// and that the perform and process list match up?
}
{
try {
}
// likely a cast exception, we'll ignore the exception, aGrounding will be null
// and the below error message will be recorded.
}
if (aGrounding == null)
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No grounding specified for service: "+theService.getLocalName());
return;
}
{
// invalid, can only have 0,1 supportedBy
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"The grounding '"+aGrounding.getLocalName()+"' cannot have more than one supportedBy property");
}
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"The grounding '"+aGrounding.getLocalName()+"' does not specify a service.");
}
// TODO: is at least one grounding required?
try {
{
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"The atomic grounding '"+aAtomicGrounding.getLocalName()+"' does not specify its process.");
}
{
}
{
validateWSDLAtomicGrounding(theService,(WSDLAtomicGrounding)aAtomicGrounding.castTo(WSDLAtomicGrounding.class));
}
}
}
catch (ConversionException ce) {
}
catch (CastingException ex) {
}
}
private void validateWSDLAtomicGrounding(Service theService, WSDLAtomicGrounding theWSDLAtomicGrounding)
{
// todo: are the wsdlInputMessage/wsdlOutputMessage required? what about getWSDL()?
addMessage(theService,CODE_INVALID_VALUE,"The grounding '"+theWSDLAtomicGrounding.getLocalName()+"' has a missing, or invalid operationRef.");
else {
addMessage(theService, CODE_MISSING_VALUE,"The grounding '"+theWSDLAtomicGrounding.getLocalName()+"' must specify a portType for its operationRef.");
addMessage(theService, CODE_MISSING_VALUE,"The grounding '"+theWSDLAtomicGrounding.getLocalName()+"' must specify an operation for its operationRef");
}
// TODO: are you required to have input and output maps?
{
addMessage(theService,CODE_MISSING_VALUE,"The input map for grounding '"+theWSDLAtomicGrounding.getLocalName()+"' requires a grounding parameter (wsdlMessagePart).");
addMessage(theService,CODE_MISSING_VALUE,"The input map for grounding '"+theWSDLAtomicGrounding.getLocalName()+"' must specify either an owlsParameter or an xlstTransformation.");
}
{
addMessage(theService,CODE_MISSING_VALUE,"The output map for grounding '"+theWSDLAtomicGrounding.getLocalName()+"' requires an owlsParameter.");
addMessage(theService,CODE_MISSING_VALUE,"The output map for grounding '"+theWSDLAtomicGrounding.getLocalName()+"' must specify either an grounding parameter (wsdlMessagePart) or an xlstTransformation.");
}
}
{
{
}
}
{
else
{
}
//Perform aPerform = (Perform)aList.get(i);
//validatePerform(aService, aPerform);
}
{
{
}
{
// OWLIndividual aInd = aList.individualAt(i);
// are these the preconditions? or post conditions?
}
{
addMessage(theService,CODE_MISSING_VALUE,"Result '"+theResult.getLocalName()+"' must specify an Output for its toParam property.");
}
}
{
try {
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Perform '"+thePerform.getLocalName()+"' must specify a process");
}
//else validateProcess(theService, thePerform.getProcess());
}
catch (CastingException ex) {
}
catch (ConversionException ce) {
}
{
try {
addMessage(theService,CODE_MISSING_VALUE,"Perform '"+thePerform.getLocalName()+"' must specify an Input for the toParam property.");
}
catch (CastingException ex) {
}
catch (ConversionException ex) {
}
}
// TODO: is there any way to validate the valueSource for the perform?
}
{
try {
}
// cast exception most likely, let the null check below handle the error message
}
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"No profile specified for service: "+theService.getLocalName());
return;
}
{
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");
}
{
// invalid, must have a service name
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"The profile '"+aProfile.getLocalName()+"' must specify only one serviceName. ");
}
{
// invalid, must have a text description
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"The profile '"+aProfile.getLocalName()+"' must specify only one textDescription.");
}
{
// profile inputs should match process inputs
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"Profile inputs for service '"+theService.getLocalName()+"' do not match the process inputs!");
}
{
// profile outputs should match process outputs
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_INVALID_VALUE,"Profile outputs for service '"+theService.getLocalName()+"' do not match the process outputs!");
}
{
// TODO, why does this give a cast exception?
}
{
}
try {
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Profile '"+aProfile.getLocalName()+"' do not specify a process!");
}
}
catch (ConversionException ce) {
}
catch (CastingException ex) {
}
catch (NullPointerException npe) {
// we'll do nothing in this case for now, the above check should catch this problem
// you'll get an NPE here if the service for this profile is not properly specified.
// there is a check above that will print a msg for this, so I think we can
// ignore it here
}
// what about Classification, Products??
}
{
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a name for serviceParameter: "+theServiceParameter.getLocalName());
}
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a parameter for serviceParameter: "+theServiceParameter.getLocalName());
}
}
{
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a code for serviceCategory: "+theServiceCategory.getLocalName());
}
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a value for serviceCategory "+theServiceCategory.getLocalName());
}
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a taxonomy for serviceCategory: "+theServiceCategory.getLocalName());
}
{
OWLSValidatorMessage msg = new OWLSValidatorMessage(CODE_MISSING_VALUE,"Must specify a name for serviceCategory: "+theServiceCategory.getLocalName());
}
}
{
}
{
}
{
// OWLSValidator aValidator = new OWLSValidator();
try {
// OWLOntology theSourceOntology = OWLFactory.createOntology();
// OWLOntology theDestinationOntology = OWLFactory.createOntology();
//
// java.net.URI theIndToRemoveURI = java.net.URI.create("<some uri>");
// java.net.URI thePredicateURI = java.net.URI.create("<some property uri>");
//
// OWLIndividual aInd = theSourceOntology.getIndividual(theIndToRemoveURI);
// OWLObjectProperty aProp = theSourceOntology.getObjectProperty(thePredicateURI);
// OWLIndividual aValue = aInd.getProperty(aProp);
//
// aInd.removeProperty(aProp,aValue);
// aInd = theDestinationOntology.getIndividual(theIndToRemoveURI);
// aInd.addProperty(aProp,aValue);
// OWLKnowledgeBase kb = OWLFactory.createKB();
// kb.setReasoner("RDFS");
// Service aService = kb.readService("http://bai-hu.ethz.ch/next/ont/comp/NMRCompSampleSetup.owl");
// aService.removeProperty(org.mindswap.owls.vocabulary.OWLS_1_1.Service.supports,aService.getGrounding());
// System.err.println(aService.getProperty(org.mindswap.owls.vocabulary.OWLS_1_1.Service.supports));
// System.err.println(aService.getGrounding());
//new OWLSValidator().validate("http://bai-hu.ethz.ch/next/ont/comp/NMRCompSampleSetup.owl").print(System.err);
//org.mindswap.owl.OWLConfig.setStrictConversion(false);
//new OWLSValidator().validate(new java.io.File("BookPrice.owl").toURL().toExternalForm().replaceAll(" ","%20")).print(System.err);
//new OWLSValidator().validate("http://www.kellyjoe.com/services/commissioning/CommissioningService.owl").print(System.err);
new OWLSValidator().validate(new java.io.File("composite.owl").toURL().toExternalForm().replaceAll(" ","%20")).print(System.err);
//OWLKnowledgeBase kb = OWLFactory.createKB();
//kb.setReasoner("Pellet");
//Service aService = kb.readService("http://www.kellyjoe.com/services/commissioning/CommissioningService.owl");
// execution engine error test code
// OWLKnowledgeBase kb = OWLFactory.createKB();
// kb.setReasoner("Pellet");
// Service aService = kb.readService("http://bai-hu.ethz.ch/next/ont/comp/NMRCompSampleSetup.owl");
//
// Process aProcess = aService.getProcess();
// try {
// //values = exec.execute(aProcess, values);
// ValueMap aValueMap = new ValueMap();
//
// ProcessExecutionEngine exec = org.mindswap.owls.OWLSFactory.createExecutionEngine();
// impl.owls.process.execution.ProcessExecutionEngineImpl.DEBUG = true;
//
// aValueMap = exec.execute(aProcess,aValueMap);
// } catch (Exception e) {
// //System.err.println(e.getMessage());
// e.printStackTrace();
// }
// this code illustrates the cast exception that arises when getting the service parameters for a profile
// String aURI = "http://www.mindswap.org/2004/owl-s/1.1/sensor/GetData2.owl";
// OWLKnowledgeBase kb = OWLFactory.createKB();
// kb.setReasoner("Pellet");
// Service aService = kb.readService(aURI);
// OWLIndividualList aList = aService.getProfile().getServiceParameters();
// for (int i = 0; i < aList.size(); i++)
// System.err.println(aList.individualAt(i));
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/sensor/GetData2.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/BNPrice.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/BookPrice.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/AmazonBookPrice.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/BabelFishTranslator.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/CheaperBookFinder.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/Dictionary.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/CurrencyConverter.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/FindCheaperBook.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/FindLatLong.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/FrenchDictionary.owl";
//String aURI = "http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl";
// OWLSValidatorReport aReport = aValidator.validate(aURI);
// aReport.print(System.err);
}
}
}
}