- public void delete() {\r
- if(parent == null) {\r
- return;\r
- }\r
-\r
- synchronized (children) {\r
- // 1. Add children under parent\r
- parent.appendChildren(children);\r
-\r
- // 2. Clear children\r
- children.clear();\r
- }\r
-\r
- // 3. Remove this node from parent\r
- parent.unlinkChild(this);\r
-\r
- // 4. Cleanup, this node is now disposed\r
- cleanup();\r
- }\r
-\r
- /**\r
- * Helper method for delete()\r
- * @param children\r
- */\r
- @SuppressWarnings("unchecked")\r
- protected void appendChildren(Map<String, ?> children) {\r
- synchronized(this.children) {\r
- for(String id : children.keySet()) {\r
- INode child = (INode)children.get(id);\r
- this.children.put(id, (T)child); // Hopefully cast works\r
- child.setParent(this);\r
-\r
- // Send notify only if we are on server side (or standalone)\r
- if (propertyChangeListener != null && location.equals(Location.LOCAL)) {\r
- propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "children["+child.getId()+"]", null, EXISTING)); // "children" is a special field name\r
- }\r
- }\r
- }\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- protected void appendChild(String id, INode child) {\r
- children.put(id, (T)child);\r
- child.setParent(this);\r
- // Send notify only if we are on server side (or standalone)\r
- if (propertyChangeListener != null && location.equals(Location.LOCAL)) {\r
- propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "children["+(child).getId()+"]", null, EXISTING)); // "children" is a special field name\r
- }\r
- }\r
-\r
- /**\r
- * Same as removeNode, but does not perform cleanup for the child\r
- * @param child\r
- */\r
- protected void unlinkChild(INode child) {\r
- synchronized(children) {\r
- String id = null;\r
- // FIXME: damn slow, needs more data structure to be supported well\r
- // One option would be to store the id<->node mappings in a BidiMap.\r
- for(String tmp : children.keySet()) {\r
- if(children.get(tmp).equals(child)) {\r
- id = tmp;\r
- break;\r
- }\r
- }\r
- if(id == null) return;\r
- children.remove(id);\r
- childrenChanged();\r
- }\r
-\r
- if(propertyChangeListener != null && location.equals(Location.LOCAL)) {\r
- propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "children["+child.getId()+"]", child.getClass(), UNLINK)); // "children" is a special field name\r
- }\r
- }\r
+ public void delete() {
+ if(parent == null) {
+ return;
+ }
+
+ synchronized (children) {
+ // 1. Add children under parent
+ parent.appendChildren(children);
+
+ // 2. Clear children
+ children.clear();
+ }
+
+ // 3. Remove this node from parent
+ parent.unlinkChild(this);
+
+ // 4. Cleanup, this node is now disposed
+ cleanup();
+ }
+
+ /**
+ * Helper method for delete()
+ * @param children
+ */
+ @SuppressWarnings("unchecked")
+ protected void appendChildren(Map<String, ?> children) {
+ synchronized(this.children) {
+ for(String id : children.keySet()) {
+ INode child = (INode)children.get(id);
+ this.children.put(id, (T)child); // Hopefully cast works
+ child.setParent(this);
+
+ // Send notify only if we are on server side (or standalone)
+ if (propertyChangeListener != null && location.equals(Location.LOCAL)) {
+ propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "children["+child.getId()+"]", null, EXISTING)); // "children" is a special field name
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void appendChild(String id, INode child) {
+ children.put(id, (T)child);
+ child.setParent(this);
+ // Send notify only if we are on server side (or standalone)
+ if (propertyChangeListener != null && location.equals(Location.LOCAL)) {
+ propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "children["+(child).getId()+"]", null, EXISTING)); // "children" is a special field name
+ }
+ }
+
+ /**
+ * Same as removeNode, but does not perform cleanup for the child
+ * @param child
+ */
+ protected void unlinkChild(INode child) {
+ synchronized(children) {
+ String id = null;
+ // FIXME: damn slow, needs more data structure to be supported well
+ // One option would be to store the id<->node mappings in a BidiMap.
+ for(String tmp : children.keySet()) {
+ if(children.get(tmp).equals(child)) {
+ id = tmp;
+ break;
+ }
+ }
+ if(id == null) return;
+ children.remove(id);
+ childrenChanged();
+ }
+
+ if(propertyChangeListener != null && location.equals(Location.LOCAL)) {
+ propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "children["+child.getId()+"]", child.getClass(), UNLINK)); // "children" is a special field name
+ }
+ }