src/share/jaxws_classes/com/sun/xml/internal/xsom/impl/SchemaSetImpl.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/xsom/impl/SchemaSetImpl.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,394 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.xsom.impl;
    1.30 +
    1.31 +import com.sun.xml.internal.xsom.SCD;
    1.32 +import com.sun.xml.internal.xsom.XSAttGroupDecl;
    1.33 +import com.sun.xml.internal.xsom.XSAttributeDecl;
    1.34 +import com.sun.xml.internal.xsom.XSAttributeUse;
    1.35 +import com.sun.xml.internal.xsom.XSComplexType;
    1.36 +import com.sun.xml.internal.xsom.XSComponent;
    1.37 +import com.sun.xml.internal.xsom.XSContentType;
    1.38 +import com.sun.xml.internal.xsom.XSElementDecl;
    1.39 +import com.sun.xml.internal.xsom.XSFacet;
    1.40 +import com.sun.xml.internal.xsom.XSIdentityConstraint;
    1.41 +import com.sun.xml.internal.xsom.XSListSimpleType;
    1.42 +import com.sun.xml.internal.xsom.XSModelGroup;
    1.43 +import com.sun.xml.internal.xsom.XSModelGroupDecl;
    1.44 +import com.sun.xml.internal.xsom.XSNotation;
    1.45 +import com.sun.xml.internal.xsom.XSParticle;
    1.46 +import com.sun.xml.internal.xsom.XSRestrictionSimpleType;
    1.47 +import com.sun.xml.internal.xsom.XSSchema;
    1.48 +import com.sun.xml.internal.xsom.XSSchemaSet;
    1.49 +import com.sun.xml.internal.xsom.XSSimpleType;
    1.50 +import com.sun.xml.internal.xsom.XSType;
    1.51 +import com.sun.xml.internal.xsom.XSUnionSimpleType;
    1.52 +import com.sun.xml.internal.xsom.XSVariety;
    1.53 +import com.sun.xml.internal.xsom.XSWildcard;
    1.54 +import com.sun.xml.internal.xsom.impl.scd.Iterators;
    1.55 +import com.sun.xml.internal.xsom.visitor.XSContentTypeFunction;
    1.56 +import com.sun.xml.internal.xsom.visitor.XSContentTypeVisitor;
    1.57 +import com.sun.xml.internal.xsom.visitor.XSFunction;
    1.58 +import com.sun.xml.internal.xsom.visitor.XSSimpleTypeFunction;
    1.59 +import com.sun.xml.internal.xsom.visitor.XSSimpleTypeVisitor;
    1.60 +import com.sun.xml.internal.xsom.visitor.XSVisitor;
    1.61 +import org.xml.sax.Locator;
    1.62 +
    1.63 +import javax.xml.namespace.NamespaceContext;
    1.64 +import java.text.ParseException;
    1.65 +import java.util.ArrayList;
    1.66 +import java.util.Collection;
    1.67 +import java.util.Collections;
    1.68 +import java.util.HashMap;
    1.69 +import java.util.Iterator;
    1.70 +import java.util.List;
    1.71 +import java.util.Map;
    1.72 +import java.util.Vector;
    1.73 +
    1.74 +public class SchemaSetImpl implements XSSchemaSet
    1.75 +{
    1.76 +    private final Map<String,XSSchema> schemas = new HashMap<String,XSSchema>();
    1.77 +    private final Vector<XSSchema> schemas2 = new Vector<XSSchema>();
    1.78 +    private final List<XSSchema> readonlySchemaList = Collections.unmodifiableList(schemas2);
    1.79 +
    1.80 +    /**
    1.81 +     * Gets a reference to the existing schema or creates a new one
    1.82 +     * if none exists yet.
    1.83 +     */
    1.84 +    public SchemaImpl createSchema(String targetNamespace, Locator location) {
    1.85 +        SchemaImpl obj = (SchemaImpl)schemas.get(targetNamespace);
    1.86 +        if (obj == null) {
    1.87 +            obj = new SchemaImpl(this, location, targetNamespace);
    1.88 +            schemas.put(targetNamespace, obj);
    1.89 +            schemas2.add(obj);
    1.90 +        }
    1.91 +        return obj;
    1.92 +    }
    1.93 +
    1.94 +    public int getSchemaSize() {
    1.95 +        return schemas.size();
    1.96 +    }
    1.97 +    public XSSchema getSchema(String targetNamespace) {
    1.98 +        return schemas.get(targetNamespace);
    1.99 +    }
   1.100 +    public XSSchema getSchema(int idx) {
   1.101 +        return schemas2.get(idx);
   1.102 +    }
   1.103 +    public Iterator<XSSchema> iterateSchema() {
   1.104 +        return schemas2.iterator();
   1.105 +    }
   1.106 +
   1.107 +    public final Collection<XSSchema> getSchemas() {
   1.108 +        return readonlySchemaList;
   1.109 +    }
   1.110 +
   1.111 +    public XSType getType(String ns, String localName) {
   1.112 +        XSSchema schema = getSchema(ns);
   1.113 +        if(schema==null)    return null;
   1.114 +
   1.115 +        return schema.getType(localName);
   1.116 +    }
   1.117 +
   1.118 +    public XSSimpleType getSimpleType( String ns, String localName ) {
   1.119 +        XSSchema schema = getSchema(ns);
   1.120 +        if(schema==null)    return null;
   1.121 +
   1.122 +        return schema.getSimpleType(localName);
   1.123 +    }
   1.124 +
   1.125 +    public XSElementDecl getElementDecl( String ns, String localName ) {
   1.126 +        XSSchema schema = getSchema(ns);
   1.127 +        if(schema==null)    return null;
   1.128 +
   1.129 +        return schema.getElementDecl(localName);
   1.130 +    }
   1.131 +
   1.132 +    public XSAttributeDecl getAttributeDecl( String ns, String localName ) {
   1.133 +        XSSchema schema = getSchema(ns);
   1.134 +        if(schema==null)    return null;
   1.135 +
   1.136 +        return schema.getAttributeDecl(localName);
   1.137 +    }
   1.138 +
   1.139 +    public XSModelGroupDecl getModelGroupDecl( String ns, String localName ) {
   1.140 +        XSSchema schema = getSchema(ns);
   1.141 +        if(schema==null)    return null;
   1.142 +
   1.143 +        return schema.getModelGroupDecl(localName);
   1.144 +    }
   1.145 +
   1.146 +    public XSAttGroupDecl getAttGroupDecl( String ns, String localName ) {
   1.147 +        XSSchema schema = getSchema(ns);
   1.148 +        if(schema==null)    return null;
   1.149 +
   1.150 +        return schema.getAttGroupDecl(localName);
   1.151 +    }
   1.152 +
   1.153 +    public XSComplexType getComplexType( String ns, String localName ) {
   1.154 +        XSSchema schema = getSchema(ns);
   1.155 +        if(schema==null)    return null;
   1.156 +
   1.157 +        return schema.getComplexType(localName);
   1.158 +    }
   1.159 +
   1.160 +    public XSIdentityConstraint getIdentityConstraint(String ns, String localName) {
   1.161 +        XSSchema schema = getSchema(ns);
   1.162 +        if(schema==null)    return null;
   1.163 +
   1.164 +        return schema.getIdentityConstraint(localName);
   1.165 +    }
   1.166 +
   1.167 +    public Iterator<XSElementDecl> iterateElementDecls() {
   1.168 +        return new Iterators.Map<XSElementDecl,XSSchema>(iterateSchema()) {
   1.169 +            protected Iterator<XSElementDecl> apply(XSSchema u) {
   1.170 +                return u.iterateElementDecls();
   1.171 +            }
   1.172 +        };
   1.173 +    }
   1.174 +
   1.175 +    public Iterator<XSType> iterateTypes() {
   1.176 +        return new Iterators.Map<XSType,XSSchema>(iterateSchema()) {
   1.177 +            protected Iterator<XSType> apply(XSSchema u) {
   1.178 +                return u.iterateTypes();
   1.179 +            }
   1.180 +        };
   1.181 +    }
   1.182 +
   1.183 +    public Iterator<XSAttributeDecl> iterateAttributeDecls() {
   1.184 +        return new Iterators.Map<XSAttributeDecl,XSSchema>(iterateSchema()) {
   1.185 +            protected Iterator<XSAttributeDecl> apply(XSSchema u) {
   1.186 +                return u.iterateAttributeDecls();
   1.187 +            }
   1.188 +        };
   1.189 +    }
   1.190 +    public Iterator<XSAttGroupDecl> iterateAttGroupDecls() {
   1.191 +        return new Iterators.Map<XSAttGroupDecl,XSSchema>(iterateSchema()) {
   1.192 +            protected Iterator<XSAttGroupDecl> apply(XSSchema u) {
   1.193 +                return u.iterateAttGroupDecls();
   1.194 +            }
   1.195 +        };
   1.196 +    }
   1.197 +    public Iterator<XSModelGroupDecl> iterateModelGroupDecls() {
   1.198 +        return new Iterators.Map<XSModelGroupDecl,XSSchema>(iterateSchema()) {
   1.199 +            protected Iterator<XSModelGroupDecl> apply(XSSchema u) {
   1.200 +                return u.iterateModelGroupDecls();
   1.201 +            }
   1.202 +        };
   1.203 +    }
   1.204 +    public Iterator<XSSimpleType> iterateSimpleTypes() {
   1.205 +        return new Iterators.Map<XSSimpleType,XSSchema>(iterateSchema()) {
   1.206 +            protected Iterator<XSSimpleType> apply(XSSchema u) {
   1.207 +                return u.iterateSimpleTypes();
   1.208 +            }
   1.209 +        };
   1.210 +    }
   1.211 +    public Iterator<XSComplexType> iterateComplexTypes() {
   1.212 +        return new Iterators.Map<XSComplexType,XSSchema>(iterateSchema()) {
   1.213 +            protected Iterator<XSComplexType> apply(XSSchema u) {
   1.214 +                return u.iterateComplexTypes();
   1.215 +            }
   1.216 +        };
   1.217 +    }
   1.218 +    public Iterator<XSNotation> iterateNotations() {
   1.219 +        return new Iterators.Map<XSNotation,XSSchema>(iterateSchema()) {
   1.220 +            protected Iterator<XSNotation> apply(XSSchema u) {
   1.221 +                return u.iterateNotations();
   1.222 +            }
   1.223 +        };
   1.224 +    }
   1.225 +
   1.226 +    public Iterator<XSIdentityConstraint> iterateIdentityConstraints() {
   1.227 +        return new Iterators.Map<XSIdentityConstraint,XSSchema>(iterateSchema()) {
   1.228 +            protected Iterator<XSIdentityConstraint> apply(XSSchema u) {
   1.229 +                return u.getIdentityConstraints().values().iterator();
   1.230 +            }
   1.231 +        };
   1.232 +    }
   1.233 +
   1.234 +    public Collection<XSComponent> select(String scd, NamespaceContext nsContext) {
   1.235 +        try {
   1.236 +            return SCD.create(scd,nsContext).select(this);
   1.237 +        } catch (ParseException e) {
   1.238 +            throw new IllegalArgumentException(e);
   1.239 +        }
   1.240 +    }
   1.241 +
   1.242 +    public XSComponent selectSingle(String scd, NamespaceContext nsContext) {
   1.243 +        try {
   1.244 +            return SCD.create(scd,nsContext).selectSingle(this);
   1.245 +        } catch (ParseException e) {
   1.246 +            throw new IllegalArgumentException(e);
   1.247 +        }
   1.248 +    }
   1.249 +
   1.250 +
   1.251 +    public final EmptyImpl empty = new EmptyImpl();
   1.252 +    public XSContentType getEmpty() { return empty; }
   1.253 +
   1.254 +    public XSSimpleType getAnySimpleType() { return anySimpleType; }
   1.255 +    public final AnySimpleType anySimpleType = new AnySimpleType();
   1.256 +    private class AnySimpleType extends DeclarationImpl
   1.257 +        implements XSRestrictionSimpleType, Ref.SimpleType {
   1.258 +
   1.259 +        AnySimpleType() {
   1.260 +            super(null,null,null,null,"http://www.w3.org/2001/XMLSchema","anySimpleType",false);
   1.261 +        }
   1.262 +        public SchemaImpl getOwnerSchema() {
   1.263 +            return createSchema("http://www.w3.org/2001/XMLSchema",null);
   1.264 +        }
   1.265 +        public XSSimpleType asSimpleType() { return this; }
   1.266 +        public XSComplexType asComplexType() { return null; }
   1.267 +
   1.268 +        public boolean isDerivedFrom(XSType t) {
   1.269 +            return t==this || t==anyType;
   1.270 +        }
   1.271 +
   1.272 +        public boolean isSimpleType()       { return true; }
   1.273 +        public boolean isComplexType()      { return false; }
   1.274 +        public XSContentType asEmpty() { return null; }
   1.275 +        public XSParticle asParticle() { return null; }
   1.276 +        public XSType getBaseType() { return anyType; }
   1.277 +        public XSSimpleType getSimpleBaseType() { return null; }
   1.278 +        public int getDerivationMethod() { return RESTRICTION; }
   1.279 +        public Iterator<XSFacet> iterateDeclaredFacets() { return Iterators.empty(); }
   1.280 +        public Collection<? extends XSFacet> getDeclaredFacets() { return Collections.EMPTY_LIST; }
   1.281 +        public void visit( XSSimpleTypeVisitor visitor ) {visitor.restrictionSimpleType(this); }
   1.282 +        public void visit( XSContentTypeVisitor visitor ) {visitor.simpleType(this); }
   1.283 +        public void visit( XSVisitor visitor ) {visitor.simpleType(this); }
   1.284 +        public <T> T apply( XSSimpleTypeFunction<T> f ) {return f.restrictionSimpleType(this); }
   1.285 +        public <T> T apply( XSContentTypeFunction<T> f ) { return f.simpleType(this); }
   1.286 +        public <T> T apply( XSFunction<T> f ) { return f.simpleType(this); }
   1.287 +        public XSVariety getVariety() { return XSVariety.ATOMIC; }
   1.288 +        public XSSimpleType getPrimitiveType() {return this;}
   1.289 +        public boolean isPrimitive() {return true;}
   1.290 +        public XSListSimpleType getBaseListType() {return null;}
   1.291 +        public XSUnionSimpleType getBaseUnionType() {return null;}
   1.292 +        public XSFacet getFacet(String name) { return null; }
   1.293 +        public List<XSFacet> getFacets( String name ) { return Collections.EMPTY_LIST; }
   1.294 +        public XSFacet getDeclaredFacet(String name) { return null; }
   1.295 +        public List<XSFacet> getDeclaredFacets(String name) { return Collections.EMPTY_LIST; }
   1.296 +
   1.297 +        public boolean isRestriction() { return true; }
   1.298 +        public boolean isList() { return false; }
   1.299 +        public boolean isUnion() { return false; }
   1.300 +        public boolean isFinal(XSVariety v) { return false; }
   1.301 +        public XSRestrictionSimpleType asRestriction() { return this; }
   1.302 +        public XSListSimpleType asList() { return null; }
   1.303 +        public XSUnionSimpleType asUnion() { return null; }
   1.304 +        public XSSimpleType getType() { return this; } // Ref.SimpleType implementation
   1.305 +        public XSSimpleType getRedefinedBy() { return null; }
   1.306 +        public int getRedefinedCount() { return 0; }
   1.307 +
   1.308 +        public XSType[] listSubstitutables() {
   1.309 +            return Util.listSubstitutables(this);
   1.310 +        }
   1.311 +    }
   1.312 +
   1.313 +    public XSComplexType getAnyType() { return anyType; }
   1.314 +    public final AnyType anyType = new AnyType();
   1.315 +    private class AnyType extends DeclarationImpl implements XSComplexType, Ref.Type {
   1.316 +        AnyType() {
   1.317 +            super(null,null,null,null,"http://www.w3.org/2001/XMLSchema","anyType",false);
   1.318 +        }
   1.319 +        public SchemaImpl getOwnerSchema() {
   1.320 +            return createSchema("http://www.w3.org/2001/XMLSchema",null);
   1.321 +        }
   1.322 +        public boolean isAbstract() { return false; }
   1.323 +        public XSWildcard getAttributeWildcard() { return anyWildcard; }
   1.324 +        public XSAttributeUse getAttributeUse( String nsURI, String localName ) { return null; }
   1.325 +        public Iterator<XSAttributeUse> iterateAttributeUses() { return Iterators.empty(); }
   1.326 +        public XSAttributeUse getDeclaredAttributeUse( String nsURI, String localName ) { return null; }
   1.327 +        public Iterator<XSAttributeUse> iterateDeclaredAttributeUses() { return Iterators.empty(); }
   1.328 +        public Iterator<XSAttGroupDecl> iterateAttGroups() { return Iterators.empty(); }
   1.329 +        public Collection<XSAttributeUse> getAttributeUses() { return Collections.EMPTY_LIST; }
   1.330 +        public Collection<? extends XSAttributeUse> getDeclaredAttributeUses() { return Collections.EMPTY_LIST; }
   1.331 +        public Collection<? extends XSAttGroupDecl> getAttGroups() { return Collections.EMPTY_LIST; }
   1.332 +        public boolean isFinal( int i ) { return false; }
   1.333 +        public boolean isSubstitutionProhibited( int i ) { return false; }
   1.334 +        public boolean isMixed() { return true; }
   1.335 +        public XSContentType getContentType() { return contentType; }
   1.336 +        public XSContentType getExplicitContent() { return null; }
   1.337 +        public XSType getBaseType() { return this; }
   1.338 +        public XSSimpleType asSimpleType() { return null; }
   1.339 +        public XSComplexType asComplexType() { return this; }
   1.340 +
   1.341 +        public boolean isDerivedFrom(XSType t) {
   1.342 +            return t==this;
   1.343 +        }
   1.344 +
   1.345 +        public boolean isSimpleType()       { return false; }
   1.346 +        public boolean isComplexType()      { return true; }
   1.347 +        public XSContentType asEmpty() { return null; }
   1.348 +        public int getDerivationMethod() { return XSType.RESTRICTION; }
   1.349 +
   1.350 +        public XSElementDecl getScope() { return null; }
   1.351 +        public void visit( XSVisitor visitor ) { visitor.complexType(this); }
   1.352 +        public <T> T apply( XSFunction<T> f ) { return f.complexType(this); }
   1.353 +
   1.354 +        public XSType getType() { return this; } // Ref.Type implementation
   1.355 +
   1.356 +        public XSComplexType getRedefinedBy() { return null; }
   1.357 +        public int getRedefinedCount() { return 0; }
   1.358 +
   1.359 +        public XSType[] listSubstitutables() {
   1.360 +            return Util.listSubstitutables(this);
   1.361 +        }
   1.362 +
   1.363 +        private final WildcardImpl anyWildcard = new WildcardImpl.Any(null,null,null,null,XSWildcard.SKIP);
   1.364 +        private final XSContentType contentType = new ParticleImpl( null, null,
   1.365 +                new ModelGroupImpl(null, null, null, null,XSModelGroup.SEQUENCE, new ParticleImpl[]{
   1.366 +                    new ParticleImpl( null, null,
   1.367 +                        anyWildcard, null,
   1.368 +                        XSParticle.UNBOUNDED, 0 )
   1.369 +                })
   1.370 +                ,null,1,1);
   1.371 +        public List<XSComplexType> getSubtypes() {
   1.372 +            ArrayList subtypeList = new ArrayList();
   1.373 +            Iterator<XSComplexType> cTypes = getRoot().iterateComplexTypes();
   1.374 +            while (cTypes.hasNext()) {
   1.375 +                XSComplexType cType= cTypes.next();
   1.376 +                XSType base = cType.getBaseType();
   1.377 +                if ((base != null) && (base.equals(this))) {
   1.378 +                    subtypeList.add(cType);
   1.379 +                }
   1.380 +            }
   1.381 +            return subtypeList;
   1.382 +        }
   1.383 +
   1.384 +        public List<XSElementDecl> getElementDecls() {
   1.385 +            ArrayList declList = new ArrayList();
   1.386 +            XSSchemaSet schemaSet = getRoot();
   1.387 +            for (XSSchema sch : schemaSet.getSchemas()) {
   1.388 +                for (XSElementDecl decl : sch.getElementDecls().values()) {
   1.389 +                    if (decl.getType().equals(this)) {
   1.390 +                        declList.add(decl);
   1.391 +                    }
   1.392 +                }
   1.393 +            }
   1.394 +            return declList;
   1.395 +        }
   1.396 +    }
   1.397 +}

mercurial