1 /* 2 * jSDP: A Java implementation of SDP protocol Copyright (C) 2007 Claudio Di 3 * Vita 4 */ 5 package net.sourceforge.jsdp; 6 7 import net.sourceforge.jsdp.util.Contact; 8 9 /** 10 * An <tt>Email</tt> represents an <b>e=<i><field value></i></b> 11 * field contained in a SDP message. An email field specify contact information 12 * for the person responsible for the conference. This is not necessarily the 13 * same person that created the conference announcement. 14 * 15 * @since 0.1.0 16 * 17 * @version 1.0 18 * 19 * @author <a href="mailto:cdivita@users.sourceforge.net">Claudio Di Vita</a> 20 */ 21 public class Email implements Field { 22 23 /** The class Stream Unique Identifier, SUID */ 24 private static final long serialVersionUID = 3055937612221619818L; 25 26 /** The field contact information */ 27 protected Contact contact; 28 29 /** 30 * Creates a new <tt>Email</tt>. 31 */ 32 protected Email() { 33 34 super(); 35 } 36 37 /** 38 * Creates a new <tt>Email</tt>. 39 * 40 * @param info the field contact information 41 * 42 * @throws SDPException if the contact information are not valid 43 */ 44 public Email(final String info) throws SDPException { 45 46 super(); 47 48 this.contact = new Contact(info); 49 } 50 51 /** 52 * Parse an input string and constructs the equivalent email field. 53 * 54 * @param field the string to parse 55 * 56 * @return a new <tt>Email</tt> instance 57 * 58 * @throws SDPParseException if an error occurs while parsing 59 */ 60 public static Email parse(final String field) throws SDPParseException { 61 62 if (!field.startsWith("e=")) { 63 throw new SDPParseException("The string \"" + field + "\" isn't an email field"); 64 } 65 66 Email e = null; 67 68 try { 69 e = new Email(field.substring(2)); 70 } 71 catch (SDPException parseException) { 72 throw new SDPParseException("The string \"" + field + "\" isn't a valid email field", parseException); 73 } 74 75 return e; 76 } 77 78 /* 79 * (non-Javadoc) 80 * 81 * @see java.lang.Object#clone() 82 */ 83 public Object clone() { 84 85 Email field = new Email(); 86 field.contact = (Contact) this.contact.clone(); 87 88 return field; 89 } 90 91 /** 92 * Returns the e-mail address of the contact. 93 * 94 * @return a string that represensts an e-mail address 95 */ 96 public String getEmail() { 97 98 return contact.getAddress(); 99 } 100 101 /** 102 * Returns the personal information of the contact. 103 * 104 * @return the personal information of the contact 105 */ 106 public String getPersonal() { 107 108 return contact.getPersonal(); 109 } 110 111 /** 112 * Returns the type character for the field. 113 * 114 * @return the field type character: <b>e</b> 115 */ 116 public char getType() { 117 118 return Field.EMAIL_FIELD; 119 } 120 121 /** 122 * Sets the e-mail address of the contact. 123 * 124 * @param email the e-mail address to set 125 * 126 * @throws SDPException if the em-mail address is not valid 127 */ 128 public void setEmail(final String email) throws SDPException { 129 130 contact.setAddress(email); 131 } 132 133 /** 134 * Sets the personal information of the contact 135 * 136 * @param personal the personal information to set 137 * 138 * @throws SDPException if the personal information are not valid 139 */ 140 public void setPersonal(final String personal) throws SDPException { 141 142 contact.setPersonal(personal); 143 } 144 145 /** 146 * Returns a string representation of the field. The representation has the 147 * form: <b>e=<i><e-mail></i> <i><info></i></b> 148 * 149 * @return The string representation of the field 150 */ 151 public String toString() { 152 153 return getType() + "=" + contact.toString(); 154 } 155 }