Coverage Report - org.deri.wsmo4j.rule.ConditionRI
 
Classes in this File Line Coverage Branch Coverage Complexity
ConditionRI
0%
0/21
N/A
0
ConditionRI$1
N/A
N/A
0
ConditionRI$RestrictedLEValidator
0%
0/33
N/A
0
 
 1  
 /*
 2  
  wsmo4j extension - a Choreography API and Reference Implementation
 3  
 
 4  
  Copyright (c) 2005, University of Innsbruck, Austria
 5  
 
 6  
  This library is free software; you can redistribute it and/or modify it under
 7  
  the terms of the GNU Lesser General Public License as published by the Free
 8  
  Software Foundation; either version 2.1 of the License, or (at your option)
 9  
  any later version.
 10  
  This library is distributed in the hope that it will be useful, but WITHOUT
 11  
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 12  
  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 13  
  details.
 14  
  You should have received a copy of the GNU Lesser General Public License along
 15  
  with this library; if not, write to the Free Software Foundation, Inc.,
 16  
  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17  
  */
 18  
 
 19  
 package org.deri.wsmo4j.rule;
 20  
 
 21  
 import org.omwg.logicalexpression.*;
 22  
 import org.omwg.logicalexpression.Visitor;
 23  
 import org.wsmo.common.*;
 24  
 import org.wsmo.common.exception.*;
 25  
 import org.wsmo.service.rule.*;
 26  
 
 27  
 /**
 28  
  * Reference Implementation for Condition
 29  
  * 
 30  
  * @author James Scicluna
 31  
  * @author Thomas Haselwanter
 32  
  * @author Holger Lausen
 33  
  * 
 34  
  * Created on 17-Oct-2005 Committed by $Author: vassil_momtchev $
 35  
  * 
 36  
  * $Source:
 37  
  * /cvsroot/wsmo4j/ext/choreography/src/ri/org/deri/wsmo4j/choreography/rule/ConditionRI.java,v $,
 38  
  * @version $Revision: 1844 $ $Date: 2006-10-24 17:11:48 +0300 (Tue, 24 Oct 2006) $
 39  
  */
 40  
 
 41  
 public class ConditionRI implements Condition {
 42  
 
 43  
     protected LogicalExpression le;
 44  
 
 45  
     /**
 46  
      * Factory for creating a condition from an already existing Logical
 47  
      * Expression
 48  
      * 
 49  
      * @param e
 50  
      *            LogicalExpression object from which the condition is to be
 51  
      *            created
 52  
      */
 53  0
     public ConditionRI(LogicalExpression e) throws InvalidModelException {
 54  
         try {
 55  0
             validateLogicalExpression(e);
 56  
         } 
 57  0
         catch (UnsupportedOperationException ex){
 58  0
             throw new InvalidModelException(ex.getMessage());
 59  0
         }
 60  0
         this.le = e;
 61  0
     }
 62  
 
 63  
     /*
 64  
      * (non-Javadoc)
 65  
      * 
 66  
      * @see org.omwg.logicalexpression.LogicalExpression#accept(org.omwg.logicalexpression.Visitor)
 67  
      */
 68  
     public void accept(Visitor v) {
 69  0
         le.accept(v);
 70  0
     }
 71  
 
 72  
     @Override
 73  
     public String toString() {
 74  0
         return le.toString();
 75  
     }
 76  
 
 77  
     public String toString(TopEntity nsHolder) {
 78  0
         return le.toString(nsHolder);
 79  
     }
 80  
 
 81  
     public LogicalExpression getRestrictedLogicalExpression() {
 82  0
         return le;
 83  
     }
 84  
 
 85  
     public void setRestrictedLogicalExpression(LogicalExpression le) throws InvalidModelException {
 86  
         try {
 87  0
             validateLogicalExpression(le);
 88  
         } 
 89  0
         catch (UnsupportedOperationException ex){
 90  0
             throw new InvalidModelException(ex.getMessage());
 91  0
         }
 92  0
         this.le = le;
 93  0
     }
 94  
 
 95  
     private void validateLogicalExpression(LogicalExpression le) throws InvalidModelException {
 96  0
         RestrictedLEValidator validator = new RestrictedLEValidator();
 97  0
         le.accept(validator);
 98  0
     }
 99  
     
 100  0
     private class RestrictedLEValidator implements Visitor {
 101  0
         private String error = "{0} is not allowed for a restricted LogicalExpression use in Condition!";
 102  
         
 103  
         public void visitAtom(Atom expr) {
 104  0
         };
 105  
 
 106  
         public void visitCompoundMolecule(CompoundMolecule expr) {
 107  0
         };
 108  
 
 109  
         public void visitSubConceptMolecule(SubConceptMolecule expr) {
 110  0
         };
 111  
 
 112  
         public void visitMemberShipMolecule(MembershipMolecule expr) {
 113  0
         };
 114  
 
 115  
         public void visitAttributeValueMolecule(AttributeValueMolecule expr) {
 116  0
         };
 117  
 
 118  
         public void visitAttributeContraintMolecule(AttributeConstraintMolecule expr) {
 119  0
         };
 120  
 
 121  
         public void visitAttributeInferenceMolecule(AttributeInferenceMolecule expr) {
 122  0
         };
 123  
 
 124  
         public void visitNegation(Negation expr) {
 125  0
             expr.getOperand().accept(this);
 126  0
         };
 127  
 
 128  
         public void visitNegationAsFailure(NegationAsFailure expr) {
 129  0
             throw new UnsupportedOperationException(String.format(error, "NegationAsFailure"));
 130  
         };
 131  
 
 132  
         public void visitConstraint(Constraint expr) {
 133  0
             throw new UnsupportedOperationException(String.format(error, "Constraint"));
 134  
         };
 135  
 
 136  
         public void visitConjunction(Conjunction expr) {
 137  0
             expr.getLeftOperand().accept(this);
 138  0
             expr.getRightOperand().accept(this);
 139  0
         };
 140  
 
 141  
         public void visitDisjunction(Disjunction expr) {
 142  0
             expr.getLeftOperand().accept(this);
 143  0
             expr.getRightOperand().accept(this);
 144  0
         };
 145  
 
 146  
         public void visitInverseImplication(InverseImplication expr) {
 147  0
             expr.getLeftOperand().accept(this);
 148  0
             expr.getRightOperand().accept(this);
 149  0
         };
 150  
 
 151  
         public void visitImplication(Implication expr) {
 152  0
             expr.getLeftOperand().accept(this);
 153  0
             expr.getRightOperand().accept(this);
 154  0
         };
 155  
 
 156  
         public void visitEquivalence(Equivalence expr) {
 157  0
             expr.getLeftOperand().accept(this);
 158  0
             expr.getRightOperand().accept(this);
 159  0
         };
 160  
 
 161  
         public void visitLogicProgrammingRule(LogicProgrammingRule expr) {
 162  0
             throw new UnsupportedOperationException(String.format(error, "LogicProgrammingRule"));
 163  
         };
 164  
 
 165  
         public void visitUniversalQuantification(UniversalQuantification expr) {
 166  0
             expr.getOperand().accept(this);
 167  0
         };
 168  
 
 169  
         public void visitExistentialQuantification(ExistentialQuantification expr) {
 170  0
             expr.getOperand().accept(this);
 171  0
         };
 172  
     }
 173  
 }
 174  
 
 175  
 /*
 176  
  * $Log$
 177  
  * Revision 1.1  2006/10/24 14:11:48  vassil_momtchev
 178  
  * choreography/orchestration rules refactored. different types where appropriate now supported
 179  
  *
 180  
  * Revision 1.7  2006/04/17 09:49:02  vassil_momtchev
 181  
  * validation of the LogicalExpression - only restricted LE (with no naf, :-, !-) allowed
 182  
  *
 183  
  */