@JRubyMethod( name = {"register_namespaces"}, rest = true) public IRubyObject registerNamespaces(ThreadContext context, IRubyObject[] args) { for (int i = 0; i < args.length; i++) { if ((args[i] instanceof RubyString)) { String str = args[i].asJavaString(); int j = str.indexOf(':'); this.namespaceMapping.put(str.substring(0, j), str.substring(j + 1)); } else { if ((args[i] instanceof RubyHash)) { RubyHash hash = (RubyHash) args[i]; for (Object obj : hash.entrySet()) { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj; String prefix = UtilJ.toJavaString(entry.getKey()); String uri = UtilJ.toJavaString(entry.getValue()); this.namespaceMapping.put(prefix, uri); } } else if ((args[i] instanceof RubyArray)) { RubyArray array = (RubyArray) args[i]; for (IRubyObject obj : UtilJ.toStringArray(context, array, 0)) { String str = obj.asJavaString(); int x = str.indexOf(':'); this.namespaceMapping.put(str.substring(0, x), str.substring(x + 1)); } } else { throw context .getRuntime() .newArgumentError("unsupported argument type " + args[i].getMetaClass().getName()); } } } return this; }
private static RubyClass getRubyClass(Ruby runtime) { return UtilJ.getClass(runtime, XPathContextJ.class); }
public static RubyClass define(Ruby runtime) { return UtilJ.defineClass(runtime, XPathContextJ.class, ALLOCATOR); }