Author: reto
Date: Sun May 30 21:57:34 2010
New Revision: 949595
URL: http://svn.apache.org/viewvc?rev=949595&view=rev
Log:
CLEREZZA-221: started pax-exam tests, reorganized project
Added:
incubator/clerezza/trunk/scala-scripting/script-engine/ (props changed)
- copied from r948559, incubator/clerezza/trunk/scala-scripting/console/
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/BundleContextScalaInterpreter.scala
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterFactory.scala
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/ScriptEngineFactory.scala
Modified:
incubator/clerezza/trunk/scala-scripting/script-engine/pom.xml
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/resources/OSGI-INF/serviceComponents.xml
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterService.scala
Propchange: incubator/clerezza/trunk/scala-scripting/script-engine/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun May 30 21:57:34 2010
@@ -0,0 +1 @@
+target
Modified: incubator/clerezza/trunk/scala-scripting/script-engine/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/scala-scripting/script-engine/pom.xml?rev=949595&r1=948559&r2=949595&view=diff
==============================================================================
--- incubator/clerezza/trunk/scala-scripting/script-engine/pom.xml (original)
+++ incubator/clerezza/trunk/scala-scripting/script-engine/pom.xml Sun May 30
21:57:34 2010
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.clerezza.scala</groupId>
- <artifactId>console</artifactId>
- <version>0.1-incubating-SNAPSHOT</version>
+ <parent>
+ <groupId>org.apache.clerezza.scala</groupId>
+ <artifactId>scala</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+ <artifactId>script-engine</artifactId>
<packaging>bundle</packaging>
- <name>Scala Console Launcher</name>
+ <name>Scala OSGi Services - Script Engine</name>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
@@ -33,23 +36,8 @@
</dependency>
</dependencies>
<build>
- <sourceDirectory>src/main/scala</sourceDirectory>
- <testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
- <groupId>org.scala-tools</groupId>
- <artifactId>maven-scala-plugin</artifactId>
- <version>2.13.1</version>
- <executions>
- <execution>
- <goals>
- <goal>compile</goal>
- <goal>testCompile</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
Modified:
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/resources/OSGI-INF/serviceComponents.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/scala-scripting/script-engine/src/main/resources/OSGI-INF/serviceComponents.xml?rev=949595&r1=948559&r2=949595&view=diff
==============================================================================
---
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/resources/OSGI-INF/serviceComponents.xml
(original)
+++
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/resources/OSGI-INF/serviceComponents.xml
Sun May 30 21:57:34 2010
@@ -4,6 +4,24 @@
<implementation
class="org.apache.clerezza.scala.console.InterpreterService"/>
<property name="service.pid"
value="org.apache.clerezza.scala.console.InterpreterService"/>
</scr:component>
+ <scr:component enabled="true" immediate="true"
name="org.apache.clerezza.scala.console.InterpreterFactory">
+ <implementation
class="org.apache.clerezza.scala.console.InterpreterFactory"/>
+ <service servicefactory="false">
+ <provide
interface="org.apache.clerezza.scala.console.InterpreterFactory"/>
+ </service>
+ <property name="service.pid"
value="org.apache.clerezza.scala.console.InterpreterFactory"/>
+ </scr:component>
+ <scr:component enabled="true" immediate="true"
name="org.apache.clerezza.scala.console.ScriptEngineFactory">
+ <implementation
class="org.apache.clerezza.scala.console.ScriptEngineFactory"/>
+ <service servicefactory="false">
+ <provide interface="javax.script.ScriptEngineFactory"/>
+ </service>
+ <property name="service.pid"
value="org.apache.clerezza.scala.console.ScriptEngineFactory"/>
+ <reference name="interpreterFactory"
+
interface="org.apache.clerezza.scala.console.InterpreterFactory"
+ cardinality="1..1"
+ bind="bindInterpreterFactory"
unbind="unbindInterpreterFactory"/>
+ </scr:component>
<!-- <scr:component enabled="true" immediate="true"
name="org.apache.clerezza.scala.console.Launcher">
<implementation class="org.apache.clerezza.scala.console.Launcher"/>
<property name="service.pid"
value="org.apache.clerezza.scala.console.Launcher"/>
Added:
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/BundleContextScalaInterpreter.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/BundleContextScalaInterpreter.scala?rev=949595&view=auto
==============================================================================
---
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/BundleContextScalaInterpreter.scala
(added)
+++
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/BundleContextScalaInterpreter.scala
Sun May 30 21:57:34 2010
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.scala.console;
+
+
+
+import org.apache.felix.scr.annotations.Component;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.framework.Bundle
+import java.io.{File, PrintWriter}
+import java.util.{ArrayList, Arrays};
+import scala.tools.nsc._;
+import scala.tools.nsc.interpreter._;
+import scala.tools.nsc.io.{AbstractFile, PlainFile}
+import scala.tools.nsc.util._
+import scala.tools.nsc.symtab.SymbolLoaders
+import java.net._
+import scala.tools.nsc.reporters.ConsoleReporter
+import scala.tools.nsc.reporters.Reporter
+import scala.tools.util.PathResolver
+import scala.tools.nsc.util.{ClassPath, JavaClassPath}
+
+
+class BundleContextScalaInterpreter(bundles: Array[Bundle], out: PrintWriter)
+ extends Interpreter(new Settings, out) {
+
+ def this(bundles: Array[Bundle]) = {
+ this(bundles, new PrintWriter(System.out))
+ }
+ protected val PATH_SEPARATOR = System.getProperty("path.separator")
+
+ override lazy val classLoader: AbstractFileClassLoader = {
+ new AbstractFileClassLoader(virtualDirectory,
this.getClass.getClassLoader())
+ }
+ override protected def newCompiler(settings: Settings,
reporter: Reporter) = {
+ reporter.info(scala.tools.nsc.util.NoPosition, "new
Compiler", true)
+ settings.outputDirs setSingleOutput virtualDirectory
+ new Global(settings, reporter) {
+ private lazy val _classPath:
ClassPath[AbstractFile] = {
+
+ val classPathOrig:
ClassPath[AbstractFile] = new PathResolver(settings).result
+
+ val classPathAbstractFiles = for
(bundle <- bundles;
+ val url =
bundle.getResource("/");
+ if url != null) yield {
+ if
("file".equals(url.getProtocol())) {
+ new PlainFile(new
File(url.toURI()))
+ }
+ else {
+ BundleFS.create(bundle);
+ }
+ }
+ val classPaths:
List[ClassPath[AbstractFile]] = (for (abstractFile <- classPathAbstractFiles)
+ yield {
+ new
DirectoryClassPath(abstractFile, classPathOrig.context)
+ }) toList
+
+ val classPath = new
MergedClassPath[AbstractFile](classPathOrig :: classPaths,
+
classPathOrig.context)
+ classPath
+ }
+ override lazy val classPath: ClassPath[_] = {
+ _classPath
+ }
+
+ override def rootLoader: LazyType = {
+
+ new
loaders.JavaPackageLoader(_classPath)
+ }
+ }
+ }
+ }
+
Added:
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterFactory.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterFactory.scala?rev=949595&view=auto
==============================================================================
---
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterFactory.scala
(added)
+++
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterFactory.scala
Sun May 30 21:57:34 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.scala.console;
+
+
+
+import org.apache.felix.scr.annotations.Component;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.framework.Bundle
+import java.io.{File, PrintWriter}
+import java.util.{ArrayList, Arrays};
+import scala.tools.nsc._;
+import scala.tools.nsc.interpreter._;
+import scala.tools.nsc.io.{AbstractFile, PlainFile}
+import scala.tools.nsc.util._
+import scala.tools.nsc.symtab.SymbolLoaders
+import java.net._
+import scala.tools.nsc.reporters.ConsoleReporter
+import scala.tools.nsc.reporters.Reporter
+import scala.tools.util.PathResolver
+import scala.tools.nsc.util.{ClassPath, JavaClassPath}
+
+
+class InterpreterFactory() {
+
+ protected var bundles: Array[Bundle] = null
+
+ def activate(componentContext: ComponentContext)= {
+ bundles = componentContext.getBundleContext.getBundles
+ //TODO register listener for bunle-changed events
+ }
+
+ def deactivate(componentContext: ComponentContext) = {
+ bundles = null
+ }
+
+ def createInterpreter(out: PrintWriter) : Interpreter =
+ new BundleContextScalaInterpreter(bundles, out)
+
+
+}
Modified:
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterService.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterService.scala?rev=949595&r1=948559&r2=949595&view=diff
==============================================================================
---
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterService.scala
(original)
+++
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/InterpreterService.scala
Sun May 30 21:57:34 2010
@@ -41,22 +41,19 @@ class InterpreterService() {
protected val PATH_SEPARATOR = System.getProperty("path.separator")
- var bundles: Array[Bundle] = null;
- val parentClassLoader: ClassLoader = this.getClass.getClassLoader()
-
def activate(componentContext: ComponentContext) {
System.out.println("activating");
//val bundle = componentContext.getBundleContext.getBundle
- bundles = componentContext.getBundleContext.getBundles
+ val bundles = componentContext.getBundleContext.getBundles
val settings = new Settings();/*createSettings(
bundles,
componentContext)*/
val origBootclasspath = settings.bootclasspath.value
//settings.bootclasspath.value = (origBootclasspath ::
pathList).mkString(java.io.File.separator)
-
-
- for (i <- 1 to 1000) {
+ val interpreter = new BundleContextScalaInterpreter(bundles)
+ println(new java.util.Date)
+ for (i <- 1 to 100) {
val script = """
println("hello"""+Math.random+"""");
"good bye"
@@ -68,6 +65,7 @@ class InterpreterService() {
case e:Exception => e.printStackTrace()
}
}
+ println(new java.util.Date)
//scala.tools.nsc.MainGenericRunner.main(new String[0]);
@@ -104,106 +102,5 @@ class InterpreterService() {
return urls.toArray(new Array[URL](urls.size))
}
- lazy val interpreter = new Interpreter(new Settings, new
PrintWriter(System.out)) { // new Interpreter(settings){
- /*override object reporter extends
ConsoleReporter(settings, null, new PrintWriter(System.out)) {
- override def printMessage(msg: String) {
- println(msg)
- }
- }*/
-
-
- override def classLoader: AbstractFileClassLoader = {
- println("requested classLoader")
- new AbstractFileClassLoader(virtualDirectory,
parentClassLoader) {
- override def tryToInitializeClass[T <:
AnyRef](path: String): Option[Class[T]] = {
- println("initializing "+path)
- super.tryToInitializeClass(path)
- }
- }
- }
- override protected def newCompiler(settings: Settings,
reporter: Reporter) = {
- println("requested compiler for "+settings)
- reporter.info(scala.tools.nsc.util.NoPosition
/* {
- override def source = null}*/, "new
Compiler", true)
- //super.newCompiler(settings, reporter)
- settings.outputDirs setSingleOutput
virtualDirectory
- new Global(settings, reporter) {
- println("constructing compiler")
-
- private lazy val _classPath:
ClassPath[AbstractFile] = {
- //println("getting ClassPath!")
- //throw new RuntimeException
- //super.classPath
- //of classpath.packages is a
seq of ClassPath[AbstractFile]
- val classPathOrig:
ClassPath[AbstractFile] = new PathResolver(settings).result
-
- val classPathAbstractFiles =
for (bundle <- bundles;
- val url =
bundle.getResource("/");
- if url != null)
yield {
- if
("file".equals(url.getProtocol())) {
- new
PlainFile(new File(url.toURI()))
- }
- else {
-
BundleFS.create(bundle);
- }
- }
- val classPaths:
List[ClassPath[AbstractFile]] = (for (abstractFile <- classPathAbstractFiles)
- yield {
- new
DirectoryClassPath(abstractFile, classPathOrig.context)
- }) toList
-
- val classPath = new
MergedClassPath[AbstractFile](classPathOrig :: classPaths,
-
classPathOrig.context)
- classPath
- }
- override lazy val classPath:
ClassPath[_] = {
- _classPath
- }
-
- override def rootLoader: LazyType = {
- println("getting
rootLoader:"+platform.rootLoader+"("+platform.rootLoader.getClass+")")
- //platform.rootLoader
- //new
PathResolver(settings).result is a ClassPath[AbstractFile]
- //of classpath.packages is a
seq of ClassPath[AbstractFile]
- /*val classPathOrig:
ClassPath[AbstractFile] = new PathResolver(settings).result
- val classPathAbstractFiles =
for (bundle <- bundles;
- val url =
bundle.getResource("/");
- if url != null)
yield {
- if
("file".equals(url.getProtocol())) {
- new
PlainFile(new File(url.toURI()))
- }
- else {
-
BundleFS.create(bundle);
- }
- }
- val classPaths:
List[ClassPath[AbstractFile]] = (for (abstractFile <- classPathAbstractFiles)
- yield {
- new
DirectoryClassPath(abstractFile, classPathOrig.context)
- }) toList
-
- val classPath = new
MergedClassPath[AbstractFile](classPathOrig :: classPaths,
-
classPathOrig.context)*/
- //new
DirectoryClassPath(BundleFS.create(bundle), classPathOrig.context)
- //class
JavaClassPath(containers: List[ClassPath[AbstractFile]], context: JavaContext)
- class
MyPackageLoader(loaderClassPath: ClassPath[AbstractFile])
- extends
loaders.JavaPackageLoader(loaderClassPath) /*{
- override protected def
newClassLoader(bin: AbstractFile) = {
-
println("getting newClassLoader "+bin+"------")
-
super.newClassLoader(bin)
- }
-
- override protected def
newPackageLoader(pkg: ClassPath[AbstractFile]) = {
-
println("getting newPackageLoader "+pkg+"------*")
-
super.newPackageLoader(pkg)
- //throw new
RuntimeException
- new
MyPackageLoader(pkg)
- }
- }*/
- val result = new
MyPackageLoader(_classPath)
- println("result: "+result)
- result
- }
- }
- }
- }
+
}
Added:
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/ScriptEngineFactory.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/ScriptEngineFactory.scala?rev=949595&view=auto
==============================================================================
---
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/ScriptEngineFactory.scala
(added)
+++
incubator/clerezza/trunk/scala-scripting/script-engine/src/main/scala/org/apache/clerezza/scala/console/ScriptEngineFactory.scala
Sun May 30 21:57:34 2010
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.scala.console;
+
+
+
+import org.apache.felix.scr.annotations.Component;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.framework.Bundle
+import java.io.{File, PrintWriter, Reader, StringWriter}
+import java.util.{ArrayList, Arrays};
+import scala.tools.nsc._;
+import scala.tools.nsc.interpreter._;
+import scala.tools.nsc.io.{AbstractFile, PlainFile}
+import scala.tools.nsc.util._
+import scala.tools.nsc.symtab.SymbolLoaders
+import java.net._
+import scala.tools.nsc.reporters.ConsoleReporter
+import scala.tools.nsc.reporters.Reporter
+import scala.tools.util.PathResolver
+import scala.tools.nsc.util.{ClassPath, JavaClassPath}
+import javax.script.ScriptContext
+import javax.script.{ScriptEngineFactory => JavaxEngineFactory, ScriptEngine,
AbstractScriptEngine, Bindings, SimpleBindings}
+
+
+class ScriptEngineFactory() extends JavaxEngineFactory {
+
+ var interpreter : Interpreter = null;
+
+
+ //methods from ScriptEngineFactory
+ override def getEngineName() = "Scala Scripting Engine for OSGi"
+ override def getEngineVersion() = "0.2/scala 2.8.0.RC2"
+ override def getExtensions() =
java.util.Collections.singletonList("scala")
+ override def getMimeTypes() =
java.util.Collections.singletonList("application/x-scala")
+ override def getNames() = java.util.Collections.singletonList("scala")
+ override def getLanguageName() = "Scala"
+ override def getLanguageVersion ="2.8.0.RC2"
+ override def getParameter(key : String) = {
+ key match {
+ case ScriptEngine.ENGINE => getEngineName
+ case ScriptEngine.ENGINE_VERSION => getEngineVersion
+ case ScriptEngine.NAME => getNames.get(0)
+ case ScriptEngine.LANGUAGE => getLanguageName
+ case ScriptEngine.LANGUAGE_VERSION => getLanguageVersion
+ case _ => null
+ }
+ }
+ override def getMethodCallSyntax(obj : String,
+ m :
String,
+ args :
String*) = {
+ obj+"."+m+"("+args.mkString(",")+")"
+ }
+ override def getOutputStatement(toDisplay : String) =
"println(\""+toDisplay+"\")"
+ override def getProgram(statements : String*) =
statements.mkString("\n")
+ override def getScriptEngine : ScriptEngine = MyScriptEngine
+
+ def activate(componentContext: ComponentContext)= {
+
+ }
+
+ def deactivate(componentContext: ComponentContext) = {
+
+ }
+
+ def bindInterpreterFactory(f: InterpreterFactory) = {
+ interpreter = f.createInterpreter(new PrintWriter(System.out))
+ }
+
+ def unbindInterpreterFactory(f: InterpreterFactory) = {
+ interpreter = null
+ }
+ /** Inner object as it accesse interpreter
+ */
+ object MyScriptEngine extends AbstractScriptEngine() {
+ override def eval(script : Reader, context : ScriptContext) :
Object = {
+ val scriptStringWriter = new StringWriter()
+ var ch = script.read
+ while (ch != -1) {
+ scriptStringWriter.write(ch)
+ ch = script.read
+ }
+ eval(scriptStringWriter.toString, context)
+ }
+ override def eval(script : String, context : ScriptContext) :
Object = {
+ //not yet threadsafe
+ val jTypeMap : java.util.Map[String,
java.lang.reflect.Type] =
+ new java.util.HashMap[String,
java.lang.reflect.Type]()
+ val valueMap = new java.util.HashMap[String, Any]()
+ import _root_.scala.collection.JavaConversions._
+ for (scope <- context.getScopes;
+ if (context.getBindings(scope.intValue)
!= null);
+ entry <-
context.getBindings(scope.intValue)) {
+ interpreter.bind(entry._1,
+
getAccessibleClass(entry._2.getClass).getName, entry._2)
+ }
+
+ interpreter.eval[Object](script) match {
+ case Some(x) => x
+ case None => null
+ }
+ }
+ override def getFactory() = ScriptEngineFactory.this
+ override def createBindings() : Bindings = new SimpleBindings
+
+ /**
+ * returns an accessible class or interface that is implemented
by class,
+ * is doesn't look for superinterfaces of implement interfaces
+ */
+ private def getAccessibleClass(clazz : Class[_]) : Class[_] = {
+ if(isAccessible(clazz)) {
+ return clazz
+ } else {
+ val foo : Class[_] = clazz.getInterfaces()(0)
+ for (implementedInterface <-
clazz.getInterfaces()) {
+ if (isAccessible(implementedInterface))
return implementedInterface
+ }
+ }
+ return getAccessibleSuperClass(clazz)
+ }
+
+ private def getAccessibleSuperClass(clazz : Class[_]) :
Class[_] = {
+ val superClass = clazz.getSuperclass
+ if (superClass == null) {
+ throw new RuntimeException("No upper class to
be checked for accessibility for "+clazz)
+ }
+ if (isAccessible(superClass)) {
+ superClass
+ } else {
+ getAccessibleSuperClass(superClass)
+ }
+ }
+
+ private def isAccessible(clazz : Class[_]) = {
+ try {
+ Class.forName(clazz.getName)
+ true
+ } catch {
+ case e: Exception => false
+ }
+ }
+ }
+}
+
+