clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1082755 - in /incubator/clerezza/trunk/parent/shell/src/main: resources/OSGI-INF/ scala/org/apache/clerezza/shell/
Date Thu, 17 Mar 2011 23:50:34 GMT
Author: reto
Date: Thu Mar 17 23:50:34 2011
New Revision: 1082755

URL: http://svn.apache.org/viewvc?rev=1082755&view=rev
Log:
CLEREZZA-464: Added support for ShellCustomizerS. Its now possible to provide additional objects
and import available on any shell

Added:
    incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala
Modified:
    incubator/clerezza/trunk/parent/shell/src/main/resources/OSGI-INF/serviceComponents.xml
    incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
    incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
    incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala

Modified: incubator/clerezza/trunk/parent/shell/src/main/resources/OSGI-INF/serviceComponents.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/shell/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1082755&r1=1082754&r2=1082755&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/shell/src/main/resources/OSGI-INF/serviceComponents.xml
(original)
+++ incubator/clerezza/trunk/parent/shell/src/main/resources/OSGI-INF/serviceComponents.xml
Thu Mar 17 23:50:34 2011
@@ -22,5 +22,9 @@
 				interface="org.apache.clerezza.shell.ShellCommand"
 				cardinality="0..n"
 				bind="bindCommand" unbind="unbindCommand"/>
+		<reference name="customizers"
+				interface="org.apache.clerezza.shell.ShellCustomizer"
+				cardinality="0..n"
+				bind="bindCustomizer" unbind="unbindCustomizer"/>
     </scr:component>
 </components>

Modified: incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala?rev=1082755&r1=1082754&r2=1082755&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
(original)
+++ incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
Thu Mar 17 23:50:34 2011
@@ -219,4 +219,10 @@ object Shell {
 	trait TerminationListener {
 		def terminated: Unit
 	}
+	
+	trait Environment {
+		val componentContext: ComponentContext;
+		val in: InputStream;
+		val out: OutputStream;
+	}
 }
\ No newline at end of file

Modified: incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala?rev=1082755&r1=1082754&r2=1082755&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
(original)
+++ incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCommand.scala
Thu Mar 17 23:50:34 2011
@@ -1,24 +1,24 @@
 /*
- *  Copyright 2010 reto.
- * 
- *  Licensed 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.
- *  under the License.
+ * 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.shell
 
 import java.io.OutputStream
-import java.io.Writer
 
 trait ShellCommand {
 	def command: String

Added: incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala?rev=1082755&view=auto
==============================================================================
--- incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala
(added)
+++ incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellCustomizer.scala
Thu Mar 17 23:50:34 2011
@@ -0,0 +1,42 @@
+/*
+ * 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.shell
+
+
+import java.io.InputStream
+import java.io.OutputStream
+import org.osgi.service.component.ComponentContext
+
+/**
+ * A service implemebting this trait provides bjects and/or imports available
+ * on any shell by default
+ */
+trait ShellCustomizer {
+
+	/**
+	 * A list of bindings that will be available in the shell
+	 * The tuple consist of: bindingName, typeName, value
+	 */
+	def bindings(e: Shell.Environment): List[(String, String, Any)]
+
+	/**
+	 * A list of imports that will be available in the shell
+	 */
+	def imports: List[String]
+}

Modified: incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala?rev=1082755&r1=1082754&r2=1082755&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala
(original)
+++ incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/ShellFactory.scala
Thu Mar 17 23:50:34 2011
@@ -34,9 +34,10 @@ class ShellFactory()  {
 
 
 
-	var interpreterFactory: InterpreterFactory = null
-	var componentContext: ComponentContext = null
-	var commands = Set[ShellCommand]()
+	private var interpreterFactory: InterpreterFactory = null
+	private var componentContext: ComponentContext = null
+	private var commands = Set[ShellCommand]()
+	private var customizers = Set[ShellCustomizer]()
 	
 	def activate(componentContext: ComponentContext)= {
 		this.componentContext = componentContext
@@ -46,16 +47,29 @@ class ShellFactory()  {
 		this.componentContext = componentContext
 	}
 
-	def createShell(in: InputStream, out: OutputStream) = {
+	def createShell(pIn: InputStream, pOut: OutputStream) = {
 		AccessController.checkPermission(new ShellPermission())
 		AccessController.doPrivileged(new PrivilegedAction[Shell] {
 				override def run() = {
-					val shell = new Shell(interpreterFactory, in, out, commands)
+					val shell = new Shell(interpreterFactory, pIn, pOut, commands)
 					//shell.bind("bundleContext", classOf[BundleContext].getName, componentContext.getBundleContext)
 					//shell.bind("componentContext", classOf[ComponentContext].getName, componentContext)
-					shell.bind("osgiDsl", classOf[OsgiDsl].getName, new OsgiDsl(componentContext, out))
+					shell.bind("osgiDsl", classOf[OsgiDsl].getName, new OsgiDsl(componentContext, pOut))
 					shell.addImport("org.apache.clerezza.{scala => zzscala, _ }")
 					shell.addImport("osgiDsl._")
+					val environment = new Shell.Environment {
+						val componentContext: ComponentContext = ShellFactory.this.componentContext
+						val in: InputStream = pIn;
+						val out: OutputStream = pOut;
+					}
+					for (c <- customizers) {
+						for(b <- c.bindings(environment)) {
+							shell.bind(b._1, b._2, b._3)
+						}
+						for(i <- c.imports) {
+							shell.addImport(i)
+						}
+					}
 					shell
 				}
 			})
@@ -76,4 +90,12 @@ class ShellFactory()  {
 	def unbindCommand(c: ShellCommand) = {
 		commands -= c
 	}
+
+	def bindCustomizer(c: ShellCustomizer) = {
+		customizers += c
+	}
+
+	def unbindCustomizer(c: ShellCustomizer) = {
+		customizers -= c
+	}
 }
\ No newline at end of file



Mime
View raw message