View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3   
4    Copyright (c) 2005, University of Innsbruck, Austria
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  package org.deri.wsmo4j.io.parser.wsml;
19  
20  import java.util.*;
21  
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   * <pre>
31   * Created on 21.11.2005
32   * Committed by $Author$
33   * $Source$,
34   * </pre>
35   *
36   * @author Holger Lausen
37   * @version $Revision$ $Date$
38   */
39  public class VariableAnalysis extends ASTAnalysis {
40      private LogicalExpressionFactory factory;
41      private ASTAnalysisContainer container;
42      
43      private Stack terms; // handle to terms stack
44      private Stack varLists; // handle to var lists stack
45      private Stack myVars = new Stack();
46      public VariableAnalysis(ASTAnalysisContainer container, 
47              LogicalExpressionFactory factory) {
48          
49          if (container == null || factory == null) {
50              throw new IllegalArgumentException();
51          }
52          this.factory = factory;
53          this.container = container;
54          
55          // register the handled nodes
56          container.registerNodeHandler(AVariableVariables.class, this);
57          container.registerNodeHandler(AVariableVariablelist.class, this);
58          container.registerNodeHandler(AVariableListVariablelist.class, this);
59          container.registerNodeHandler(AVariables.class, this);
60          
61          varLists = container.getStack(Variable[].class);
62      }
63  
64  
65      public void outAVariableVariablelist(AVariableVariablelist node) {
66          outVarList();
67      }
68  
69      public void outAVariableListVariablelist(AVariableListVariablelist node) {
70          outVarList();
71      }
72  
73      public void outAVariables(AVariables node) {
74          outVarList();
75      }
76  
77      public void outAVariableVariables(AVariableVariables node) {
78          outVarList();
79      }
80  
81      public void caseAVariables(AVariables node) {
82          myVars.add(factory.createVariable(
83                  node.getVariable().getText()));
84      }
85  
86  
87      public void caseAVariableVariablelist(AVariableVariablelist node) {
88          myVars.add(factory.createVariable(
89                  node.getVariable().getText()));
90      }
91  
92  
93      public void caseAVariableVariables(AVariableVariables node) {
94          myVars.add(factory.createVariable(
95                  node.getVariable().getText()));
96      }
97      
98      private void outVarList(){
99          if (!myVars.isEmpty()){
100             varLists.add((Variable[])
101                     myVars.toArray(new Variable[myVars.size()]));
102             myVars.clear();
103         }
104     }
105 
106 }