001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.xsom.impl;
027:
028: import com.sun.xml.internal.xsom.XSAttGroupDecl;
029: import com.sun.xml.internal.xsom.XSAttributeUse;
030: import com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl;
031: import org.xml.sax.Locator;
032:
033: import java.util.AbstractSet;
034: import java.util.ArrayList;
035: import java.util.Collection;
036: import java.util.HashSet;
037: import java.util.Iterator;
038: import java.util.List;
039: import java.util.Map;
040: import java.util.Set;
041: import java.util.TreeMap;
042:
043: public abstract class AttributesHolder extends DeclarationImpl {
044:
045: protected AttributesHolder(SchemaDocumentImpl _parent,
046: AnnotationImpl _annon, Locator loc,
047: ForeignAttributesImpl _fa, String _name, boolean _anonymous) {
048:
049: super (_parent, _annon, loc, _fa, _parent.getTargetNamespace(),
050: _name, _anonymous);
051: }
052:
053: /** set the local wildcard. */
054: public abstract void setWildcard(WildcardImpl wc);
055:
056: /**
057: * Local attribute use.
058: * It has to be {@link TreeMap} or otherwise we cannot guarantee
059: * the order of iteration.
060: */
061: protected final Map<UName, AttributeUseImpl> attributes = new TreeMap<UName, AttributeUseImpl>(
062: UName.comparator);
063:
064: public void addAttributeUse(UName name, AttributeUseImpl a) {
065: attributes.put(name, a);
066: }
067:
068: /** prohibited attributes. */
069: protected final Set<UName> prohibitedAtts = new HashSet<UName>();
070:
071: public void addProhibitedAttribute(UName name) {
072: prohibitedAtts.add(name);
073: }
074:
075: public List<XSAttributeUse> getAttributeUses() {
076: // TODO: this is fairly inefficient
077: List<XSAttributeUse> v = new ArrayList<XSAttributeUse>();
078: v.addAll(attributes.values());
079: for (XSAttGroupDecl agd : getAttGroups())
080: v.addAll(agd.getAttributeUses());
081: return v;
082: }
083:
084: public Iterator<XSAttributeUse> iterateAttributeUses() {
085: return getAttributeUses().iterator();
086: }
087:
088: public XSAttributeUse getDeclaredAttributeUse(String nsURI,
089: String localName) {
090: return attributes.get(new UName(nsURI, localName));
091: }
092:
093: public Iterator<AttributeUseImpl> iterateDeclaredAttributeUses() {
094: return attributes.values().iterator();
095: }
096:
097: public Collection<AttributeUseImpl> getDeclaredAttributeUses() {
098: return attributes.values();
099: }
100:
101: /** {@link Ref.AttGroup}s that are directly refered from this. */
102: protected final Set<Ref.AttGroup> attGroups = new HashSet<Ref.AttGroup>();
103:
104: public void addAttGroup(Ref.AttGroup a) {
105: attGroups.add(a);
106: }
107:
108: // Iterates all AttGroups which are directly referenced from this component
109: // this does not iterate att groups referenced from the base type
110: public Iterator<XSAttGroupDecl> iterateAttGroups() {
111: return new Iterator<XSAttGroupDecl>() {
112: private final Iterator<Ref.AttGroup> itr = attGroups
113: .iterator();
114:
115: public boolean hasNext() {
116: return itr.hasNext();
117: }
118:
119: public XSAttGroupDecl next() {
120: return itr.next().get();
121: }
122:
123: public void remove() {
124: itr.remove();
125: }
126: };
127: }
128:
129: public Set<XSAttGroupDecl> getAttGroups() {
130: return new AbstractSet<XSAttGroupDecl>() {
131: public Iterator<XSAttGroupDecl> iterator() {
132: return iterateAttGroups();
133: }
134:
135: public int size() {
136: return attGroups.size();
137: }
138: };
139: }
140: }
|