KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > schema > IterationVisitor


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.schema;
24
25 import java.util.Iterator JavaDoc;
26
27 public class IterationVisitor extends DefaultSchemaVisitor {
28   private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
29   private static final String JavaDoc RCSName = "$Name: $";
30
31   protected SchemaVisitor pre;
32   protected SchemaVisitor post;
33   protected boolean inTopLevelDeclaration = true;
34   protected boolean inAttributeWildcard = false;
35
36   public IterationVisitor(SchemaVisitor pre, SchemaVisitor post) {
37     this.pre = pre;
38     this.post = post;
39   }
40   
41   public IterationVisitor(SchemaVisitor visitor) {
42     this(visitor, null);
43   }
44   
45   public boolean isTopLevel() {
46     return inTopLevelDeclaration;
47   }
48
49   public boolean isAttributeWildcard() {
50     return inAttributeWildcard;
51   }
52
53   public void visit(Schema schema) throws SchemaException {
54         
55     if (pre != null) schema.accept(pre);
56         
57     Iterator JavaDoc it = schema.getAttributeDeclarations().iterator();
58     while (it.hasNext()) {
59       inTopLevelDeclaration = true;
60       ((SchemaVisitable)it.next()).accept(this);
61     }
62
63     it = schema.getElementDeclarations().iterator();
64     while (it.hasNext()) {
65       inTopLevelDeclaration = true;
66       ((SchemaVisitable)it.next()).accept(this);
67     }
68
69     it = schema.getTypes().iterator();
70     while (it.hasNext()) ((SchemaVisitable)it.next()).accept(this);
71
72     it = schema.getModelGroupDefinitions().iterator();
73     while (it.hasNext()) ((SchemaVisitable)it.next()).accept(this);
74
75     it = schema.getAttributeGroupDefinitions().iterator();
76     while (it.hasNext()) ((SchemaVisitable)it.next()).accept(this);
77         
78     if (post != null) schema.accept(post);
79   }
80   
81   public void visit(SchemaComponent comp) throws SchemaException {
82     if (pre != null) comp.accept(pre);
83     if (post != null) comp.accept(post);
84   }
85   
86   public void visit(ComplexType type) throws SchemaException {
87     inTopLevelDeclaration = false;
88     if (pre != null) type.accept(pre);
89         
90     type.getContentModel().accept(this);
91         
92     Iterator JavaDoc it = type.getAttributeDeclarations().iterator();
93     while (it.hasNext()) ((SchemaVisitable)it.next()).accept(this);
94                 
95     if (type.getAttributeWildcard() != null) {
96       inAttributeWildcard = true;
97       type.getAttributeWildcard().accept(this);
98       inAttributeWildcard = false;
99     }
100         
101     if (post != null) type.accept(post);
102   }
103
104   public void visit(Declaration decl) throws SchemaException {
105     if (pre != null) decl.accept(pre);
106     if (inTopLevelDeclaration || !decl.getScope().isGlobalScope()) {
107       Type type = decl.getType();
108       if (type != null && type.getName() == null) type.accept(this);
109     }
110     if (post != null) decl.accept(post);
111   }
112
113   public void visit(Wildcard wildcard) throws SchemaException {
114     if (pre != null) wildcard.accept(pre);
115     if (post != null) wildcard.accept(post);
116   }
117   
118   public void visit(ModelGroupDefinition def) throws SchemaException {
119     if (pre != null) def.accept(pre);
120     ModelGroup model = def.getModelGroup();
121     model.accept(this);
122     if (post != null) def.accept(post);
123   }
124     
125   public void visit(AttributeGroupDefinition def) throws SchemaException {
126     if (pre != null) def.accept(pre);
127     Iterator JavaDoc it = def.getContents().iterator();
128     while (it.hasNext()) ((SchemaVisitable)it.next()).accept(this);
129     if (post != null) def.accept(post);
130   }
131   
132   public void visit(ContentModel model) throws SchemaException {
133     if (pre != null) model.accept(pre);
134     if ( model.getModel() != null )
135       ((SchemaVisitable)model.getModel()).accept(this);
136     if (post != null) model.accept(post);
137   }
138   
139   public void visit(Particle particle) throws SchemaException {
140     if (pre != null) particle.accept(pre);
141     ((SchemaVisitable)particle.getTerm()).accept(this);
142     if (post != null) particle.accept(post);
143   }
144   
145   public void visit(ModelGroup group) throws SchemaException {
146     if (pre != null) group.accept(pre);
147     Iterator JavaDoc it = group.iterator();
148     while (it.hasNext()) ((SchemaVisitable)it.next()).accept(this);
149     if (post != null) group.accept(post);
150   }
151   
152 }
153
Popular Tags