View Javadoc

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.omwg.logicalexpression.*;
31  import org.omwg.ontology.*;
32  import org.wsmo.common.*;
33  import org.wsmo.factory.*;
34  import org.wsmo.wsml.compiler.node.*;
35  
36  
37  public class AxiomAnalysis extends ASTAnalysis {
38  
39      private WsmoFactory factory;
40      private ASTAnalysisContainer container;
41  
42      public AxiomAnalysis(ASTAnalysisContainer container, WsmoFactory factory) {
43          if (factory == null || container == null) {
44              throw new IllegalArgumentException();
45          }
46          this.factory = factory;
47          this.container = container;
48  
49          // register the handled nodes
50          container.registerNodeHandler(ADefinedAxiomAxiomdefinition.class, this);
51          container.registerNodeHandler(ANfpAxiomAxiomdefinition.class, this);
52          container.registerNodeHandler(AUseAxiomAxiomdefinition.class, this);
53      }
54  
55      public void inADefinedAxiomAxiomdefinition(ADefinedAxiomAxiomdefinition node) {
56          _inAxiomdefinition(node.getId());
57      }
58  
59      public void inANfpAxiomAxiomdefinition(ANfpAxiomAxiomdefinition node) {
60          _inAxiomdefinition(node.getId());
61      }
62  
63      public void inAUseAxiomAxiomdefinition(AUseAxiomAxiomdefinition node) {
64          _inAxiomdefinition(node.getId());
65      }
66  
67      public void outADefinedAxiomAxiomdefinition(ADefinedAxiomAxiomdefinition node) {
68          _outAAxiomdefinition();
69      }
70  
71      public void outANfpAxiomAxiomdefinition(ANfpAxiomAxiomdefinition node) {
72          _outAAxiomdefinition();
73      }
74  
75      public void outAUseAxiomAxiomdefinition(AUseAxiomAxiomdefinition node) {
76          _outAAxiomdefinition();
77      }
78  
79  
80      private void _outAAxiomdefinition() {
81          Axiom a = (Axiom) container.popFromStack(Entity.class, Axiom.class);
82          Stack s = container.getStack(LogicalExpression.class);
83          while (!s.isEmpty()) {
84              a.addDefinition((LogicalExpression) s.remove(0));
85          }
86      }
87  
88      private void _inAxiomdefinition(PId id) {
89          Axiom axiom = null;
90          if (id == null) {
91              axiom = factory.createAxiom(factory.createAnonymousID());
92          }
93          else {
94              id.apply(container.getNodeHandler(PId.class));
95              axiom = factory.createAxiom((Identifier) container.popFromStack(Identifier.class,
96                      Identifier.class));
97          }
98  
99          container.getStack(Entity.class).push(axiom);
100         container.getStack(Axiom.class).push(axiom);
101     }
102 }
103 
104 /*
105  * $Log$
106  * Revision 1.2  2005/11/29 14:44:24  holgerlausen
107  * fixed axiom analysis, logexp are now removed from stack
108  *
109  * Revision 1.1  2005/11/28 13:55:26  vassil_momtchev
110  * AST analyses
111  *
112 */