| 1 |
package com.thaiopensource.relaxng.output.xsd.basic; |
| 2 |
|
| 3 |
import com.thaiopensource.relaxng.edit.SourceLocation; |
| 4 |
|
| 5 |
import java.util.HashMap; |
| 6 |
import java.util.List; |
| 7 |
import java.util.Map; |
| 8 |
import java.util.Vector; |
| 9 |
|
| 10 |
public class Schema extends Annotated { |
| 11 |
private final String uri; |
| 12 |
private final String encoding; |
| 13 |
private Schema parent; |
| 14 |
private final List<TopLevel> topLevel = new Vector<TopLevel>(); |
| 15 |
private final Map<String, GroupDefinition> groupMap; |
| 16 |
private final Map<String, AttributeGroupDefinition> attributeGroupMap; |
| 17 |
private final Map<String, SimpleTypeDefinition> simpleTypeMap; |
| 18 |
private final List<Schema> subSchemas; |
| 19 |
private final List<Comment> leadingComments = new Vector<Comment>(); |
| 20 |
private final List<Comment> trailingComments = new Vector<Comment>(); |
| 21 |
|
| 22 |
public Schema(SourceLocation location, Annotation annotation, String uri, String encoding) { |
| 23 |
super(location, annotation); |
| 24 |
this.uri = uri; |
| 25 |
this.encoding = encoding; |
| 26 |
this.groupMap = new HashMap<String, GroupDefinition>(); |
| 27 |
this.attributeGroupMap = new HashMap<String, AttributeGroupDefinition>(); |
| 28 |
this.simpleTypeMap = new HashMap<String, SimpleTypeDefinition>(); |
| 29 |
this.subSchemas = new Vector<Schema>(); |
| 30 |
this.subSchemas.add(this); |
| 31 |
} |
| 32 |
|
| 33 |
private Schema(SourceLocation location, Annotation annotation, String uri, String encoding, Schema parent) { |
| 34 |
super(location, annotation); |
| 35 |
this.parent = parent; |
| 36 |
this.uri = uri; |
| 37 |
this.encoding = encoding; |
| 38 |
this.groupMap = parent.groupMap; |
| 39 |
this.attributeGroupMap = parent.attributeGroupMap; |
| 40 |
this.simpleTypeMap = parent.simpleTypeMap; |
| 41 |
this.subSchemas = parent.subSchemas; |
| 42 |
this.subSchemas.add(this); |
| 43 |
} |
| 44 |
|
| 45 |
public String getUri() { |
| 46 |
return uri; |
| 47 |
} |
| 48 |
|
| 49 |
public String getEncoding() { |
| 50 |
return encoding; |
| 51 |
} |
| 52 |
|
| 53 |
public Schema getParent() { |
| 54 |
return parent; |
| 55 |
} |
| 56 |
|
| 57 |
public void defineGroup(String name, Particle particle, SourceLocation location, Annotation annotation) { |
| 58 |
GroupDefinition def = new GroupDefinition(location, annotation, this, name, particle); |
| 59 |
topLevel.add(def); |
| 60 |
groupMap.put(name, def); |
| 61 |
} |
| 62 |
|
| 63 |
public void defineAttributeGroup(String name, AttributeUse attributeUses, SourceLocation location, Annotation annotation) { |
| 64 |
AttributeGroupDefinition def = new AttributeGroupDefinition(location, annotation, this, name, attributeUses); |
| 65 |
topLevel.add(def); |
| 66 |
attributeGroupMap.put(name, def); |
| 67 |
} |
| 68 |
|
| 69 |
public void defineSimpleType(String name, SimpleType simpleType, SourceLocation location, Annotation annotation) { |
| 70 |
SimpleTypeDefinition def = new SimpleTypeDefinition(location, annotation, this, name, simpleType); |
| 71 |
topLevel.add(def); |
| 72 |
simpleTypeMap.put(name, def); |
| 73 |
} |
| 74 |
|
| 75 |
public void addRoot(Particle particle, SourceLocation location, Annotation annotation) { |
| 76 |
topLevel.add(new RootDeclaration(location, annotation, particle)); |
| 77 |
} |
| 78 |
|
| 79 |
public Schema addInclude(String uri, String encoding, SourceLocation location, Annotation annotation) { |
| 80 |
Schema included = new Schema(location, annotation, uri, encoding, this); |
| 81 |
topLevel.add(new Include(location, annotation, included)); |
| 82 |
return included; |
| 83 |
} |
| 84 |
|
| 85 |
public void addComment(String content, SourceLocation location) { |
| 86 |
topLevel.add(new Comment(location, content)); |
| 87 |
} |
| 88 |
|
| 89 |
public GroupDefinition getGroup(String name) { |
| 90 |
return groupMap.get(name); |
| 91 |
} |
| 92 |
|
| 93 |
public SimpleTypeDefinition getSimpleType(String name) { |
| 94 |
return simpleTypeMap.get(name); |
| 95 |
} |
| 96 |
|
| 97 |
public AttributeGroupDefinition getAttributeGroup(String name) { |
| 98 |
return attributeGroupMap.get(name); |
| 99 |
} |
| 100 |
|
| 101 |
public void accept(SchemaVisitor visitor) { |
| 102 |
for (TopLevel t : this.topLevel) |
| 103 |
t.accept(visitor); |
| 104 |
} |
| 105 |
|
| 106 |
public List<Schema> getSubSchemas() { |
| 107 |
return subSchemas; |
| 108 |
} |
| 109 |
|
| 110 |
public List<Comment> getLeadingComments() { |
| 111 |
return leadingComments; |
| 112 |
} |
| 113 |
|
| 114 |
public List<Comment> getTrailingComments() { |
| 115 |
return trailingComments; |
| 116 |
} |
| 117 |
|
| 118 |
public boolean equals(Object obj) { |
| 119 |
return obj == this; |
| 120 |
} |
| 121 |
|
| 122 |
public int hashCode() { |
| 123 |
return System.identityHashCode(this); |
| 124 |
} |
| 125 |
} |