1 22 23 package org.xquark.schema; 24 25 import java.util.Iterator ; 26 27 public class IterationVisitor extends DefaultSchemaVisitor { 28 private static final String RCSRevision = "$Revision: 1.1 $"; 29 private static final String 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 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 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 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 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 |