Package org.jruby

Examples of org.jruby.RubyClass.newInstance()


            // if the given parameter is a Generator::State, return itself
            if (klass.isInstance(opts)) return (GeneratorState)opts;

            // if the given parameter is a Hash, pass it to the instantiator
            if (context.getRuntime().getHash().isInstance(opts)) {
                return (GeneratorState)klass.newInstance(context,
                        new IRubyObject[] {opts}, Block.NULL_BLOCK);
            }
        }

        // for other values, return the safe prototype
View Full Code Here


        IRubyObject arg = (message != null) ? runtime.newString(message) : runtime.getNil();

        RubyClass instance = runtime.getErrno(n);
        if(instance == null) {
            instance = runtime.getSystemCallError();
            throw new RaiseException((RubyException)(instance.newInstance(runtime.getCurrentContext(), new IRubyObject[]{arg, runtime.newFixnum(n)}, Block.NULL_BLOCK)));
        } else {
            throw new RaiseException((RubyException)(instance.newInstance(runtime.getCurrentContext(), new IRubyObject[]{arg}, Block.NULL_BLOCK)));
        }
    }
View Full Code Here

        RubyClass instance = runtime.getErrno(n);
        if(instance == null) {
            instance = runtime.getSystemCallError();
            throw new RaiseException((RubyException)(instance.newInstance(runtime.getCurrentContext(), new IRubyObject[]{arg, runtime.newFixnum(n)}, Block.NULL_BLOCK)));
        } else {
            throw new RaiseException((RubyException)(instance.newInstance(runtime.getCurrentContext(), new IRubyObject[]{arg}, Block.NULL_BLOCK)));
        }
    }

    public static void threadSleep(Ruby runtime, int interval) {
        try {
View Full Code Here

        Runnable timeoutRunnable = new Runnable() {
            public void run() {
                if (latch.compareAndSet(false, true)) {
                    if (currentThread.alive_p().isTrue()) {
                        RubyClass anonException = (RubyClass)runtime.getClassFromPath("Timeout::AnonymousException");
                        IRubyObject anonExceptionObj = anonException.newInstance(runtime.getCurrentContext(), runtime.newString("execution expired"), Block.NULL_BLOCK);
                        anonExceptionObj.getInternalVariables().setInternalVariable("__identifier__", id);
                        currentThread.internalRaise(new IRubyObject[] {anonExceptionObj});
                    }
                }
            }
View Full Code Here

  }
 
  public Object instantiate(Serializable id) {
    Ruby runtime = rc.getRuntime();
    RubyClass rubyClass = rc;
    IRubyObject ro = rubyClass.newInstance(runtime.getCurrentContext(), new IRubyObject[0], null);
        if(meta != null && !meta.isNil()) {
            meta.callMethod(runtime.getCurrentContext(), "persistent", ro);
        }
    return ro;
  }
View Full Code Here

            // if the given parameter is a Generator::State, return itself
            if (klass.isInstance(opts)) return (GeneratorState)opts;

            // if the given parameter is a Hash, pass it to the instantiator
            if (context.getRuntime().getHash().isInstance(opts)) {
                return (GeneratorState)klass.newInstance(context,
                        new IRubyObject[] {opts}, Block.NULL_BLOCK);
            }
        }

        // for other values, return the safe prototype
View Full Code Here

        PreparedStatement sqlStatement = null;
        ResultSet resultSet = null;
        ResultSetMetaData metaData;

        // instantiate a new reader
        Reader reader = (Reader) readerClass.newInstance(runtime.getCurrentContext(),
                                                     new IRubyObject[] { }, Block.NULL_BLOCK);

        // execute the query
        try {
            String doSqlText = api.convertToRubyString(
View Full Code Here

          "@connection");
      RubyModule doModule  = runtime.getModule(DATA_OBJECTS_MODULE_NAME);
      RubyClass loggerClass = doModule.getClass("Logger");
      RubyClass messageClass = loggerClass.getClass("Message");

      IRubyObject loggerMsg  = messageClass.newInstance(runtime.getCurrentContext(),
          runtime.newString(logMessage),    // query
          runtime.newString(""),            // start
          runtime.newFixnum(executionTime), // duration
          Block.NULL_BLOCK);
View Full Code Here

    public static RaiseException newSqlError(Ruby runtime,
            DriverDefinition driver,
            String message) {
        RubyModule doModule = runtime.getModule(DATA_OBJECTS_MODULE_NAME);
        RubyClass driverError = doModule.getClass(Type.SQL_ERROR.getRubyName());
        RubyException doSqlError = (RubyException) driverError.newInstance(
                runtime.getCurrentContext(),
                new IRubyObject[]{
                    runtime.newString(message)
                },
                Block.NULL_BLOCK);
View Full Code Here

        String uri = null;      // TODO: implement me

        if (statement != null)
            query = driver.statementToString(statement);

        RubyException doSqlError = (RubyException) driverError.newInstance(
                runtime.getCurrentContext(),
                new IRubyObject[]{
                    runtime.newString(message),
                    runtime.newFixnum(code),
                    (sqlState != null) ? runtime.newString(sqlState) : runtime.getNil(),
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.