incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r790523 - in /sling/trunk/bundles: api/src/main/java/org/apache/sling/api/SlingConstants.java scripting/core/pom.xml scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java scripting/jsp/pom.xml
Date Thu, 02 Jul 2009 09:45:54 GMT
Author: cziegeler
Date: Thu Jul  2 09:45:54 2009
New Revision: 790523

URL: http://svn.apache.org/viewvc?rev=790523&view=rev
Log:
SLING-1030 : Send events when a new script engine factory is added or an old one is removed.

Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java
    sling/trunk/bundles/scripting/core/pom.xml
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
    sling/trunk/bundles/scripting/jsp/pom.xml

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java?rev=790523&r1=790522&r2=790523&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/SlingConstants.java Thu Jul
 2 09:45:54 2009
@@ -238,4 +238,68 @@
      * @since 2.0.6
      */
     public static final String PROPERTY_ADAPTER_CLASSES = "adapters";
+
+    /**
+     * The topic for the OSGi event which is sent when a script engine factory has been added.
+     * The event contains at least the {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_NAME},
+     * {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_VERSION},
+     * {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_EXTENSIONS},
+     * {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_NAME},
+     * {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_VERSION},
+     * and {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_MIME_TYPES} poperties.
+     * @since 2.0.6
+     */
+    public static final String TOPIC_SCRIPT_ENGINE_FACTORY_ADDED = "javax/script/ScriptEngineFactory/ADDED";
+
+    /**
+     * The topic for the OSGi event which is sent when a script engine factory has been removed.
+     * The event contains at least the {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_NAME},
+     * {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_VERSION},
+     * {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_EXTENSIONS},
+     * {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_NAME},
+     * {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_VERSION},
+     * and {@link #PROPERTY_SCRIPT_ENGINE_FACTORY_MIME_TYPES} poperties.
+     * @since 2.0.6
+     */
+    public static final String TOPIC_SCRIPT_ENGINE_FACTORY_REMOVED = "javax/script/ScriptEngineFactory/REMOVED";
+
+    /**
+     * The event property listing the script engine factory name. The value is a string.
+     * @since 2.0.6
+     */
+    public static final String PROPERTY_SCRIPT_ENGINE_FACTORY_NAME = "engineName";
+
+    /**
+     * The event property listing the script engine factory name. The value is a string.
+     * @since 2.0.6
+     */
+    public static final String PROPERTY_SCRIPT_ENGINE_FACTORY_VERSION = "engineVersion";
+
+    /**
+     * The event property listing the script engine factory extensions. The value is
+     * a string array.
+     * @since 2.0.6
+     */
+    public static final String PROPERTY_SCRIPT_ENGINE_FACTORY_EXTENSIONS = "extensions";
+
+    /**
+     * The event property listing the script engine factory language. The value is
+     * a string.
+     * @since 2.0.6
+     */
+    public static final String PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_NAME = "languageName";
+
+    /**
+     * The event property listing the script engine factory language version. The value is
+     * a string.
+     * @since 2.0.6
+     */
+    public static final String PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_VERSION = "languageVersion";
+
+    /**
+     * The event property listing the script engine factory mime types. The value is
+     * a string array.
+     * @since 2.0.6
+     */
+    public static final String PROPERTY_SCRIPT_ENGINE_FACTORY_MIME_TYPES = "mimeTypes";
 }

