325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.xsom.impl;
325N/A
325N/Aimport com.sun.xml.internal.xsom.XSComplexType;
325N/Aimport com.sun.xml.internal.xsom.XSContentType;
325N/Aimport com.sun.xml.internal.xsom.XSListSimpleType;
325N/Aimport com.sun.xml.internal.xsom.XSParticle;
325N/Aimport com.sun.xml.internal.xsom.XSRestrictionSimpleType;
325N/Aimport com.sun.xml.internal.xsom.XSSimpleType;
325N/Aimport com.sun.xml.internal.xsom.XSType;
325N/Aimport com.sun.xml.internal.xsom.XSUnionSimpleType;
325N/Aimport com.sun.xml.internal.xsom.XSVariety;
325N/Aimport com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl;
325N/Aimport com.sun.xml.internal.xsom.visitor.XSContentTypeFunction;
325N/Aimport com.sun.xml.internal.xsom.visitor.XSContentTypeVisitor;
325N/Aimport com.sun.xml.internal.xsom.visitor.XSFunction;
325N/Aimport com.sun.xml.internal.xsom.visitor.XSVisitor;
325N/Aimport org.xml.sax.Locator;
325N/A
325N/Aimport java.util.Set;
325N/A
325N/Apublic abstract class SimpleTypeImpl extends DeclarationImpl
325N/A implements XSSimpleType, ContentTypeImpl, Ref.SimpleType
325N/A{
325N/A SimpleTypeImpl(
325N/A SchemaDocumentImpl _parent,
325N/A AnnotationImpl _annon,
325N/A Locator _loc,
325N/A ForeignAttributesImpl _fa,
325N/A String _name,
325N/A boolean _anonymous,
325N/A Set<XSVariety> finalSet,
325N/A Ref.SimpleType _baseType) {
325N/A
325N/A super(_parent, _annon, _loc, _fa, _parent.getTargetNamespace(), _name, _anonymous);
325N/A
325N/A this.baseType = _baseType;
325N/A this.finalSet = finalSet;
325N/A }
325N/A
325N/A private Ref.SimpleType baseType;
325N/A
325N/A public XSType[] listSubstitutables() {
325N/A return Util.listSubstitutables(this);
325N/A }
325N/A
325N/A public void redefine( SimpleTypeImpl st ) {
325N/A baseType = st;
325N/A st.redefinedBy = this;
325N/A redefiningCount = (short)(st.redefiningCount+1);
325N/A }
325N/A
325N/A /**
325N/A * Number of times this component redefines other components.
325N/A */
325N/A private short redefiningCount = 0;
325N/A
325N/A private SimpleTypeImpl redefinedBy = null;
325N/A
325N/A public XSSimpleType getRedefinedBy() {
325N/A return redefinedBy;
325N/A }
325N/A
325N/A public int getRedefinedCount() {
325N/A int i=0;
325N/A for( SimpleTypeImpl st =this.redefinedBy; st !=null; st =st.redefinedBy)
325N/A i++;
325N/A return i;
325N/A }
325N/A
325N/A public XSType getBaseType() { return baseType.getType(); }
325N/A public XSSimpleType getSimpleBaseType() { return baseType.getType(); }
325N/A public boolean isPrimitive() { return false; }
325N/A
325N/A public XSListSimpleType getBaseListType() {
325N/A return getSimpleBaseType().getBaseListType();
325N/A }
325N/A
325N/A public XSUnionSimpleType getBaseUnionType() {
325N/A return getSimpleBaseType().getBaseUnionType();
325N/A }
325N/A
325N/A private final Set<XSVariety> finalSet;
325N/A
325N/A public boolean isFinal(XSVariety v) {
325N/A return finalSet.contains(v);
325N/A }
325N/A
325N/A
325N/A public final int getDerivationMethod() { return XSType.RESTRICTION; }
325N/A
325N/A
325N/A public final XSSimpleType asSimpleType() { return this; }
325N/A public final XSComplexType asComplexType(){ return null; }
325N/A
325N/A public boolean isDerivedFrom(XSType t) {
325N/A XSType x = this;
325N/A while(true) {
325N/A if(t==x)
325N/A return true;
325N/A XSType s = x.getBaseType();
325N/A if(s==x)
325N/A return false;
325N/A x = s;
325N/A }
325N/A }
325N/A
325N/A public final boolean isSimpleType() { return true; }
325N/A public final boolean isComplexType() { return false; }
325N/A public final XSParticle asParticle() { return null; }
325N/A public final XSContentType asEmpty() { return null; }
325N/A
325N/A
325N/A public boolean isRestriction() { return false; }
325N/A public boolean isList() { return false; }
325N/A public boolean isUnion() { return false; }
325N/A public XSRestrictionSimpleType asRestriction() { return null; }
325N/A public XSListSimpleType asList() { return null; }
325N/A public XSUnionSimpleType asUnion() { return null; }
325N/A
325N/A
325N/A
325N/A
325N/A public final void visit( XSVisitor visitor ) {
325N/A visitor.simpleType(this);
325N/A }
325N/A public final void visit( XSContentTypeVisitor visitor ) {
325N/A visitor.simpleType(this);
325N/A }
325N/A public final Object apply( XSFunction function ) {
325N/A return function.simpleType(this);
325N/A }
325N/A public final Object apply( XSContentTypeFunction function ) {
325N/A return function.simpleType(this);
325N/A }
325N/A
325N/A // Ref.ContentType implementation
325N/A public XSContentType getContentType() { return this; }
325N/A // Ref.SimpleType implementation
325N/A public XSSimpleType getType() { return this; }
325N/A}