use of org.jruby.RubyClass in project nokogiri by sparklemotion.
the class NokogiriService method createHtmlModule.
private void createHtmlModule(Ruby ruby, RubyModule htmlModule) {
RubyClass htmlElemDesc = htmlModule.defineClassUnder("ElementDescription", ruby.getObject(), HTML_ELEMENT_DESCRIPTION_ALLOCATOR);
htmlElemDesc.defineAnnotatedMethods(HtmlElementDescription.class);
RubyClass htmlEntityLookup = htmlModule.defineClassUnder("EntityLookup", ruby.getObject(), HTML_ENTITY_LOOKUP_ALLOCATOR);
htmlEntityLookup.defineAnnotatedMethods(HtmlEntityLookup.class);
}
use of org.jruby.RubyClass in project nokogiri by sparklemotion.
the class NokogiriService method createXmlModule.
private RubyClass createXmlModule(Ruby ruby, RubyModule xmlModule) {
RubyClass node = xmlModule.defineClassUnder("Node", ruby.getObject(), XML_NODE_ALLOCATOR);
node.defineAnnotatedMethods(XmlNode.class);
RubyClass attr = xmlModule.defineClassUnder("Attr", node, XML_ATTR_ALLOCATOR);
attr.defineAnnotatedMethods(XmlAttr.class);
RubyClass attrDecl = xmlModule.defineClassUnder("AttributeDecl", node, XML_ATTRIBUTE_DECL_ALLOCATOR);
attrDecl.defineAnnotatedMethods(XmlAttributeDecl.class);
RubyClass characterData = xmlModule.defineClassUnder("CharacterData", node, null);
RubyClass comment = xmlModule.defineClassUnder("Comment", characterData, XML_COMMENT_ALLOCATOR);
comment.defineAnnotatedMethods(XmlComment.class);
RubyClass text = xmlModule.defineClassUnder("Text", characterData, XML_TEXT_ALLOCATOR);
text.defineAnnotatedMethods(XmlText.class);
RubyModule cdata = xmlModule.defineClassUnder("CDATA", text, XML_CDATA_ALLOCATOR);
cdata.defineAnnotatedMethods(XmlCdata.class);
RubyClass dtd = xmlModule.defineClassUnder("DTD", node, XML_DTD_ALLOCATOR);
dtd.defineAnnotatedMethods(XmlDtd.class);
RubyClass documentFragment = xmlModule.defineClassUnder("DocumentFragment", node, XML_DOCUMENT_FRAGMENT_ALLOCATOR);
documentFragment.defineAnnotatedMethods(XmlDocumentFragment.class);
RubyClass element = xmlModule.defineClassUnder("Element", node, XML_ELEMENT_ALLOCATOR);
element.defineAnnotatedMethods(XmlElement.class);
RubyClass elementContent = xmlModule.defineClassUnder("ElementContent", ruby.getObject(), XML_ELEMENT_CONTENT_ALLOCATOR);
elementContent.defineAnnotatedMethods(XmlElementContent.class);
RubyClass elementDecl = xmlModule.defineClassUnder("ElementDecl", node, XML_ELEMENT_DECL_ALLOCATOR);
elementDecl.defineAnnotatedMethods(XmlElementDecl.class);
RubyClass entityDecl = xmlModule.defineClassUnder("EntityDecl", node, XML_ENTITY_DECL_ALLOCATOR);
entityDecl.defineAnnotatedMethods(XmlEntityDecl.class);
entityDecl.defineConstant("INTERNAL_GENERAL", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_GENERAL));
entityDecl.defineConstant("EXTERNAL_GENERAL_PARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_PARSED));
entityDecl.defineConstant("EXTERNAL_GENERAL_UNPARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_UNPARSED));
entityDecl.defineConstant("INTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PARAMETER));
entityDecl.defineConstant("EXTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_PARAMETER));
entityDecl.defineConstant("INTERNAL_PREDEFINED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PREDEFINED));
RubyClass entref = xmlModule.defineClassUnder("EntityReference", node, XML_ENTITY_REFERENCE_ALLOCATOR);
entref.defineAnnotatedMethods(XmlEntityReference.class);
RubyClass namespace = xmlModule.defineClassUnder("Namespace", ruby.getObject(), XML_NAMESPACE_ALLOCATOR);
namespace.defineAnnotatedMethods(XmlNamespace.class);
RubyClass nodeSet = xmlModule.defineClassUnder("NodeSet", ruby.getObject(), XML_NODESET_ALLOCATOR);
nodeSet.defineAnnotatedMethods(XmlNodeSet.class);
RubyClass pi = xmlModule.defineClassUnder("ProcessingInstruction", node, XML_PROCESSING_INSTRUCTION_ALLOCATOR);
pi.defineAnnotatedMethods(XmlProcessingInstruction.class);
RubyClass reader = xmlModule.defineClassUnder("Reader", ruby.getObject(), XML_READER_ALLOCATOR);
reader.defineAnnotatedMethods(XmlReader.class);
RubyClass schema = xmlModule.defineClassUnder("Schema", ruby.getObject(), XML_SCHEMA_ALLOCATOR);
schema.defineAnnotatedMethods(XmlSchema.class);
RubyClass relaxng = xmlModule.defineClassUnder("RelaxNG", schema, XML_RELAXNG_ALLOCATOR);
relaxng.defineAnnotatedMethods(XmlRelaxng.class);
RubyClass xpathContext = xmlModule.defineClassUnder("XPathContext", ruby.getObject(), XML_XPATHCONTEXT_ALLOCATOR);
xpathContext.defineAnnotatedMethods(XmlXpathContext.class);
return node;
}
use of org.jruby.RubyClass in project nokogiri by sparklemotion.
the class XmlNode method rbNew.
/**
* Allocate a new object, perform initialization, call that
* object's initialize method, and call any block passing the
* object as the only argument. If <code>cls</code> is
* Nokogiri::XML::Node, creates a new Nokogiri::XML::Element
* instead.
*
* This static method seems to be inherited, strangely enough.
* E.g. creating a new XmlAttr from Ruby code calls this method if
* XmlAttr does not define its own 'new' method.
*
* Since there is some Java bookkeeping that always needs to
* happen, we don't define the 'initialize' method in Java because
* we'd have to count on subclasses calling 'super'.
*
* The main consequence of this is that every subclass needs to
* define its own 'new' method.
*
* As a convenience, this method does the following:
*
* <ul>
*
* <li>allocates a new object using the allocator assigned to
* <code>cls</code></li>
*
* <li>calls the Java method init(); subclasses can override this,
* otherwise they should implement a specific 'new' method</li>
*
* <li>invokes the Ruby initializer</li>
*
* <li>if a block is given, calls the block with the new node as
* the argument</li>
*
* </ul>
*
* -pmahoney
*/
@JRubyMethod(name = "new", meta = true, rest = true)
public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args, Block block) {
Ruby ruby = context.getRuntime();
RubyClass klazz = (RubyClass) cls;
if ("Nokogiri::XML::Node".equals(klazz.getName())) {
klazz = getNokogiriClass(ruby, "Nokogiri::XML::Element");
}
XmlNode xmlNode = (XmlNode) klazz.allocate();
xmlNode.init(context, args);
xmlNode.callInit(args, block);
assert xmlNode.node != null;
if (block.isGiven())
block.call(context, xmlNode);
return xmlNode;
}
use of org.jruby.RubyClass in project cuke4duke by cucumber.
the class JRubyExceptionFactory method error.
public Exception error(String errorClass, String message) {
RubyModule cucumber = JRuby.getRuntime().getModule("Cucumber");
RubyClass error = cucumber.getClass(errorClass);
return new RaiseException(JRuby.getRuntime(), error, message, true);
}
Aggregations