View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 package com.sun.xml.registry.client.browser.registration; 11 12 import java.util.Collection; 13 import java.util.HashMap; 14 import java.util.Iterator; 15 import java.util.Map; 16 17 import javax.xml.registry.JAXRException; 18 import javax.xml.registry.infomodel.EmailAddress; 19 import javax.xml.registry.infomodel.User; 20 21 import com.sun.xml.registry.client.browser.swing.RegistryMappedModel; 22 23 /*** 24 * @author Fabian Ritzmann 25 */ 26 public class EmailAddressModel extends RegistryMappedModel { 27 28 public static final String[] EMAIL_TYPES = { 29 "Office email", 30 "Home email", 31 }; 32 33 private final User user; 34 private final Map addresses = new HashMap(); 35 36 37 EmailAddressModel(User u) { 38 super(EMAIL_TYPES[0]); 39 this.user = u; 40 } 41 42 43 /*** 44 * Method setAddress. 45 * @param emailType 46 * @param text 47 */ 48 public void setAddress(String address) 49 throws JAXRException { 50 51 address = address.trim(); 52 53 // Address already exists, just need to modify entry. 54 if (this.addresses.containsKey(this.key)) { 55 EmailAddress emailAddress = (EmailAddress) this.addresses.get(this.key); 56 emailAddress.setAddress(address); 57 } 58 // Create new address and add to user. 59 else { 60 EmailAddress emailAddress = 61 this.user.getLifeCycleManager().createEmailAddress(address, this.key); 62 this.addresses.put(this.key, emailAddress); 63 this.user.setEmailAddresses(this.addresses.values()); 64 } 65 } 66 67 68 public EmailAddress getAddress() { 69 EmailAddress address = (EmailAddress) this.addresses.get(this.key); 70 return address; 71 } 72 73 74 public void validate() throws JAXRException { 75 // Remove empty addresses 76 Collection addressSet = this.addresses.values(); 77 EmailAddress address = null; 78 Iterator i = addressSet.iterator(); 79 while (i.hasNext()) { 80 address = (EmailAddress) i.next(); 81 String emailAddress = address.getAddress(); 82 if ((emailAddress == null) || (emailAddress.length() == 0)) { 83 this.addresses.remove(address.getType()); 84 } 85 } 86 this.user.setEmailAddresses(this.addresses.values()); 87 88 // Check if at least one address is set. 89 if (this.addresses.isEmpty()) { 90 throw new JAXRException("Missing required EmailAddress on User"); 91 } 92 } 93 94 }

This page was automatically generated by Maven