001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.betwixt.schema;
019:
020: import java.beans.IntrospectionException;
021: import java.util.Collection;
022: import java.util.Iterator;
023:
024: import org.apache.commons.betwixt.ElementDescriptor;
025:
026: /**
027: * Models a local <code>complexType</code> definition.
028: * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
029: * @version $Revision: 438373 $
030: */
031: public class LocalComplexType extends ComplexType {
032:
033: public LocalComplexType() {
034: }
035:
036: public LocalComplexType(TranscriptionConfiguration configuration,
037: ElementDescriptor elementDescriptor, Schema schema)
038: throws IntrospectionException {
039: super (configuration, elementDescriptor, schema);
040: }
041:
042: public boolean equals(Object obj) {
043: boolean result = false;
044: if (obj instanceof GlobalComplexType) {
045: GlobalComplexType complexType = (GlobalComplexType) obj;
046: result = equalContents(attributes, complexType.attributes)
047: && equalContents(elements, complexType.elements);
048:
049: }
050: return result;
051: }
052:
053: private boolean equalContents(Collection one, Collection two) {
054: // doesn't check cardinality but should be ok
055: if (one.size() != two.size()) {
056: return false;
057: }
058: for (Iterator it = one.iterator(); it.hasNext();) {
059: Object object = it.next();
060: if (!two.contains(object)) {
061: return false;
062: }
063: }
064: return true;
065: }
066:
067: public int hashCode() {
068: return 0;
069: }
070:
071: /**
072: * Null safe equals method
073: * @param one
074: * @param two
075: * @return
076: */
077: private boolean isEqual(String one, String two) {
078: boolean result = false;
079: if (one == null) {
080: result = (two == null);
081: } else {
082: result = one.equals(two);
083: }
084:
085: return result;
086: }
087:
088: public String toString() {
089: StringBuffer buffer = new StringBuffer();
090: buffer.append("<xsd:complexType>");
091: buffer.append("<xsd:sequence>");
092: for (Iterator it = elements.iterator(); it.hasNext();) {
093: buffer.append(it.next());
094: }
095: buffer.append("</xsd:sequence>");
096:
097: for (Iterator it = attributes.iterator(); it.hasNext();) {
098: buffer.append(it.next());
099: }
100: buffer.append("</xsd:complexType>");
101: return buffer.toString();
102: }
103: }
|