Thu, 31 Aug 2017 15:18:52 +0800
merge
1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.xsom.impl;
28 import com.sun.xml.internal.xsom.XSAttGroupDecl;
29 import com.sun.xml.internal.xsom.XSAttributeUse;
30 import com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl;
31 import com.sun.xml.internal.xsom.impl.scd.Iterators;
32 import com.sun.xml.internal.xsom.impl.Ref.AttGroup;
33 import org.xml.sax.Locator;
35 import java.util.AbstractSet;
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.HashSet;
39 import java.util.Iterator;
40 import java.util.List;
41 import java.util.Map;
42 import java.util.Set;
43 import java.util.TreeMap;
44 import java.util.LinkedHashMap;
46 public abstract class AttributesHolder extends DeclarationImpl {
48 protected AttributesHolder( SchemaDocumentImpl _parent, AnnotationImpl _annon,
49 Locator loc, ForeignAttributesImpl _fa, String _name, boolean _anonymous ) {
51 super(_parent,_annon,loc,_fa,_parent.getTargetNamespace(),_name,_anonymous);
52 }
54 /** set the local wildcard. */
55 public abstract void setWildcard(WildcardImpl wc);
57 /**
58 * Local attribute use.
59 * Use linked hash map to guarantee the iteration order, and make it close to
60 * what was in the schema document.
61 */
62 protected final Map<UName,AttributeUseImpl> attributes = new LinkedHashMap<UName,AttributeUseImpl>();
63 public void addAttributeUse( UName name, AttributeUseImpl a ) {
64 attributes.put( name, a );
65 }
66 /** prohibited attributes. */
67 protected final Set<UName> prohibitedAtts = new HashSet<UName>();
68 public void addProhibitedAttribute( UName name ) {
69 prohibitedAtts.add(name);
70 }
72 /**
73 * Returns the attribute uses by looking at attribute groups and etc.
74 * Searching for the base type is done in {@link ComplexTypeImpl}.
75 */
76 public Collection<XSAttributeUse> getAttributeUses() {
77 // TODO: this is fairly inefficient
78 List<XSAttributeUse> v = new ArrayList<XSAttributeUse>();
79 v.addAll(attributes.values());
80 for( XSAttGroupDecl agd : getAttGroups() )
81 v.addAll(agd.getAttributeUses());
82 return v;
83 }
84 public Iterator<XSAttributeUse> iterateAttributeUses() {
85 return getAttributeUses().iterator();
86 }
90 public XSAttributeUse getDeclaredAttributeUse( String nsURI, String localName ) {
91 return attributes.get(new UName(nsURI,localName));
92 }
94 public Iterator<AttributeUseImpl> iterateDeclaredAttributeUses() {
95 return attributes.values().iterator();
96 }
98 public Collection<AttributeUseImpl> getDeclaredAttributeUses() {
99 return attributes.values();
100 }
103 /** {@link Ref.AttGroup}s that are directly refered from this. */
104 protected final Set<Ref.AttGroup> attGroups = new HashSet<Ref.AttGroup>();
106 public void addAttGroup( Ref.AttGroup a ) { attGroups.add(a); }
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 Iterators.Adapter<XSAttGroupDecl,Ref.AttGroup>(attGroups.iterator()) {
112 protected XSAttGroupDecl filter(AttGroup u) {
113 return u.get();
114 }
115 };
116 }
118 public Set<XSAttGroupDecl> getAttGroups() {
119 return new AbstractSet<XSAttGroupDecl>() {
120 public Iterator<XSAttGroupDecl> iterator() {
121 return iterateAttGroups();
122 }
124 public int size() {
125 return attGroups.size();
126 }
127 };
128 }
129 }