Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 254   Methods: 16
NCLOC: 160   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ValueAnalysis.java 0% 0% 0% 0%
coverage
 1    /*
 2    wsmo4j - a WSMO API and Reference Implementation
 3   
 4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
 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    /**
 20    * <p>Title: WSMO4J</p>
 21    * <p>Description: WSMO API and a Reference Implementation</p>
 22    * <p>Copyright: Copyright (c) 2004-2005</p>
 23    * <p>Company: OntoText Lab. / SIRMA </p>
 24    */
 25   
 26    package com.ontotext.wsmo4j.parser.wsml;
 27   
 28    import java.util.*;
 29   
 30    import org.deri.wsmo4j.io.parser.WrappedParsingException;
 31    import org.deri.wsmo4j.logicalexpression.*;
 32    import org.omwg.logicalexpression.terms.*;
 33    import org.omwg.ontology.*;
 34    import org.wsmo.common.*;
 35    import org.wsmo.factory.*;
 36    import org.wsmo.wsml.ParserException;
 37    import org.wsmo.wsml.compiler.node.*;
 38   
 39    public class ValueAnalysis extends ASTAnalysis {
 40   
 41    private DataFactory dFactory;
 42    private LogicalExpressionFactory lFactory;
 43    private ASTAnalysisContainer container;
 44    private WsmoFactory factory;
 45   
 46    private Stack termStack;
 47    private Stack lastTermBeforeFunctionSymbol = new Stack();
 48    private ConstantTransformer cf = ConstantTransformer.getInstance();
 49   
 50  0 public ValueAnalysis(ASTAnalysisContainer container,
 51    DataFactory dFactory,
 52    LogicalExpressionFactory lFactory,
 53    WsmoFactory factory) {
 54  0 if (container == null || dFactory == null || lFactory == null) {
 55  0 throw new IllegalArgumentException();
 56    }
 57  0 this.dFactory = dFactory;
 58  0 this.lFactory = lFactory;
 59  0 this.factory = factory;
 60  0 this.container = container;
 61  0 termStack = container.getStack(Term.class);
 62   
 63    // register the handled nodes
 64  0 container.registerNodeHandler(AVarTerm.class, this);
 65  0 container.registerNodeHandler(AParametrizedFunctionsymbol.class, this);
 66  0 container.registerNodeHandler(ADecimalNumber.class, this);
 67  0 container.registerNodeHandler(AIntegerNumber.class, this);
 68  0 container.registerNodeHandler(AStringValue.class, this);
 69  0 container.registerNodeHandler(ATermlist.class, this);
 70  0 container.registerNodeHandler(ATermTermlist.class, this);
 71  0 container.registerNodeHandler(ATermValue.class, this);
 72  0 container.registerNodeHandler(ATermValuelist.class, this);
 73  0 container.registerNodeHandler(AValuelistValuelist.class, this);
 74  0 container.registerNodeHandler(ANbAnonymousTerm.class, this);
 75   
 76    }
 77   
 78  0 public void inAParametrizedFunctionsymbol(AParametrizedFunctionsymbol node) {
 79  0 if (!termStack.isEmpty()){
 80  0 lastTermBeforeFunctionSymbol.add(termStack.peek());
 81    }
 82    }
 83   
 84    // PValueList types
 85   
 86    Object lastItem;
 87   
 88  0 public void inATermValuelist(ATermValuelist node) {
 89  0 if (!termStack.isEmpty())
 90  0 lastItem = termStack.peek();
 91    }
 92   
 93  0 public void outATermValuelist(ATermValuelist node) {
 94  0 if (termStack.isEmpty()) {
 95  0 throw new RuntimeException("No data value nodes processed!");
 96    }
 97   
 98  0 Vector terms = new Vector();
 99  0 while (!termStack.isEmpty() &&
 100    termStack.peek() != lastItem) {
 101  0 terms.add(0, termStack.pop());
 102    }
 103   
 104  0 container.getStack(Term[].class).push(terms.toArray(new Term[]{}));
 105    }
 106   
 107  0 public void inAValuelistValuelist(AValuelistValuelist node) {
 108  0 inATermValuelist(null); // same implementation
 109    }
 110   
 111  0 public void outAValuelistValuelist(AValuelistValuelist node) {
 112  0 outATermValuelist(null); // same implementation
 113    }
 114   
 115    // PValue types
 116   
 117  0 public void outAParametrizedFunctionsymbol(AParametrizedFunctionsymbol node) {
 118  0 IRI type = (IRI) container.popFromStack(Identifier.class, IRI.class);
 119  0 Vector args = new Vector();
 120  0 Object last = null;
 121  0 if (!lastTermBeforeFunctionSymbol.isEmpty()){
 122  0 last=lastTermBeforeFunctionSymbol.pop();
 123    }
 124  0 while (!termStack.isEmpty() &&
 125    termStack.peek()!=last){
 126  0 args.add(0,termStack.pop());
 127    }
 128   
 129  0 if (cf.isSimpleDataType(type.toString())) {
 130  0 termStack.push(args.get(0));
 131    }
 132  0 else if (cf.isDataType(type.toString())) {
 133  0 ComplexDataType complexType = (ComplexDataType) dFactory.createWsmlDataType(type);
 134  0 if (complexType.getIRI().toString().equals(WsmlDataType.WSML_IRI)) {
 135  0 termStack.push(args.firstElement());
 136    }
 137  0 else if (complexType.getIRI().toString().equals(WsmlDataType.WSML_SQNAME) &&
 138    args.size() == 2) {
 139  0 AAnySqname sqname = new AAnySqname();
 140  0 sqname.setName(new TName(args.get(1).toString()));
 141  0 sqname.setPrefix(new APrefix(new TName(args.get(0).toString()), new THash()));
 142  0 sqname.apply(container.getNodeHandler(PId.class));
 143  0 termStack.push(container.getStack(Identifier.class).pop());
 144    }
 145    else {
 146  0 if (args.firstElement() instanceof SimpleDataValue == false) {
 147  0 ParserException pe = new ParserException("Data type has no valid value", null);
 148  0 pe.setExpectedToken("Value");
 149  0 pe.setErrorLine(node.getLpar().getLine());
 150  0 pe.setErrorPos(node.getLpar().getPos()+1);
 151  0 throw new WrappedParsingException(pe);
 152    }
 153  0 termStack.push(dFactory.createDataValue(complexType,
 154    (SimpleDataValue[]) args.toArray(new SimpleDataValue[]{})));
 155    }
 156    }
 157    else{ //no DATATYPE
 158  0 termStack.add(lFactory.createConstructedTerm(type,args));
 159    }
 160    }
 161   
 162  0 public void inADecimalNumber(ADecimalNumber node) {
 163  0 termStack.push(dFactory.createWsmlDecimal(node.toString().trim()));
 164    }
 165   
 166  0 public void inAIntegerNumber(AIntegerNumber node) {
 167  0 String intAsString = node.getInteger().toString().trim();
 168    // sablecc does change "-5" to "- 5" which will later not be parsed
 169    // correctly
 170  0 if (intAsString.length() >= 2 && intAsString.charAt(1) == ' ') {
 171  0 intAsString = "-" + intAsString.substring(2);
 172   
 173    }
 174  0 termStack.push(dFactory.createWsmlInteger(intAsString));
 175    }
 176   
 177  0 public void inAStringValue(AStringValue node) {
 178  0 String str = node.getString().toString();
 179    //get rid of quotes
 180  0 str = str.substring(1,str.length()-2);
 181    //unescape
 182  0 str = str.replaceAll("\\\\\\\\", "\\\\");
 183  0 str = str.replaceAll("\\\\\"","\"");
 184   
 185  0 termStack.push(dFactory.createWsmlString(str));
 186    }
 187   
 188  0 public void inATermValue(ATermValue node) {
 189  0 node.getId().apply(container.getNodeHandler(PId.class));
 190  0 termStack.push((Term) container.getStack(Identifier.class).pop());
 191    }
 192   
 193  0 public void inAVarTerm(AVarTerm node) {
 194  0 termStack.push(lFactory.createVariable(
 195    node.getVariable().getText()));
 196    }
 197   
 198  0 public void outATermTermlist(ATermTermlist node) {
 199  0 container.getStack(Term[].class).push(
 200    new Term[]{(Term)termStack.pop()});
 201    }
 202   
 203  0 public void inATermlist(ATermlist node) {
 204  0 if (!termStack.isEmpty())
 205  0 lastItem = termStack.peek();
 206    }
 207   
 208  0 public void outATermlist(ATermlist node) {
 209  0 Vector terms = new Vector();
 210  0 while (!termStack.isEmpty() &&
 211    termStack.peek() != lastItem) {
 212  0 terms.add(0, termStack.pop());
 213    }
 214  0 container.getStack(Term[].class).push(terms.toArray(new Term[]{}));
 215    }
 216   
 217  0 public void inANbAnonymousTerm(ANbAnonymousTerm arg0) {
 218  0 String no = arg0.getNbAnonymous().getText();
 219  0 no = no.substring(2);
 220  0 byte number = (byte)Integer.parseInt(no);
 221  0 termStack.push(lFactory.createAnonymousID(number));
 222    }
 223    }
 224   
 225    /*
 226    * $Log$
 227    * Revision 1.9 2006/11/10 14:46:21 holgerlausen
 228    * fixed bug with negative ints
 229    *
 230    * Revision 1.8 2006/11/08 12:02:48 vassil_momtchev
 231    * fixed bug when parsed data value "_boolean(IRI)"
 232    *
 233    * Revision 1.7 2006/11/03 07:17:32 holgerlausen
 234    * fixed a bug in parsing nested function symbols (only arguments of last functionsymbol where added correctly but args of rest has been ignored)
 235    *
 236    * Revision 1.6 2006/06/21 07:46:29 vassil_momtchev
 237    * createVariable(String) method moved from WsmoFactory to LogicalExpressionFactory interface
 238    *
 239    * Revision 1.5 2006/03/06 14:58:41 vassil_momtchev
 240    * unused imports removed
 241    *
 242    * Revision 1.4 2006/03/06 14:55:45 vassil_momtchev
 243    * _iri(_"http://iri...") and _sqname("prefix", "localpart") construction handled also
 244    *
 245    * Revision 1.3 2005/12/02 14:11:59 holgerlausen
 246    * fixed the handling of escpaed character during parsing and serialization
 247    *
 248    * Revision 1.2 2005/12/02 12:47:59 holgerlausen
 249    * numbered anon id processing added
 250    *
 251    * Revision 1.1 2005/11/28 13:55:26 vassil_momtchev
 252    * AST analyses
 253    *
 254    */