001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: package com.sun.xml.xsom.impl;
021:
022: import com.sun.xml.xsom.XSAttGroupDecl;
023: import com.sun.xml.xsom.XSAttributeUse;
024: import com.sun.xml.xsom.impl.parser.SchemaDocumentImpl;
025: import com.sun.xml.xsom.impl.scd.Iterators;
026: import com.sun.xml.xsom.impl.Ref.AttGroup;
027: import org.xml.sax.Locator;
028:
029: import java.util.AbstractSet;
030: import java.util.ArrayList;
031: import java.util.Collection;
032: import java.util.HashSet;
033: import java.util.Iterator;
034: import java.util.List;
035: import java.util.Map;
036: import java.util.Set;
037: import java.util.TreeMap;
038: import java.util.LinkedHashMap;
039:
040: public abstract class AttributesHolder extends DeclarationImpl {
041:
042: protected AttributesHolder(SchemaDocumentImpl _parent,
043: AnnotationImpl _annon, Locator loc,
044: ForeignAttributesImpl _fa, String _name, boolean _anonymous) {
045:
046: super (_parent, _annon, loc, _fa, _parent.getTargetNamespace(),
047: _name, _anonymous);
048: }
049:
050: /** set the local wildcard. */
051: public abstract void setWildcard(WildcardImpl wc);
052:
053: /**
054: * Local attribute use.
055: * Use linked hash map to guarantee the iteration order, and make it close to
056: * what was in the schema document.
057: */
058: protected final Map<UName, AttributeUseImpl> attributes = new LinkedHashMap<UName, AttributeUseImpl>();
059:
060: public void addAttributeUse(UName name, AttributeUseImpl a) {
061: attributes.put(name, a);
062: }
063:
064: /** prohibited attributes. */
065: protected final Set<UName> prohibitedAtts = new HashSet<UName>();
066:
067: public void addProhibitedAttribute(UName name) {
068: prohibitedAtts.add(name);
069: }
070:
071: public List<XSAttributeUse> getAttributeUses() {
072: // TODO: this is fairly inefficient
073: List<XSAttributeUse> v = new ArrayList<XSAttributeUse>();
074: v.addAll(attributes.values());
075: for (XSAttGroupDecl agd : getAttGroups())
076: v.addAll(agd.getAttributeUses());
077: return v;
078: }
079:
080: public Iterator<XSAttributeUse> iterateAttributeUses() {
081: return getAttributeUses().iterator();
082: }
083:
084: public XSAttributeUse getDeclaredAttributeUse(String nsURI,
085: String localName) {
086: return attributes.get(new UName(nsURI, localName));
087: }
088:
089: public Iterator<AttributeUseImpl> iterateDeclaredAttributeUses() {
090: return attributes.values().iterator();
091: }
092:
093: public Collection<AttributeUseImpl> getDeclaredAttributeUses() {
094: return attributes.values();
095: }
096:
097: /** {@link Ref.AttGroup}s that are directly refered from this. */
098: protected final Set<Ref.AttGroup> attGroups = new HashSet<Ref.AttGroup>();
099:
100: public void addAttGroup(Ref.AttGroup a) {
101: attGroups.add(a);
102: }
103:
104: // Iterates all AttGroups which are directly referenced from this component
105: // this does not iterate att groups referenced from the base type
106: public Iterator<XSAttGroupDecl> iterateAttGroups() {
107: return new Iterators.Adapter<XSAttGroupDecl, Ref.AttGroup>(
108: attGroups.iterator()) {
109: protected XSAttGroupDecl filter(AttGroup u) {
110: return u.get();
111: }
112: };
113: }
114:
115: public Set<XSAttGroupDecl> getAttGroups() {
116: return new AbstractSet<XSAttGroupDecl>() {
117: public Iterator<XSAttGroupDecl> iterator() {
118: return iterateAttGroups();
119: }
120:
121: public int size() {
122: return attGroups.size();
123: }
124: };
125: }
126: }
|