001    /*-----------------------------------------------------------------------
002     *  Copyright (C) 2006
003     *  Associated Universities, Inc. Washington DC, USA.
004     *  This program is free software; you can redistribute it and/or
005     *  modify it under the terms of the GNU General Public License as
006     *  published by the Free Software Foundation; either version 2 of
007     *  the License, or (at your option) any later version.
008     *
009     *  This program is distributed in the hope that it will be useful,
010     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
011     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     *  GNU General Public License for more details.
013     *
014     *  Correspondence concerning this software should be addressed as follows:
015     *         Internet email: switz@nrao.edu
016     *         Postal address: User Database
017     *                         National Radio Astronomy Observatory
018     *                         Post Office Box 0
019     *                         Socorro, NM 87801  USA
020     *-----------------------------------------------------------------------*/
021    package edu.nrao.sss.model.user;
022    
023    import edu.nrao.sss.xml.XMLTransform;
024    
025    public class Fax extends Contact implements XMLable {
026    
027            private static final long serialVersionUID = 1L;
028    
029            private String contactValue;
030    
031            public Fax() {
032                    super();
033                    this.contactType = ContactType.FAX;
034            }
035    
036            public Fax(Fax fax) {
037                    copy(fax);
038            }
039            
040            public void copy(Fax fax) {
041                    super.copy(fax);
042                    set(fax);
043            }
044    
045            public boolean equals(Object obj) {
046                    if (null == obj)
047                            return false;
048                    if (!(obj instanceof Fax))
049                            return false;
050                    else {
051                            Fax mObj = (Fax) obj;
052                            return (this.getId() == mObj.getId());
053                    }
054            }
055    
056            public String getContactValue() {
057                    return contactValue;
058            }
059    
060            public void set(Fax fax) {
061                    this.setContactValue(fax.getContactValue());
062            }
063    
064            public void setContactValue(String contactValue) {
065                    this.contactValue = contactValue;
066            }
067    
068            public final String toXML() {
069                    StringBuffer result = new StringBuffer();
070                    if (isDefaultContact()) {
071                            result.append("<default-fax-number number=\"");
072                    } else {
073                            result.append("<additional-fax-number number=\"");
074                    }
075                    result.append(XMLTransform.encode(getContactValue()) + "\">\n");
076                    result.append("<description>"
077                                    + XMLTransform.encode(getContactDescription())
078                                    + "</description>\n");
079                    if (isDefaultContact()) {
080                            result.append("</default-fax-number>\n");
081                    } else {
082                            result.append("</additional-fax-number>\n");
083                    }
084                    return result.toString();
085            }
086    
087    }