Revision 10620
trunk/libraries/libIverUtiles/src/com/iver/utiles/XMLEntity.java | ||
---|---|---|
103 | 103 |
putProperty(p, matters); |
104 | 104 |
} |
105 | 105 |
|
106 |
public void putProperty(String key, String value) { |
|
107 |
putProperty(key, value, true); |
|
108 |
} |
|
106 | 109 |
/** |
107 | 110 |
* A?ade una propiedad con un String como clave y un Object como valor. |
108 | 111 |
* |
... | ... | |
243 | 246 |
p.setValue(ret); |
244 | 247 |
putProperty(p, matters); |
245 | 248 |
} |
246 |
|
|
249 |
|
|
247 | 250 |
/** |
248 | 251 |
* A?ade una propiedad con un String como clave y un double como valor. |
249 | 252 |
* La propiedad a?adida afecta al valor calculado por toHashCode() |
... | ... | |
257 | 260 |
public void putProperty(String key, Object value) { |
258 | 261 |
putProperty(key, value, true); |
259 | 262 |
} |
260 |
|
|
263 |
|
|
261 | 264 |
/** |
262 | 265 |
* A?ade una propiedad con un String como clave y un entero como valor. |
263 | 266 |
* |
... | ... | |
279 | 282 |
p.setValue(new Integer(value).toString()); |
280 | 283 |
putProperty(p, matters); |
281 | 284 |
} |
282 |
|
|
285 |
|
|
283 | 286 |
/** |
284 | 287 |
* A?ade una propiedad con un String como clave y un double como valor. |
285 | 288 |
* La propiedad a?adida afecta al valor calculado por toHashCode() |
... | ... | |
293 | 296 |
public void putProperty(String key, int value) { |
294 | 297 |
putProperty(key, value, true); |
295 | 298 |
} |
296 |
|
|
299 |
|
|
297 | 300 |
/** |
298 | 301 |
* A?ade una propiedad con un String como clave y un long como valor. |
299 | 302 |
* |
... | ... | |
352 | 355 |
p.setValue(new Boolean(value).toString()); |
353 | 356 |
putProperty(p, matters); |
354 | 357 |
} |
355 |
|
|
358 |
|
|
356 | 359 |
/** |
357 | 360 |
* A?ade una propiedad con un String como clave y un double como valor. |
358 | 361 |
* La propiedad a?adida afecta al valor calculado por toHashCode() |
... | ... | |
366 | 369 |
public void putProperty(String key, boolean value) { |
367 | 370 |
putProperty(key, value, true); |
368 | 371 |
} |
369 |
|
|
370 | 372 |
|
373 |
|
|
371 | 374 |
/** |
372 | 375 |
* A?ade una propiedad con un String como clave y un float como valor. |
373 | 376 |
* |
... | ... | |
438 | 441 |
*/ |
439 | 442 |
public void putProperty(String key, double value) { |
440 | 443 |
putProperty(key, value, true); |
441 |
}
|
|
444 |
} |
|
442 | 445 |
/** |
443 | 446 |
* Devuelve el String que corresponda a la clave que se pasa como par?metro. |
444 | 447 |
* |
... | ... | |
1091 | 1094 |
private Vector getWhiteAttrList() { |
1092 | 1095 |
if (whiteAttrList == null) { |
1093 | 1096 |
whiteAttrList = new Vector(); |
1094 |
|
|
1097 |
|
|
1095 | 1098 |
} |
1096 | 1099 |
|
1097 | 1100 |
return whiteAttrList; |
... | ... | |
1203 | 1206 |
// jaume (en proves) |
1204 | 1207 |
/** |
1205 | 1208 |
* <p> |
1206 |
* <code>hash()</code> method is used to know if this <b>XMLEntity</b>
|
|
1207 |
* can be considered as changed. At the loading of the <b>XMLEntity</b> tree
|
|
1208 |
* you can invoke this method. The result of it is a <code>int</code> hash
|
|
1209 |
* <code>hash()</code> method is used to know if this <b>XMLEntity</b> |
|
1210 |
* can be considered as changed. At the loading of the <b>XMLEntity</b> tree |
|
1211 |
* you can invoke this method. The result of it is a <code>int</code> hash |
|
1209 | 1212 |
* value calculated from the contents of this and its children. Then, if you |
1210 | 1213 |
* store this value you can recognize if the <b>XMLEntity</b> has changed |
1211 | 1214 |
* since the last time you called <code>hash()</code> just by comparing |
... | ... | |
1220 | 1223 |
* the session but you don't care about the values between sessions as |
1221 | 1224 |
* properties which don't matter to detect if your XMLEntity has changed.<br> |
1222 | 1225 |
* </p> |
1223 |
*
|
|
1226 |
* |
|
1224 | 1227 |
*/ |
1225 | 1228 |
public long hash() { |
1226 | 1229 |
long result = 17; |
... | ... | |
1240 | 1243 |
// then it will not take effect in the hash calculation |
1241 | 1244 |
if (whiteAttrList!=null && whiteAttrList.contains(strKey)) |
1242 | 1245 |
continue; |
1243 |
|
|
1246 |
|
|
1244 | 1247 |
char[] key = strKey.toCharArray(); |
1245 | 1248 |
for (int j = 0; j < key.length; j++) { |
1246 | 1249 |
result = 37 + result + (int) key[j]; |
... | ... | |
1262 | 1265 |
} |
1263 | 1266 |
return result; |
1264 | 1267 |
} |
1265 |
|
|
1268 |
|
|
1266 | 1269 |
/** |
1267 | 1270 |
* Devuelve el primer hijo que el valor de su propieda 'key' |
1268 | 1271 |
* es igual a 'value' |
1269 |
*
|
|
1270 |
* @param key propiedad a comparar
|
|
1272 |
* |
|
1273 |
* @param key propiedad a comparar |
|
1271 | 1274 |
* @param value valor a comparar |
1272 | 1275 |
* @return XMLEntity hijo o null si no se encuentra |
1273 | 1276 |
*/ |
... | ... | |
1284 | 1287 |
// Nothing to do |
1285 | 1288 |
} |
1286 | 1289 |
} |
1287 |
return null;
|
|
1290 |
return null; |
|
1288 | 1291 |
} |
1289 |
|
|
1292 |
|
|
1290 | 1293 |
/** |
1291 | 1294 |
* Devuelve el indice del primer hijo que el valor de su propieda 'key' |
1292 | 1295 |
* es igual a 'value' |
1293 |
*
|
|
1294 |
* @param key propiedad a comparar
|
|
1296 |
* |
|
1297 |
* @param key propiedad a comparar |
|
1295 | 1298 |
* @param value valor a comparar |
1296 | 1299 |
* @return int indice del hijo o -1 si no se encuentra |
1297 | 1300 |
*/ |
... | ... | |
1308 | 1311 |
// Nothing to do |
1309 | 1312 |
} |
1310 | 1313 |
} |
1311 |
return -1;
|
|
1314 |
return -1; |
|
1312 | 1315 |
} |
1313 |
|
|
1316 |
|
|
1314 | 1317 |
/** |
1315 | 1318 |
* Devuelve un iterador sobre los hijos que cumplen la condicion |
1316 | 1319 |
* que el valor de su propiedad 'key' es igual a 'value' |
1317 |
*
|
|
1320 |
* |
|
1318 | 1321 |
* El iterador no permite eliminacion |
1319 |
*
|
|
1322 |
* |
|
1320 | 1323 |
* @param key nombre de la propidedad |
1321 | 1324 |
* @param value valor de la propiedad |
1322 | 1325 |
* @return |
... | ... | |
1324 | 1327 |
public Iterator findChildren(String key, String value) { |
1325 | 1328 |
return new XMLEntityIterator(this,key,value); |
1326 | 1329 |
} |
1327 |
|
|
1330 |
|
|
1328 | 1331 |
public String toString() { |
1329 | 1332 |
StringWriter buffer = new StringWriter(); |
1330 | 1333 |
|
... | ... | |
1339 | 1342 |
m.setEncoding("ISO-8859-1"); |
1340 | 1343 |
|
1341 | 1344 |
try { |
1342 |
m.marshal(this.getXmlTag());
|
|
1345 |
m.marshal(this.getXmlTag()); |
|
1343 | 1346 |
} catch (MarshalException e2) { |
1344 | 1347 |
// TODO Auto-generated catch block |
1345 | 1348 |
e2.printStackTrace(); |
... | ... | |
1350 | 1353 |
return null; |
1351 | 1354 |
} |
1352 | 1355 |
|
1353 |
return buffer.toString();
|
|
1356 |
return buffer.toString(); |
|
1354 | 1357 |
} |
1355 |
|
|
1358 |
|
|
1356 | 1359 |
public static XMLEntity parse(String data) throws MarshalException, ValidationException { |
1357 | 1360 |
StringReader reader = new StringReader(data); |
1358 | 1361 |
|
... | ... | |
1360 | 1363 |
tag = (XmlTag) XmlTag.unmarshal(reader); |
1361 | 1364 |
return new XMLEntity(tag); |
1362 | 1365 |
} |
1363 |
|
|
1366 |
|
|
1364 | 1367 |
} |
1365 | 1368 |
|
1366 | 1369 |
class XMLEntityIterator implements Iterator { |
... | ... | |
1369 | 1372 |
private XMLEntity entity; |
1370 | 1373 |
private String key; |
1371 | 1374 |
private String value; |
1372 |
|
|
1375 |
|
|
1373 | 1376 |
public XMLEntityIterator(XMLEntity entity,String key,String value) { |
1374 | 1377 |
this.entity = entity; |
1375 | 1378 |
this.key = key; |
... | ... | |
1378 | 1381 |
this.lastHasNextIndex = -1; |
1379 | 1382 |
} |
1380 | 1383 |
public void remove() { |
1381 |
throw new UnsupportedOperationException();
|
|
1384 |
throw new UnsupportedOperationException(); |
|
1382 | 1385 |
} |
1383 |
|
|
1386 |
|
|
1384 | 1387 |
public boolean hasNext() { |
1385 | 1388 |
if (entity.getChildrenCount() == 0 || entity.getChildrenCount() <= this.lastIndex){ |
1386 | 1389 |
return false; |
... | ... | |
1397 | 1400 |
} catch (NotExistInXMLEntity e) { |
1398 | 1401 |
// Nothing to do |
1399 | 1402 |
} |
1400 |
}
|
|
1403 |
} |
|
1401 | 1404 |
return false; |
1402 | 1405 |
} |
1403 |
|
|
1406 |
|
|
1404 | 1407 |
public Object next() { |
1405 | 1408 |
if (entity.getChildrenCount() == 0 || entity.getChildrenCount() <= this.lastIndex){ |
1406 | 1409 |
throw new NoSuchElementException(); |
1407 | 1410 |
} |
1408 |
|
|
1411 |
|
|
1409 | 1412 |
XMLEntity child; |
1410 |
|
|
1413 |
|
|
1411 | 1414 |
if (this.lastHasNextIndex > -1) { |
1412 | 1415 |
if (this.entity.getChildrenCount() > this.lastHasNextIndex) { |
1413 | 1416 |
child = this.entity.getChild(this.lastHasNextIndex); |
... | ... | |
1422 | 1425 |
} |
1423 | 1426 |
} |
1424 | 1427 |
} |
1425 |
|
|
1426 |
|
|
1428 |
|
|
1429 |
|
|
1427 | 1430 |
int num = this.entity.getChildrenCount(); |
1428 |
|
|
1431 |
|
|
1429 | 1432 |
for (int i=this.lastIndex+1;i < num; i++) { |
1430 | 1433 |
child = this.entity.getChild(i); |
1431 |
try {
|
|
1434 |
try { |
|
1432 | 1435 |
if (child.getStringProperty(key).equals(value)) { |
1433 | 1436 |
this.lastIndex = i; |
1434 | 1437 |
this.lastHasNextIndex = -1; |
... | ... | |
1436 | 1439 |
} |
1437 | 1440 |
} catch (NotExistInXMLEntity e) { |
1438 | 1441 |
// Nothing to do |
1439 |
}
|
|
1442 |
} |
|
1440 | 1443 |
} |
1441 | 1444 |
this.lastHasNextIndex = -1; |
1442 | 1445 |
throw new NoSuchElementException(); |
Also available in: Unified diff