1. /*
  2. * Copyright 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.commons.betwixt.schema;
  17. import java.beans.IntrospectionException;
  18. import java.util.Iterator;
  19. import java.util.Collection;
  20. import org.apache.commons.betwixt.ElementDescriptor;
  21. /**
  22. * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
  23. * @version $Revision: 1.2.2.1 $
  24. */
  25. public class LocalComplexType extends ComplexType {
  26. public LocalComplexType() {}
  27. public LocalComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
  28. super(configuration, elementDescriptor, schema);
  29. }
  30. public boolean equals(Object obj) {
  31. boolean result = false;
  32. if (obj instanceof GlobalComplexType) {
  33. GlobalComplexType complexType = (GlobalComplexType) obj;
  34. result =
  35. equalContents(attributes, complexType.attributes) &&
  36. equalContents(elements, complexType.elements);
  37. }
  38. return result;
  39. }
  40. private boolean equalContents(Collection one, Collection two)
  41. {
  42. // doesn't check cardinality but should be ok
  43. if (one.size() != two.size()) {
  44. return false;
  45. }
  46. for (Iterator it=one.iterator();it.hasNext();) {
  47. Object object = it.next();
  48. if (!two.contains(object)) {
  49. return false;
  50. }
  51. }
  52. return true;
  53. }
  54. public int hashCode() {
  55. return 0;
  56. }
  57. /**
  58. * Null safe equals method
  59. * @param one
  60. * @param two
  61. * @return
  62. */
  63. private boolean isEqual(String one, String two) {
  64. boolean result = false;
  65. if (one == null) {
  66. result = (two == null);
  67. }
  68. else
  69. {
  70. result = one.equals(two);
  71. }
  72. return result;
  73. }
  74. public String toString() {
  75. StringBuffer buffer = new StringBuffer();
  76. buffer.append("<xsd:complexType>");
  77. buffer.append("<xsd:sequence>");
  78. for (Iterator it=elements.iterator(); it.hasNext();) {
  79. buffer.append(it.next());
  80. }
  81. buffer.append("</xsd:sequence>");
  82. for (Iterator it=attributes.iterator(); it.hasNext();) {
  83. buffer.append(it.next());
  84. }
  85. buffer.append("</xsd:complexType>");
  86. return buffer.toString();
  87. }
  88. }