Modified: sling/trunk/bundles/scripting/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/pom.xml?rev=790523&r1=790522&r2=790523&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/pom.xml (original)
+++ sling/trunk/bundles/scripting/core/pom.xml Thu Jul  2 09:45:54 2009
@@ -124,7 +124,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.0.2-incubator</version>
+            <version>2.0.5-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java?rev=790523&r1=790522&r2=790523&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
(original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
Thu Jul  2 09:45:54 2009
@@ -22,6 +22,8 @@
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.SortedSet;
@@ -31,6 +33,7 @@
 import javax.script.ScriptEngineFactory;
 import javax.script.ScriptEngineManager;
 
+import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.commons.mime.MimeTypeProvider;
@@ -40,13 +43,16 @@
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleListener;
 import org.osgi.service.component.ComponentContext;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * AdapterFactory that adapts Resources to the DefaultSlingScript servlet, which
  * executes the Resources as scripts.
- * 
+ *
  * @scr.component metatype="no" immediate="true"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
  * @scr.property name="service.description" value="Default SlingScriptResolver"
@@ -82,6 +88,10 @@
 
     private BundleContext bundleContext;
 
+    /** The service tracker for the event admin
+     */
+    private ServiceTracker eventAdminTracker;
+
     // ---------- AdapterFactory -----------------------------------------------
 
     @SuppressWarnings("unchecked")
@@ -215,7 +225,7 @@
      * name. If no ScriptEngineFactory is registered for the given extension or
      * the registered ScriptEngineFactory is not registered for a MIME type,
      * this method returns <code>null</code>.
-     * 
+     *
      * @param name The name whose extension is to be mapped to a MIME type. The
      *            extension is the string after the last dot in the name. If the
      *            name contains no dot, the entire name is considered the
@@ -240,7 +250,7 @@
      * ScriptEngineFactory is registered for the given MIME type or the
      * registered ScriptEngineFactory is not registered for an extensions, this
      * method returns <code>null</code>.
-     * 
+     *
      * @param mimeType The MIME type to be mapped to an extension.
      */
     public String getExtension(String mimeType) {
@@ -258,6 +268,11 @@
     // ---------- SCR integration ----------------------------------------------
 
     protected void activate(ComponentContext context) {
+        // setup tracker first as this is used in the bind/unbind methods
+        this.eventAdminTracker = new ServiceTracker(context.getBundleContext(),
+                EventAdmin.class.getName(), null);
+        this.eventAdminTracker.open();
+
         this.bundleContext = context.getBundleContext();
         this.bundleContext.addBundleListener(this);
 
@@ -290,19 +305,54 @@
         engineSpiBundles.clear();
         engineSpiServices.clear();
         scriptEngineManager = null;
+        if ( this.eventAdminTracker != null ) {
+            this.eventAdminTracker.close();
+            this.eventAdminTracker = null;
+        }
         this.bundleContext = null;
     }
 
+    /**
+     * Get the event admin.
+     * @return The event admin or <code>null</code>
+     */
+    private EventAdmin getEventAdmin() {
+        return (EventAdmin) (this.eventAdminTracker != null ? this.eventAdminTracker.getService()
: null);
+    }
+
+    @SuppressWarnings("unchecked")
+    private String[] toArray(List list) {
+        return (String[])list.toArray(new String[list.size()]);
+    }
+
+    private void postEvent(final String topic, final ScriptEngineFactory scriptEngineFactory)
{
+        final EventAdmin localEA = this.getEventAdmin();
+        if ( localEA != null ) {
+            final Dictionary<String, Object> props = new Hashtable<String, Object>();
+            props.put(SlingConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_NAME, scriptEngineFactory.getEngineName());
+            props.put(SlingConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_VERSION, scriptEngineFactory.getEngineVersion());
+            props.put(SlingConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_EXTENSIONS, toArray(scriptEngineFactory.getExtensions()));
+            props.put(SlingConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_NAME, scriptEngineFactory.getLanguageName());
+            props.put(SlingConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_VERSION, scriptEngineFactory.getLanguageVersion());
+            props.put(SlingConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_MIME_TYPES, toArray(scriptEngineFactory.getMimeTypes()));
+            localEA.postEvent(new Event(topic, props));
+        }
+    }
+
     protected void bindScriptEngineFactory(
             ScriptEngineFactory scriptEngineFactory) {
         engineSpiServices.add(scriptEngineFactory);
         scriptEngineManager = null;
+        // send event
+        postEvent(SlingConstants.TOPIC_SCRIPT_ENGINE_FACTORY_ADDED, scriptEngineFactory);
     }
 
     protected void unbindScriptEngineFactory(
             ScriptEngineFactory scriptEngineFactory) {
         engineSpiServices.remove(scriptEngineFactory);
         scriptEngineManager = null;
+        // send event
+        postEvent(SlingConstants.TOPIC_SCRIPT_ENGINE_FACTORY_REMOVED, scriptEngineFactory);
     }
 
 }

Modified: sling/trunk/bundles/scripting/jsp/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/pom.xml?rev=790523&r1=790522&r2=790523&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/pom.xml (original)
+++ sling/trunk/bundles/scripting/jsp/pom.xml Thu Jul  2 09:45:54 2009
@@ -28,7 +28,7 @@
     </parent>
 
     <artifactId>org.apache.sling.scripting.jsp</artifactId>
-    <version>2.0.7-SNAPSHOT</version>
+    <version>2.0.7-tlp-790463</version>
     <packaging>bundle</packaging>
 
     <name>Apache Sling Scripting JSP Support</name>



Mime
View raw message