001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: package com.sun.xml.xsom.impl;
021:
022: import com.sun.xml.xsom.XSElementDecl;
023: import com.sun.xml.xsom.XSModelGroup;
024: import com.sun.xml.xsom.XSModelGroupDecl;
025: import com.sun.xml.xsom.XSParticle;
026: import com.sun.xml.xsom.XSTerm;
027: import com.sun.xml.xsom.XSWildcard;
028: import com.sun.xml.xsom.impl.parser.SchemaDocumentImpl;
029: import com.sun.xml.xsom.visitor.XSFunction;
030: import com.sun.xml.xsom.visitor.XSTermFunction;
031: import com.sun.xml.xsom.visitor.XSTermFunctionWithParam;
032: import com.sun.xml.xsom.visitor.XSTermVisitor;
033: import com.sun.xml.xsom.visitor.XSVisitor;
034: import org.xml.sax.Locator;
035:
036: import java.util.Arrays;
037: import java.util.Iterator;
038:
039: public class ModelGroupImpl extends ComponentImpl implements
040: XSModelGroup, Ref.Term {
041: public ModelGroupImpl(SchemaDocumentImpl owner,
042: AnnotationImpl _annon, Locator _loc,
043: ForeignAttributesImpl _fa, Compositor _compositor,
044: ParticleImpl[] _children) {
045:
046: super (owner, _annon, _loc, _fa);
047: this .compositor = _compositor;
048: this .children = _children;
049:
050: if (compositor == null)
051: throw new IllegalArgumentException();
052: for (int i = children.length - 1; i >= 0; i--)
053: if (children[i] == null)
054: throw new IllegalArgumentException();
055: }
056:
057: private final ParticleImpl[] children;
058:
059: public ParticleImpl getChild(int idx) {
060: return children[idx];
061: }
062:
063: public int getSize() {
064: return children.length;
065: }
066:
067: public ParticleImpl[] getChildren() {
068: return children;
069: }
070:
071: private final Compositor compositor;
072:
073: public Compositor getCompositor() {
074: return compositor;
075: }
076:
077: public void redefine(ModelGroupDeclImpl oldMG) {
078: for (ParticleImpl p : children)
079: p.redefine(oldMG);
080: }
081:
082: public Iterator<XSParticle> iterator() {
083: return Arrays.asList((XSParticle[]) children).iterator();
084: }
085:
086: public boolean isWildcard() {
087: return false;
088: }
089:
090: public boolean isModelGroupDecl() {
091: return false;
092: }
093:
094: public boolean isModelGroup() {
095: return true;
096: }
097:
098: public boolean isElementDecl() {
099: return false;
100: }
101:
102: public XSWildcard asWildcard() {
103: return null;
104: }
105:
106: public XSModelGroupDecl asModelGroupDecl() {
107: return null;
108: }
109:
110: public XSModelGroup asModelGroup() {
111: return this ;
112: }
113:
114: public XSElementDecl asElementDecl() {
115: return null;
116: }
117:
118: public void visit(XSVisitor visitor) {
119: visitor.modelGroup(this );
120: }
121:
122: public void visit(XSTermVisitor visitor) {
123: visitor.modelGroup(this );
124: }
125:
126: public Object apply(XSTermFunction function) {
127: return function.modelGroup(this );
128: }
129:
130: public <T, P> T apply(XSTermFunctionWithParam<T, P> function,
131: P param) {
132: return function.modelGroup(this , param);
133: }
134:
135: public Object apply(XSFunction function) {
136: return function.modelGroup(this );
137: }
138:
139: // Ref.Term implementation
140: public XSTerm getTerm() {
141: return this;
142: }
143: }
|