Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 167   Methods: 6
NCLOC: 93   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TopEntityAnalysis.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    University of Innsbruck, Austria
 6   
 7    This library is free software; you can redistribute it and/or modify it under
 8    the terms of the GNU Lesser General Public License as published by the Free
 9    Software Foundation; either version 2.1 of the License, or (at your option)
 10    any later version.
 11    This library is distributed in the hope that it will be useful, but WITHOUT
 12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 13    FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 14    details.
 15    You should have received a copy of the GNU Lesser General Public License along
 16    with this library; if not, write to the Free Software Foundation, Inc.,
 17    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 18    */
 19   
 20    /**
 21    * <p>Title: WSMO4J</p>
 22    * <p>Description: WSMO API and a Reference Implementation</p>
 23    * <p>Copyright: Copyright (c) 2004-2005</p>
 24    * <p>Company: OntoText Lab. / SIRMA </p>
 25    */
 26   
 27    package com.ontotext.wsmo4j.parser.wsml;
 28   
 29    import java.util.*;
 30   
 31    import org.deri.wsmo4j.io.parser.*;
 32    import org.wsmo.common.*;
 33    import org.wsmo.factory.*;
 34    import org.wsmo.wsml.*;
 35    import org.wsmo.wsml.compiler.node.*;
 36   
 37    public class TopEntityAnalysis extends ASTAnalysis {
 38   
 39    private ASTAnalysisContainer container;
 40   
 41    private WsmoFactory factory;
 42   
 43    private Stack topEntityStack;
 44   
 45  0 public TopEntityAnalysis(ASTAnalysisContainer container, WsmoFactory factory) {
 46  0 if (container == null) {
 47  0 throw new IllegalArgumentException();
 48    }
 49  0 this.container = container;
 50  0 this.factory = factory;
 51  0 topEntityStack = container.getStack(TopEntity.class);
 52   
 53    // register the handled nodes
 54  0 container.registerNodeHandler(AImportsontology.class, this);
 55  0 container.registerNodeHandler(AUsesmediator.class, this);
 56  0 container.registerNodeHandler(AWsmlvariant.class, this);
 57    }
 58   
 59  0 public void outAImportsontology(AImportsontology node) {
 60  0 if (topEntityStack.isEmpty()) {
 61  0 return;
 62    }
 63  0 Identifier[] iris = (Identifier[]) container.popFromStack(Identifier[].class,
 64    Identifier[].class);
 65  0 TopEntity topEntity = (TopEntity) topEntityStack.peek();
 66  0 for (int i = 0; i < iris.length; i++) {
 67  0 topEntity.addOntology(factory.getOntology((IRI) iris[i]));
 68    }
 69    }
 70   
 71  0 public void outAUsesmediator(AUsesmediator node) {
 72  0 if (topEntityStack.isEmpty()) {
 73  0 return;
 74    }
 75  0 Identifier[] iris = (Identifier[]) container.popFromStack(Identifier[].class,
 76    Identifier[].class);
 77  0 TopEntity topEntity = (TopEntity) topEntityStack.peek();
 78  0 for (int i = 0; i < iris.length; i++) {
 79  0 if (iris[i] instanceof IRI) {
 80  0 topEntity.addMediator((IRI) iris[i]);
 81    }
 82    else {
 83  0 ParserException pe = new ParserException("usesMediator could "
 84    + "refer Mediators only by IRI!", null);
 85  0 pe.setErrorLine(node.getTUsemediator().getLine());
 86  0 pe.setErrorPos(node.getTUsemediator().getPos());
 87  0 throw new WrappedParsingException(pe);
 88    }
 89    }
 90    }
 91   
 92  0 public void inAWsmlvariant(AWsmlvariant node) {
 93  0 String wsmlVariant = node.getFullIri().toString().trim();
 94  0 wsmlVariant = wsmlVariant.substring(2, wsmlVariant.length() - 1);
 95  0 container.getStack(AWsmlvariant.class).push(wsmlVariant);
 96    }
 97   
 98  0 public static void addNamespaceAndVariant(TopEntity entity, Stack namespaces, Stack variant) {
 99  0 for (int i = 0; i < namespaces.size(); i++) {
 100  0 Namespace namespace = (Namespace) namespaces.get(i);
 101  0 if (namespace.getPrefix().equals("_")) {
 102  0 entity.setDefaultNamespace(namespace);
 103    }
 104    else {
 105  0 entity.addNamespace(namespace);
 106    }
 107    }
 108   
 109  0 if (!variant.isEmpty()) {
 110  0 entity.setWsmlVariant((String) variant.peek());
 111    }
 112    }
 113   
 114    /**
 115    *
 116    * @param id id of top entitiy
 117    * @param token: token of parent node of id
 118    * (used for error msg in case id is null)
 119    */
 120  0 public static void isValidTopEntityIdentifier(PId id, Token token) {
 121  0 if (id instanceof AIriId == false) {
 122  0 ParserException pe =
 123    new ParserException("Expected IRI but found Identifier,", null);
 124  0 pe.setExpectedToken("IRI");
 125  0 if (id!=null){
 126  0 pe.setFoundToken(id.toString());
 127    }
 128  0 if (id instanceof AAnonymousId) {
 129  0 Token t = ((AAnonymousId) id).getAnonymous();
 130  0 pe.setErrorLine(t.getLine());
 131  0 pe.setErrorPos(t.getPos());
 132    }
 133    //in case id is null take end position of parent element
 134  0 if (id == null && token != null){
 135  0 pe.setErrorLine(token.getLine());
 136  0 pe.setErrorPos(token.getPos()+token.getText().length());
 137    }
 138  0 throw new WrappedParsingException(pe);
 139    }
 140    }
 141    }
 142   
 143    /*
 144    * $Log$
 145    * Revision 1.7 2006/11/17 12:02:11 vassil_momtchev
 146    * validation of Identifier = IRI is not longer specific to TopEntity types only
 147    *
 148    * Revision 1.6 2006/04/24 08:04:58 holgerlausen
 149    * improved error handling in case of topentities without identifier
 150    * moved thomas unit test to "open" package, since it does not break expected behavior, but just document some derivations from the spec
 151    *
 152    * Revision 1.5 2006/04/05 13:24:45 vassil_momtchev
 153    * usesMediator now refer mediators by IRI instead of handle to object
 154    *
 155    * Revision 1.4 2006/03/07 10:43:20 vassil_momtchev
 156    * parser tries to get one of the 4 kind of mediators in the usesMediator constructions
 157    *
 158    * Revision 1.3 2006/02/13 09:48:52 vassil_momtchev
 159    * the code to handle the topentities identifier validity refactored
 160    *
 161    * Revision 1.2 2006/02/10 14:37:25 vassil_momtchev
 162    * parser addapted to the grammar changes; unused class variables removed;
 163    *
 164    * Revision 1.1 2005/11/28 13:55:26 vassil_momtchev
 165    * AST analyses
 166    *
 167    */