View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    Copyright (c) 2005, University of Innsbruck, Austria
4    This library is free software; you can redistribute it and/or modify it under
5    the terms of the GNU Lesser General Public License as published by the Free
6    Software Foundation; either version 2.1 of the License, or (at your option)
7    any later version.
8    This library is distributed in the hope that it will be useful, but WITHOUT
9    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11   details.
12   You should have received a copy of the GNU Lesser General Public License along
13   with this library; if not, write to the Free Software Foundation, Inc.,
14   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15   */
16  package org.deri.wsmo4j.validator;
17  
18  
19  import java.util.*;
20  
21  import org.omwg.logicalexpression.*;
22  import org.omwg.ontology.*;
23  import org.wsmo.common.WSML;
24  import org.wsmo.common.exception.*;
25  import org.wsmo.factory.LogicalExpressionFactory;
26  import org.wsmo.validator.ValidationError;
27  import org.wsmo.validator.ValidationWarning;
28  
29  
30  /**
31   * Checks an ontology for wsml-flight validity.
32   *
33   * <pre>
34   *  Created on Aug 18, 2005
35   *  Committed by $Author: morcen $
36   *  $Source$,
37   * </pre>
38   *
39   * @author Holger Lausen (holger.lausen@deri.org)
40   * @author nathalie.steinmetz@deri.org
41   * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $
42   */
43  public class WsmlFlightValidator
44          extends WsmlRuleValidator {
45      
46      public WsmlFlightValidator(LogicalExpressionFactory leFactory) {
47          super(leFactory);
48      }
49      
50      /**
51       * Checks if an axiom is valid to wsml-flight.
52       * 
53       * @see org.deri.wsmo4j.validator.WsmlRuleValidator#visitAxiom(org.omwg.ontology.Axiom)
54       */
55      protected void visitAxiom(Axiom axiom) {
56          WsmlFlightExpressionValidator flightExprVal = new WsmlFlightExpressionValidator(axiom, leFactory, errors, this);
57          WsmlRuleExpressionValidator ruleExprVal = new WsmlRuleExpressionValidator(axiom, errors, this);
58          WsmlFullExpressionValidator fullExprVal = new WsmlFullExpressionValidator(axiom, errors);
59          FunctionSymbolHelper fsHelper = new FunctionSymbolHelper(
60                  axiom, errors, WSML.WSML_FLIGHT, this);
61          Iterator axioms = axiom.listDefinitions().iterator();
62          while (axioms.hasNext()) {
63              LogicalExpression le = (LogicalExpression) axioms.next();
64              le.accept(fsHelper);
65              
66              le.accept(fullExprVal);
67              ruleExprVal.setup();
68              le.accept(ruleExprVal);
69              flightExprVal.setup();
70              le.accept(flightExprVal);
71          }
72      }
73  
74      /**
75       * Checks if a concept is valid to wsml-flight.
76       * 
77       * @see org.deri.wsmo4j.validator.WsmlRuleValidator#visitConcept(org.omwg.ontology.Concept)
78       */
79      protected void visitConcept(Concept concept) {
80          super.visitConcept(concept);
81      }
82  
83      /**
84       * Checks if an instance is valid to wsml-flight.
85       * 
86       * @see org.deri.wsmo4j.validator.WsmlRuleValidator#visitInstance(org.omwg.ontology.Instance)
87       */
88      protected void visitInstance(Instance instance) {
89          super.visitInstance(instance);
90      }
91  
92      /**
93       * Checks if a relation is valid to wsml-flight.
94       * 
95       * @see org.deri.wsmo4j.validator.WsmlRuleValidator#visitRelation(org.omwg.ontology.Relation)
96       */
97      protected void visitRelation(Relation relation) {
98          super.visitRelation(relation);
99      }
100 
101     /**
102      * Checks if a relation instance is valid to wsml-flight.
103      * 
104      * @throws InvalidModelException
105      * @throws SynchronisationException
106      * @see org.deri.wsmo4j.validator.WsmlRuleValidator#visitRelationInstance(org.omwg.ontology.RelationInstance)
107      */
108     protected void visitRelationInstance(RelationInstance relationInstance)
109             throws SynchronisationException, InvalidModelException {
110         super.visitRelationInstance(relationInstance);
111     }
112 
113     public boolean isValid(LogicalExpression logExpr, List <ValidationError> errorMessages, List <ValidationWarning> warningMessages) {
114     	super.isValid(logExpr, errorMessages, warningMessages);
115     	errors = errorMessages;
116         warnings = warningMessages;
117         WsmlFlightExpressionValidator flightExprVal = new WsmlFlightExpressionValidator(null, leFactory, errors, this);
118         WsmlRuleExpressionValidator ruleExprVal = new WsmlRuleExpressionValidator(null, errors, this);
119         WsmlFullExpressionValidator fullExprVal = new WsmlFullExpressionValidator(null, errors);
120         FunctionSymbolHelper fsHelper = new FunctionSymbolHelper(
121                 null, errors, WSML.WSML_FLIGHT, this);
122 
123         logExpr.accept(fsHelper);      
124         logExpr.accept(fullExprVal);
125         ruleExprVal.setup();
126         logExpr.accept(ruleExprVal);
127         flightExprVal.setup();
128         logExpr.accept(flightExprVal);
129     	return (errors.isEmpty());
130     }
131     
132     public void setErrors(List <ValidationError> errors) {
133         this.errors = errors;
134     }
135     
136     public void setWarnings(List <ValidationWarning> warnings) {
137         this.warnings = warnings;
138     }
139     
140 }