Thu, 31 Aug 2017 15:18:52 +0800
merge
1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.xsom.impl;
28 import com.sun.xml.internal.xsom.XSElementDecl;
29 import com.sun.xml.internal.xsom.XSModelGroup;
30 import com.sun.xml.internal.xsom.XSModelGroupDecl;
31 import com.sun.xml.internal.xsom.XSParticle;
32 import com.sun.xml.internal.xsom.XSTerm;
33 import com.sun.xml.internal.xsom.XSWildcard;
34 import com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl;
35 import com.sun.xml.internal.xsom.visitor.XSFunction;
36 import com.sun.xml.internal.xsom.visitor.XSTermFunction;
37 import com.sun.xml.internal.xsom.visitor.XSTermFunctionWithParam;
38 import com.sun.xml.internal.xsom.visitor.XSTermVisitor;
39 import com.sun.xml.internal.xsom.visitor.XSVisitor;
40 import org.xml.sax.Locator;
42 import java.util.Arrays;
43 import java.util.Iterator;
45 public class ModelGroupImpl extends ComponentImpl implements XSModelGroup, Ref.Term
46 {
47 public ModelGroupImpl( SchemaDocumentImpl owner, AnnotationImpl _annon, Locator _loc, ForeignAttributesImpl _fa,
48 Compositor _compositor, ParticleImpl[] _children ) {
50 super(owner,_annon,_loc,_fa);
51 this.compositor = _compositor;
52 this.children = _children;
54 if(compositor==null)
55 throw new IllegalArgumentException();
56 for( int i=children.length-1; i>=0; i-- )
57 if(children[i]==null)
58 throw new IllegalArgumentException();
59 }
61 private final ParticleImpl[] children;
62 public ParticleImpl getChild( int idx ) { return children[idx]; }
63 public int getSize() { return children.length; }
65 public ParticleImpl[] getChildren() { return children; }
68 private final Compositor compositor;
69 public Compositor getCompositor() { return compositor; }
72 public void redefine(ModelGroupDeclImpl oldMG) {
73 for (ParticleImpl p : children)
74 p.redefine(oldMG);
75 }
77 public Iterator<XSParticle> iterator() {
78 return Arrays.asList((XSParticle[])children).iterator();
79 }
82 public boolean isWildcard() { return false; }
83 public boolean isModelGroupDecl() { return false; }
84 public boolean isModelGroup() { return true; }
85 public boolean isElementDecl() { return false; }
87 public XSWildcard asWildcard() { return null; }
88 public XSModelGroupDecl asModelGroupDecl() { return null; }
89 public XSModelGroup asModelGroup() { return this; }
90 public XSElementDecl asElementDecl() { return null; }
94 public void visit( XSVisitor visitor ) {
95 visitor.modelGroup(this);
96 }
97 public void visit( XSTermVisitor visitor ) {
98 visitor.modelGroup(this);
99 }
100 public Object apply( XSTermFunction function ) {
101 return function.modelGroup(this);
102 }
104 public <T,P> T apply(XSTermFunctionWithParam<T, P> function, P param) {
105 return function.modelGroup(this,param);
106 }
108 public Object apply( XSFunction function ) {
109 return function.modelGroup(this);
110 }
112 // Ref.Term implementation
113 public XSTerm getTerm() { return this; }
114 }