1 16 17 package org.apache.commons.betwixt.schema; 18 19 import java.beans.IntrospectionException ; 20 import java.util.Iterator ; 21 import java.util.Collection ; 22 23 import org.apache.commons.betwixt.ElementDescriptor; 24 25 31 public class GlobalComplexType extends ComplexType { 32 33 private String name; 34 35 public GlobalComplexType() {} 36 37 41 public GlobalComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException { 42 super(configuration, elementDescriptor, schema); 43 } 44 45 protected void init(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException { 46 setName(elementDescriptor.getPropertyType().getName()); 47 super.init(configuration, elementDescriptor, schema); 48 } 49 50 54 public String getName() { 55 return name; 56 } 57 58 62 public void setName(String string) { 63 name = string; 64 } 65 66 public boolean equals(Object obj) { 67 boolean result = false; 68 if (obj instanceof GlobalComplexType) { 69 GlobalComplexType complexType = (GlobalComplexType) obj; 70 result = isEqual(name, complexType.name) && 71 equalContents(attributes, complexType.attributes) && 72 equalContents(elements, complexType.elements); 73 74 } 75 return result; 76 } 77 78 public int hashCode() { 79 return 0; 80 } 81 82 private boolean equalContents(Collection one, Collection two) 83 { 84 if (one.size() != two.size()) { 86 return false; 87 } 88 for (Iterator it=one.iterator();it.hasNext();) { 89 Object object = it.next(); 90 if (!two.contains(object)) { 91 return false; 92 } 93 } 94 return true; 95 } 96 97 103 private boolean isEqual(String one, String two) { 104 boolean result = false; 105 if (one == null) { 106 result = (two == null); 107 } 108 else 109 { 110 result = one.equals(two); 111 } 112 113 return result; 114 } 115 116 public String toString() { 117 StringBuffer buffer = new StringBuffer (); 118 buffer.append("<xsd:complexType name='"); 119 buffer.append(name); 120 buffer.append("'>"); 121 buffer.append("<xsd:sequence>"); 122 for (Iterator it=elements.iterator(); it.hasNext();) { 123 buffer.append(it.next()); 124 } 125 buffer.append("</xsd:sequence>"); 126 127 for (Iterator it=attributes.iterator(); it.hasNext();) { 128 buffer.append(it.next()); 129 } 130 buffer.append("</xsd:complexType>"); 131 return buffer.toString(); 132 } 133 } 134 | Popular Tags |