View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */ 
17  
18  package org.apache.commons.betwixt.schema;
19  
20  import java.beans.IntrospectionException;
21  import java.util.Collection;
22  import java.util.Iterator;
23  
24  import org.apache.commons.betwixt.ElementDescriptor;
25  
26  /**
27   * Models a local <code>complexType</code> definition.
28   * @author <a href='http://commons.apache.org/'>Apache Commons Team</a>
29   * @version $Revision: 561314 $
30   */
31  public class LocalComplexType extends ComplexType {
32  
33  
34      public LocalComplexType() {}
35  
36      public LocalComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
37          super(configuration, elementDescriptor, schema);   
38      }
39  
40      public boolean equals(Object obj) {
41            boolean result = false;
42            if (obj instanceof GlobalComplexType) {
43                GlobalComplexType complexType = (GlobalComplexType) obj;
44                result =  
45                          equalContents(attributes, complexType.attributes) &&
46                          equalContents(elements, complexType.elements);
47                                     
48            }
49            return result;
50        }
51  
52      
53      private boolean equalContents(Collection one, Collection two)
54      {
55          // doesn't check cardinality but should be ok
56          if (one.size() != two.size()) {
57              return false;
58          }
59          for (Iterator it=one.iterator();it.hasNext();) {
60              Object object = it.next();
61              if (!two.contains(object)) {
62                  return false;
63              }
64          }
65          return true;
66      }
67  
68      public int hashCode() {
69          return 0;
70      }
71  
72        /**
73         * Null safe equals method
74         * @param one
75         * @param two
76         * @return
77         */
78        private boolean isEqual(String one, String two) {
79            boolean result = false;
80            if (one == null) {
81                result = (two == null); 
82            }
83            else
84            {
85                result = one.equals(two);
86            }
87          
88            return result;
89        }
90        
91        public String toString() {
92            StringBuffer buffer = new StringBuffer();
93            buffer.append("<xsd:complexType>");
94            buffer.append("<xsd:sequence>");
95            for (Iterator it=elements.iterator(); it.hasNext();) {
96                  buffer.append(it.next());    
97            }
98            buffer.append("</xsd:sequence>");
99            
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 }