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://commons.apache.org/'>Apache Commons Team</a> 029 * @version $Revision: 561314 $ 030 */ 031 public class LocalComplexType extends ComplexType { 032 033 034 public LocalComplexType() {} 035 036 public LocalComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException { 037 super(configuration, elementDescriptor, schema); 038 } 039 040 public boolean equals(Object obj) { 041 boolean result = false; 042 if (obj instanceof GlobalComplexType) { 043 GlobalComplexType complexType = (GlobalComplexType) obj; 044 result = 045 equalContents(attributes, complexType.attributes) && 046 equalContents(elements, complexType.elements); 047 048 } 049 return result; 050 } 051 052 053 private boolean equalContents(Collection one, Collection two) 054 { 055 // doesn't check cardinality but should be ok 056 if (one.size() != two.size()) { 057 return false; 058 } 059 for (Iterator it=one.iterator();it.hasNext();) { 060 Object object = it.next(); 061 if (!two.contains(object)) { 062 return false; 063 } 064 } 065 return true; 066 } 067 068 public int hashCode() { 069 return 0; 070 } 071 072 /** 073 * Null safe equals method 074 * @param one 075 * @param two 076 * @return 077 */ 078 private boolean isEqual(String one, String two) { 079 boolean result = false; 080 if (one == null) { 081 result = (two == null); 082 } 083 else 084 { 085 result = one.equals(two); 086 } 087 088 return result; 089 } 090 091 public String toString() { 092 StringBuffer buffer = new StringBuffer(); 093 buffer.append("<xsd:complexType>"); 094 buffer.append("<xsd:sequence>"); 095 for (Iterator it=elements.iterator(); it.hasNext();) { 096 buffer.append(it.next()); 097 } 098 buffer.append("</xsd:sequence>"); 099 100 for (Iterator it=attributes.iterator(); it.hasNext();) { 101 buffer.append(it.next()); 102 } 103 buffer.append("</xsd:complexType>"); 104 return buffer.toString(); 105 } 106 }