Thu, 31 Aug 2017 15:18:52 +0800
merge
1 /*
2 * Copyright (c) 1997, 2010, 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.XSFacet;
29 import com.sun.xml.internal.xsom.XSSimpleType;
30 import com.sun.xml.internal.xsom.XSUnionSimpleType;
31 import com.sun.xml.internal.xsom.XSVariety;
32 import com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl;
33 import com.sun.xml.internal.xsom.visitor.XSSimpleTypeFunction;
34 import com.sun.xml.internal.xsom.visitor.XSSimpleTypeVisitor;
35 import org.xml.sax.Locator;
37 import java.util.Iterator;
38 import java.util.Set;
39 import java.util.List;
40 import java.util.Collections;
42 public class UnionSimpleTypeImpl extends SimpleTypeImpl implements XSUnionSimpleType
43 {
44 public UnionSimpleTypeImpl( SchemaDocumentImpl _parent,
45 AnnotationImpl _annon, Locator _loc, ForeignAttributesImpl _fa,
46 String _name, boolean _anonymous, Set<XSVariety> finalSet,
47 Ref.SimpleType[] _members ) {
49 super(_parent,_annon,_loc,_fa,_name,_anonymous, finalSet,
50 _parent.getSchema().parent.anySimpleType);
52 this.memberTypes = _members;
53 }
55 private final Ref.SimpleType[] memberTypes;
56 public XSSimpleType getMember( int idx ) { return memberTypes[idx].getType(); }
57 public int getMemberSize() { return memberTypes.length; }
59 public Iterator<XSSimpleType> iterator() {
60 return new Iterator<XSSimpleType>() {
61 int idx=0;
62 public boolean hasNext() {
63 return idx<memberTypes.length;
64 }
66 public XSSimpleType next() {
67 return memberTypes[idx++].getType();
68 }
70 public void remove() {
71 throw new UnsupportedOperationException();
72 }
73 };
74 }
76 public void visit( XSSimpleTypeVisitor visitor ) {
77 visitor.unionSimpleType(this);
78 }
79 public Object apply( XSSimpleTypeFunction function ) {
80 return function.unionSimpleType(this);
81 }
83 public XSUnionSimpleType getBaseUnionType() {
84 return this;
85 }
87 // union type by itself doesn't have any facet. */
88 public XSFacet getFacet( String name ) { return null; }
89 public List<XSFacet> getFacets( String name ) { return Collections.EMPTY_LIST; }
91 public XSVariety getVariety() { return XSVariety.UNION; }
93 public XSSimpleType getPrimitiveType() { return null; }
95 public boolean isUnion() { return true; }
96 public XSUnionSimpleType asUnion() { return this; }
97 }