01: package com.xoetrope.data.pojo;
02:
03: import java.util.Hashtable;
04: import net.xoetrope.xui.data.XModel;
05:
06: /**
07: * Used for storing the additional data
08: * of the visualiser tree model nodes.
09: * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
10: * the GNU Public License (GPL), please see license.txt for more details. If
11: * you make commercial use of this software you must purchase a commercial
12: * license from Xoetrope.</p>
13: */
14: public class PropertiesRetriever implements XPropertiesRetriever {
15: protected Hashtable propertyHash;
16: protected Hashtable attributeHash;
17:
18: public PropertiesRetriever() {
19: propertyHash = new Hashtable();
20: }
21:
22: public Object getPropertyValue(XPojoModelVis model, String property) {
23: String path = getModelPath(model) + "@" + property;
24: return ((PropertyValue) propertyHash.get(path)).argVal;
25: }
26:
27: public void setPropertyValue(XPojoModelVis model, String property,
28: Object value) {
29: String path = getModelPath((XPojoModelVis) model) + "@"
30: + property;
31: propertyHash.put(path, new PropertyValue(value));
32: }
33:
34: public void removeProperty(XPojoModelVis model, String property) {
35: String path = getModelPath((XPojoModelVis) model) + "@"
36: + property;
37: propertyHash.remove(path);
38: }
39:
40: public boolean containsProperty(XPojoModelVis model, String property) {
41: String path = getModelPath(model) + "@" + property;
42: return ((path != null) && propertyHash.containsKey(path));
43: }
44:
45: private class PropertyValue {
46: Object argVal;
47:
48: public PropertyValue(Object av) {
49: argVal = av;
50: }
51: }
52:
53: protected String getModelPath(XModel model) {
54: XModel firstModel = model;
55: if (model == null)
56: return null;
57: String path = "";
58: while (model != null) {
59: String modelId = "";
60: int i = 0;
61: if (model instanceof XPojoModelVis) {
62: modelId = ((XPojoModelVis) model).getCaption();
63:
64: // this node might not have been initialized yet
65: if (modelId == null)
66: return null;
67:
68: int idx = modelId.lastIndexOf(": ");
69: if (idx >= 0)
70: modelId = modelId.substring(0, idx);
71: } else {
72: modelId = model.getId();
73: }
74: if (modelId != null)
75: path = ("/" + modelId + path);
76: model = model.getParent();
77: }
78: if (path.charAt(0) == '/')
79: path = path.substring(1);
80: return path;
81: }
82:
83: }
|