felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From don...@apache.org
Subject svn commit: r601892 - in /felix/sandbox/donsez/sosoc/src: main/java/org/apache/felix/sandbox/sosoc/ main/java/org/apache/felix/sandbox/sosoc/manager/javascript/ main/java/org/apache/felix/sandbox/sosoc/manager/rhino/ main/java/org/apache/felix/sandbox/...
Date Thu, 06 Dec 2007 22:47:05 GMT
Author: donsez
Date: Thu Dec  6 14:47:04 2007
New Revision: 601892

URL: http://svn.apache.org/viewvc?rev=601892&view=rev
Log:
add a component manager for javax.script engines of the Java Platform 6.0
rename org.apache.felix.sandbox.sosoc.manager.javascript in org.apache.felix.sandbox.sosoc.manager.rhino

Added:
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/
      - copied from r601740, felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/javascript/
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentManager.java
  (with props)
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentReferenceManager.java
  (with props)
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptContainer.java
  (with props)
    felix/sandbox/donsez/sosoc/src/site/component.hotdog.vendor.xml   (with props)
    felix/sandbox/donsez/sosoc/src/site/component.runnable6.xml   (with props)
Removed:
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/javascript/
Modified:
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentManager.java
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentReferenceManager.java
    felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptContainer.java
    felix/sandbox/donsez/sosoc/src/site/index.html
    felix/sandbox/donsez/sosoc/src/site/script.txt

Modified: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java?rev=601892&r1=601891&r2=601892&view=diff
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java
(original)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java
Thu Dec  6 14:47:04 2007
@@ -40,7 +40,8 @@
 import org.apache.felix.sandbox.sosoc.manager.ComponentManager;
 import org.apache.felix.sandbox.sosoc.manager.LoggerImpl;
 import org.apache.felix.sandbox.sosoc.manager.java.JavaComponentManager;
-import org.apache.felix.sandbox.sosoc.manager.javascript.JavaScriptComponentManager;
+import org.apache.felix.sandbox.sosoc.manager.rhino.JavaScriptComponentManager;
+import org.apache.felix.sandbox.sosoc.manager.script.ScriptComponentManager;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -235,13 +236,17 @@
 			 // create the instance manager for JavaScript component
 			 componentManager = new JavaScriptComponentManager(this, descriptor,m_logger,m_baseUrlStr);
 		} else {
-//			componentManager = new JSR223ComponentManager(this,descriptor,m_logger);
-			throw new IllegalArgumentException(language+ " components are not supported in this version");
+			 // create the instance manager for Script component (javax.script)
+			componentManager = new ScriptComponentManager(this,descriptor,m_logger,m_baseUrlStr);
 		}
-
+//		 else {
+//			throw new IllegalArgumentException(language+ " components are not supported in this
version");
+//		}
 		if (componentManager != null) {
 			// start managing lifecycle
 			componentManager.validate();
+		} else {
+			throw new IllegalArgumentException("can not instanciate a manager for " +language+ " components");
		
 		}
 	}
 

Modified: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentManager.java?rev=601892&r1=601740&r2=601892&view=diff
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentManager.java
(original)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentManager.java
Thu Dec  6 14:47:04 2007
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.felix.sandbox.sosoc.manager.javascript;
+package org.apache.felix.sandbox.sosoc.manager.rhino;
 
 import java.lang.reflect.Proxy;
 import java.net.MalformedURLException;
@@ -36,7 +36,7 @@
  */
 public class JavaScriptComponentManager extends ComponentManager {
 
-	JavaScriptContainer javaScriptContainer;
+	JavaScriptContainer container;
 	
 	private String baseUrlStr; 
 	
@@ -90,12 +90,12 @@
 			}
 		}
 
-		javaScriptContainer=new JavaScriptContainer(scriptText,m_logger);
+		container=new JavaScriptContainer(scriptText,m_logger);
 
 		if(interfaces!=null){
-			return Proxy.newProxyInstance(cl, interfaces, javaScriptContainer);
+			return Proxy.newProxyInstance(cl, interfaces, container);
 		} else {
-			return javaScriptContainer;
+			return container;
 		}
 	}
 

Modified: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentReferenceManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentReferenceManager.java?rev=601892&r1=601740&r2=601892&view=diff
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentReferenceManager.java
(original)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptComponentReferenceManager.java
Thu Dec  6 14:47:04 2007
@@ -17,9 +17,8 @@
  * under the License.
  */
 
