1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
106
107
108
109
110
111
112