Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.xsom.impl; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.xml.internal.xsom.XSElementDecl; |
aoqi@0 | 29 | import com.sun.xml.internal.xsom.XSModelGroup; |
aoqi@0 | 30 | import com.sun.xml.internal.xsom.XSModelGroupDecl; |
aoqi@0 | 31 | import com.sun.xml.internal.xsom.XSTerm; |
aoqi@0 | 32 | import com.sun.xml.internal.xsom.XSWildcard; |
aoqi@0 | 33 | import com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl; |
aoqi@0 | 34 | import com.sun.xml.internal.xsom.visitor.XSFunction; |
aoqi@0 | 35 | import com.sun.xml.internal.xsom.visitor.XSTermFunction; |
aoqi@0 | 36 | import com.sun.xml.internal.xsom.visitor.XSTermFunctionWithParam; |
aoqi@0 | 37 | import com.sun.xml.internal.xsom.visitor.XSTermVisitor; |
aoqi@0 | 38 | import com.sun.xml.internal.xsom.visitor.XSVisitor; |
aoqi@0 | 39 | import com.sun.xml.internal.xsom.visitor.XSWildcardFunction; |
aoqi@0 | 40 | import com.sun.xml.internal.xsom.visitor.XSWildcardVisitor; |
aoqi@0 | 41 | import org.xml.sax.Locator; |
aoqi@0 | 42 | |
aoqi@0 | 43 | import java.util.Collection; |
aoqi@0 | 44 | import java.util.Collections; |
aoqi@0 | 45 | import java.util.HashSet; |
aoqi@0 | 46 | import java.util.Iterator; |
aoqi@0 | 47 | import java.util.Set; |
aoqi@0 | 48 | |
aoqi@0 | 49 | public abstract class WildcardImpl extends ComponentImpl implements XSWildcard, Ref.Term |
aoqi@0 | 50 | { |
aoqi@0 | 51 | protected WildcardImpl( SchemaDocumentImpl owner, AnnotationImpl _annon, Locator _loc, ForeignAttributesImpl _fa, int _mode ) { |
aoqi@0 | 52 | super(owner,_annon,_loc,_fa); |
aoqi@0 | 53 | this.mode = _mode; |
aoqi@0 | 54 | } |
aoqi@0 | 55 | |
aoqi@0 | 56 | private final int mode; |
aoqi@0 | 57 | public int getMode() { return mode; } |
aoqi@0 | 58 | |
aoqi@0 | 59 | // compute the union |
aoqi@0 | 60 | public WildcardImpl union( SchemaDocumentImpl owner, WildcardImpl rhs ) { |
aoqi@0 | 61 | if(this instanceof Any || rhs instanceof Any) |
aoqi@0 | 62 | return new Any(owner,null,null,null,mode); |
aoqi@0 | 63 | |
aoqi@0 | 64 | if(this instanceof Finite && rhs instanceof Finite) { |
aoqi@0 | 65 | Set<String> values = new HashSet<String>(); |
aoqi@0 | 66 | values.addAll( ((Finite)this).names ); |
aoqi@0 | 67 | values.addAll( ((Finite)rhs ).names ); |
aoqi@0 | 68 | return new Finite(owner,null,null,null,values,mode); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | |
aoqi@0 | 71 | if(this instanceof Other && rhs instanceof Other) { |
aoqi@0 | 72 | if( ((Other)this).otherNamespace.equals( |
aoqi@0 | 73 | ((Other)rhs).otherNamespace) ) |
aoqi@0 | 74 | return new Other(owner,null,null,null, ((Other)this).otherNamespace, mode ); |
aoqi@0 | 75 | else |
aoqi@0 | 76 | // this somewhat strange rule is indeed in the spec |
aoqi@0 | 77 | return new Other(owner,null,null,null, "", mode ); |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | Other o; |
aoqi@0 | 81 | Finite f; |
aoqi@0 | 82 | |
aoqi@0 | 83 | if( this instanceof Other ) { |
aoqi@0 | 84 | o=(Other)this; f=(Finite)rhs; |
aoqi@0 | 85 | } else { |
aoqi@0 | 86 | o=(Other)rhs; f=(Finite)this; |
aoqi@0 | 87 | } |
aoqi@0 | 88 | |
aoqi@0 | 89 | if(f.names.contains(o.otherNamespace)) |
aoqi@0 | 90 | return new Any(owner,null,null,null,mode); |
aoqi@0 | 91 | else |
aoqi@0 | 92 | return new Other(owner,null,null,null,o.otherNamespace,mode); |
aoqi@0 | 93 | } |
aoqi@0 | 94 | |
aoqi@0 | 95 | |
aoqi@0 | 96 | |
aoqi@0 | 97 | public final static class Any extends WildcardImpl implements XSWildcard.Any { |
aoqi@0 | 98 | public Any( SchemaDocumentImpl owner, AnnotationImpl _annon, Locator _loc, ForeignAttributesImpl _fa, int _mode ) { |
aoqi@0 | 99 | super(owner,_annon,_loc,_fa,_mode); |
aoqi@0 | 100 | } |
aoqi@0 | 101 | |
aoqi@0 | 102 | public boolean acceptsNamespace( String namespaceURI ) { |
aoqi@0 | 103 | return true; |
aoqi@0 | 104 | } |
aoqi@0 | 105 | public void visit( XSWildcardVisitor visitor ) { |
aoqi@0 | 106 | visitor.any(this); |
aoqi@0 | 107 | } |
aoqi@0 | 108 | public Object apply( XSWildcardFunction function ) { |
aoqi@0 | 109 | return function.any(this); |
aoqi@0 | 110 | } |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | public final static class Other extends WildcardImpl implements XSWildcard.Other { |
aoqi@0 | 114 | public Other( SchemaDocumentImpl owner, AnnotationImpl _annon, Locator _loc, ForeignAttributesImpl _fa, |
aoqi@0 | 115 | String otherNamespace, int _mode ) { |
aoqi@0 | 116 | super(owner,_annon,_loc,_fa,_mode); |
aoqi@0 | 117 | this.otherNamespace = otherNamespace; |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | private final String otherNamespace; |
aoqi@0 | 121 | |
aoqi@0 | 122 | public String getOtherNamespace() { return otherNamespace; } |
aoqi@0 | 123 | |
aoqi@0 | 124 | public boolean acceptsNamespace( String namespaceURI ) { |
aoqi@0 | 125 | return !namespaceURI.equals(otherNamespace); |
aoqi@0 | 126 | } |
aoqi@0 | 127 | |
aoqi@0 | 128 | public void visit( XSWildcardVisitor visitor ) { |
aoqi@0 | 129 | visitor.other(this); |
aoqi@0 | 130 | } |
aoqi@0 | 131 | public Object apply( XSWildcardFunction function ) { |
aoqi@0 | 132 | return function.other(this); |
aoqi@0 | 133 | } |
aoqi@0 | 134 | } |
aoqi@0 | 135 | |
aoqi@0 | 136 | public final static class Finite extends WildcardImpl implements XSWildcard.Union { |
aoqi@0 | 137 | public Finite( SchemaDocumentImpl owner, AnnotationImpl _annon, Locator _loc, ForeignAttributesImpl _fa, |
aoqi@0 | 138 | Set<String> ns, int _mode ) { |
aoqi@0 | 139 | super(owner,_annon,_loc,_fa,_mode); |
aoqi@0 | 140 | names = ns; |
aoqi@0 | 141 | namesView = Collections.unmodifiableSet(names); |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | private final Set<String> names; |
aoqi@0 | 145 | private final Set<String> namesView; |
aoqi@0 | 146 | |
aoqi@0 | 147 | public Iterator<String> iterateNamespaces() { |
aoqi@0 | 148 | return names.iterator(); |
aoqi@0 | 149 | } |
aoqi@0 | 150 | |
aoqi@0 | 151 | public Collection<String> getNamespaces() { |
aoqi@0 | 152 | return namesView; |
aoqi@0 | 153 | } |
aoqi@0 | 154 | |
aoqi@0 | 155 | public boolean acceptsNamespace( String namespaceURI ) { |
aoqi@0 | 156 | return names.contains(namespaceURI); |
aoqi@0 | 157 | } |
aoqi@0 | 158 | |
aoqi@0 | 159 | public void visit( XSWildcardVisitor visitor ) { |
aoqi@0 | 160 | visitor.union(this); |
aoqi@0 | 161 | } |
aoqi@0 | 162 | public Object apply( XSWildcardFunction function ) { |
aoqi@0 | 163 | return function.union(this); |
aoqi@0 | 164 | } |
aoqi@0 | 165 | } |
aoqi@0 | 166 | |
aoqi@0 | 167 | public final void visit( XSVisitor visitor ) { |
aoqi@0 | 168 | visitor.wildcard(this); |
aoqi@0 | 169 | } |
aoqi@0 | 170 | public final void visit( XSTermVisitor visitor ) { |
aoqi@0 | 171 | visitor.wildcard(this); |
aoqi@0 | 172 | } |
aoqi@0 | 173 | public Object apply( XSTermFunction function ) { |
aoqi@0 | 174 | return function.wildcard(this); |
aoqi@0 | 175 | } |
aoqi@0 | 176 | |
aoqi@0 | 177 | public <T,P> T apply(XSTermFunctionWithParam<T, P> function, P param) { |
aoqi@0 | 178 | return function.wildcard(this,param); |
aoqi@0 | 179 | } |
aoqi@0 | 180 | |
aoqi@0 | 181 | public Object apply( XSFunction function ) { |
aoqi@0 | 182 | return function.wildcard(this); |
aoqi@0 | 183 | } |
aoqi@0 | 184 | |
aoqi@0 | 185 | |
aoqi@0 | 186 | public boolean isWildcard() { return true; } |
aoqi@0 | 187 | public boolean isModelGroupDecl() { return false; } |
aoqi@0 | 188 | public boolean isModelGroup() { return false; } |
aoqi@0 | 189 | public boolean isElementDecl() { return false; } |
aoqi@0 | 190 | |
aoqi@0 | 191 | public XSWildcard asWildcard() { return this; } |
aoqi@0 | 192 | public XSModelGroupDecl asModelGroupDecl() { return null; } |
aoqi@0 | 193 | public XSModelGroup asModelGroup() { return null; } |
aoqi@0 | 194 | public XSElementDecl asElementDecl() { return null; } |
aoqi@0 | 195 | |
aoqi@0 | 196 | |
aoqi@0 | 197 | // Ref.Term implementation |
aoqi@0 | 198 | public XSTerm getTerm() { return this; } |
aoqi@0 | 199 | } |