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.XSContentType;
023: import com.sun.xml.xsom.XSParticle;
024: import com.sun.xml.xsom.XSSimpleType;
025: import com.sun.xml.xsom.XSTerm;
026: import com.sun.xml.xsom.impl.parser.DelayedRef;
027: import com.sun.xml.xsom.impl.parser.SchemaDocumentImpl;
028: import com.sun.xml.xsom.parser.SchemaDocument;
029: import com.sun.xml.xsom.visitor.XSContentTypeFunction;
030: import com.sun.xml.xsom.visitor.XSContentTypeVisitor;
031: import com.sun.xml.xsom.visitor.XSFunction;
032: import com.sun.xml.xsom.visitor.XSVisitor;
033: import org.xml.sax.Locator;
034:
035: import java.util.List;
036:
037: public class ParticleImpl extends ComponentImpl implements XSParticle,
038: ContentTypeImpl {
039: public ParticleImpl(SchemaDocumentImpl owner, AnnotationImpl _ann,
040: Ref.Term _term, Locator _loc, int _maxOccurs, int _minOccurs) {
041:
042: super (owner, _ann, _loc, null);
043: this .term = _term;
044: this .maxOccurs = _maxOccurs;
045: this .minOccurs = _minOccurs;
046: }
047:
048: public ParticleImpl(SchemaDocumentImpl owner, AnnotationImpl _ann,
049: Ref.Term _term, Locator _loc) {
050: this (owner, _ann, _term, _loc, 1, 1);
051: }
052:
053: private Ref.Term term;
054:
055: public XSTerm getTerm() {
056: return term.getTerm();
057: }
058:
059: private int maxOccurs;
060:
061: public int getMaxOccurs() {
062: return maxOccurs;
063: }
064:
065: public boolean isRepeated() {
066: return maxOccurs != 0 && maxOccurs != 1;
067: }
068:
069: private int minOccurs;
070:
071: public int getMinOccurs() {
072: return minOccurs;
073: }
074:
075: public void redefine(ModelGroupDeclImpl oldMG) {
076: if (term instanceof ModelGroupImpl) {
077: ((ModelGroupImpl) term).redefine(oldMG);
078: return;
079: }
080: if (term instanceof DelayedRef.ModelGroup) {
081: ((DelayedRef) term).redefine(oldMG);
082: }
083: }
084:
085: public XSSimpleType asSimpleType() {
086: return null;
087: }
088:
089: public XSParticle asParticle() {
090: return this ;
091: }
092:
093: public XSContentType asEmpty() {
094: return null;
095: }
096:
097: public final Object apply(XSFunction function) {
098: return function.particle(this );
099: }
100:
101: public final Object apply(XSContentTypeFunction function) {
102: return function.particle(this );
103: }
104:
105: public final void visit(XSVisitor visitor) {
106: visitor.particle(this );
107: }
108:
109: public final void visit(XSContentTypeVisitor visitor) {
110: visitor.particle(this );
111: }
112:
113: // Ref.ContentType implementation
114: public XSContentType getContentType() {
115: return this ;
116: }
117:
118: /**
119: * Foreign attribuets are considered to be on terms.
120: *
121: * REVISIT: is this a good design?
122: */
123: public List getForeignAttributes() {
124: return getTerm().getForeignAttributes();
125: }
126: }
|