svn-gvsig-desktop / trunk / libraries / libIverUtiles / src / com / iver / utiles / XMLEntity.java @ 1836
History | View | Annotate | Download (19.5 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.utiles; |
42 |
|
43 |
import com.iver.utiles.xmlEntity.generate.Property; |
44 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
45 |
|
46 |
|
47 |
/**
|
48 |
* Adaptador de las llamadas a sus m?todos sobre los generados por castor para
|
49 |
* generar despu?s los XML.
|
50 |
*
|
51 |
* @author Vicente Caballero Navarro
|
52 |
*/
|
53 |
public class XMLEntity { |
54 |
private XmlTag xmltag;
|
55 |
|
56 |
/**
|
57 |
* Crea un nuevo XMLEntity.
|
58 |
*
|
59 |
* @param tag DOCUMENT ME!
|
60 |
*/
|
61 |
public XMLEntity(XmlTag tag) {
|
62 |
xmltag = tag; |
63 |
} |
64 |
|
65 |
/**
|
66 |
* Crea un nuevo XMLEntity.
|
67 |
*/
|
68 |
public XMLEntity() {
|
69 |
xmltag = new XmlTag();
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* A?ade una propiedad con un String como clave y un String como valor.
|
74 |
*
|
75 |
* @param key clave.
|
76 |
* @param value valor.
|
77 |
*/
|
78 |
public void putProperty(String key, String value) { |
79 |
if ((key == null)) { |
80 |
return;
|
81 |
} |
82 |
|
83 |
Property p = new Property();
|
84 |
p.setKey(key); |
85 |
p.setValue(value); |
86 |
putProperty(p); |
87 |
} |
88 |
|
89 |
/**
|
90 |
* A?ade una propiedad con un String como clave y un Object como valor.
|
91 |
*
|
92 |
* @param key clave.
|
93 |
* @param value valor.
|
94 |
*/
|
95 |
public void putProperty(String key, Object value) { |
96 |
String ret = ""; |
97 |
|
98 |
if (key == null) { |
99 |
return;
|
100 |
} |
101 |
|
102 |
Class valueClass = value.getClass();
|
103 |
|
104 |
if (valueClass.isArray()) {
|
105 |
Class compType = valueClass.getComponentType();
|
106 |
|
107 |
if (compType == byte.class) { |
108 |
byte[] array = (byte[]) value; |
109 |
|
110 |
if (!(array.length == 0)) { |
111 |
ret += ("" + array[0]).replaceAll("[,]", "\\\\,"); |
112 |
|
113 |
for (int i = 1; i < array.length; i++) { |
114 |
ret += (" ," +
|
115 |
("" + array[i]).replaceAll("[,]", "\\\\,")); |
116 |
} |
117 |
} |
118 |
} else if (compType == short.class) { |
119 |
short[] array = (short[]) value; |
120 |
|
121 |
if (!(array.length == 0)) { |
122 |
ret += ("" + array[0]).replaceAll("[,]", "\\\\,"); |
123 |
|
124 |
for (int i = 1; i < array.length; i++) { |
125 |
ret += (" ," +
|
126 |
("" + array[i]).replaceAll("[,]", "\\\\,")); |
127 |
} |
128 |
} |
129 |
} else if (compType == int.class) { |
130 |
int[] array = (int[]) value; |
131 |
|
132 |
if (!(array.length == 0)) { |
133 |
ret += ("" + array[0]).replaceAll("[,]", "\\\\,"); |
134 |
|
135 |
for (int i = 1; i < array.length; i++) { |
136 |
ret += (" ," +
|
137 |
("" + array[i]).replaceAll("[,]", "\\\\,")); |
138 |
} |
139 |
} |
140 |
} else if (compType == long.class) { |
141 |
long[] array = (long[]) value; |
142 |
|
143 |
if (!(array.length == 0)) { |
144 |
ret += ("" + array[0]).replaceAll("[,]", "\\\\,"); |
145 |
|
146 |
for (int i = 1; i < array.length; i++) { |
147 |
ret += (" ," +
|
148 |
("" + array[i]).replaceAll("[,]", "\\\\,")); |
149 |
} |
150 |
} |
151 |
} else if (compType == float.class) { |
152 |
float[] array = (float[]) value; |
153 |
|
154 |
if (!(array.length == 0)) { |
155 |
ret += ("" + array[0]).replaceAll("[,]", "\\\\,"); |
156 |
|
157 |
for (int i = 1; i < array.length; i++) { |
158 |
ret += (" ," +
|
159 |
("" + array[i]).replaceAll("[,]", "\\\\,")); |
160 |
} |
161 |
} |
162 |
} else if (compType == double.class) { |
163 |
double[] array = (double[]) value; |
164 |
|
165 |
if (!(array.length == 0)) { |
166 |
ret += ("" + array[0]).replaceAll("[,]", "\\\\,"); |
167 |
|
168 |
for (int i = 1; i < array.length; i++) { |
169 |
ret += (" ," +
|
170 |
("" + array[i]).replaceAll("[,]", "\\\\,")); |
171 |
} |
172 |
} |
173 |
} else if (compType == boolean.class) { |
174 |
boolean[] array = (boolean[]) value; |
175 |
|
176 |
if (!(array.length == 0)) { |
177 |
ret += ("" + array[0]).replaceAll("[,]", "\\\\,"); |
178 |
|
179 |
for (int i = 1; i < array.length; i++) { |
180 |
ret += (" ," +
|
181 |
("" + array[i]).replaceAll("[,]", "\\\\,")); |
182 |
} |
183 |
} |
184 |
} else if (compType == String.class) { |
185 |
String[] array = (String[]) value; |
186 |
|
187 |
if (!(array.length == 0)) { |
188 |
if (array[0] == null) { |
189 |
array[0] = "null"; |
190 |
} |
191 |
|
192 |
ret += array[0].replaceAll("[,]", "\\\\,"); |
193 |
|
194 |
for (int i = 1; i < array.length; i++) { |
195 |
if (array[i] == null) { |
196 |
array[i] = "null";
|
197 |
} |
198 |
|
199 |
array[i] = array[i].replaceAll("[,]", "\\\\,"); |
200 |
ret += (" ," + array[i]);
|
201 |
} |
202 |
} |
203 |
} else {
|
204 |
Object[] array = (Object[]) value; |
205 |
|
206 |
if (!(array.length == 0)) { |
207 |
ret += ("" + array[0]).replaceAll("[,]", "\\\\,"); |
208 |
|
209 |
for (int i = 1; i < array.length; i++) { |
210 |
array[i] = ("" + array[i]).replaceAll("[,]", "\\\\,"); |
211 |
ret += (" ," + array[i]);
|
212 |
} |
213 |
} |
214 |
} |
215 |
} else {
|
216 |
ret = value.toString(); |
217 |
} |
218 |
|
219 |
Property p = new Property();
|
220 |
p.setKey(key); |
221 |
p.setValue(ret); |
222 |
putProperty(p); |
223 |
} |
224 |
|
225 |
/**
|
226 |
* A?ade una propiedad con un String como clave y un entero como valor.
|
227 |
*
|
228 |
* @param key clave.
|
229 |
* @param value valor.
|
230 |
*/
|
231 |
public void putProperty(String key, int value) { |
232 |
if (key == null) { |
233 |
return;
|
234 |
} |
235 |
|
236 |
Property p = new Property();
|
237 |
p.setKey(key); |
238 |
p.setValue(new Integer(value).toString()); |
239 |
putProperty(p); |
240 |
} |
241 |
|
242 |
/**
|
243 |
* A?ade una propiedad con un String como clave y un long como valor.
|
244 |
*
|
245 |
* @param key clave.
|
246 |
* @param value valor.
|
247 |
*/
|
248 |
public void putProperty(String key, long value) { |
249 |
if (key == null) { |
250 |
return;
|
251 |
} |
252 |
|
253 |
Property p = new Property();
|
254 |
p.setKey(key); |
255 |
p.setValue(new Long(value).toString()); |
256 |
putProperty(p); |
257 |
} |
258 |
|
259 |
/**
|
260 |
* A?ade una propiedad con un String como clave y un boolean como valor.
|
261 |
*
|
262 |
* @param key clave.
|
263 |
* @param value valor.
|
264 |
*/
|
265 |
public void putProperty(String key, boolean value) { |
266 |
if (key == null) { |
267 |
return;
|
268 |
} |
269 |
|
270 |
Property p = new Property();
|
271 |
p.setKey(key); |
272 |
p.setValue(new Boolean(value).toString()); |
273 |
putProperty(p); |
274 |
} |
275 |
|
276 |
/**
|
277 |
* A?ade una propiedad con un String como clave y un float como valor.
|
278 |
*
|
279 |
* @param key clave.
|
280 |
* @param value valor.
|
281 |
*/
|
282 |
public void putProperty(String key, float value) { |
283 |
if (key == null) { |
284 |
return;
|
285 |
} |
286 |
|
287 |
Property p = new Property();
|
288 |
p.setKey(key); |
289 |
p.setValue(new Float(value).toString()); |
290 |
putProperty(p); |
291 |
} |
292 |
|
293 |
/**
|
294 |
* A?ade una propiedad con un String como clave y un double como valor.
|
295 |
*
|
296 |
* @param key clave.
|
297 |
* @param value valor.
|
298 |
*/
|
299 |
public void putProperty(String key, double value) { |
300 |
if (key == null) { |
301 |
return;
|
302 |
} |
303 |
|
304 |
Property p = new Property();
|
305 |
p.setKey(key); |
306 |
p.setValue(new Double(value).toString()); |
307 |
putProperty(p); |
308 |
} |
309 |
|
310 |
/**
|
311 |
* Devuelve el String que corresponda a la clave que se pasa como
|
312 |
* par?metro.
|
313 |
*
|
314 |
* @param key clave
|
315 |
*
|
316 |
* @return valor.
|
317 |
*
|
318 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
319 |
* ning?n elemento con esa clave.
|
320 |
*/
|
321 |
public String getStringProperty(String key) { |
322 |
Property[] properties = xmltag.getProperty();
|
323 |
String res = null; |
324 |
boolean exists = false; |
325 |
|
326 |
for (int i = 0; i < properties.length; i++) { |
327 |
if (properties[i].getKey().compareTo(key) == 0) { |
328 |
res = properties[i].getValue(); |
329 |
exists = true;
|
330 |
} |
331 |
} |
332 |
|
333 |
if (exists) {
|
334 |
return res;
|
335 |
} |
336 |
|
337 |
throw new NotExistInXMLEntity(); |
338 |
} |
339 |
|
340 |
/**
|
341 |
* Devuelve el double que corresponda a la clave que se pasa como
|
342 |
* par?metro.
|
343 |
*
|
344 |
* @param key clave
|
345 |
*
|
346 |
* @return valor.
|
347 |
*
|
348 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
349 |
* ning?n elemento con esa clave.
|
350 |
*/
|
351 |
public double getDoubleProperty(String key) { |
352 |
Property[] properties = xmltag.getProperty();
|
353 |
double res = 0; |
354 |
boolean exists = false; |
355 |
|
356 |
for (int i = 0; i < properties.length; i++) { |
357 |
if (properties[i].getKey().compareTo(key) == 0) { |
358 |
res = Double.parseDouble(properties[i].getValue());
|
359 |
exists = true;
|
360 |
} |
361 |
} |
362 |
|
363 |
if (exists) {
|
364 |
return res;
|
365 |
} |
366 |
|
367 |
throw new NotExistInXMLEntity(); |
368 |
} |
369 |
|
370 |
/**
|
371 |
* Devuelve el array de doubles que corresponda a la clave que se pasa como
|
372 |
* par?metro.
|
373 |
*
|
374 |
* @param key clave
|
375 |
*
|
376 |
* @return valor.
|
377 |
*
|
378 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
379 |
* ning?n elemento con esa clave.
|
380 |
*/
|
381 |
public double[] getDoubleArrayProperty(String key) { |
382 |
Property[] properties = xmltag.getProperty();
|
383 |
String value = null; |
384 |
boolean exists = false; |
385 |
|
386 |
for (int i = 0; i < properties.length; i++) { |
387 |
if (properties[i].getKey().compareTo(key) == 0) { |
388 |
value = properties[i].getValue(); |
389 |
exists = true;
|
390 |
} |
391 |
} |
392 |
|
393 |
if (!exists) {
|
394 |
throw new NotExistInXMLEntity(); |
395 |
} |
396 |
|
397 |
if (value.compareTo("") == 0) { |
398 |
return new double[0]; |
399 |
} |
400 |
|
401 |
String[] aux = (String[]) value.split(" ,"); |
402 |
double[] ret = new double[aux.length]; |
403 |
|
404 |
for (int i = 0; i < aux.length; i++) { |
405 |
ret[i] = Double.parseDouble(aux[i].replaceAll("\\\\,", ",")); |
406 |
} |
407 |
|
408 |
return ret;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* Devuelve el Object que corresponda a la clave que se pasa como
|
413 |
* par?metro.
|
414 |
*
|
415 |
* @param key clave
|
416 |
*
|
417 |
* @return valor.
|
418 |
*
|
419 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
420 |
* ning?n elemento con esa clave.
|
421 |
*/
|
422 |
public Object getObjectProperty(String key) { |
423 |
Property[] properties = xmltag.getProperty();
|
424 |
Object res = null; |
425 |
boolean exists = false; |
426 |
|
427 |
for (int i = 0; i < properties.length; i++) { |
428 |
if (properties[i].getKey().compareTo(key) == 0) { |
429 |
res = properties[i].getValue(); |
430 |
exists = true;
|
431 |
} |
432 |
} |
433 |
|
434 |
if (exists) {
|
435 |
return res;
|
436 |
} |
437 |
|
438 |
throw new NotExistInXMLEntity(); |
439 |
} |
440 |
|
441 |
/**
|
442 |
* Devuelve el array de float que corresponda a la clave que se pasa como
|
443 |
* par?metro.
|
444 |
*
|
445 |
* @param key clave
|
446 |
*
|
447 |
* @return valor.
|
448 |
*
|
449 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
450 |
* ning?n elemento con esa clave.
|
451 |
*/
|
452 |
public float[] getFloatArrayProperty(String key) { |
453 |
Property[] properties = xmltag.getProperty();
|
454 |
String value = null; |
455 |
boolean exists = false; |
456 |
|
457 |
for (int i = 0; i < properties.length; i++) { |
458 |
if (properties[i].getKey().compareTo(key) == 0) { |
459 |
value = properties[i].getValue(); |
460 |
exists = true;
|
461 |
} |
462 |
} |
463 |
|
464 |
if (!exists) {
|
465 |
throw new NotExistInXMLEntity(); |
466 |
} |
467 |
|
468 |
if (value.compareTo("") == 0) { |
469 |
return new float[0]; |
470 |
} |
471 |
|
472 |
String[] aux = (String[]) value.split(" ,"); |
473 |
float[] ret = new float[aux.length]; |
474 |
|
475 |
for (int i = 0; i < aux.length; i++) { |
476 |
ret[i] = Float.parseFloat(aux[i].replaceAll("\\\\,", ",")); |
477 |
} |
478 |
|
479 |
return ret;
|
480 |
} |
481 |
|
482 |
/**
|
483 |
* Devuelve el array de long que corresponda a la clave que se pasa como
|
484 |
* par?metro.
|
485 |
*
|
486 |
* @param key clave
|
487 |
*
|
488 |
* @return valor.
|
489 |
*
|
490 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
491 |
* ning?n elemento con esa clave.
|
492 |
*/
|
493 |
public long[] getLongArrayProperty(String key) { |
494 |
Property[] properties = xmltag.getProperty();
|
495 |
String value = null; |
496 |
boolean exists = false; |
497 |
|
498 |
for (int i = 0; i < properties.length; i++) { |
499 |
if (properties[i].getKey().compareTo(key) == 0) { |
500 |
value = properties[i].getValue(); |
501 |
exists = true;
|
502 |
} |
503 |
} |
504 |
|
505 |
if (!exists) {
|
506 |
throw new NotExistInXMLEntity(); |
507 |
} |
508 |
|
509 |
if (value.compareTo("") == 0) { |
510 |
return new long[0]; |
511 |
} |
512 |
|
513 |
String[] aux = (String[]) value.split(" ,"); |
514 |
long[] ret = new long[aux.length]; |
515 |
|
516 |
for (int i = 0; i < aux.length; i++) { |
517 |
ret[i] = Long.parseLong(aux[i].replaceAll("\\\\,", ",")); |
518 |
} |
519 |
|
520 |
return ret;
|
521 |
} |
522 |
|
523 |
/**
|
524 |
* Devuelve el array de enteros que corresponda a la clave que se pasa como
|
525 |
* par?metro.
|
526 |
*
|
527 |
* @param key clave
|
528 |
*
|
529 |
* @return valor.
|
530 |
*
|
531 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
532 |
* ning?n elemento con esa clave.
|
533 |
*/
|
534 |
public int[] getIntArrayProperty(String key) { |
535 |
Property[] properties = xmltag.getProperty();
|
536 |
String value = null; |
537 |
boolean exists = false; |
538 |
|
539 |
for (int i = 0; i < properties.length; i++) { |
540 |
if (properties[i].getKey().compareTo(key) == 0) { |
541 |
value = properties[i].getValue(); |
542 |
exists = true;
|
543 |
} |
544 |
} |
545 |
|
546 |
if (!exists) {
|
547 |
throw new NotExistInXMLEntity(); |
548 |
} |
549 |
|
550 |
if (value.compareTo("") == 0) { |
551 |
return new int[0]; |
552 |
} |
553 |
|
554 |
String[] aux = (String[]) value.split(" ,"); |
555 |
int[] ret = new int[aux.length]; |
556 |
|
557 |
for (int i = 0; i < aux.length; i++) { |
558 |
ret[i] = Integer.parseInt(aux[i].replaceAll("\\\\,", ",")); |
559 |
} |
560 |
|
561 |
return ret;
|
562 |
} |
563 |
|
564 |
/**
|
565 |
* Devuelve el array de boolean que corresponda a la clave que se pasa como
|
566 |
* par?metro.
|
567 |
*
|
568 |
* @param key clave
|
569 |
*
|
570 |
* @return valor.
|
571 |
*
|
572 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
573 |
* ning?n elemento con esa clave.
|
574 |
*/
|
575 |
public boolean[] getBooleanArrayProperty(String key) { |
576 |
Property[] properties = xmltag.getProperty();
|
577 |
String value = null; |
578 |
boolean exists = false; |
579 |
|
580 |
for (int i = 0; i < properties.length; i++) { |
581 |
if (properties[i].getKey().compareTo(key) == 0) { |
582 |
value = properties[i].getValue(); |
583 |
exists = true;
|
584 |
} |
585 |
} |
586 |
|
587 |
if (!exists) {
|
588 |
throw new NotExistInXMLEntity(); |
589 |
} |
590 |
|
591 |
if (value.compareTo("") == 0) { |
592 |
return new boolean[0]; |
593 |
} |
594 |
|
595 |
String[] aux = (String[]) value.split(" ,"); |
596 |
boolean[] ret = new boolean[aux.length]; |
597 |
|
598 |
for (int i = 0; i < aux.length; i++) { |
599 |
ret[i] = Boolean.valueOf(aux[i].replaceAll("\\\\,", ",")) |
600 |
.booleanValue(); |
601 |
} |
602 |
|
603 |
return ret;
|
604 |
} |
605 |
|
606 |
/**
|
607 |
* Devuelve el array de String que corresponda a la clave que se pasa como
|
608 |
* par?metro.
|
609 |
*
|
610 |
* @param key clave
|
611 |
*
|
612 |
* @return valor.
|
613 |
*
|
614 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
615 |
* ning?n elemento con esa clave.
|
616 |
*/
|
617 |
public String[] getStringArrayProperty(String key) { |
618 |
///String value = (String) properties.get(key);
|
619 |
Property[] properties = xmltag.getProperty();
|
620 |
String value = null; |
621 |
boolean exists = false; |
622 |
|
623 |
for (int i = 0; i < properties.length; i++) { |
624 |
if (properties[i].getKey().compareTo(key) == 0) { |
625 |
value = properties[i].getValue(); |
626 |
exists = true;
|
627 |
} |
628 |
} |
629 |
|
630 |
if (!exists) {
|
631 |
throw new NotExistInXMLEntity(); |
632 |
} |
633 |
|
634 |
if (value.compareTo("") == 0) { |
635 |
return new String[0]; |
636 |
} |
637 |
|
638 |
String[] aux = (String[]) value.split(" ,"); |
639 |
|
640 |
for (int i = 0; i < aux.length; i++) { |
641 |
aux[i] = aux[i].replaceAll("\\\\,", ","); |
642 |
} |
643 |
|
644 |
return aux;
|
645 |
} |
646 |
|
647 |
/**
|
648 |
* Devuelve el boolean que corresponda a la clave que se pasa como
|
649 |
* par?metro.
|
650 |
*
|
651 |
* @param key clave
|
652 |
*
|
653 |
* @return valor.
|
654 |
*
|
655 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
656 |
* ning?n elemento con esa clave.
|
657 |
*/
|
658 |
public boolean getBooleanProperty(String key) { |
659 |
Property[] properties = xmltag.getProperty();
|
660 |
boolean res = false; |
661 |
boolean exists = false; |
662 |
|
663 |
for (int i = 0; i < properties.length; i++) { |
664 |
if (properties[i].getKey().compareTo(key) == 0) { |
665 |
res = (boolean) Boolean.valueOf(properties[i].getValue()) |
666 |
.booleanValue(); |
667 |
exists = true;
|
668 |
} |
669 |
} |
670 |
|
671 |
if (exists) {
|
672 |
return res;
|
673 |
} |
674 |
|
675 |
throw new NotExistInXMLEntity(); |
676 |
} |
677 |
|
678 |
/**
|
679 |
* Devuelve el entero que corresponda a la clave que se pasa como
|
680 |
* par?metro.
|
681 |
*
|
682 |
* @param key clave
|
683 |
*
|
684 |
* @return valor.
|
685 |
*
|
686 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
687 |
* ning?n elemento con esa clave.
|
688 |
*/
|
689 |
public int getIntProperty(String key) { |
690 |
Property[] properties = xmltag.getProperty();
|
691 |
int res = 0; |
692 |
boolean exists = false; |
693 |
|
694 |
for (int i = 0; i < properties.length; i++) { |
695 |
if (properties[i].getKey().compareTo(key) == 0) { |
696 |
res = Integer.parseInt(properties[i].getValue());
|
697 |
exists=true;
|
698 |
} |
699 |
} |
700 |
|
701 |
if (exists) {
|
702 |
return res;
|
703 |
} |
704 |
|
705 |
throw new NotExistInXMLEntity(); |
706 |
} |
707 |
|
708 |
/**
|
709 |
* Devuelve el long que corresponda a la clave que se pasa como par?metro.
|
710 |
*
|
711 |
* @param key clave
|
712 |
*
|
713 |
* @return valor.
|
714 |
*
|
715 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
716 |
* ning?n elemento con esa clave.
|
717 |
*/
|
718 |
public long getLongProperty(String key) { |
719 |
Property[] properties = xmltag.getProperty();
|
720 |
long res = 0; |
721 |
boolean exists = false; |
722 |
|
723 |
for (int i = 0; i < properties.length; i++) { |
724 |
if (properties[i].getKey().compareTo(key) == 0) { |
725 |
res = Long.valueOf(properties[i].getValue()).longValue();
|
726 |
exists = true;
|
727 |
} |
728 |
} |
729 |
|
730 |
if (exists) {
|
731 |
return res;
|
732 |
} |
733 |
|
734 |
throw new NotExistInXMLEntity(); |
735 |
} |
736 |
|
737 |
/**
|
738 |
* Devuelve el float que corresponda a la clave que se pasa como par?metro.
|
739 |
*
|
740 |
* @param key clave
|
741 |
*
|
742 |
* @return valor.
|
743 |
*
|
744 |
* @throws NotExistInXMLEntity Lanza esta excepci?n si no se encuentra
|
745 |
* ning?n elemento con esa clave.
|
746 |
*/
|
747 |
public float getFloatProperty(String key) { |
748 |
Property[] properties = xmltag.getProperty();
|
749 |
float res = 0; |
750 |
boolean exists = false; |
751 |
|
752 |
for (int i = 0; i < properties.length; i++) { |
753 |
if (properties[i].getKey().compareTo(key) == 0) { |
754 |
res = Float.valueOf(properties[i].getValue()).floatValue();
|
755 |
exists = true;
|
756 |
} |
757 |
} |
758 |
|
759 |
if (exists) {
|
760 |
return res;
|
761 |
} |
762 |
|
763 |
throw new NotExistInXMLEntity(); |
764 |
} |
765 |
|
766 |
/**
|
767 |
* A?ade el nombre con clave name y valor el String que se pasa como
|
768 |
* par?metro.
|
769 |
*
|
770 |
* @param name nombre.
|
771 |
*/
|
772 |
public void setName(String name) { |
773 |
Property p = new Property();
|
774 |
p.setKey("name");
|
775 |
p.setValue(name); |
776 |
xmltag.addProperty(p); |
777 |
} |
778 |
|
779 |
/**
|
780 |
* Devuelve el nombre.
|
781 |
*
|
782 |
* @return nombre.
|
783 |
*/
|
784 |
public String getName() { |
785 |
Property p = getProperty("name");
|
786 |
|
787 |
return (String) p.getValue(); |
788 |
} |
789 |
|
790 |
/**
|
791 |
* Devuelve la clase que implementa.
|
792 |
*
|
793 |
* @return clase.
|
794 |
*/
|
795 |
public Class getImplementingClass() { |
796 |
Property p = getProperty("class");
|
797 |
Object ob = p.getValue();
|
798 |
|
799 |
return (Class) ob; |
800 |
} |
801 |
|
802 |
/**
|
803 |
* A?ade la clase que implementa
|
804 |
*
|
805 |
* @param c
|
806 |
*/
|
807 |
public void setImplementingClass(Class c) { |
808 |
Property p = new Property();
|
809 |
p.setKey("class");
|
810 |
p.setValue(c.toString()); |
811 |
xmltag.addProperty(p); |
812 |
} |
813 |
|
814 |
/**
|
815 |
* A?ade un hijo al XMLEntity.
|
816 |
*
|
817 |
* @param entity xml para a?adir.
|
818 |
*/
|
819 |
public void addChild(XMLEntity entity) { |
820 |
xmltag.addXmlTag(entity.getXmlTag()); |
821 |
} |
822 |
|
823 |
/**
|
824 |
* Devuelve un hijo a partir de un indice.
|
825 |
*
|
826 |
* @param i indice.
|
827 |
*
|
828 |
* @return hijo.
|
829 |
*/
|
830 |
public XMLEntity getChild(int i) { |
831 |
return new XMLEntity(xmltag.getXmlTag(i)); |
832 |
} |
833 |
|
834 |
/**
|
835 |
* Devuelve el n?mero de hijos que contiene el XMLEntity.
|
836 |
*
|
837 |
* @return n?mero de hijos.
|
838 |
*/
|
839 |
public int getNumChild() { |
840 |
return xmltag.getXmlTagCount();
|
841 |
} |
842 |
|
843 |
/**
|
844 |
* Devuelve los xmlTag hijos del actual xmltag.
|
845 |
*
|
846 |
* @return hijo.
|
847 |
*/
|
848 |
public XmlTag[] hijos() { |
849 |
return xmltag.getXmlTag();
|
850 |
} |
851 |
|
852 |
/**
|
853 |
* Devuelve el Property a partir de la clave.
|
854 |
*
|
855 |
* @param key clave.
|
856 |
*
|
857 |
* @return Property.
|
858 |
*/
|
859 |
private Property getProperty(String key) { |
860 |
Property[] ps = xmltag.getProperty();
|
861 |
|
862 |
for (int i = 0; i < ps.length; i++) { |
863 |
if (ps[i].getKey().compareTo(key) == 0) { |
864 |
return ps[i];
|
865 |
} |
866 |
} |
867 |
|
868 |
return null; |
869 |
} |
870 |
|
871 |
/**
|
872 |
* Devuelve el xmltag.
|
873 |
*
|
874 |
* @return xmltag.
|
875 |
*/
|
876 |
public XmlTag getXmlTag() {
|
877 |
return xmltag;
|
878 |
} |
879 |
|
880 |
/**
|
881 |
* A?ade el property que se pasa como par?metro.
|
882 |
*
|
883 |
* @param p property.
|
884 |
*/
|
885 |
private void putProperty(Property p) { |
886 |
for (int i = 0; i < xmltag.getPropertyCount(); i++) { |
887 |
if (xmltag.getProperty(i).getKey().compareTo(p.getKey()) == 0) { |
888 |
xmltag.getProperty(i).setValue(p.getValue()); |
889 |
|
890 |
return;
|
891 |
} |
892 |
} |
893 |
|
894 |
xmltag.addProperty(p); |
895 |
} |
896 |
public boolean contains(String key) { |
897 |
Property[] properties = xmltag.getProperty();
|
898 |
boolean exists = false; |
899 |
|
900 |
for (int i = 0; i < properties.length; i++) { |
901 |
if (properties[i].getKey().compareTo(key) == 0) { |
902 |
exists = true;
|
903 |
} |
904 |
} |
905 |
return exists;
|
906 |
} |
907 |
|
908 |
public int getPropertyCount(){ |
909 |
return xmltag.getPropertyCount();
|
910 |
} |
911 |
|
912 |
public String getPropertyValue(int index){ |
913 |
return xmltag.getProperty(index).getValue();
|
914 |
} |
915 |
|
916 |
public String getPropertyName(int index){ |
917 |
return xmltag.getProperty(index).getKey();
|
918 |
} |
919 |
} |