View Javadoc

1   /* $Id: Address.java 1102402 2011-05-12 18:03:26Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.digester3.annotations.employee;
19  
20  import org.apache.commons.digester3.annotations.rules.BeanPropertySetter;
21  import org.apache.commons.digester3.annotations.rules.ObjectCreate;
22  import org.apache.commons.digester3.annotations.rules.SetProperty;
23  import org.apache.commons.digester3.annotations.rules.SetTop;
24  
25  /**
26   * @since 2.1
27   */
28  @ObjectCreate( pattern = "employee/address" )
29  public class Address
30  {
31  
32      @BeanPropertySetter( pattern = "employee/address/city" )
33      private String city;
34  
35      @BeanPropertySetter( pattern = "employee/address/state" )
36      private String state;
37  
38      @BeanPropertySetter( pattern = "employee/address/street" )
39      private String street;
40  
41      @SetProperty( pattern = "employee/address", attributeName = "place" )
42      private String type;
43  
44      @BeanPropertySetter( pattern = "employee/address/zip-code" )
45      private String zipCode;
46  
47      @SetTop( pattern = "employee/address" )
48      public void setEmployee( Employee employee )
49      {
50          employee.addAddress( this );
51      }
52  
53      public String getCity()
54      {
55          return this.city;
56      }
57  
58      public void setCity( String city )
59      {
60          this.city = city;
61      }
62  
63      public String getState()
64      {
65          return this.state;
66      }
67  
68      public void setState( String state )
69      {
70          this.state = state;
71      }
72  
73      public String getStreet()
74      {
75          return this.street;
76      }
77  
78      public void setStreet( String street )
79      {
80          this.street = street;
81      }
82  
83      public String getType()
84      {
85          return this.type;
86      }
87  
88      public void setType( String type )
89      {
90          this.type = type;
91      }
92  
93      public String getZipCode()
94      {
95          return this.zipCode;
96      }
97  
98      public void setZipCode( String zipCode )
99      {
100         this.zipCode = zipCode;
101     }
102 
103     @Override
104     public boolean equals( Object obj )
105     {
106         if ( this == obj )
107             return true;
108         if ( obj == null )
109             return false;
110         if ( getClass() != obj.getClass() )
111             return false;
112         Address other = (Address) obj;
113         if ( this.city == null )
114         {
115             if ( other.getCity() != null )
116                 return false;
117         }
118         else if ( !this.city.equals( other.getCity() ) )
119             return false;
120         if ( this.state == null )
121         {
122             if ( other.getState() != null )
123                 return false;
124         }
125         else if ( !this.state.equals( other.getState() ) )
126             return false;
127         if ( this.street == null )
128         {
129             if ( other.getStreet() != null )
130                 return false;
131         }
132         else if ( !this.street.equals( other.getStreet() ) )
133             return false;
134         if ( this.type == null )
135         {
136             if ( other.getType() != null )
137                 return false;
138         }
139         else if ( !this.type.equals( other.getType() ) )
140             return false;
141         if ( this.zipCode == null )
142         {
143             if ( other.getZipCode() != null )
144                 return false;
145         }
146         else if ( !this.zipCode.equals( other.getZipCode() ) )
147             return false;
148         return true;
149     }
150 
151     @Override
152     public String toString()
153     {
154         return "Address [city=" + city + ", state=" + state + ", street=" + street + ", type=" + type + ", zipCode="
155             + zipCode + "]";
156     }
157 
158 }