View Javadoc

1   /********************************************************************************
2    * InternetCafe is a software solution that helps the management of Cybercafes 
3    * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4    * Copyright (C) 2006  Guido Angelo Ingenito
5   
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10  
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19   *******************************************************************************/
20  package base.user;
21  
22  import org.w3c.dom.Document;
23  import org.w3c.dom.Element;
24  import org.w3c.dom.Node;
25  
26  import base.ICXmlTags;
27  import base.IXMLSaveable;
28  
29  public class PhoneNumber implements IXMLSaveable {
30  
31  	private int id;
32  
33  	private String areaCode;
34  
35  	private String exchange;
36  
37  	private String number;
38  
39  	private String description;
40  
41  	/***
42  	 * @param id
43  	 * @param areaCode
44  	 * @param exchange
45  	 * @param number
46  	 */
47  	protected PhoneNumber(int id, String areaCode, String exchange,
48  			String number) {
49  		super();
50  		// TODO Auto-generated constructor stub
51  		this.id = id;
52  		this.areaCode = areaCode;
53  		this.exchange = exchange;
54  		this.number = number;
55  	}
56  
57  	/***
58  	 * @param id
59  	 * @param areaCode
60  	 * @param exchange
61  	 * @param number
62  	 * @param description
63  	 */
64  	protected PhoneNumber(int id, String areaCode, String exchange,
65  			String number, String description) {
66  		super();
67  		// TODO Auto-generated constructor stub
68  		this.id = id;
69  		this.areaCode = areaCode;
70  		this.exchange = exchange;
71  		this.number = number;
72  		this.description = description;
73  	}
74  
75  	public PhoneNumber() {
76  		// TODO Auto-generated constructor stub
77  	}
78  
79  	/***
80  	 * @return Returns the areaCode.
81  	 */
82  	public String getAreaCode() {
83  		return areaCode;
84  	}
85  
86  	/***
87  	 * @param areaCode
88  	 *            The areaCode to set.
89  	 */
90  	public void setAreaCode(String areaCode) {
91  		this.areaCode = areaCode;
92  	}
93  
94  	/***
95  	 * @return Returns the description.
96  	 */
97  	public String getDescription() {
98  		return description;
99  	}
100 
101 	/***
102 	 * @param description
103 	 *            The description to set.
104 	 */
105 	public void setDescription(String description) {
106 		this.description = description;
107 	}
108 
109 	/***
110 	 * @return Returns the exchange.
111 	 */
112 	public String getExchange() {
113 		return exchange;
114 	}
115 
116 	/***
117 	 * @param exchange
118 	 *            The exchange to set.
119 	 */
120 	public void setExchange(String exchange) {
121 		this.exchange = exchange;
122 	}
123 
124 	/***
125 	 * @return Returns the number.
126 	 */
127 	public String getNumber() {
128 		return number;
129 	}
130 
131 	/***
132 	 * @param number
133 	 *            The number to set.
134 	 */
135 	public void setNumber(String number) {
136 		this.number = number;
137 	}
138 
139 	/***
140 	 * @return Returns the id.
141 	 */
142 	public int getId() {
143 		return id;
144 	}
145 
146 	/***
147 	 * @param id
148 	 *            The id to set.
149 	 */
150 	protected void setId(int id) {
151 		this.id = id;
152 	}
153 
154 	public Node toXml(Document document) {
155 		Element phoneNumberElement = document
156 				.createElement(ICXmlTags.IC_PHONE_NUMBER_TAG);
157 		phoneNumberElement.setAttribute(ICXmlTags.IC_PHONE_NUMBER_ID_ATTRIBUTE,
158 				"" + this.id);
159 
160 		Element areaCodeElement = document
161 				.createElement(ICXmlTags.IC_PHONE_AREA_CODE_TAG);
162 		areaCodeElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
163 				this.areaCode);
164 		phoneNumberElement.appendChild(areaCodeElement);
165 
166 		Element exchangeElement = document
167 				.createElement(ICXmlTags.IC_PHONE_NUMBER_EXCHANGE_TAG);
168 		exchangeElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
169 				this.exchange);
170 		phoneNumberElement.appendChild(exchangeElement);
171 
172 		Element numberElement = document
173 				.createElement(ICXmlTags.IC_PHONE_NUMBER_NUMBER_TAG);
174 		numberElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.number);
175 		phoneNumberElement.appendChild(numberElement);
176 
177 		Element descriptionElement = document
178 				.createElement(ICXmlTags.IC_PHONE_NUMBER_DESCRIPTION_TAG);
179 		descriptionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
180 				this.description);
181 		phoneNumberElement.appendChild(descriptionElement);
182 
183 		return phoneNumberElement;
184 	}
185 
186 	public PhoneNumber fromXml(Node node) {
187 		int id = Integer.parseInt(node.getAttributes().getNamedItem(ICXmlTags.IC_PHONE_NUMBER_ID_ATTRIBUTE).getNodeValue());
188 
189 		String areaCode="";
190 		String exchange="";
191 		String number="";
192 		String description="";
193 		
194 		for(int i=0;i<node.getChildNodes().getLength();i++){
195 			if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_PHONE_AREA_CODE_TAG))
196 				areaCode = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();			
197 			if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_PHONE_NUMBER_EXCHANGE_TAG))
198 				exchange = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();			
199 			if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_PHONE_NUMBER_NUMBER_TAG))
200 				number = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();			
201 			if(node.getChildNodes().item(i).getNodeName().equalsIgnoreCase(ICXmlTags.IC_PHONE_NUMBER_DESCRIPTION_TAG))
202 				description = node.getChildNodes().item(i).getAttributes().getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE).getNodeValue();			
203 			
204 		}
205 		
206 		return new PhoneNumber(id, areaCode, exchange, number,description);
207 	}
208 
209 }