KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > schema > LocalComplexType


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 JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Collection JavaDoc;
22
23 import org.apache.commons.betwixt.ElementDescriptor;
24
25 /**
26  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
27  * @version $Revision: 1.2.2.1 $
28  */

29 public class LocalComplexType extends ComplexType {
30
31
32     public LocalComplexType() {}
33
34     public LocalComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException JavaDoc {
35         super(configuration, elementDescriptor, schema);
36     }
37
38     public boolean equals(Object JavaDoc obj) {
39           boolean result = false;
40           if (obj instanceof GlobalComplexType) {
41               GlobalComplexType complexType = (GlobalComplexType) obj;
42               result =
43                         equalContents(attributes, complexType.attributes) &&
44                         equalContents(elements, complexType.elements);
45                                    
46           }
47           return result;
48       }
49
50     
51     private boolean equalContents(Collection JavaDoc one, Collection JavaDoc two)
52     {
53         // doesn't check cardinality but should be ok
54
if (one.size() != two.size()) {
55             return false;
56         }
57         for (Iterator JavaDoc it=one.iterator();it.hasNext();) {
58             Object JavaDoc object = it.next();
59             if (!two.contains(object)) {
60                 return false;
61             }
62         }
63         return true;
64     }
65
66     public int hashCode() {
67         return 0;
68     }
69
70       /**
71        * Null safe equals method
72        * @param one
73        * @param two
74        * @return
75        */

76       private boolean isEqual(String JavaDoc one, String JavaDoc two) {
77           boolean result = false;
78           if (one == null) {
79               result = (two == null);
80           }
81           else
82           {
83               result = one.equals(two);
84           }
85         
86           return result;
87       }
88       
89       public String JavaDoc toString() {
90           StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
91           buffer.append("<xsd:complexType>");
92           buffer.append("<xsd:sequence>");
93           for (Iterator JavaDoc it=elements.iterator(); it.hasNext();) {
94                 buffer.append(it.next());
95           }
96           buffer.append("</xsd:sequence>");
97           
98           for (Iterator JavaDoc it=attributes.iterator(); it.hasNext();) {
99                 buffer.append(it.next());
100           }
101           buffer.append("</xsd:complexType>");
102           return buffer.toString();
103       }
104 }
105
Popular Tags