Add a separate removeChild() function to remove a child object.
Add safety check to remove() to prevent accidental use of the old version.
This commit is contained in:
parent
6f39e2109c
commit
3e6f4392c7
1 changed files with 30 additions and 18 deletions
|
@ -569,30 +569,42 @@ public class HopObject extends ScriptableObject implements Wrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove node itself or one or more subnodes.
|
* Remove this object from the database.
|
||||||
*/
|
*/
|
||||||
public boolean jsFunction_remove(Object child) {
|
public boolean jsFunction_remove(Object arg) {
|
||||||
// semantics: if called without arguments, remove self.
|
// shield off usage of old deprecated version taking an argument
|
||||||
// otherwise, remove given subnodes.
|
if (arg != Undefined.instance) {
|
||||||
|
System.err.println(" ************* WARNING *************************");
|
||||||
|
System.err.println(" The version of HopObject.remove(child) you were ");
|
||||||
|
System.err.println(" trying to use has been deprecated. Please use ");
|
||||||
|
System.err.println(" hopobj.removeChild(child)");
|
||||||
|
System.err.println(" to remove a child object from a collection without");
|
||||||
|
System.err.println(" deleting it, or ");
|
||||||
|
System.err.println(" hopobj.remove()");
|
||||||
|
System.err.println(" without argument to delete the object itself.");
|
||||||
|
System.err.println(" *************************************************");
|
||||||
|
throw new RuntimeException("Caught deprecated usage of HopObject.remove(child)");
|
||||||
|
}
|
||||||
|
|
||||||
checkNode();
|
checkNode();
|
||||||
|
|
||||||
if (child == Undefined.instance) {
|
return node.remove();
|
||||||
return node.remove();
|
}
|
||||||
} else if (node != null) {
|
|
||||||
try {
|
|
||||||
if (child instanceof HopObject) {
|
|
||||||
HopObject hobj = (HopObject) child;
|
|
||||||
|
|
||||||
if (hobj.node != null) {
|
/**
|
||||||
node.removeNode(hobj.node);
|
* Remove a child node from this node's collection without deleting
|
||||||
|
* it from the database.
|
||||||
|
*/
|
||||||
|
public boolean jsFunction_removeChild(Object child) {
|
||||||
|
|
||||||
return true;
|
checkNode();
|
||||||
}
|
|
||||||
}
|
if (child instanceof HopObject) {
|
||||||
} catch (Exception x) {
|
HopObject hobj = (HopObject) child;
|
||||||
System.err.println("Error in HopObject.remove(): " + x);
|
|
||||||
x.printStackTrace();
|
if (hobj.node != null) {
|
||||||
|
node.removeNode(hobj.node);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue