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.XSContentType;
29 import com.sun.xml.internal.xsom.XSParticle;
30 import com.sun.xml.internal.xsom.XSSimpleType;
31 import com.sun.xml.internal.xsom.XSTerm;
32 import com.sun.xml.internal.xsom.impl.parser.DelayedRef;
33 import com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl;
34 import com.sun.xml.internal.xsom.visitor.XSContentTypeFunction;
35 import com.sun.xml.internal.xsom.visitor.XSContentTypeVisitor;
36 import com.sun.xml.internal.xsom.visitor.XSFunction;
37 import com.sun.xml.internal.xsom.visitor.XSVisitor;
38 import java.math.BigInteger;
39 import org.xml.sax.Locator;
41 import java.util.List;
43 public class ParticleImpl extends ComponentImpl implements XSParticle, ContentTypeImpl
44 {
45 public ParticleImpl( SchemaDocumentImpl owner, AnnotationImpl _ann,
46 Ref.Term _term, Locator _loc, BigInteger _maxOccurs, BigInteger _minOccurs ) {
48 super(owner,_ann,_loc,null);
49 this.term = _term;
50 this.maxOccurs = _maxOccurs;
51 this.minOccurs = _minOccurs;
52 }
53 public ParticleImpl( SchemaDocumentImpl owner, AnnotationImpl _ann,
54 Ref.Term _term, Locator _loc, int _maxOccurs, int _minOccurs ) {
56 super(owner,_ann,_loc,null);
57 this.term = _term;
58 this.maxOccurs = BigInteger.valueOf(_maxOccurs);
59 this.minOccurs = BigInteger.valueOf(_minOccurs);
60 }
61 public ParticleImpl( SchemaDocumentImpl owner, AnnotationImpl _ann, Ref.Term _term, Locator _loc ) {
62 this(owner,_ann,_term,_loc,1,1);
63 }
65 private Ref.Term term;
66 public XSTerm getTerm() { return term.getTerm(); }
68 private BigInteger maxOccurs;
69 public BigInteger getMaxOccurs() { return maxOccurs; }
71 public boolean isRepeated() {
72 return !maxOccurs.equals(BigInteger.ZERO) && !maxOccurs.equals(BigInteger.ONE);
73 }
75 private BigInteger minOccurs;
76 public BigInteger getMinOccurs() { return minOccurs; }
79 public void redefine(ModelGroupDeclImpl oldMG) {
80 if( term instanceof ModelGroupImpl ) {
81 ((ModelGroupImpl)term).redefine(oldMG);
82 return;
83 }
84 if( term instanceof DelayedRef.ModelGroup ) {
85 ((DelayedRef)term).redefine(oldMG);
86 }
87 }
90 public XSSimpleType asSimpleType() { return null; }
91 public XSParticle asParticle() { return this; }
92 public XSContentType asEmpty() { return null; }
95 public final Object apply( XSFunction function ) {
96 return function.particle(this);
97 }
98 public final Object apply( XSContentTypeFunction function ) {
99 return function.particle(this);
100 }
101 public final void visit( XSVisitor visitor ) {
102 visitor.particle(this);
103 }
104 public final void visit( XSContentTypeVisitor visitor ) {
105 visitor.particle(this);
106 }
108 // Ref.ContentType implementation
109 public XSContentType getContentType() { return this; }
111 /**
112 * Foreign attribuets are considered to be on terms.
113 *
114 * REVISIT: is this a good design?
115 */
116 public List getForeignAttributes() {
117 return getTerm().getForeignAttributes();
118 }
119 }