Package org.jruby.ribs

Source Code of org.jruby.ribs.RubyInstantiator

package org.jruby.ribs;

import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.runtime.builtin.IRubyObject;

import java.io.Serializable;

import org.hibernate.mapping.PersistentClass;
import org.hibernate.tuple.Instantiator;
import org.hibernate.mapping.Component;


public class RubyInstantiator implements Instantiator {
    private RubyClass rc;
    private IRubyObject meta;

  public RubyInstantiator(Component component) {
  }
 
  public RubyInstantiator(PersistentClass mappingInfo) {
        rc = ((WithRubyClass)mappingInfo).getRubyClass();
        meta = ((WithRubyClass)mappingInfo).getRubyData("meatspace");
  }
 
  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;
  }

  public Object instantiate() {
    return this.instantiate(null);
  }

  public boolean isInstance(Object object) {
    return object instanceof IRubyObject;
  }
}
TOP

Related Classes of org.jruby.ribs.RubyInstantiator

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.