KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > encoding > AttributeBean


1 /*
2  * Copyright 2001-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 test.encoding;
18
19 import org.apache.axis.description.AttributeDesc;
20 import org.apache.axis.description.ElementDesc;
21 import org.apache.axis.description.FieldDesc;
22 import org.apache.axis.description.TypeDesc;
23
24 import javax.xml.namespace.QName JavaDoc;
25
26 /**
27  * Simple Java Bean with fields that should be serialized as attributes
28  */

29 public class AttributeBean extends ParentBean {
30     private int age;
31     private float iD;
32     public String JavaDoc company; // element without getter/setter
33
private java.lang.String JavaDoc name; // attribute
34
private boolean male; // attribute
35

36     public AttributeBean() {}
37     
38     public AttributeBean(int age, float iD, String JavaDoc name, String JavaDoc company, boolean male) {
39         this.age = age;
40         this.iD = iD;
41         this.name = name;
42         this.male = male;
43         this.company = company;
44     }
45     
46     public int getAge() {
47         return age;
48     }
49     
50     public void setAge(int age) {
51         this.age = age;
52     }
53     
54     public float getID() {
55         return iD;
56     }
57     
58     public void setID(float iD) {
59         this.iD = iD;
60     }
61     
62     public java.lang.String JavaDoc getName() {
63         return name;
64     }
65     
66     public void setName(java.lang.String JavaDoc name) {
67         this.name = name;
68     }
69     
70     public boolean getMale() {
71         return male;
72     }
73     
74     public void setMale(boolean male) {
75         this.male = male;
76     }
77
78     public boolean equals(Object JavaDoc obj)
79     {
80         if (obj == null || !(obj instanceof AttributeBean))
81             return false;
82         AttributeBean other = (AttributeBean)obj;
83         if (other.getAge() != age)
84             return false;
85         if (other.getID() != iD)
86             return false;
87         if (other.getMale() != male)
88             return false;
89         if (name == null) {
90             if (other.getName() != null) {
91                 return false;
92             }
93         }else if (!name.equals(other.getName())) {
94             return false;
95         }
96         if (company == null) {
97             if (other.company != null) {
98                 return false;
99             }
100         } else if (!company.equals(other.company)) {
101             return false;
102         }
103         if (getParentFloat() != other.getParentFloat())
104             return false;
105         if (getParentStr() != null) {
106             return getParentStr().equals(other.getParentStr());
107         }
108         return other.getParentStr() == null;
109     }
110
111     // Type metadata
112
private static TypeDesc typeDesc;
113     
114     static {
115         typeDesc = new TypeDesc(AttributeBean.class);
116         FieldDesc field;
117
118         // An attribute with a specified QName
119
field = new AttributeDesc();
120         field.setFieldName("name");
121         field.setXmlName(new QName JavaDoc("foo", "nameAttr"));
122         typeDesc.addFieldDesc(field);
123
124         // An attribute with a default QName
125
field = new AttributeDesc();
126         field.setFieldName("male");
127         typeDesc.addFieldDesc(field);
128
129         // An element with a specified QName
130
field = new ElementDesc();
131         field.setFieldName("age");
132         field.setXmlName(new QName JavaDoc("foo", "ageElement"));
133         typeDesc.addFieldDesc(field);
134     }
135     
136     public static TypeDesc getTypeDesc()
137     {
138         return typeDesc;
139     }
140 }
141
Popular Tags