Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 167   Methods: 10
NCLOC: 112   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CompoundExpressionAnalysis.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3    Copyright (c) 2004, University of Innsbruck, Institute of Computer Science
 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.io.parser.wsml;
 17   
 18    import java.util.*;
 19   
 20    import org.deri.wsmo4j.logicalexpression.LogicalExpressionImpl;
 21    import org.omwg.logicalexpression.*;
 22    import org.omwg.ontology.*;
 23    import org.wsmo.factory.*;
 24    import org.wsmo.wsml.compiler.node.*;
 25   
 26    import com.ontotext.wsmo4j.parser.wsml.*;
 27   
 28   
 29    /**
 30    *
 31    * <pre>
 32    * Created on 21.11.2005
 33    * Committed by $Author$
 34    * $Source$,
 35    * </pre>
 36    *
 37    * @author Holger Lausen
 38    * @version $Revision$ $Date$
 39    */
 40    public class CompoundExpressionAnalysis extends ASTAnalysis {
 41    private LogicalExpressionFactory lFactory;
 42    private ASTAnalysisContainer container;
 43   
 44    private Stack logexps; // handle to logexp stack
 45   
 46    /**
 47    * Adapter for all Compound Expressions
 48    * @param container
 49    * @param lFactory
 50    */
 51  0 public CompoundExpressionAnalysis(ASTAnalysisContainer container,
 52    LogicalExpressionFactory lFactory) {
 53   
 54  0 if (container == null || lFactory == null) {
 55  0 throw new IllegalArgumentException();
 56    }
 57  0 this.container = container;
 58  0 this.lFactory = lFactory;
 59   
 60    // register the handled nodes
 61  0 container.registerNodeHandler(AConjunction.class, this);
 62  0 container.registerNodeHandler(ADisjunction.class, this);
 63  0 container.registerNodeHandler(AConstraintLogExpr.class, this);
 64  0 container.registerNodeHandler(ALpRuleLogExpr.class, this);
 65  0 container.registerNodeHandler(AQuantified.class, this);
 66  0 container.registerNodeHandler(ANegatedSubexpr.class, this);
 67  0 container.registerNodeHandler(AImplicationExpr.class, this);
 68   
 69  0 container.registerNodeHandler(AOtherExpressionLogExpr.class, this);
 70   
 71    //shortcuts
 72  0 logexps = container.getStack(LogicalExpression.class);
 73   
 74    }
 75   
 76  0 private void outALogDefinition(){
 77  0 Stack orgLes = container.getStack(String.class);
 78  0 Object le = logexps.peek();
 79  0 if (orgLes.size()==0 || !(le instanceof LogicalExpressionImpl)){
 80  0 return;
 81    }
 82  0 String org = (String)orgLes.remove(0);
 83  0 ((LogicalExpressionImpl)le).setStringRepresentation(org);
 84    }
 85   
 86  0 public void outAOtherExpressionLogExpr(AOtherExpressionLogExpr node){
 87  0 outALogDefinition();
 88    }
 89   
 90  0 public void outAConjunction(AConjunction node) {
 91  0 LogicalExpression le2 = (LogicalExpression)logexps.pop();
 92  0 LogicalExpression le1 = (LogicalExpression)logexps.pop();
 93  0 logexps.add(lFactory.createConjunction(le1,le2));
 94    }
 95   
 96  0 public void outADisjunction(ADisjunction node) {
 97  0 LogicalExpression le2 = (LogicalExpression)logexps.pop();
 98  0 LogicalExpression le1 = (LogicalExpression)logexps.pop();
 99  0 logexps.add(lFactory.createDisjunction(le1,le2));
 100    }
 101   
 102  0 public void outAConstraintLogExpr(AConstraintLogExpr node) {
 103  0 logexps.add(lFactory.createConstraint(
 104    (LogicalExpression)logexps.pop()));
 105  0 outALogDefinition();
 106    }
 107   
 108  0 public void outALpRuleLogExpr(ALpRuleLogExpr node) {
 109  0 LogicalExpression le2 = (LogicalExpression)logexps.pop();
 110  0 LogicalExpression le1 = (LogicalExpression)logexps.pop();
 111  0 logexps.add(lFactory.createLogicProgrammingRule(
 112    le1,le2));
 113  0 outALogDefinition();
 114    }
 115   
 116  0 public void outAQuantified(AQuantified node) {
 117  0 PQuantifierKey quantifierKey = node.getQuantifierKey();
 118  0 Variable[] vars = (Variable[])container.popFromStack(Variable[].class,Variable[].class);
 119  0 Set <Variable> variables = new HashSet <Variable> ();
 120  0 for (int i=0; i<vars.length; i++){
 121  0 variables.add(vars[i]);
 122    }
 123   
 124  0 if (quantifierKey instanceof AExistsQuantifierKey) {
 125  0 logexps.add(lFactory.createExistentialQuantification(
 126    variables,
 127    (LogicalExpression)logexps.pop()));
 128    }
 129    else {
 130  0 logexps.add(lFactory.createUniversalQuantification(
 131    variables,
 132    (LogicalExpression)logexps.pop()));
 133    }
 134    }
 135   
 136  0 public void outANegatedSubexpr(ANegatedSubexpr node) {
 137  0 if (node.getTNot().getText().equals("neg")) {
 138  0 logexps.add(lFactory.createNegation(
 139    (LogicalExpression)logexps.pop()));
 140    }
 141    else {
 142  0 logexps.add(lFactory.createNegationAsFailure(
 143    (LogicalExpression)logexps.pop()));
 144    }
 145    }
 146   
 147  0 public void outAImplicationExpr(AImplicationExpr node) {
 148  0 PImplyOp pOp = node.getImplyOp();
 149  0 LogicalExpression le2 = (LogicalExpression)logexps.pop();
 150  0 LogicalExpression le1 = (LogicalExpression)logexps.pop();
 151  0 if (pOp instanceof AImpliesImplyOp) {
 152  0 logexps.add(lFactory.createImplication(
 153    (LogicalExpression)le1,
 154    (LogicalExpression)le2));
 155    }
 156  0 else if (pOp instanceof AEquivalentImplyOp) {
 157  0 logexps.add(lFactory.createEquivalence(
 158    (LogicalExpression)le1,
 159    (LogicalExpression)le2));
 160    }
 161    else {
 162  0 logexps.add(lFactory.createInverseImplication(
 163    (LogicalExpression)le1,
 164    (LogicalExpression)le2));
 165    }
 166    }
 167    }