-package org.apache.felix.sandbox.sosoc.manager.javascript;
+package org.apache.felix.sandbox.sosoc.manager.rhino;
 
-import org.apache.felix.sandbox.sosoc.SOSOCActivator;
 import org.apache.felix.sandbox.sosoc.descriptor.xml.Reference;
 import org.apache.felix.sandbox.sosoc.manager.ComponentManager;
 import org.apache.felix.sandbox.sosoc.manager.Logger;
@@ -36,9 +35,7 @@
  */
 class JavaScriptComponentReferenceManager extends ReferenceManager {
 
-	JavaScriptComponentReferenceManager(
-			ComponentManager javaScriptComponentManager, Reference reference, Logger logger)
-			throws Exception {
+	JavaScriptComponentReferenceManager(ComponentManager javaScriptComponentManager, Reference
reference, Logger logger) throws Exception {
 		super(javaScriptComponentManager, reference, logger);
 	}
 
@@ -65,7 +62,7 @@
 			}
 			String methodName = reference.getBind();
 			if (methodName != null) {
-				((JavaScriptComponentManager)componentManager).javaScriptContainer
+				((JavaScriptComponentManager)componentManager).container
 					.bind(methodName, serviceReference, proxy);
 			}
 
@@ -101,7 +98,7 @@
 		try {
 			String methodName = reference.getUnbind();
 			if (methodName != null)
-				((JavaScriptComponentManager)componentManager).javaScriptContainer
+				((JavaScriptComponentManager)componentManager).container
 					.unbind(methodName, serviceReference, requiredService);
 
 			boundServices.remove(serviceReference);

Modified: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptContainer.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptContainer.java?rev=601892&r1=601740&r2=601892&view=diff
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptContainer.java
(original)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/rhino/JavaScriptContainer.java
Thu Dec  6 14:47:04 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.felix.sandbox.sosoc.manager.javascript;
+package org.apache.felix.sandbox.sosoc.manager.rhino;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;

Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentManager.java?rev=601892&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentManager.java
(added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentManager.java
Thu Dec  6 14:47:04 2007
@@ -0,0 +1,106 @@
+/*
+ * 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.felix.sandbox.sosoc.manager.script;
+
+import java.lang.reflect.Proxy;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.felix.sandbox.sosoc.SOSOCActivator;
+import org.apache.felix.sandbox.sosoc.descriptor.xml.Component;
+import org.apache.felix.sandbox.sosoc.descriptor.xml.Implementation;
+import org.apache.felix.sandbox.sosoc.descriptor.xml.Reference;
+import org.apache.felix.sandbox.sosoc.manager.ComponentManager;
+import org.apache.felix.sandbox.sosoc.manager.Logger;
+import org.apache.felix.sandbox.sosoc.manager.ReferenceManager;
+import org.apache.felix.sandbox.util.load.LoadUtils;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ScriptComponentManager extends ComponentManager {
+
+	ScriptContainer container;
+
+	private String baseUrlStr; 
+	
+	public ScriptComponentManager(SOSOCActivator activator, Component componentDescriptor, Logger
logger, String baseUrlStr) throws Exception {
+		super(activator, componentDescriptor,logger);
+		this.baseUrlStr=baseUrlStr;
+	}
+
+	protected Object instanciateImplementorObject() throws Exception {
+
+		// load the text of the script
+		Implementation implementation = componentDescription.getImplementation();
+		String scriptText = null;
+		if (implementation.getUrl() != null) {
+			String urlStr=implementation.getUrl();
+						
+			URL url=null;
+			try {
+				url=new URL(urlStr);
+			} catch (MalformedURLException e) {
+				try {
+					if(baseUrlStr==null){
+						throw e;
+					}
+					url=new URL(new URL(baseUrlStr),urlStr);
+				} catch (MalformedURLException e1) {
+					throw e1;
+				}
+			}
+			scriptText = LoadUtils.loadAsUrl(url.toExternalForm());
+		} else if (implementation.getEntry() != null) {
+			scriptText = LoadUtils.loadAsRessource(m_activator.getClass().getClassLoader(), implementation.getEntry());
+		}
+				
+		// text is appended to the external script texts
+		if (implementation.getText() != null) {
+			if(scriptText==null) {
+				scriptText = implementation.getText();				
+			} else {
+				scriptText += implementation.getText();
+			}
+		}
+
+		String[] interfaceNames = componentDescription.getServiceInterfaces();
+		ClassLoader cl = m_activator.getClass().getClassLoader();
+		Class[] interfaces=null;
+		if(interfaceNames!=null){
+			interfaces = new Class[interfaceNames.length];
+			for (int i = 0; i < interfaceNames.length; i++) {
+				interfaces[i] = cl.loadClass(interfaceNames[i]);
+			}
+		}
+
+		container = new ScriptContainer(implementation.getLanguage(),scriptText,m_logger);
+
+		if(interfaces!=null){
+			return Proxy.newProxyInstance(cl, interfaces, container);
+		} else {
+			return container;
+		}
+	}
+
+	protected ReferenceManager instianciateReferenceManager(ComponentManager manager, Reference
reference) throws Exception {
+		return new ScriptComponentReferenceManager(this, reference,m_logger);
+	}
+}
+

Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentReferenceManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentReferenceManager.java?rev=601892&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentReferenceManager.java
(added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentReferenceManager.java
Thu Dec  6 14:47:04 2007
@@ -0,0 +1,117 @@
+/*
+ * ServiceBinder - A mechanism to automate service binding in OSGi
+ * Copyright (C) 2002  Humberto Cervantes
+ *
+ * This program is licensed under the BSD Software License;
+ * refer to the LICENSE.txt file included with this program for details.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Contact: Humberto Cervantes (Humberto.Cervantes@imag.fr)
+ * Contributor(s): Richard S. Hall (heavy@ungoverned.org)
+ *
+ **/
+
+package org.apache.felix.sandbox.sosoc.manager.script;
+
+import org.apache.felix.sandbox.sosoc.descriptor.xml.Reference;
+import org.apache.felix.sandbox.sosoc.manager.ComponentManager;
+import org.apache.felix.sandbox.sosoc.manager.Logger;
+import org.apache.felix.sandbox.sosoc.manager.ReferenceManager;
+import org.osgi.framework.ServiceReference;
+
+
+/**
+ * The ScriptComponentReferenceManager task is to listen to service events
+ * and to call the bind/unbind methods on a given object. It is also responsible
+ * for requesting the unregistration of a service in case a dependency is
+ * broken.
+ */
+
+class ScriptComponentReferenceManager extends ReferenceManager {
+
+	ScriptComponentReferenceManager(ComponentManager componentManager, Reference reference,
Logger logger) throws Exception {
+		super(componentManager, reference, logger);
+	}
+
+	/**
+	 * Call the bind method. In case there is an exception while calling the
+	 * bind method, the service is not considered to be bound to the instance
+	 * object
+	 * 
+	 * @param serviceReference
+	 *            A ServiceReference with the service that will be bound to the
+	 *            instance object
+	 * @return true if the call was successful, false otherwise
+	 */
+	protected boolean callBindMethod(ServiceReference serviceReference) {
+		try {
+			Object requiredService = componentManager.getBundleContext()
+					.getService(serviceReference);
+			Object proxy = componentManager.proxyRequiredServiceObject(
+					requiredService, serviceReference, reference);
+
+			if (proxy == null) {
+				// ignore a null return value from the proxy method
+				proxy = requiredService;
+			}
+			String methodName = reference.getBind();
+			if (methodName != null) {
+				((ScriptComponentManager)componentManager).container
+					.bind(methodName, serviceReference, proxy);
+			}
+
+			boundServices.put(serviceReference, proxy);
+
+			return true;
+		} catch (ClassCastException e) {
+			m_logger.error(this.getClass().getName() + " : exception while invoking "
+							+ reference.getBind() + " :" + e);
+			e.printStackTrace();
+		} catch (Exception e) {
+			m_logger.error(this.getClass().getName() + " : exception while invoking "
+							+ reference.getBind() + " :" + e);
+			e.printStackTrace();
+		}
+		return false;
+	}
+
+	/**
+	 * Call the unbind method
+	 * 
+	 * @param serviceReference
+	 *            A service reference corresponding to the service that will be
+	 *            unbound
+	 */
+	protected void callUnbindMethod(ServiceReference serviceReference) {
+		Object requiredService = boundServices.get(serviceReference);
+		if (requiredService == null) {
+			m_logger.error(this.getClass().getName() + " : callUnbindMethod UNBINDING UNKNOWN SERVICE
!!!!");
+			return;
+		}
+
+		try {
+			String methodName = reference.getUnbind();
+			if (methodName != null)
+				((ScriptComponentManager)componentManager).container
+					.unbind(methodName, serviceReference, requiredService);
+
+			boundServices.remove(serviceReference);
+			componentManager.getBundleContext().ungetService(serviceReference);
+		} catch (ClassCastException e) {
+			m_logger.error(this.getClass().getName() + " : exception while invoking "
+							+ reference.getUnbind() + " :" + e);
+			e.printStackTrace();
+		} catch (Exception e) {
+		m_logger.error(this.getClass().getName() + " : exception while invoking "
+						+ reference.getUnbind() + " :" + e);
+		e.printStackTrace();
+	}
+	}
+
+	protected void setBindingMethods() throws Exception {
+		// do nothing
+	}
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptComponentReferenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptContainer.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptContainer.java?rev=601892&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptContainer.java
(added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptContainer.java
Thu Dec  6 14:47:04 2007
@@ -0,0 +1,179 @@
+/*
+ * 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.felix.sandbox.sosoc.manager.script;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import javax.script.Bindings;
+import javax.script.Invocable;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+import org.apache.felix.sandbox.sosoc.manager.Logger;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ScriptContainer implements InvocationHandler {
+
+	private static ScriptEngineManager manager = new ScriptEngineManager();
+	
+	private String scriptText;
+
+	private Bindings bindings;
+
+	private ScriptEngine engine;
+	
+	private ScriptContext scriptContext;
+
+	private String language;
+
+	private Logger m_logger;
+
+	public ScriptContainer(String language, String scriptText, Logger logger) throws Exception
{
+		this.scriptText = scriptText;
+		this.m_logger = logger;
+		// Return script engine by name
+		engine = manager.getEngineByName(language);
+
+		if (engine == null)
+			throw new Exception(
+					"Could not create objects from an unknown script language :"
+							+ language);
+
+	    scriptContext = engine.getContext();
+	    bindings=engine.getBindings(ScriptContext.ENGINE_SCOPE);
+	    scriptContext.setBindings(bindings,ScriptContext.ENGINE_SCOPE);
+		engine.eval(this.scriptText);
+	}
+
+	/**
+	 * stop the manager
+	 */
+	private void stop() {
+		scriptContext = null;
+		engine=null;
+		bindings=null;
+	}
+
+	/**
+	 * activate the call the activate() function if it exists in the script
+	 */
+	/* synchronized */public void activate(ComponentContext componentContext) {
+		m_logger.trace(this.getClass().getName() + ":call activate");
+		try {
+			((Invocable)engine).invokeFunction("activate",new Object[]{componentContext});
+		} catch (ScriptException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (NoSuchMethodException e) {
+			// do nothing
+		}
+	}
+
+	/**
+	 * call the deactivate() function if it exists in the script
+	 */
+	/* synchronized */public void deactivate(ComponentContext componentContext) {
+		m_logger.trace(this.getClass().getName() + ":call deactivate");
+		try {
+			((Invocable)engine).invokeFunction("deactivate",new Object[]{componentContext});
+		} catch (ScriptException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (NoSuchMethodException e) {
+			// do nothing
+		}
+		stop();
+	}
+
+	/**
+	 * call the binding function in the script
+	 * 
+	 * @param methodName
+	 *            the name of the binding function
+	 * @param serviceReference
+	 *            the service reference
+	 * @param service
+	 *            the object that provides the service
+	 * @throws NoSuchMethodException
+	 */
+	/* synchronized */public void bind(String methodName,
+			ServiceReference serviceReference, Object service)
+			throws NoSuchMethodException {
+		m_logger.trace(this.getClass().getName() + ":call bind for "
+				+ methodName);
+		// 2 cases : ServiceReference (TODO), the object
+		
+		try {
+			((Invocable)engine).invokeFunction(methodName, new Object[]{service});
+		} catch (ScriptException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (NoSuchMethodException e) {
+			throw e;
+		}		
+	}
+
+	/**
+	 * call the unbinding function in the script
+	 * 
+	 * @param methodName
+	 *            the name of the unbinding function
+	 * @param serviceReference
+	 *            the service reference
+	 * @param service
+	 *            the object that provides the service
+	 * @throws NoSuchMethodException
+	 */
+	/* synchronized */public void unbind(String methodName,
+			ServiceReference serviceReference, Object service)
+			throws NoSuchMethodException {
+		m_logger.trace(this.getClass().getName() + ":call bind for "+ methodName);
+		// 2 cases : ServiceReference (TODO), the object
+		
+		try {
+			((Invocable)engine).invokeFunction(methodName,new Object[]{service});
+		} catch (ScriptException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (NoSuchMethodException e) {
+			throw e;
+		}		
+	}
+
+	/**
+	 * call the function in the script corresponding to the called method on the
+	 * service object
+	 * 
+	 * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
+	 *      java.lang.reflect.Method, java.lang.Object[])
+	 */
+	/* synchronized */public Object invoke(Object proxy, Method meth,Object[] args) throws Throwable
{
+
+		String methodName = meth.getName();
+		m_logger.trace(this.getClass().getName() + ":call method " + methodName);	
+		return ((Invocable)engine).invokeFunction(meth.getName(),args);
+	}
+}

Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/script/ScriptContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/sosoc/src/site/component.hotdog.vendor.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/site/component.hotdog.vendor.xml?rev=601892&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/site/component.hotdog.vendor.xml (added)
+++ felix/sandbox/donsez/sosoc/src/site/component.hotdog.vendor.xml Thu Dec  6 14:47:04 2007
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<!-- Component Description used by SOSOC -->
+<!--
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+-->
+<!-- July 17 2005  -->
+
+// see Snackbar tutorial http://www.plop-plop.net/eOSGi/index.php?title=TP2
+<component name="sosoc.snackbar.hotdogvendor">
+	<implementation language="javascript" url="./hotdog.vendor.js"/>
+
+		<service>
+			<provide interface="eosgi.snackbar.service.vendor.VendorService"/>		   
+		</service>
+		
+		<property value="type" name="hotdog" type="string" /> 
+		
+		<!-- Required services -->		
+		<reference name="LOG"
+			interface="org.osgi.service.log.LogService"
+			cardinality="0..1"
+			policy="dynamic"
+			bind="bindLogService" 
+			unbind="unbindLogService"
+		/>
+
+		<!-- Required services -->		
+		<reference name="WEINER"
+			interface="eosgi.snackbar.service.vendor.VendorService"
+			target="(type=weiner)"
+			cardinality="1..1"
+			policy="dynamic"
+			bind="bindWeinerVendorService" 
+			unbind="unbindWeinerVendorService"
+		/>
+
+		<!-- Required services -->		
+		<reference name="BUN"
+			interface="eosgi.snackbar.service.vendor.VendorService"
+			target="(type=bun)"
+			cardinality="1..1"
+			policy="dynamic"
+			bind="bindBunVendorService" 
+			unbind="unbindBunVendorService"
+		/>
+		
+</component>

Propchange: felix/sandbox/donsez/sosoc/src/site/component.hotdog.vendor.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/sosoc/src/site/component.runnable6.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/site/component.runnable6.xml?rev=601892&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/site/component.runnable6.xml (added)
+++ felix/sandbox/donsez/sosoc/src/site/component.runnable6.xml Thu Dec  6 14:47:04 2007
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<!-- Component Description used by SOSOC -->
+<!--
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+-->
+<!-- July 17 2005  -->
+
+<component name="sosoc.bench.server">
+	<implementation language="js"><![CDATA[
+
+			function run(){
+				// do nothing
+			}
+						
+			// Lifecycle functions
+			function activate(){
+				// do something
+				java.lang.System.out.println("sosoc.bench.server: call activate() function");
+			}
+			
+			function deactivate(){
+				java.lang.System.out.println("sosoc.bench.server: call deactivate() function");
+				// do something
+			}
+				
+		]]></implementation>
+	
+	<service>
+		<provide interface="java.lang.Runnable"/>		   
+		<!-- <provide interface="org.osgi.service.cm.ManagedService"/> -->		   
+	</service>
+		
+	<property value="service.pid" name="sosoc.bench.server" type="string" /> 
+		
+</component>

Propchange: felix/sandbox/donsez/sosoc/src/site/component.runnable6.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/sandbox/donsez/sosoc/src/site/index.html
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/site/index.html?rev=601892&r1=601891&r2=601892&view=diff
==============================================================================
--- felix/sandbox/donsez/sosoc/src/site/index.html (original)
+++ felix/sandbox/donsez/sosoc/src/site/index.html Thu Dec  6 14:47:04 2007
@@ -106,14 +106,12 @@
 <p id="todo">
 <b>TODO (contributions are welcome)</b><br>
 <ul>
-<li>TODO: add a "base" mechanism for URL completion: so, scripts file could have a
relative URL according to the component XML descriptor file</li>
 <li>TODO: add append and prepend elements in implementation element : useful to complete
import (legacy) scripts</li>
 <li>TODO: add field attribute in reference for direct IoD</li>
 <li>TODO: use dynamic import to load scripting engine classes</li>
 <li>TODO: org.mozilla.javascript.Context.setErrorReporter(org.mozilla.javascript.ErrorReporter)
with XML start line</li>
 <li>TODO: use org.mozilla.javascript.ContextFactory instead of org.mozilla.javascript.Context</li>
 <li>TODO: add manager for other scripting language : Groovy, PHP, Jython, Jacl, BeanShell,
NetRexx, JRuby, JudoScript, ObjectScript ... </li>
-<li>TODO: use JSR223 ("Scripting for the JavaTM Platform") for other scripting language
: Groovy, PHP, Jython, Jacl, BeanShell, NetRexx, JRuby, JudoScript, ObjectScript ... </li>
 <li>TODO: synchronization on bind/unbind and invoke in the JavaScriptInstanceManager.ScriptComponent</li>
 <li>TODO: use Apache BSF as in the ANT script task</li>
 <li>TODO: object sharing between script components ?? useful or not</li>
@@ -123,6 +121,10 @@
 </ul>
 
 <ul>
+<li>DONE (06/12/2007): use JSR223 ("Scripting for the JavaTM Platform 6") for other
scripting language : Groovy, PHP, Jython, Jacl, BeanShell, NetRexx, JRuby, JudoScript, ObjectScript
... </li>
+<li>DONE (05/12/2007): rename SCRScript in SOSOC </li>
+<li>DONE (05/12/2007): append CDATA to the script located in the entry or url attributes
of the implementation element : useful to complete import (legacy) scripts</li>
+<li>DONE (05/12/2007): add a "base" mechanism for URL completion: so, scripts file
could have a relative URL according to the component XML descriptor file</li>
 <li>DONE (26/07/2005): defines a service and a command to start and stop scripts (embedded
in the component description) from a URL (see <a href="http://people.apache.org/~donsez/dev/osgi/sosoc">http://people.apache.org/~donsez/dev/osgi/sosoc</a></li>
 <li>DONE (27/07/2005): provisioning the script outside the descriptor to ease script
writing (specialized editor plugin) and off-bundle debugging (thanks to Rick Hall for his
remark)</li>
 <li>DONE (27/07/2005): &lt;script language="javascript" res="echocmd.js"/&gt;
when the script is provisioned in the bundle jar as a ressource</li>

Modified: felix/sandbox/donsez/sosoc/src/site/script.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/site/script.txt?rev=601892&r1=601891&r2=601892&view=diff
==============================================================================
--- felix/sandbox/donsez/sosoc/src/site/script.txt (original)
+++ felix/sandbox/donsez/sosoc/src/site/script.txt Thu Dec  6 14:47:04 2007
@@ -9,7 +9,7 @@
 sosoc
 sosoc base
 sosoc base file:C:\felix-svn\sandbox\donsez\sosoc\src\site\
-sosoc base file:F:\osgi\bundlefarm\sosoc\src\site\
+sosoc base file:F:\osgi\felix-sandbox-donsez-2\sosoc\src\site\
 
 sosoc start component.echocmd.xml
 echo Felix is great !
@@ -27,12 +27,24 @@
 
 sosoc list
 
+sosoc prop sosoc.showtrace true
+sosoc start component.benchcmd.xml
+
 sosoc prop sosoc.showtrace false
 sosoc start component.runnable.xml
+bench 1000000
+REM with the rhino.JavaScriptComponentManager
+REM 3218 millisec. for 1000000 calls (3.218 microsec. per call)
+REM on T2400@1.83GHz, 2GB RAM, Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)
 
-sosoc prop sosoc.showtrace true
-sosoc start component.benchcmd.xml
+sosoc stop 5
+
+sosoc prop sosoc.showtrace false
+sosoc start component.runnable6.xml
 bench 1000000
+REM with the script.ScriptComponentManager
+REM 89547 millisec. for 1000000 calls (89.547 microsec. per call) on 
+REM on T2400@1.83GHz, 2GB RAM, Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)
 
 services -a
 



Mime
View raw message