title: Rhino: How to pass Java object to script, where can be referenced as "this"
body: <p>I am new to JSR-223 Java Scripting, actually I'm switching from <a href="http://mvel.codehaus.org/" rel="nofollow"><strong>MVEL</strong></a> to standard <a href="http://www.mozilla.org/rhino/" rel="nofollow"><strong>Mozilla Rhino JS</strong></a>. I have read all documentation, but get stuck. I have tried to reference some Java objects from script by bindings just like in tutorial:</p>
  
  <pre><code>    // my object
      public class MyBean {
         public String getStringValue() { return "abc" };
      }
  
      // initialization
      ScriptEngineManager manager = new ScriptEngineManager();
      ScriptEngine engine = manager.getEngineByName("JavaScript");
  
      // add bindings
      engine.put("bean", new MyBean());
  
      // evaluate script, output is "abc"
      engine.eval("print(bean.stringValue)");
  </code></pre>
  
  <p>Java object is referenced from script as property <code>bean</code>. So far so good. </p>
  
  <p>But I want to reference my object in script as <code>this</code>, I want to use its properties and methods without any prefix or explicitely with prefix <code>this</code>. Just like this:</p>
  
  <pre><code>    // add bindings
      engine.put(....., new MyBean()); // or whatever ???
  
      // evaluate scripts, all have the same output "abc"
      engine.eval("print(stringValue)");
      engine.eval("print(this.stringValue)");
  </code></pre>
  
  <p>I know that <code>this</code> in JavaScript has special meaning (as in Java) but in MVEL scripting that could be done by using custom <a href="http://codehaus.org/~mvel/javadoc/2.0/org/mvel2/ParserContext.html" rel="nofollow"><code>ParserContext</code></a> and custom <a href="http://codehaus.org/~mvel/javadoc/2.0/org/mvel2/integration/PropertyHandler.html" rel="nofollow"><code>PropertyHandler</code></a>. </p>
  
  <p><strong>Is something like this possible in Rhino?</strong></p>
  
  <p>Thanks a lot.</p>