1 17 package org.apache.ws.jaxme.xs.xml.impl; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.apache.ws.jaxme.xs.xml.*; 23 24 25 62 public class XsGSimpleRestrictionModelImpl implements XsGSimpleRestrictionModel { 63 private final XsObject owner; 64 private XsTLocalSimpleType simpleType; 65 private List facets; 66 67 protected XsGSimpleRestrictionModelImpl(XsObject pOwner) { 68 owner = pOwner; 69 } 70 71 public XsTLocalSimpleType createSimpleType() { 72 if (simpleType != null) { 73 throw new IllegalStateException ("Multiple 'simpleType' childs are forbidden."); 74 } 75 if (facets != null && facets.size() > 0) { 76 throw new IllegalStateException ("The 'simpleType' child element must precede the '" + 77 ((XsTFacetBase) facets.get(0)).getFacetName() + "' child element."); 78 } 79 return simpleType = owner.getObjectFactory().newXsTLocalSimpleType(owner); 80 } 81 82 public XsTLocalSimpleType getSimpleType() { 83 return simpleType; 84 } 85 86 protected XsTFacetBase getFacetByName(String pName) { 87 if (facets != null) { 88 for (int i = 0; i < facets.size(); i++) { 89 XsTFacetBase facet = (XsTFacetBase) facets.get(i); 90 if (pName.equals(facet.getFacetName())) { 91 return facet; 92 } 93 } 94 } 95 return null; 96 } 97 98 protected void addFacet(XsTFacetBase pFacet) { 99 if (facets == null) { 100 facets = new ArrayList (); 101 } 102 facets.add(pFacet); 103 } 104 105 protected void addUniqueFacet(XsTFacetBase pFacet) { 106 if (getFacetByName(pFacet.getFacetName()) != null) { 107 throw new IllegalStateException ("Multiple '" + pFacet.getFacetName() + "' childs are forbidden."); 108 } 109 addFacet(pFacet); 110 } 111 112 public XsEMinExclusive createMinExclusive() { 113 XsEMinExclusive minExclusive = owner.getObjectFactory().newXsEMinExclusive(owner); 114 addUniqueFacet(minExclusive); 115 return minExclusive; 116 } 117 118 public XsEMinExclusive getMinExclusive() { 119 return (XsEMinExclusive) getFacetByName("minExclusive"); 120 } 121 122 public XsEMinInclusive createMinInclusive() { 123 XsEMinInclusive minInclusive = owner.getObjectFactory().newXsEMinInclusive(owner); 124 addUniqueFacet(minInclusive); 125 return minInclusive; 126 } 127 128 public XsEMinInclusive getMinInclusive() { 129 return (XsEMinInclusive) getFacetByName("minInclusive"); 130 } 131 132 public XsEMaxExclusive createMaxExclusive() { 133 XsEMaxExclusive maxExclusive = owner.getObjectFactory().newXsEMaxExclusive(owner); 134 addUniqueFacet(maxExclusive); 135 return maxExclusive; 136 } 137 138 public XsEMaxExclusive getMaxExclusive() { 139 return (XsEMaxExclusive) getFacetByName("maxExclusive"); 140 } 141 142 public XsEMaxInclusive createMaxInclusive() { 143 XsEMaxInclusive maxInclusive = owner.getObjectFactory().newXsEMaxInclusive(owner); 144 addUniqueFacet(maxInclusive); 145 return maxInclusive; 146 } 147 148 public XsEMaxInclusive getMaxInclusive() { 149 return (XsEMaxInclusive) getFacetByName("maxInclusive"); 150 } 151 152 public XsETotalDigits createTotalDigits() { 153 XsETotalDigits totalDigits = owner.getObjectFactory().newXsETotalDigits(owner); 154 addUniqueFacet(totalDigits); 155 return totalDigits; 156 } 157 158 public XsETotalDigits getTotalDigits() { 159 return (XsETotalDigits) getFacetByName("totalDigits"); 160 } 161 162 public XsEFractionDigits createFractionDigits() { 163 XsEFractionDigits fractionDigits = owner.getObjectFactory().newXsEFractionDigits(owner); 164 addUniqueFacet(fractionDigits); 165 return fractionDigits; 166 } 167 168 public XsEFractionDigits getFractionDigits() { 169 return (XsEFractionDigits) getFacetByName("fractionDigits"); 170 } 171 172 public XsELength createLength() { 173 XsELength length = owner.getObjectFactory().newXsELength(owner); 174 addUniqueFacet(length); 175 return length; 176 } 177 178 public XsELength getLength() { 179 return (XsELength) getFacetByName("length"); 180 } 181 182 public XsEMinLength createMinLength() { 183 XsEMinLength minLength = owner.getObjectFactory().newXsEMinLength(owner); 184 addUniqueFacet(minLength); 185 return minLength; 186 } 187 188 public XsEMinLength getMinLength() { 189 return (XsEMinLength) getFacetByName("minLength"); 190 } 191 192 public XsEMaxLength createMaxLength() { 193 XsEMaxLength maxLength = owner.getObjectFactory().newXsEMaxLength(owner); 194 addUniqueFacet(maxLength); 195 return maxLength; 196 } 197 198 public XsEMaxLength getMaxLength() { 199 return (XsEMaxLength) getFacetByName("maxLength"); 200 } 201 202 public XsEWhiteSpace createWhiteSpace() { 203 XsEWhiteSpace whiteSpace = owner.getObjectFactory().newXsEWhiteSpace(owner); 204 addUniqueFacet(whiteSpace); 205 return whiteSpace; 206 } 207 208 public XsEWhiteSpace getWhiteSpace() { 209 return (XsEWhiteSpace) getFacetByName("whiteSpace"); 210 } 211 212 public XsEPattern createPattern() { 213 XsEPattern pattern = owner.getObjectFactory().newXsEPattern(owner); 214 addFacet(pattern); 215 return pattern; 216 } 217 218 public XsEPattern[] getPatterns() { 219 if (facets == null) { 220 return new XsEPattern[0]; 221 } 222 List result = new ArrayList (); 223 for (int i = 0; i < facets.size(); i++) { 224 XsTFacetBase facet = (XsTFacetBase) facets.get(i); 225 if ("pattern".equals(facet.getFacetName())) { 226 result.add(facet); 227 } 228 } 229 return (XsEPattern[]) result.toArray(new XsEPattern[result.size()]); 230 } 231 232 public XsEEnumeration createEnumeration() { 233 XsEEnumeration enumeration = owner.getObjectFactory().newXsEEnumeration(owner); 234 addFacet(enumeration); 235 return enumeration; 236 } 237 238 public XsEEnumeration[] getEnumerations() { 239 if (facets == null) { 240 return new XsEEnumeration[0]; 241 } 242 List result = new ArrayList (); 243 for (int i = 0; i < facets.size(); i++) { 244 XsTFacetBase facet = (XsTFacetBase) facets.get(i); 245 if ("enumeration".equals(facet.getFacetName())) { 246 result.add(facet); 247 } 248 } 249 return (XsEEnumeration[]) result.toArray(new XsEEnumeration[result.size()]); 250 } 251 252 public boolean hasFacets() { 253 return facets != null && facets.size() > 0; 254 } 255 256 public XsTFacetBase[] getFacets() { 257 if (facets == null) { 258 return new XsEEnumeration[0]; 259 } 260 return (XsTFacetBase[]) facets.toArray(new XsTFacetBase[facets.size()]); 261 } 262 } 263 | Popular Tags |