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.Iterator;
20  import java.util.List;
21  
22  import org.omwg.logicalexpression.LogicalExpression;
23  import org.omwg.ontology.Axiom;
24  import org.omwg.ontology.Concept;
25  import org.omwg.ontology.Instance;
26  import org.omwg.ontology.Relation;
27  import org.omwg.ontology.RelationInstance;
28  import org.wsmo.common.exception.InvalidModelException;
29  import org.wsmo.common.exception.SynchronisationException;
30  import org.wsmo.factory.LogicalExpressionFactory;
31  import org.wsmo.validator.ValidationError;
32  import org.wsmo.validator.ValidationWarning;
33  
34  
35  /**
36   * Checks an ontology for wsml-rule validity.
37   *
38   * <pre>
39   *  Created on Aug 18, 2005
40   *  Committed by $Author: morcen $
41   *  $Source$,
42   * </pre>
43   *
44   * @author Holger Lausen (holger.lausen@deri.org)
45   * @author nathalie.steinmetz@deri.org
46   * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $
47   */
48  public class WsmlRuleValidator
49          extends WsmlFullValidator {
50  
51      public WsmlRuleValidator(LogicalExpressionFactory leFactory) {
52          super(leFactory);
53      }
54      
55      /**
56       * Checks if an axiom is valid to wsml-rule.
57       * 
58       * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitAxiom(org.omwg.ontology.Axiom)
59       */
60      protected void visitAxiom(Axiom axiom) {
61          WsmlRuleExpressionValidator ruleExprVal = new WsmlRuleExpressionValidator(axiom, errors, this);
62          WsmlFullExpressionValidator fullExprVal = new WsmlFullExpressionValidator(axiom, errors);
63          Iterator axioms = axiom.listDefinitions().iterator();
64          while (axioms.hasNext()) {
65              LogicalExpression le = (LogicalExpression) axioms.next();
66              le.accept(fullExprVal);
67              ruleExprVal.setup();
68              le.accept(ruleExprVal);
69          }
70      }
71  
72      /**
73       * Checks if a concept is valid to wsml-rule.
74       * 
75       * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitConcept(org.omwg.ontology.Concept)
76       */
77      protected void visitConcept(Concept concept) {
78          super.visitConcept(concept);
79      }
80  
81      /**
82       * Checks if an instance is valid to wsml-rule.
83       * 
84       * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitInstance(org.omwg.ontology.Instance)
85       */
86      protected void visitInstance(Instance instance) {
87          super.visitInstance(instance);
88      }
89  
90      /**
91       * Checks if a relation is valid to wsml-rule.
92       * 
93       * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitRelation(org.omwg.ontology.Relation)
94       */
95      protected void visitRelation(Relation relation) {
96          super.visitRelation(relation);
97      }
98  
99      /**
100      * Checks if a relation instance is valid to wsml-rule.
101      * 
102      * @throws InvalidModelException
103      * @throws SynchronisationException
104      * @see org.deri.wsmo4j.validator.WsmlFullValidator#visitRelationInstance(org.omwg.ontology.RelationInstance)
105      */
106     protected void visitRelationInstance(RelationInstance relationInstance)
107             throws SynchronisationException, InvalidModelException {
108         super.visitRelationInstance(relationInstance);
109     }
110     
111     public boolean isValid(LogicalExpression logExpr, List <ValidationError> errorMessages, List <ValidationWarning> warningMessages) {
112     	super.isValid(logExpr, errorMessages, warningMessages);
113     	errors = errorMessages;
114     	warnings = warningMessages;
115     	WsmlRuleExpressionValidator ruleExprVal = new WsmlRuleExpressionValidator(null, errors, this);
116         WsmlFullExpressionValidator fullExprVal = new WsmlFullExpressionValidator(null, errors);
117         logExpr.accept(fullExprVal);
118         ruleExprVal.setup();
119         logExpr.accept(ruleExprVal);
120         return (errors.isEmpty());
121     }
122     
123 }