org.jruby.embed.osgi
Class OSGiScriptingContainer

java.lang.Object
  extended by org.jruby.embed.ScriptingContainer
      extended by org.jruby.embed.osgi.OSGiScriptingContainer
All Implemented Interfaces:
EmbedRubyInstanceConfigAdapter

public class OSGiScriptingContainer
extends ScriptingContainer

Helpers to create a ScriptingContainer and set it up so it lives as well as possible in the OSGi world.

Currently:

  1. Access to the java classes and resources provided by the osgi bundle.
  2. Setup of jruby home pointing at the jruby bundle by default. Supporting unzipped jruby bundle for now.

TODO: look into using the LoadService of jruby. Look if it would be possible to reuse the base runtime and minimize the cost of new jruby runtimes.

Author:
hmalphettes

Constructor Summary
OSGiScriptingContainer(org.osgi.framework.Bundle creator)
           
OSGiScriptingContainer(org.osgi.framework.Bundle creator, LocalContextScope scope, LocalVariableBehavior behavior)
           
 
Method Summary
 void addToClassPath(org.osgi.framework.Bundle bundle)
           
 JRubyOSGiBundleClassLoader getOSGiBundleClassLoader()
           
 EmbedEvalUnit parse(org.osgi.framework.Bundle bundle, java.lang.String path, int... lines)
          Parses a script given by a input stream and return an object which can be run().
 java.lang.Object runScriptlet(org.osgi.framework.Bundle bundle, java.lang.String path)
           
 java.lang.Object runScriptlet(java.lang.String bundleSymbolicName, java.lang.String path)
           
 
Methods inherited from class org.jruby.embed.ScriptingContainer
callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, callSuper, clear, finalize, get, get, getArgv, getAttribute, getAttributeMap, getClassCache, getClassLoader, getCompatVersion, getCompileMode, getCurrentDirectory, getEnvironment, getErr, getError, getErrorWriter, getHomeDirectory, getIn, getInput, getInstance, getJitLogEvery, getJitMax, getJitMaxSize, getJitThreshold, getKCode, getLoadPaths, getLoadServiceCreator, getOut, getOutput, getProfile, getProperty, getProvider, getReader, getRecordSeparator, getRuntime, getScriptFilename, getSupportedRubyVersion, getVarMap, getWriter, isObjectSpaceEnabled, isRunRubyInProcess, newObjectAdapter, newRuntimeAdapter, parse, parse, parse, parse, put, put, remove, remove, removeAttribute, resetErrorWriter, resetWriter, runScriptlet, runScriptlet, runScriptlet, runScriptlet, setArgv, setAttribute, setClassCache, setClassLoader, setCompatVersion, setCompileMode, setCurrentDirectory, setEnvironment, setError, setError, setErrorWriter, setHomeDirectory, setInput, setInput, setJitLogEvery, setJitMax, setJitMaxSize, setJitThreshold, setKCode, setLoadPaths, setLoadServiceCreator, setObjectSpaceEnabled, setOutput, setOutput, setProfile, setReader, setRecordSeparator, setRunRubyInProcess, setScriptFilename, setWriter, terminate
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OSGiScriptingContainer

public OSGiScriptingContainer(org.osgi.framework.Bundle creator)

OSGiScriptingContainer

public OSGiScriptingContainer(org.osgi.framework.Bundle creator,
                              LocalContextScope scope,
                              LocalVariableBehavior behavior)
Parameters:
scope - if null, LocalContextScope.SINGLETHREAD
behavior - if null, LocalVariableBehavior.TRANSIENT
Method Detail

runScriptlet

public java.lang.Object runScriptlet(java.lang.String bundleSymbolicName,
                                     java.lang.String path)
Parameters:
bundleSymbolicName - The bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)
path - The entry in the bundle
Returns:

runScriptlet

public java.lang.Object runScriptlet(org.osgi.framework.Bundle bundle,
                                     java.lang.String path)
Parameters:
bundle - The bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)
path - The entry in the bundle
Returns:

parse

public EmbedEvalUnit parse(org.osgi.framework.Bundle bundle,
                           java.lang.String path,
                           int... lines)
                    throws java.io.IOException
Parses a script given by a input stream and return an object which can be run(). This allows the script to be parsed once and evaluated many times.

Parameters:
bundle - is where the script is located
path - is the entry in the bundle.
lines - are linenumbers to display for parse errors and backtraces. This field is optional. Only the first argument is used for parsing. When no line number is specified, 0 is applied to.
Returns:
an object which can be run
Throws:
java.io.IOException

addToClassPath

public void addToClassPath(org.osgi.framework.Bundle bundle)
Parameters:
bundle - Add a bundle to the jruby classloader. Equivalent to require "bundle:/#{bundle.symbolic.name}"

getOSGiBundleClassLoader

public JRubyOSGiBundleClassLoader getOSGiBundleClassLoader()
Returns:
The ScriptingContainer's classloader casted to a JRubyOSGiBundleClassLoader. It is the parent classloader of the actual's runtime's JRubyClassLoader. It enables finding classes and resources in the OSGi environment.


Copyright © 2002-2009 JRuby Team. All Rights Reserved.