本文整理汇总了Java中org.jruby.RubyNil类的典型用法代码示例。如果您正苦于以下问题:Java RubyNil类的具体用法?Java RubyNil怎么用?Java RubyNil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RubyNil类属于org.jruby包,在下文中一共展示了RubyNil类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJRubyObject
import org.jruby.RubyNil; //导入依赖的package包/类
/**
* Create a new JRuby-scripted object from the given script source.
* @param scriptSource the script source text
* @param interfaces the interfaces that the scripted Java object is to implement
* @param classLoader the {@link ClassLoader} to create the script proxy with
* @return the scripted Java object
* @throws JumpException in case of JRuby parsing failure
*/
public static Object createJRubyObject(String scriptSource, Class<?>[] interfaces, ClassLoader classLoader) {
Ruby ruby = initializeRuntime();
Node scriptRootNode = ruby.parseEval(scriptSource, "", null, 0);
IRubyObject rubyObject = ruby.runNormally(scriptRootNode);
if (rubyObject instanceof RubyNil) {
String className = findClassName(scriptRootNode);
rubyObject = ruby.evalScriptlet("\n" + className + ".new");
}
// still null?
if (rubyObject instanceof RubyNil) {
throw new IllegalStateException("Compilation of JRuby script returned RubyNil: " + rubyObject);
}
return Proxy.newProxyInstance(classLoader, interfaces, new RubyObjectInvocationHandler(rubyObject, ruby));
}
示例2: createJRubyObject
import org.jruby.RubyNil; //导入依赖的package包/类
/**
* Create a new JRuby-scripted object from the given script source.
* @param scriptSource the script source text
* @param interfaces the interfaces that the scripted Java object is to implement
* @param classLoader the {@link ClassLoader} to create the script proxy with
* @return the scripted Java object
* @throws JumpException in case of JRuby parsing failure
*/
@SuppressWarnings("deprecation")
public static Object createJRubyObject(String scriptSource, Class<?>[] interfaces, ClassLoader classLoader) {
Ruby ruby = initializeRuntime();
Node scriptRootNode = ruby.parseEval(scriptSource, "", null, 0);
// Keep using the deprecated runNormally variant for JRuby 1.1/1.2 compatibility...
IRubyObject rubyObject = ruby.runNormally(scriptRootNode, false);
if (rubyObject instanceof RubyNil) {
String className = findClassName(scriptRootNode);
rubyObject = ruby.evalScriptlet("\n" + className + ".new");
}
// still null?
if (rubyObject instanceof RubyNil) {
throw new IllegalStateException("Compilation of JRuby script returned RubyNil: " + rubyObject);
}
return Proxy.newProxyInstance(classLoader, interfaces, new RubyObjectInvocationHandler(rubyObject, ruby));
}
示例3: rubyToPig
import org.jruby.RubyNil; //导入依赖的package包/类
/**
* This method facilitates conversion from Ruby objects to Pig objects. This is
* a general class which detects the subclass and invokes the appropriate conversion
* routine. It will fail on an unsupported datatype.
*
* @param rbObject a Ruby object to convert
* @return the Pig analogue of the Ruby object
* @throws ExecException if rbObject is not of a known type that can be converted
*/
@SuppressWarnings("unchecked")
public static Object rubyToPig(IRubyObject rbObject) throws ExecException {
if (rbObject == null || rbObject instanceof RubyNil) {
return null;
} else if (rbObject instanceof RubyArray) {
return rubyToPig((RubyArray)rbObject);
} else if (rbObject instanceof RubyHash) {
return rubyToPig((RubyHash)rbObject);
} else if (rbObject instanceof RubyString) {
return rubyToPig((RubyString)rbObject);
} else if (rbObject instanceof RubyBignum) {
return rubyToPig((RubyBignum)rbObject);
} else if (rbObject instanceof RubyFixnum) {
return rubyToPig((RubyFixnum)rbObject);
} else if (rbObject instanceof RubyFloat) {
return rubyToPig((RubyFloat)rbObject);
} else if (rbObject instanceof RubyInteger) {
return rubyToPig((RubyInteger)rbObject);
} else if (rbObject instanceof RubyDataBag) {
return rubyToPig((RubyDataBag)rbObject);
} else if (rbObject instanceof RubyDataByteArray) {
return rubyToPig((RubyDataByteArray)rbObject);
} else if (rbObject instanceof RubySchema) {
return rubyToPig((RubySchema)rbObject);
} else if (rbObject instanceof RubyBoolean) {
return rubyToPig((RubyBoolean)rbObject);
} else {
throw new ExecException("Cannot cast into any pig supported type: " + rbObject.getClass().getName());
}
}
示例4: root_set
import org.jruby.RubyNil; //导入依赖的package包/类
@JRubyMethod(name="root=")
public IRubyObject root_set(ThreadContext context, IRubyObject newRoot_) {
// in case of document fragment, temporary root node should be deleted.
// Java can't have a root whose value is null. Instead of setting null,
// the method sets user data so that other methods are able to know the root
// 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;
}
示例5: node_name
import org.jruby.RubyNil; //导入依赖的package包/类
/**
* Returns the local part of the element name.
*/
@Override
@JRubyMethod
public IRubyObject node_name(ThreadContext context) {
IRubyObject value = getAttribute(context, "name");
if (value instanceof RubyNil) value = name;
return value;
}
示例6: content
import org.jruby.RubyNil; //导入依赖的package包/类
@JRubyMethod
public IRubyObject content(ThreadContext context) {
IRubyObject value = getAttribute(context, "value");
if (value instanceof RubyNil) value = content;
return value;
}
示例7: system_id
import org.jruby.RubyNil; //导入依赖的package包/类
@JRubyMethod
public IRubyObject system_id(ThreadContext context) {
IRubyObject value = getAttribute(context, "sysid");
if (value instanceof RubyNil) value = system_id;
return value;
}
示例8: external_id
import org.jruby.RubyNil; //导入依赖的package包/类
@JRubyMethod
public IRubyObject external_id(ThreadContext context) {
IRubyObject value = getAttribute(context, "pubid");
if (value instanceof RubyNil) value = external_id;
return value;
}