1 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 ; 24 import org.xml.sax.SAXException ; 25 26 27 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 { 39 if (pGroup == null) { 40 throw new NullPointerException ("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 ("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 ("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 ("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 ("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 ("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 ("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 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 ("Invalid particle, neither of element, wildcard, or model group."); 135 } 136 } 137 } 138 | Popular Tags |