001package org.apache.commons.digester3.examples.xmlrules.addressbook; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020import java.util.ArrayList; 021import java.util.HashMap; 022import java.util.Iterator; 023import java.util.List; 024 025/** 026 * See Main.java. 027 */ 028public class Person 029{ 030 031 private int id; 032 033 private String category; 034 035 private String name; 036 037 private HashMap<String, String> emails = new HashMap<String, String>(); 038 039 private List<Address> addresses = new ArrayList<Address>(); 040 041 /** 042 * A unique id for this person. Note that the Digester automatically converts the id to an integer. 043 */ 044 public void setId( int id ) 045 { 046 this.id = id; 047 } 048 049 public void setCategory( String category ) 050 { 051 this.category = category; 052 } 053 054 public void setName( String name ) 055 { 056 this.name = name; 057 } 058 059 /** we assume only one email of each type... */ 060 public void addEmail( String type, String address ) 061 { 062 emails.put( type, address ); 063 } 064 065 public void addAddress( Address addr ) 066 { 067 addresses.add( addr ); 068 } 069 070 public void print() 071 { 072 System.out.println( "Person #" + id ); 073 System.out.println( " category=" + category ); 074 System.out.println( " name=" + name ); 075 076 for ( Iterator<String> i = emails.keySet().iterator(); i.hasNext(); ) 077 { 078 String type = i.next(); 079 String address = emails.get( type ); 080 081 System.out.println( " email (type " + type + ") : " + address ); 082 } 083 084 for ( Iterator<Address> i = addresses.iterator(); i.hasNext(); ) 085 { 086 Address addr = i.next(); 087 addr.print( System.out, 2 ); 088 } 089 } 090 091}