Package org.jruby

Examples of org.jruby.RubyModule


        return SafeConstructorImpl.constructJava(ctor,pref,node);
    }

    public static Object constructRubyException(final Constructor ctor, final String tag, final Node node) {
        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        RubyModule objClass = runtime.getObject();
        if(tag != null) {
            final String[] nms = tag.split("::");
            try {
                for(int i=0,j=nms.length;i<j;i++) {
                    objClass = (RubyModule)objClass.getConstant(nms[i]);
                }
            } catch(Exception e) {
                // No constant available, so we'll fall back on YAML::Object
                objClass = (RubyClass)runtime.fastGetModule("YAML").fastGetConstant("Object");
                final RubyHash vars = (RubyHash)(((JRubyConstructor)ctor).constructRubyMapping(node));
View Full Code Here


        return oo;
    }

    public static Object constructRubyStruct(final Constructor ctor, final String tag, final Node node) {
        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        RubyModule sClass = runtime.fastGetModule("Struct");
        RubyClass struct_type;
        String[] nms = tag.split("::");
        for(int i=0,j=nms.length;i<j && sClass != null;i++) {
            sClass = (RubyModule)sClass.getConstant(nms[i]);
        }

        Map props = new HashMap();
        Map val = (Map)(ctor.constructMapping(node));
        for(Iterator iter = val.entrySet().iterator();iter.hasNext();) {
View Full Code Here

        }
    }

    public static Object constructRuby(final Constructor ctor, final String tag, final Node node) {
        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        RubyModule objClass = runtime.getObject();
        if(tag != null) {
            final String[] nms = tag.split("::");
            try {
                for(int i=0,j=nms.length;i<j;i++) {
                    objClass = (RubyModule)objClass.getConstant(nms[i]);
                }
            } catch(Exception e) {
                // No constant available, so we'll fall back on YAML::Object
                objClass = (RubyClass)runtime.fastGetModule("YAML").fastGetConstant("Object");
                final RubyHash vars = (RubyHash)(((JRubyConstructor)ctor).constructRubyMapping(node));
View Full Code Here

        return null;
    }

    public static Object constructRubyInt(final Constructor ctor, final String tag, final Node node) {
        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        RubyModule objClass = runtime.getObject();
        if(tag != null) {
            final String[] nms = tag.split("::");
            for(int i=0,j=nms.length;i<j;i++) {
                objClass = (RubyModule)objClass.getConstant(nms[i]);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final IRubyObject val = (IRubyObject)constructYamlInt(ctor, node);
View Full Code Here

        return oo;
    }

    public static Object constructRubyString(final Constructor ctor, final String tag, final Node node) {
        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        RubyModule objClass = runtime.getObject();
        if(tag != null) {
            final String[] nms = tag.split("::");
            for(int i=0,j=nms.length;i<j;i++) {
                objClass = (RubyModule)objClass.getConstant(nms[i]);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final IRubyObject val = (IRubyObject)constructYamlStr(ctor, node);
View Full Code Here

        return oo;
    }

    public static Object constructRubyMap(final Constructor ctor, final String tag, final Node node) {
        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        RubyModule objClass = runtime.getObject();
        if(tag != null) {
            final String[] nms = tag.split("::");
            for(int i=0,j=nms.length;i<j;i++) {
                objClass = (RubyModule)objClass.getConstant(nms[i]);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final Map vars = (Map)(ctor.constructMapping(node));
View Full Code Here

        return oo;
    }

    public static Object constructRubySequence(final Constructor ctor, final String tag, final Node node) {
        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        RubyModule objClass = runtime.getObject();
        if(tag != null) {
            final String[] nms = tag.split("::");
            for(int i=0,j=nms.length;i<j;i++) {
                objClass = (RubyModule)objClass.getConstant(nms[i]);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final List vars = (List)(ctor.constructSequence(node));
View Full Code Here

        RubyClassPathVariable.createClassPathVariable(runtime);
    }

    public static RubyModule createJavaModule(Ruby runtime) {
        ThreadContext context = runtime.getCurrentContext();
        RubyModule javaModule = runtime.defineModule("Java");
       
        javaModule.defineAnnotatedMethods(Java.class);

        JavaObject.createJavaObjectClass(runtime, javaModule);
        JavaArray.createJavaArrayClass(runtime, javaModule);
        JavaClass.createJavaClassClass(runtime, javaModule);
        JavaMethod.createJavaMethodClass(runtime, javaModule);
        JavaConstructor.createJavaConstructorClass(runtime, javaModule);
        JavaField.createJavaFieldClass(runtime, javaModule);
       
        // set of utility methods for Java-based proxy objects
        JavaProxyMethods.createJavaProxyMethods(context);
       
        // the proxy (wrapper) type hierarchy
        JavaProxy.createJavaProxy(context);
        ConcreteJavaProxy.createConcreteJavaProxy(context);
        //InterfaceJavaProxy.createInterfaceJavaProxy(context);
        ArrayJavaProxy.createArrayJavaProxy(context);

        // also create the JavaProxy* classes
        JavaProxyClass.createJavaProxyModule(runtime);

        // The template for interface modules
        JavaInterfaceTemplate.createJavaInterfaceTemplateModule(context);

        RubyModule javaUtils = runtime.defineModule("JavaUtilities");
       
        javaUtils.defineAnnotatedMethods(JavaUtilities.class);

        runtime.getJavaSupport().setConcreteProxyCallback(new Callback() {
            public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block block) {
                Arity.checkArgumentCount(recv.getRuntime(), args, 1, 1);
               
View Full Code Here

    public static RubyModule getInterfaceModule(Ruby runtime, JavaClass javaClass) {
        if (!javaClass.javaClass().isInterface()) {
            throw runtime.newArgumentError(javaClass.toString() + " is not an interface");
        }
        RubyModule interfaceModule;
        if ((interfaceModule = javaClass.getProxyModule()) != null) {
            return interfaceModule;
        }
        javaClass.lockProxy();
        try {
            if ((interfaceModule = javaClass.getProxyModule()) == null) {
                interfaceModule = (RubyModule) runtime.getJavaSupport().getJavaInterfaceTemplate().dup();
                interfaceModule.fastSetInstanceVariable("@java_class", javaClass);
                addToJavaPackageModule(interfaceModule, javaClass);
                javaClass.setupInterfaceModule(interfaceModule);
                // include any interfaces we extend
                Class<?>[] extended = javaClass.javaClass().getInterfaces();
                for (int i = extended.length; --i >= 0;) {
                    JavaClass extendedClass = JavaClass.get(runtime, extended[i]);
                    RubyModule extModule = getInterfaceModule(runtime, extendedClass);
                    interfaceModule.includeModule(extModule);
                }
            }
        } finally {
            javaClass.unlockProxy();
View Full Code Here

            return proxyClass;
        }
        javaClass.lockProxy();
        try {
            if ((proxyClass = javaClass.getProxyClass()) == null) {
                RubyModule interfaceModule = getInterfaceModule(runtime, javaClass);
                RubyClass interfaceJavaProxy = runtime.fastGetClass("InterfaceJavaProxy");
                proxyClass = RubyClass.newClass(runtime, interfaceJavaProxy);
                proxyClass.setAllocator(interfaceJavaProxy.getAllocator());
                proxyClass.makeMetaClass(interfaceJavaProxy.getMetaClass());
                // parent.setConstant(name, proxyClass); // where the name should come from ?
View Full Code Here

TOP

Related Classes of org.jruby.RubyModule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.