View Javadoc

1   /* $Id: Person.java 1127117 2011-05-24 15:28:41Z 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.person;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.apache.commons.digester3.annotations.rules.BeanPropertySetter;
24  import org.apache.commons.digester3.annotations.rules.CallMethod;
25  import org.apache.commons.digester3.annotations.rules.CallParam;
26  import org.apache.commons.digester3.annotations.rules.ObjectCreate;
27  import org.apache.commons.digester3.annotations.rules.SetProperty;
28  
29  /**
30   * @since 2.1
31   */
32  @ObjectCreate( pattern = "person" )
33  public class Person
34  {
35  
36      private final Map<String, String> emails = new HashMap<String, String>();
37  
38      @SetProperty( pattern = "person" )
39      private int id;
40  
41      @SetProperty( pattern = "person" )
42      private String category;
43  
44      @BeanPropertySetter( pattern = "person/name" )
45      private String name;
46  
47      @CallMethod( pattern = "person/email" )
48      public void addEmail( @CallParam( pattern = "person/email", attributeName = "type" ) String type,
49                            @CallParam( pattern = "person/email" ) String address )
50      {
51          this.emails.put( type, address );
52      }
53  
54      public int getId()
55      {
56          return id;
57      }
58  
59      public void setId( int id )
60      {
61          this.id = id;
62      }
63  
64      public String getCategory()
65      {
66          return category;
67      }
68  
69      public void setCategory( String category )
70      {
71          this.category = category;
72      }
73  
74      public String getName()
75      {
76          return name;
77      }
78  
79      public void setName( String name )
80      {
81          this.name = name;
82      }
83  
84      public Map<String, String> getEmails()
85      {
86          return emails;
87      }
88  
89      @Override
90      public boolean equals( Object obj )
91      {
92          if ( this == obj )
93              return true;
94          if ( obj == null )
95              return false;
96          if ( getClass() != obj.getClass() )
97              return false;
98          Person other = (Person) obj;
99          if ( category == null )
100         {
101             if ( other.category != null )
102                 return false;
103         }
104         else if ( !category.equals( other.category ) )
105             return false;
106         if ( emails == null )
107         {
108             if ( other.emails != null )
109                 return false;
110         }
111         else if ( !emails.equals( other.emails ) )
112             return false;
113         if ( id != other.id )
114             return false;
115         if ( name == null )
116         {
117             if ( other.name != null )
118                 return false;
119         }
120         else if ( !name.equals( other.name ) )
121             return false;
122         return true;
123     }
124 
125     @Override
126     public String toString()
127     {
128         return "Person [category=" + category + ", emails=" + emails + ", id=" + id + ", name=" + name + "]";
129     }
130 
131 }