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.*;
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-core 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 WsmlCoreValidator
44          extends WsmlDLValidator {
45   
46      private WsmlFlightValidator flightVal;
47      
48      public WsmlCoreValidator(LogicalExpressionFactory leFactory) {
49          super(leFactory);
50          flightVal = new WsmlFlightValidator(leFactory); 
51      }
52      
53      private void setup(){
54          flightVal.setErrors(this.errors);
55          flightVal.setWarnings(this.warnings);
56      }
57  
58      /**
59       * Checks if an axiom is valid to wsml-core.
60       * 
61       * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitAxiom(org.omwg.ontology.Axiom)
62       */
63      protected void visitAxiom(Axiom axiom) {
64          setup();
65          WsmlCoreExpressionValidator coreExprVal = new WsmlCoreExpressionValidator(axiom, leFactory, errors, this);
66          WsmlDLExpressionValidator dlExprVal = new WsmlDLExpressionValidator(axiom, leFactory, errors, this);
67          WsmlFlightExpressionValidator flightExprVal = new WsmlFlightExpressionValidator(axiom, leFactory, errors, this);
68          WsmlRuleExpressionValidator ruleExprVal = new WsmlRuleExpressionValidator(axiom, errors, this);
69          WsmlFullExpressionValidator fullExprVal = new WsmlFullExpressionValidator(axiom, errors);
70          FunctionSymbolHelper fsHelper = new FunctionSymbolHelper(axiom, errors, WSML.WSML_CORE, this);
71          IDCollectHelper idHelper = new IDCollectHelper();
72          Iterator axioms = axiom.listDefinitions().iterator();
73          while (axioms.hasNext()){
74              LogicalExpression le = (LogicalExpression) axioms.next();
75              
76              le.accept(idHelper);
77              // adding the Axiom's Concepts, Instances and Relations to the vectors
78              idConcepts.addAll(idHelper.getConceptIds());
79              idInstances.addAll(idHelper.getInstanceIds());
80              idRelations.addAll(idHelper.getRelationIds());
81              idAbstractRelations.addAll(idHelper.getIdAbstractRelations());
82              idConcreteRelations.addAll(idHelper.getIdConcreteRelations());
83              
84              le.accept(fsHelper);
85              
86              le.accept(fullExprVal);
87              ruleExprVal.setup();
88              le.accept(ruleExprVal);
89              flightExprVal.setup();
90              le.accept(flightExprVal);
91              dlExprVal.setup();
92              le.accept(dlExprVal);
93              coreExprVal.setup();
94              le.accept(coreExprVal);
95          }
96      }
97  
98      /**
99       * Checks if a concept is valid to wsml-core.
100      *      
101      * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitConcept(org.omwg.ontology.Concept)
102      */
103     protected void visitConcept(Concept concept) {  
104         super.visitConcept(concept);
105 //        setup();
106 //        flightVal.visitConcept(concept);
107     }
108 
109     /**
110      * Checks if an instance is valid to wsml-core.
111      * 
112      * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitInstance(org.omwg.ontology.Instance)
113      */
114     protected void visitInstance(Instance instance) {
115         super.visitInstance(instance); 
116 //        setup();
117 //        flightVal.visitInstance(instance);
118     }
119 
120     /**
121      * Checks if a relation is valid to wsml-core.
122      * 
123      * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitRelation(org.omwg.ontology.Relation)
124      */
125     protected void visitRelation(Relation relation) {
126         super.visitRelation(relation);
127 //        setup();
128 //        flightVal.visitRelation(relation);
129     }
130 
131     /**
132      * Checks if a relation instance is valid to wsml-core.
133      * 
134      * @throws InvalidModelException
135      * @throws SynchronisationException
136      * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitRelationInstance(org.omwg.ontology.RelationInstance)
137      */
138     protected void visitRelationInstance(RelationInstance relationInstance)
139             throws SynchronisationException, InvalidModelException {
140         super.visitRelationInstance(relationInstance);
141 //        setup();
142 //        flightVal.visitRelationInstance(relationInstance);
143     }
144     
145     public boolean isValid(LogicalExpression logExpr, List <ValidationError> errorMessages, List <ValidationWarning> warningMessages) {
146     	super.isValid(logExpr, errorMessages, warningMessages);
147     	errors = errorMessages;
148         warnings = warningMessages;
149         setup();
150         WsmlCoreExpressionValidator coreExprVal = new WsmlCoreExpressionValidator(null, leFactory, errors, this);
151         WsmlDLExpressionValidator dlExprVal = new WsmlDLExpressionValidator(null, leFactory, errors, this);
152         WsmlFlightExpressionValidator flightExprVal = new WsmlFlightExpressionValidator(null, leFactory, errors, this);
153         WsmlRuleExpressionValidator ruleExprVal = new WsmlRuleExpressionValidator(null, errors, this);
154         WsmlFullExpressionValidator fullExprVal = new WsmlFullExpressionValidator(null, errors);
155         FunctionSymbolHelper fsHelper = new FunctionSymbolHelper(
156         		null, errors, WSML.WSML_CORE, this);
157         IDCollectHelper idHelper = new IDCollectHelper();
158         
159         logExpr.accept(idHelper);
160         // adding the Axiom's Concepts, Instances and Relations to the vectors
161         idConcepts.addAll(idHelper.getConceptIds());
162         idInstances.addAll(idHelper.getInstanceIds());
163         idRelations.addAll(idHelper.getRelationIds());
164         idAbstractRelations.addAll(idHelper.getIdAbstractRelations());
165         idConcreteRelations.addAll(idHelper.getIdConcreteRelations());
166         
167         logExpr.accept(fsHelper);
168         
169         logExpr.accept(fullExprVal);
170         ruleExprVal.setup();
171         logExpr.accept(ruleExprVal);
172         flightExprVal.setup();
173         logExpr.accept(flightExprVal);
174         dlExprVal.setup();
175         logExpr.accept(dlExprVal);
176         coreExprVal.setup();
177         logExpr.accept(coreExprVal);
178         
179         return (errors.isEmpty());
180     }
181     
182     /*
183      * Adds a new ValidationError to the error list
184      */
185     protected void addError(Entity ent, String msg) {
186         ValidationErrorImpl ve = new ValidationErrorImpl(ent, msg, WSML.WSML_CORE);
187         if (!errors.contains(ve)) {
188             errors.add(ve);
189         }
190     }
191 }