use of org.jruby.RubyNil in project gocd by gocd.
the class XmlDocument method root_set.
@JRubyMethod(name = "root=")
public IRubyObject root_set(ThreadContext context, IRubyObject newRoot_) {
// should be nil.
if (newRoot_ instanceof RubyNil) {
getDocument().getDocumentElement().setUserData(NokogiriHelpers.VALID_ROOT_NODE, false, null);
return newRoot_;
}
XmlNode newRoot = asXmlNode(context, newRoot_);
IRubyObject root = root(context);
if (root.isNil()) {
Node newRootNode;
if (getDocument() == newRoot.getOwnerDocument()) {
newRootNode = newRoot.node;
} else {
// must copy otherwise newRoot may exist in two places
// with different owner document.
newRootNode = getDocument().importNode(newRoot.node, true);
}
add_child_node(context, getCachedNodeOrCreate(context.getRuntime(), newRootNode));
} else {
Node rootNode = asXmlNode(context, root).node;
((XmlNode) getCachedNodeOrCreate(context.getRuntime(), rootNode)).replace_node(context, newRoot);
}
return newRoot;
}
use of org.jruby.RubyNil in project nokogiri by sparklemotion.
the class XmlDocument method root_set.
@JRubyMethod(name = "root=")
public IRubyObject root_set(ThreadContext context, IRubyObject newRoot_) {
// should be nil.
if (newRoot_ instanceof RubyNil) {
getDocument().getDocumentElement().setUserData(NokogiriHelpers.VALID_ROOT_NODE, false, null);
return newRoot_;
}
XmlNode newRoot = asXmlNode(context, newRoot_);
IRubyObject root = root(context);
if (root.isNil()) {
Node newRootNode;
if (getDocument() == newRoot.getOwnerDocument()) {
newRootNode = newRoot.node;
} else {
// must copy otherwise newRoot may exist in two places
// with different owner document.
newRootNode = getDocument().importNode(newRoot.node, true);
}
add_child_node(context, getCachedNodeOrCreate(context.getRuntime(), newRootNode));
} else {
Node rootNode = asXmlNode(context, root).node;
((XmlNode) getCachedNodeOrCreate(context.getRuntime(), rootNode)).replace_node(context, newRoot);
}
return newRoot;
}
Aggregations