001/* $Id: Person.java 1127117 2011-05-24 15:28:41Z simonetripodi $
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements.  See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.commons.digester3.annotations.person;
019
020import java.util.HashMap;
021import java.util.Map;
022
023import org.apache.commons.digester3.annotations.rules.BeanPropertySetter;
024import org.apache.commons.digester3.annotations.rules.CallMethod;
025import org.apache.commons.digester3.annotations.rules.CallParam;
026import org.apache.commons.digester3.annotations.rules.ObjectCreate;
027import org.apache.commons.digester3.annotations.rules.SetProperty;
028
029/**
030 * @since 2.1
031 */
032@ObjectCreate( pattern = "person" )
033public class Person
034{
035
036    private final Map<String, String> emails = new HashMap<String, String>();
037
038    @SetProperty( pattern = "person" )
039    private int id;
040
041    @SetProperty( pattern = "person" )
042    private String category;
043
044    @BeanPropertySetter( pattern = "person/name" )
045    private String name;
046
047    @CallMethod( pattern = "person/email" )
048    public void addEmail( @CallParam( pattern = "person/email", attributeName = "type" ) String type,
049                          @CallParam( pattern = "person/email" ) String address )
050    {
051        this.emails.put( type, address );
052    }
053
054    public int getId()
055    {
056        return id;
057    }
058
059    public void setId( int id )
060    {
061        this.id = id;
062    }
063
064    public String getCategory()
065    {
066        return category;
067    }
068
069    public void setCategory( String category )
070    {
071        this.category = category;
072    }
073
074    public String getName()
075    {
076        return name;
077    }
078
079    public void setName( String name )
080    {
081        this.name = name;
082    }
083
084    public Map<String, String> getEmails()
085    {
086        return emails;
087    }
088
089    @Override
090    public boolean equals( Object obj )
091    {
092        if ( this == obj )
093            return true;
094        if ( obj == null )
095            return false;
096        if ( getClass() != obj.getClass() )
097            return false;
098        Person other = (Person) obj;
099        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}