001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.xsom.impl;
027:
028: import com.sun.xml.internal.xsom.XSFacet;
029: import com.sun.xml.internal.xsom.XSRestrictionSimpleType;
030: import com.sun.xml.internal.xsom.XSVariety;
031: import com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl;
032: import com.sun.xml.internal.xsom.visitor.XSSimpleTypeFunction;
033: import com.sun.xml.internal.xsom.visitor.XSSimpleTypeVisitor;
034: import org.xml.sax.Locator;
035:
036: import java.util.ArrayList;
037: import java.util.Collection;
038: import java.util.Iterator;
039: import java.util.List;
040: import java.util.Set;
041:
042: public class RestrictionSimpleTypeImpl extends SimpleTypeImpl implements
043: XSRestrictionSimpleType {
044:
045: public RestrictionSimpleTypeImpl(SchemaDocumentImpl _parent,
046: AnnotationImpl _annon, Locator _loc,
047: ForeignAttributesImpl _fa, String _name,
048: boolean _anonymous, Set<XSVariety> finalSet,
049: Ref.SimpleType _baseType) {
050:
051: super (_parent, _annon, _loc, _fa, _name, _anonymous, finalSet,
052: _baseType);
053: }
054:
055: private final List<XSFacet> facets = new ArrayList<XSFacet>();
056:
057: public void addFacet(XSFacet facet) {
058: facets.add(facet);
059: }
060:
061: public Iterator<XSFacet> iterateDeclaredFacets() {
062: return facets.iterator();
063: }
064:
065: public Collection<? extends XSFacet> getDeclaredFacets() {
066: return facets;
067: }
068:
069: public XSFacet getDeclaredFacet(String name) {
070: int len = facets.size();
071: for (int i = 0; i < len; i++) {
072: XSFacet f = facets.get(i);
073: if (f.getName().equals(name))
074: return f;
075: }
076: return null;
077: }
078:
079: public List<XSFacet> getDeclaredFacets(String name) {
080: List<XSFacet> r = new ArrayList<XSFacet>();
081: for (XSFacet f : facets)
082: if (f.getName().equals(name))
083: r.add(f);
084: return r;
085: }
086:
087: public XSFacet getFacet(String name) {
088: XSFacet f = getDeclaredFacet(name);
089: if (f != null)
090: return f;
091:
092: // none was found on this datatype. check the base type.
093: return getSimpleBaseType().getFacet(name);
094: }
095:
096: public XSVariety getVariety() {
097: return getSimpleBaseType().getVariety();
098: }
099:
100: public void visit(XSSimpleTypeVisitor visitor) {
101: visitor.restrictionSimpleType(this );
102: }
103:
104: public Object apply(XSSimpleTypeFunction function) {
105: return function.restrictionSimpleType(this );
106: }
107:
108: public boolean isRestriction() {
109: return true;
110: }
111:
112: public XSRestrictionSimpleType asRestriction() {
113: return this;
114: }
115: }
|