use of org.jruby.RubyClass in project jo by headius.
the class JoLibrary method load.
public void load(Ruby runtime, boolean wrap) throws IOException {
RubyModule jo = runtime.defineModule("Jo");
final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
}
});
jo.setInternalVariable("executor", executor);
RubyClass joFuture = jo.defineClassUnder("Future", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
RubyClass joChannel = jo.defineClassUnder("Channel", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
jo.defineAnnotatedMethods(JoMethods.class);
joFuture.defineAnnotatedMethods(JoFuture.class);
joChannel.defineAnnotatedMethods(JoChannel.class);
runtime.addFinalizer(new Finalizable() {
public void finalize() {
executor.shutdown();
}
});
}
use of org.jruby.RubyClass in project nokogiri by sparklemotion.
the class XsltStylesheet method parse_stylesheet_doc.
@JRubyMethod(meta = true, rest = true)
public static IRubyObject parse_stylesheet_doc(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
ensureFirstArgIsDocument(runtime, args[0]);
XmlDocument xmlDoc = (XmlDocument) args[0];
ensureDocumentHasNoError(context, xmlDoc);
Document doc = ((XmlDocument) xmlDoc.dup_implementation(context, true)).getDocument();
XsltStylesheet xslt = (XsltStylesheet) NokogiriService.XSLT_STYLESHEET_ALLOCATOR.allocate(runtime, (RubyClass) klazz);
try {
xslt.init(args[1], doc);
} catch (TransformerConfigurationException ex) {
throw runtime.newRuntimeError("could not parse xslt stylesheet");
}
return xslt;
}
use of org.jruby.RubyClass in project nokogiri by sparklemotion.
the class XsltStylesheet method createDocumentFromString.
private IRubyObject createDocumentFromString(ThreadContext context, Ruby runtime, String stringResult) {
IRubyObject[] args = new IRubyObject[4];
args[0] = stringOrBlank(runtime, stringResult);
// url
args[1] = runtime.getNil();
// encoding
args[2] = runtime.getNil();
RubyClass parse_options = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::ParseOptions");
if (htmlish) {
args[3] = parse_options.getConstant("DEFAULT_HTML");
RubyClass htmlDocumentClass = getNokogiriClass(runtime, "Nokogiri::HTML::Document");
return RuntimeHelpers.invoke(context, htmlDocumentClass, "parse", args);
} else {
args[3] = parse_options.getConstant("DEFAULT_XML");
RubyClass xmlDocumentClass = getNokogiriClass(runtime, "Nokogiri::XML::Document");
XmlDocument xmlDocument = (XmlDocument) RuntimeHelpers.invoke(context, xmlDocumentClass, "parse", args);
if (((Document) xmlDocument.getNode()).getDocumentElement() == null) {
RubyArray errors = (RubyArray) xmlDocument.getInstanceVariable("@errors");
RuntimeHelpers.invoke(context, errors, "<<", args[0]);
}
return xmlDocument;
}
}
use of org.jruby.RubyClass in project nokogiri by sparklemotion.
the class NokogiriService method createDocuments.
private void createDocuments(Ruby ruby, RubyModule xmlModule, RubyModule htmlModule, RubyClass node) {
RubyClass xmlDocument = xmlModule.defineClassUnder("Document", node, XML_DOCUMENT_ALLOCATOR);
xmlDocument.defineAnnotatedMethods(XmlDocument.class);
//RubyModule htmlDoc = html.defineOrGetClassUnder("Document", document);
RubyModule htmlDocument = htmlModule.defineClassUnder("Document", xmlDocument, HTML_DOCUMENT_ALLOCATOR);
htmlDocument.defineAnnotatedMethods(HtmlDocument.class);
}
use of org.jruby.RubyClass in project nokogiri by sparklemotion.
the class NokogiriService method createNokogiriModule.
private void createNokogiriModule(Ruby ruby, RubyModule nokogiri) {
RubyClass encHandler = nokogiri.defineClassUnder("EncodingHandler", ruby.getObject(), ENCODING_HANDLER_ALLOCATOR);
encHandler.defineAnnotatedMethods(EncodingHandler.class);
}
Aggregations