/ws-jaxme-0.5.2/src/xs/org/apache/ws/jaxme/xs/xml/impl/XsEListImpl.java

# · Java · 95 lines · 42 code · 10 blank · 43 comment · 10 complexity · d2044e1165a3156711a688a2b500dbf6 MD5 · raw file

  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. package org.apache.ws.jaxme.xs.xml.impl;
  17. import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
  18. import org.apache.ws.jaxme.xs.xml.*;
  19. import org.xml.sax.SAXException;
  20. /** <p>Implementation of <code>xs:list</code>, following
  21. * the specification below:
  22. * <pre>
  23. * &lt;xs:element name="list" id="list"&gt;
  24. * &lt;xs:complexType&gt;
  25. * &lt;xs:annotation&gt;
  26. * &lt;xs:documentation
  27. * source="http://www.w3.org/TR/xmlschema-2/#element-list"&gt;
  28. * itemType attribute and simpleType child are mutually
  29. * exclusive, but one or other is required
  30. * &lt;/xs:documentation&gt;
  31. * &lt;/xs:annotation&gt;
  32. * &lt;xs:complexContent&gt;
  33. * &lt;xs:extension base="xs:annotated"&gt;
  34. * &lt;xs:sequence&gt;
  35. * &lt;xs:element name="simpleType" type="xs:localSimpleType"
  36. * minOccurs="0"/&gt;
  37. * &lt;/xs:sequence&gt;
  38. * &lt;xs:attribute name="itemType" type="xs:QName" use="optional"/&gt;
  39. * &lt;/xs:extension&gt;
  40. * &lt;/xs:complexContent&gt;
  41. * &lt;/xs:complexType&gt;
  42. * &lt;/xs:element&gt;
  43. * </pre></p>
  44. *
  45. * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
  46. */
  47. public class XsEListImpl extends XsTAnnotatedImpl implements XsEList {
  48. private XsQName itemType;
  49. private XsTLocalSimpleType simpleType;
  50. protected XsEListImpl(XsObject pParent) {
  51. super(pParent);
  52. }
  53. public void setItemType(XsQName pItemType) {
  54. if (simpleType != null) {
  55. throw new IllegalStateException("The 'itemType' attribute and the 'simpleType' child element are mutually exclusive.");
  56. }
  57. itemType = pItemType;
  58. }
  59. public void setItemType(String pItemType) throws SAXException {
  60. setItemType(asXsQName(pItemType));
  61. }
  62. public XsQName getItemType() {
  63. return itemType;
  64. }
  65. public XsTLocalSimpleType createSimpleType() {
  66. if (itemType != null) {
  67. throw new IllegalStateException("The 'itemType' attribute and the 'simpleType' child element are mutually exclusive.");
  68. }
  69. if (simpleType != null) {
  70. throw new IllegalStateException("Multiple 'simpleType' child elements are forbidden.");
  71. }
  72. return simpleType = getObjectFactory().newXsTLocalSimpleType(this);
  73. }
  74. public XsTLocalSimpleType getSimpleType() {
  75. return simpleType;
  76. }
  77. public void validate() throws SAXException {
  78. super.validate();
  79. if (itemType == null && simpleType == null) {
  80. throw new LocSAXException("Either the 'itemType' attribute must be set or a 'simpleType' child element must be present.",
  81. getLocator());
  82. }
  83. }
  84. }