KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > impl > XSParticleImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.xs.impl;
18
19 import org.apache.ws.jaxme.xs.XSAny;
20 import org.apache.ws.jaxme.xs.XSElement;
21 import org.apache.ws.jaxme.xs.XSGroup;
22 import org.apache.ws.jaxme.xs.XSParticle;
23 import org.xml.sax.Locator JavaDoc;
24 import org.xml.sax.SAXException JavaDoc;
25
26
27 /** <p>Default implementation of a particle.</p>
28  *
29  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
30  */

31 public class XSParticleImpl implements XSParticle {
32   private final XSGroup group;
33   private final XSAny wildcard;
34   private final XSElement element;
35   private int minOccurs = 1;
36   private int maxOccurs = 1;
37
38   public XSParticleImpl(XSGroup pGroup) throws SAXException JavaDoc {
39     if (pGroup == null) {
40       throw new NullPointerException JavaDoc("The particle group must not be null.");
41     }
42     group = pGroup;
43     element = null;
44     wildcard = null;
45   }
46
47   public XSParticleImpl(XSAny pWildcard) {
48     if (pWildcard == null) {
49       throw new NullPointerException JavaDoc("The particle wildcard must not be null.");
50     }
51     wildcard = pWildcard;
52     group = null;
53     element = null;
54   }
55
56   public XSParticleImpl(XSElement pElement) {
57     if (pElement == null) {
58       throw new NullPointerException JavaDoc("The particle element must not be null.");
59     }
60     element = pElement;
61     group = null;
62     wildcard = null;
63   }
64
65   public XSParticle.Type getType() {
66     if (group != null) {
67       return XSParticle.GROUP;
68     } else if (wildcard != null) {
69       return XSParticle.WILDCARD;
70     } else if (element != null) {
71       return XSParticle.ELEMENT;
72     } else {
73       throw new IllegalStateException JavaDoc("Neither of the particle group, wildcard, or element has been set.");
74     }
75   }
76
77   public boolean isGroup() {
78     return group != null;
79   }
80
81   public XSGroup getGroup() {
82     if (group == null) {
83       throw new IllegalStateException JavaDoc("This particle doesn't have the group type.");
84     }
85     return group;
86   }
87
88   public boolean isWildcard() {
89     return wildcard != null;
90   }
91
92   public XSAny getWildcard() {
93     if (wildcard == null) {
94       throw new IllegalStateException JavaDoc("This particle doesn't have the wildcard type.");
95     }
96     return wildcard;
97   }
98
99   public boolean isElement() {
100     return element != null;
101   }
102
103   public XSElement getElement() {
104     if (element == null) {
105       throw new IllegalStateException JavaDoc("This particle doesn't have the element type.");
106     }
107     return element;
108   }
109
110   public int getMinOccurs() {
111     return minOccurs;
112   }
113
114   public void setMinOccurs(int pMinOccurs) {
115     minOccurs = pMinOccurs;
116   }
117
118   public int getMaxOccurs() {
119     return maxOccurs;
120   }
121
122   public void setMaxOccurs(int pMaxOccurs) {
123     maxOccurs = pMaxOccurs;
124   }
125
126   public Locator JavaDoc getLocator() {
127     if (isWildcard()) {
128       return getWildcard().getLocator();
129     } else if (isElement()) {
130       return getElement().getLocator();
131     } else if (isGroup()) {
132       return getGroup().getLocator();
133     } else {
134       throw new IllegalStateException JavaDoc("Invalid particle, neither of element, wildcard, or model group.");
135     }
136   }
137 }
138
Popular Tags