View Javadoc

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