[jboss-svn-commits] JBL Code SVN: r31114 - in labs/jbossrules/trunk: drools-api/src/main/java/org/drools/osgi/api and 9 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jan 17 21:08:00 EST 2010


Author: mark.proctor at jboss.com
Date: 2010-01-17 21:07:59 -0500 (Sun, 17 Jan 2010)
New Revision: 31114

Modified:
   labs/jbossrules/trunk/drools-api/.classpath
   labs/jbossrules/trunk/drools-api/.project
   labs/jbossrules/trunk/drools-api/build.properties
   labs/jbossrules/trunk/drools-api/pom.xml
   labs/jbossrules/trunk/drools-api/src/main/java/org/drools/osgi/api/Activator.java
   labs/jbossrules/trunk/drools-api/src/main/java/org/drools/util/ServiceRegistry.java
   labs/jbossrules/trunk/drools-api/src/main/java/org/drools/util/ServiceRegistryImpl.java
   labs/jbossrules/trunk/drools-compiler/.classpath
   labs/jbossrules/trunk/drools-compiler/pom.xml
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DecisionTableProvider.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/osgi/compiler/Activator.java
   labs/jbossrules/trunk/drools-core/.classpath
   labs/jbossrules/trunk/drools-core/pom.xml
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/osgi/core/Activator.java
   labs/jbossrules/trunk/drools-decisiontables/.classpath
   labs/jbossrules/trunk/drools-decisiontables/pom.xml
   labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/osgi/decisiontables/Activator.java
   labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/xls/ExcelParserTest.java
Log:
JBRULES-2351 OSGi Ready
-First working version, with control over optional services.

Modified: labs/jbossrules/trunk/drools-api/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-api/.classpath	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-api/.classpath	2010-01-18 02:07:59 UTC (rev 31114)
@@ -35,6 +35,7 @@
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/javassist/javassist/3.10.0.GA/javassist-3.10.0.GA.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/javax.servlet/1.0.0/javax.servlet-1.0.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jmock/jmock/2.5.1/jmock-2.5.1.jar" sourcepath="M2_REPO/org/jmock/jmock/2.5.1/jmock-2.5.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jmock/jmock-legacy/2.5.1/jmock-legacy-2.5.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/junit/junit/4.6/junit-4.6.jar"/>
@@ -45,8 +46,9 @@
   <classpathentry kind="var" path="M2_REPO/org/milyn/milyn-smooks-javabean/1.2/milyn-smooks-javabean-1.2.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mvel/mvel2/2.0.12/mvel2-2.0.12.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/objenesis/objenesis/1.0/objenesis-1.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/equinox/org.eclipse.osgi/3.5.1/org.eclipse.osgi-3.5.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/equinox/org.eclipse.osgi.util/3.5.1/org.eclipse.osgi.util-3.5.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.compendium/1.4.0/org.osgi.compendium-1.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.core/1.4.0/org.osgi.core-1.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.foundation/1.2.0/org.osgi.foundation-1.2.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/apache/poi/poi/3.2-FINAL/poi-3.2-FINAL.jar"/>
   <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar"/>

Modified: labs/jbossrules/trunk/drools-api/.project
===================================================================
--- labs/jbossrules/trunk/drools-api/.project	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-api/.project	2010-01-18 02:07:59 UTC (rev 31114)
@@ -12,6 +12,9 @@
     <buildCommand>
       <name>org.eclipse.pde.SchemaBuilder</name>
     </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.pde.ds.core.builder</name>
+    </buildCommand>
   </buildSpec>
   <natures>
     <nature>org.eclipse.jdt.core.javanature</nature>

Modified: labs/jbossrules/trunk/drools-api/build.properties
===================================================================
--- labs/jbossrules/trunk/drools-api/build.properties	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-api/build.properties	2010-01-18 02:07:59 UTC (rev 31114)
@@ -2,10 +2,12 @@
                build.properties,\
                META-INF/,\
                src/,\
-               pom.xml
+               pom.xml,\
+               OSGI-INF/
 bin.includes = .,\
                META-INF/,\
-               build.properties               
+               build.properties,\
+               OSGI-INF/
 source.. = src/main/java/,\
            src/main/resources/
 output.. = target/classes/     

Modified: labs/jbossrules/trunk/drools-api/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-api/pom.xml	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-api/pom.xml	2010-01-18 02:07:59 UTC (rev 31114)
@@ -13,16 +13,21 @@
   <name>Drools :: API</name>
 
   <dependencies>    
-            <dependency>  
-               <groupId>org.eclipse.equinox</groupId>  
-               <artifactId>org.eclipse.osgi</artifactId>  
-               <scope>provided</scope> 
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.core</artifactId>
+              <scope>provided</scope> 
+            </dependency>
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.foundation</artifactId>
+              <scope>provided</scope> 
             </dependency>            
-            <dependency>  
-               <groupId>org.eclipse.equinox</groupId>  
-               <artifactId>org.eclipse.osgi.util</artifactId>  
-               <scope>provided</scope> 
-            </dependency>
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.compendium</artifactId>
+              <scope>provided</scope> 
+            </dependency>           
          
          <dependency>  
             <groupId>com.sun.xml</groupId>  

Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/osgi/api/Activator.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/osgi/api/Activator.java	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/osgi/api/Activator.java	2010-01-18 02:07:59 UTC (rev 31114)
@@ -1,11 +1,10 @@
 package org.drools.osgi.api;
 
+import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.concurrent.Callable;
 
-import org.drools.KnowledgeBaseProvider;
 import org.drools.Service;
-import org.drools.io.ResourceProvider;
 import org.drools.util.ServiceRegistry;
 import org.drools.util.ServiceRegistryImpl;
 import org.osgi.framework.BundleActivator;
@@ -21,24 +20,24 @@
     private ServiceRegistration serviceRegistry;
     private ServiceTracker      registryTracker;
 
-
     public void start(BundleContext bc) throws Exception {
         System.out.println( "registering api services" );
+
         this.serviceRegistry = bc.registerService( ServiceRegistry.class.getName(),
                                                    new ServiceRegistryImpl(),
                                                    new Hashtable() );
 
-        registryTracker = new ServiceTracker( bc,
-                                              Service.class.getName(),
-                                              new DroolsServiceTracker( bc,
-                                                                        this ) );
+        this.registryTracker = new ServiceTracker( bc,
+                                                   Service.class.getName(),
+                                                   new DroolsServiceTracker( bc,
+                                                                             this ) );
         registryTracker.open();
         System.out.println( "api drools services registered" );
     }
 
     public void stop(BundleContext bc) throws Exception {
+        this.serviceRegistry.unregister();
         this.registryTracker.close();
-        this.serviceRegistry.unregister();
     }
 
     public static class DroolsServiceTracker
@@ -50,40 +49,55 @@
         public DroolsServiceTracker(BundleContext bc,
                                     Activator activator) {
             this.bc = bc;
+            this.activator = activator;
         }
 
         public Object addingService(ServiceReference ref) {
-            Service service = (Service) bc.getService( ref );
-            System.out.println( "registering" + service );
-            
-            
-            ServiceRegistryImpl.getInstance().registerLocator( service.getClass().getInterfaces()[0], new ReturnInstance( service ) );
+            Service service = (Service) this.bc.getService( ref );
+            System.out.println( "registering : " + service + " : " + service.getClass().getInterfaces()[0] );
+
+            Dictionary dic = new Hashtable();
+            ServiceReference regServiceRef = this.activator.serviceRegistry.getReference();
+            for ( String key : regServiceRef.getPropertyKeys() ) {
+                dic.put( key,
+                         regServiceRef.getProperty( key ) );
+            }
+            dic.put( service.getClass().getInterfaces()[0].getName(),
+                     "true" );
+            activator.serviceRegistry.setProperties( dic );
+
+            ServiceRegistryImpl.getInstance().registerLocator( service.getClass().getInterfaces()[0],
+                                                               new BundleContextInstantiator( this.bc,
+                                                                                              ref ) );
             return service;
         }
 
         public void modifiedService(ServiceReference arg0,
                                     Object arg1) {
-            
+
         }
 
         public void removedService(ServiceReference ref,
                                    Object arg1) {
             Service service = (Service) bc.getService( ref );
-            ServiceRegistryImpl.getInstance().unregisterLocator( service.getClass().getInterfaces()[0]);
+            ServiceRegistryImpl.getInstance().unregisterLocator( service.getClass().getInterfaces()[0] );
         }
     }
 
-    static class ReturnInstance<V>
+    public static class BundleContextInstantiator<V>
         implements
         Callable<V> {
-        private Service service;
+        private BundleContext    bc;
+        private ServiceReference ref;
 
-        public ReturnInstance(Service service) {
-            this.service = service;
+        public BundleContextInstantiator(BundleContext bc,
+                                         ServiceReference ref) {
+            this.bc = bc;
+            this.ref = ref;
         }
 
         public V call() throws Exception {
-            return (V) this.service;
+            return (V) this.bc.getService( this.ref );
         }
     }
 }

Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/util/ServiceRegistry.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/util/ServiceRegistry.java	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/util/ServiceRegistry.java	2010-01-18 02:07:59 UTC (rev 31114)
@@ -3,14 +3,19 @@
 import java.util.concurrent.Callable;
 
 import org.apache.poi.hssf.record.formula.functions.T;
+import org.drools.Service;
 
-public interface ServiceRegistry {
+public interface ServiceRegistry extends Service {
 
     public void registerLocator(Class cls,
                                   Callable cal);
 
     public void unregisterLocator(Class cls);
     
+//    public void registerInstance(Service service);
+//
+//  public void unregisterInstance(Service service);    
+    
     public <T> T get(Class<T> cls);
 
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/util/ServiceRegistryImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/util/ServiceRegistryImpl.java	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/util/ServiceRegistryImpl.java	2010-01-18 02:07:59 UTC (rev 31114)
@@ -14,16 +14,21 @@
 
 package org.drools.util;
 
+import java.io.IOException;
+import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.poi.hssf.record.formula.functions.T;
 import org.drools.KnowledgeBaseProvider;
 import org.drools.Service;
 import org.drools.builder.KnowledgeBuilderProvider;
 import org.drools.io.ResourceProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.component.ComponentContext;
 
 /**
  * This is an internal class, not for public consumption.
@@ -32,24 +37,27 @@
 public class ServiceRegistryImpl
     implements
     ServiceRegistry {
-    private static ServiceRegistry     instance        = new ServiceRegistryImpl();
+    private static ServiceRegistry     instance;
 
     private Map<String, Callable< ? >> registry        = new HashMap<String, Callable< ? >>();
     private Map<String, Callable< ? >> defaultServices = new HashMap<String, Callable< ? >>();
 
-    public static ServiceRegistry getInstance() {
+    public static synchronized ServiceRegistry getInstance() {
+        if ( instance == null ) {
+            instance = new ServiceRegistryImpl();
+        }
         return ServiceRegistryImpl.instance;
     }
 
     public ServiceRegistryImpl() {
         init();
     }
-    
+
     /* (non-Javadoc)
      * @see org.drools.util.internal.ServiceRegistry#registerLocator(java.lang.String, java.util.concurrent.Callable)
      */
     public synchronized void registerLocator(Class cls,
-                                                 Callable cal) {
+                                             Callable cal) {
         this.registry.put( cls.getName(),
                            cal );
     }
@@ -59,9 +67,78 @@
      */
     public synchronized void unregisterLocator(Class cls) {
         this.registry.remove( cls.getName() );
-        this.registry.put( cls.getName(), this.defaultServices.get( cls.getName() ) );
+        this.registry.put( cls.getName(),
+                           this.defaultServices.get( cls.getName() ) );
     }
+    
+    synchronized void registerInstance(Service service, Map map) {  
+        //this.context.getProperties().put( "org.dr, value )
+        System.out.println( "regInstance : " + map );
+        String[] values = ( String[] ) map.get( "objectClass" );        
 
+        for ( String v : values ) {
+            System.out.println( v );
+        }
+       // System.out.println( "register : " + service );
+        this.registry.put( service.getClass().getInterfaces()[0].getName(),
+                           new ReturnInstance<Service>( service ) );
+        
+
+//        
+//        BundleContext bc = this.context.getBundleContext();
+//        ServiceReference confAdminRef = bc.getServiceReference( ConfigurationAdmin.class.getName() );
+//        ConfigurationAdmin admin = ( ConfigurationAdmin ) bc.getService( confAdminRef );
+//        
+//        try {
+//            Configuration conf = admin.getConfiguration( (String) confAdminRef.getProperty( "service.id" ) );
+//            Dictionary properties = conf.getProperties();
+//            properties.put( values[0], "true" );
+//            conf.update( properties );
+//        } catch ( IOException e ) {
+//            e.printStackTrace();
+//        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.util.internal.ServiceRegistry#unregisterLocator(java.lang.String)
+     */
+    synchronized void unregisterInstance(Service service, Map map) {
+        System.out.println( "unregister : " + map );
+        String name = service.getClass().getInterfaces()[0].getName();
+        this.registry.remove( name );
+        this.registry.put( name,
+                           this.defaultServices.get( name ) );
+    }    
+    
+//    ConfigurationAdmin confAdmin;
+//    synchronized void setConfigurationAdmin(ConfigurationAdmin confAdmin) {
+//        this.confAdmin = confAdmin;
+//        System.out.println( "ConfAdmin : " + this.confAdmin );
+//    }   
+//    
+//    synchronized void unsetConfigurationAdmin(ConfigurationAdmin confAdmin) {
+//        this.confAdmin = null;
+//    }    
+    
+//    private ComponentContext context;
+//    void activate(ComponentContext context) {
+//        System.out.println( "reg comp" + context.getProperties() );
+//        this.context = context;
+//        
+//       
+//        
+//      BundleContext bc = this.context.getBundleContext();
+//      
+//      ServiceReference confAdminRef = bc.getServiceReference( ConfigurationAdmin.class.getName() );
+//      ConfigurationAdmin admin = ( ConfigurationAdmin ) bc.getService( confAdminRef );     
+//      System.out.println( "conf admin : " + admin );
+//        //context.
+//    //    log = (LogService) context.locateService("LOG");
+//        }
+//    void deactivate(ComponentContext context ){
+//        
+//    }
+
     public synchronized <T> T get(Class<T> cls) {
 
         Callable< ? > cal = this.registry.get( cls.getName() );
@@ -78,19 +155,23 @@
     }
 
     private void init() {
-        addDefault( KnowledgeBuilderProvider.class, "org.drools.builder.impl.KnowledgeBuilderProviderImpl" );
-        
-        addDefault( KnowledgeBaseProvider.class, "org.drools.impl.KnowledgeBaseProviderImpl" );
-        
-        addDefault( ResourceProvider.class,  "org.drools.io.impl.ResourceProviderImpl" );
+        addDefault( KnowledgeBuilderProvider.class,
+                    "org.drools.builder.impl.KnowledgeBuilderProviderImpl" );
+
+        addDefault( KnowledgeBaseProvider.class,
+                    "org.drools.impl.KnowledgeBaseProviderImpl" );
+
+        addDefault( ResourceProvider.class,
+                    "org.drools.io.impl.ResourceProviderImpl" );
     }
-    
-    private void addDefault(Class cls, String impl) {
+
+    private void addDefault(Class cls,
+                            String impl) {
         ReflectionInstantiator<Service> resourceRi = new ReflectionInstantiator<Service>( impl );
         registry.put( cls.getName(),
                       resourceRi );
         defaultServices.put( cls.getName(),
-                             resourceRi );        
+                             resourceRi );
     }
 
     static class ReflectionInstantiator<V>
@@ -107,13 +188,27 @@
         }
     }
 
+    static class ReturnInstance<V>
+        implements
+        Callable<V> {
+        private Service service;
+
+        public ReturnInstance(Service service) {
+            this.service = service;
+        }
+
+        public V call() throws Exception {
+            return (V) service;
+        }
+    }
+
     static <T> T newInstance(String name) {
         try {
             Class<T> cls = (Class<T>) Class.forName( name );
             return cls.newInstance();
         } catch ( Exception e2 ) {
             throw new IllegalArgumentException( "Unable to instantiate '" + name + "'",
-                                                       e2 );
+                                                e2 );
         }
     }
 

Modified: labs/jbossrules/trunk/drools-compiler/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-compiler/.classpath	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-compiler/.classpath	2010-01-18 02:07:59 UTC (rev 31114)
@@ -21,6 +21,7 @@
   <classpathentry kind="var" path="M2_REPO/org/antlr/gunit/3.1.3/gunit-3.1.3.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/javax.servlet/1.0.0/javax.servlet-1.0.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty/6.1.15/jetty-6.1.15.jar" sourcepath="M2_REPO/org/mortbay/jetty/jetty/6.1.15/jetty-6.1.15-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty-embedded/6.1.15/jetty-embedded-6.1.15.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty-util/6.1.15/jetty-util-6.1.15.jar"/>
@@ -30,8 +31,9 @@
   <classpathentry kind="var" path="M2_REPO/junit/junit/4.6/junit-4.6.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mvel/mvel2/2.0.12/mvel2-2.0.12.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/objenesis/objenesis/1.0/objenesis-1.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/equinox/org.eclipse.osgi/3.5.1/org.eclipse.osgi-3.5.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/equinox/org.eclipse.osgi.util/3.5.1/org.eclipse.osgi.util-3.5.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.compendium/1.4.0/org.osgi.compendium-1.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.core/1.4.0/org.osgi.core-1.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.foundation/1.2.0/org.osgi.foundation-1.2.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/antlr/stringtemplate/3.2/stringtemplate-3.2.jar"/>
 </classpath>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-compiler/pom.xml	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-compiler/pom.xml	2010-01-18 02:07:59 UTC (rev 31114)
@@ -22,16 +22,21 @@
 			<artifactId>drools-core</artifactId>
 		</dependency>
 		<!-- External dependencies -->
-            <dependency>  
-               <groupId>org.eclipse.equinox</groupId>  
-               <artifactId>org.eclipse.osgi</artifactId>  
-               <scope>provided</scope> 
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.core</artifactId>
+              <scope>provided</scope> 
+            </dependency>
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.foundation</artifactId>
+              <scope>provided</scope> 
             </dependency>            
-            <dependency>  
-               <groupId>org.eclipse.equinox</groupId>  
-               <artifactId>org.eclipse.osgi.util</artifactId>  
-               <scope>provided</scope> 
-            </dependency>
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.compendium</artifactId>
+              <scope>provided</scope> 
+            </dependency>                
             
 		<dependency>
             <groupId>org.antlr</groupId>  

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DecisionTableProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DecisionTableProvider.java	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DecisionTableProvider.java	2010-01-18 02:07:59 UTC (rev 31114)
@@ -3,9 +3,10 @@
 import java.io.InputStream;
 import java.io.Reader;
 
+import org.drools.Service;
 import org.drools.builder.DecisionTableConfiguration;
 
-public interface DecisionTableProvider {
+public interface DecisionTableProvider extends Service {
 
     String loadFromInputStream(InputStream is,
                                DecisionTableConfiguration configuration);

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/osgi/compiler/Activator.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/osgi/compiler/Activator.java	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/osgi/compiler/Activator.java	2010-01-18 02:07:59 UTC (rev 31114)
@@ -1,30 +1,90 @@
 package org.drools.osgi.compiler;
 
+import java.util.Dictionary;
 import java.util.Hashtable;
 
+import org.drools.Service;
 import org.drools.builder.KnowledgeBuilderProvider;
 import org.drools.builder.impl.KnowledgeBuilderProviderImpl;
+import org.drools.compiler.DecisionTableProvider;
+import org.drools.osgi.api.Activator.BundleContextInstantiator;
+import org.drools.util.ServiceRegistryImpl;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
 public class Activator
     implements
     BundleActivator {
     private ServiceRegistration kbuilderReg;
 
-    public static BundleContext bc;
+    private ServiceTracker      dtableTracker;
 
     public void start(BundleContext bc) throws Exception {
-        this.bc = bc;
         System.out.println( "registering compiler services" );
-        this.kbuilderReg = bc.registerService( KnowledgeBuilderProvider.class.getName(),
+        this.kbuilderReg = bc.registerService( new String[]{KnowledgeBuilderProvider.class.getName(), Service.class.getName()},
                                                new KnowledgeBuilderProviderImpl(),
                                                new Hashtable() );
+
+        this.dtableTracker = new ServiceTracker( bc,
+                                                 DecisionTableProvider.class.getName(),
+                                                 new DroolsServiceTracker( bc,
+                                                                           this ) );
+        this.dtableTracker.open();
+
         System.out.println( "compiler services registered" );
     }
 
     public void stop(BundleContext bc) throws Exception {
         this.kbuilderReg.unregister();
+        this.dtableTracker.close();
     }
+
+    public static class DroolsServiceTracker
+        implements
+        ServiceTrackerCustomizer {
+        private BundleContext bc;
+        private Activator     activator;
+
+        public DroolsServiceTracker(BundleContext bc,
+                                    Activator activator) {
+            this.bc = bc;
+            this.activator = activator;
+        }
+
+        public Object addingService(ServiceReference ref) {
+            Service service = (Service) this.bc.getService( ref );
+            System.out.println( "registering : " + service + " : " + service.getClass().getInterfaces()[0] );
+
+            Dictionary dic = new Hashtable();
+            ServiceReference regServiceRef = this.activator.kbuilderReg.getReference();
+            for ( String key : regServiceRef.getPropertyKeys() ) {
+                dic.put( key,
+                         regServiceRef.getProperty( key ) );
+            }
+            dic.put( service.getClass().getInterfaces()[0].getName(),
+                     "true" );
+            activator.kbuilderReg.setProperties( dic );
+
+            ServiceRegistryImpl.getInstance().registerLocator( service.getClass().getInterfaces()[0],
+                                                               new BundleContextInstantiator( this.bc,
+                                                                                              ref ) );
+            return service;
+        }
+
+        public void modifiedService(ServiceReference arg0,
+                                    Object arg1) {
+
+        }
+
+        public void removedService(ServiceReference ref,
+                                   Object arg1) {
+            Service service = (Service) bc.getService( ref );
+            ServiceRegistryImpl.getInstance().unregisterLocator( service.getClass().getInterfaces()[0] );
+        }
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-core/.classpath	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-core/.classpath	2010-01-18 02:07:59 UTC (rev 31114)
@@ -11,11 +11,13 @@
   <classpathentry kind="src" path="/drools-api"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/javax.servlet/1.0.0/javax.servlet-1.0.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jmock/jmock/2.5.1/jmock-2.5.1.jar" sourcepath="M2_REPO/org/jmock/jmock/2.5.1/jmock-2.5.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jmock/jmock-legacy/2.5.1/jmock-legacy-2.5.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/junit/junit/4.6/junit-4.6.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mvel/mvel2/2.0.12/mvel2-2.0.12.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/objenesis/objenesis/1.0/objenesis-1.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/equinox/org.eclipse.osgi/3.5.1/org.eclipse.osgi-3.5.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/equinox/org.eclipse.osgi.util/3.5.1/org.eclipse.osgi.util-3.5.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.compendium/1.4.0/org.osgi.compendium-1.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.core/1.4.0/org.osgi.core-1.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.foundation/1.2.0/org.osgi.foundation-1.2.0.jar"/>
 </classpath>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-core/pom.xml	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-core/pom.xml	2010-01-18 02:07:59 UTC (rev 31114)
@@ -13,16 +13,21 @@
   <name>Drools :: Core</name>
 
   <dependencies>  
-            <dependency>  
-               <groupId>org.eclipse.equinox</groupId>  
-               <artifactId>org.eclipse.osgi</artifactId>  
-               <scope>provided</scope> 
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.core</artifactId>
+              <scope>provided</scope> 
+            </dependency>
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.foundation</artifactId>
+              <scope>provided</scope> 
             </dependency>            
-            <dependency>  
-               <groupId>org.eclipse.equinox</groupId>  
-               <artifactId>org.eclipse.osgi.util</artifactId>  
-               <scope>provided</scope> 
-            </dependency>
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.compendium</artifactId>
+              <scope>provided</scope> 
+            </dependency>                
               
     <!-- following are required for parser (lang). May be refactored out of core module. -->    
       <dependency>  

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/osgi/core/Activator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/osgi/core/Activator.java	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/osgi/core/Activator.java	2010-01-18 02:07:59 UTC (rev 31114)
@@ -1,14 +1,22 @@
 package org.drools.osgi.core;
 
 import java.util.Hashtable;
+import java.util.concurrent.Callable;
 
 import org.drools.KnowledgeBaseProvider;
+import org.drools.Service;
+import org.drools.builder.KnowledgeBuilderProvider;
 import org.drools.impl.KnowledgeBaseProviderImpl;
 import org.drools.io.ResourceProvider;
 import org.drools.io.impl.ResourceProviderImpl;
+import org.drools.util.ServiceRegistry;
+import org.drools.util.ServiceRegistryImpl;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
 public class Activator
     implements
@@ -18,18 +26,19 @@
 
     public void start(BundleContext bc) throws Exception {
         System.out.println( "registering core  services" );
-        this.resourceReg = bc.registerService( ResourceProvider.class.getName(),
+        this.resourceReg = bc.registerService( new String[]{ResourceProvider.class.getName(), Service.class.getName()},
                                                new ResourceProviderImpl(),
                                                new Hashtable() );
-        this.kbaseReg = bc.registerService( KnowledgeBaseProvider.class.getName(),
+        this.kbaseReg = bc.registerService( new String[]{KnowledgeBaseProvider.class.getName(), Service.class.getName()},
                                             new KnowledgeBaseProviderImpl(),
                                             new Hashtable() );
+
         System.out.println( "core services registered" );
     }
 
     public void stop(BundleContext bc) throws Exception {
+        this.kbaseReg.unregister();
         this.resourceReg.unregister();
-        this.kbaseReg.unregister();
     }
 
 }

Modified: labs/jbossrules/trunk/drools-decisiontables/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/.classpath	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-decisiontables/.classpath	2010-01-18 02:07:59 UTC (rev 31114)
@@ -18,12 +18,14 @@
   <classpathentry kind="var" path="M2_REPO/org/antlr/gunit/3.1.3/gunit-3.1.3.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/javax.servlet/1.0.0/javax.servlet-1.0.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jmock/jmock/2.5.1/jmock-2.5.1.jar" sourcepath="M2_REPO/org/jmock/jmock/2.5.1/jmock-2.5.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jmock/jmock-legacy/2.5.1/jmock-legacy-2.5.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/junit/junit/4.6/junit-4.6.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mvel/mvel2/2.0.12/mvel2-2.0.12.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/objenesis/objenesis/1.0/objenesis-1.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/equinox/org.eclipse.osgi/3.5.1/org.eclipse.osgi-3.5.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/equinox/org.eclipse.osgi.util/3.5.1/org.eclipse.osgi.util-3.5.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.compendium/1.4.0/org.osgi.compendium-1.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.core/1.4.0/org.osgi.core-1.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/felix/org.osgi.foundation/1.2.0/org.osgi.foundation-1.2.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/antlr/stringtemplate/3.2/stringtemplate-3.2.jar"/>
 </classpath>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-decisiontables/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/pom.xml	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-decisiontables/pom.xml	2010-01-18 02:07:59 UTC (rev 31114)
@@ -28,16 +28,21 @@
     </dependency>
 
     <!-- External dependencies -->
-            <dependency>  
-               <groupId>org.eclipse.equinox</groupId>  
-               <artifactId>org.eclipse.osgi</artifactId>  
-               <scope>provided</scope> 
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.core</artifactId>
+              <scope>provided</scope> 
+            </dependency>
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.foundation</artifactId>
+              <scope>provided</scope> 
             </dependency>            
-            <dependency>  
-               <groupId>org.eclipse.equinox</groupId>  
-               <artifactId>org.eclipse.osgi.util</artifactId>  
-               <scope>provided</scope> 
-            </dependency>
+            <dependency>
+              <groupId>org.apache.felix</groupId>
+              <artifactId>org.osgi.compendium</artifactId>
+              <scope>provided</scope> 
+            </dependency>   
                 
     <dependency>  
         <groupId>net.sourceforge.jexcelapi</groupId>  

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/osgi/decisiontables/Activator.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/osgi/decisiontables/Activator.java	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/osgi/decisiontables/Activator.java	2010-01-18 02:07:59 UTC (rev 31114)
@@ -22,7 +22,7 @@
 
     public void start(BundleContext bc) throws Exception {
     	System.out.println( "registering decision tables drools services" );
-        this.kdtableReg = bc.registerService( DecisionTableProvider.class.getName(),
+        this.kdtableReg = bc.registerService(  DecisionTableProvider.class.getName(),
                                                new DecisionTableProviderImpl(),
                                                new Hashtable() );
         System.out.println( "drools decision tables services registered" );

Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/xls/ExcelParserTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/xls/ExcelParserTest.java	2010-01-18 01:13:05 UTC (rev 31113)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/xls/ExcelParserTest.java	2010-01-18 02:07:59 UTC (rev 31114)
@@ -24,6 +24,7 @@
 import junit.framework.TestCase;
 import jxl.Cell;
 //import jxl.CellFeatures;
+import jxl.CellFeatures;
 import jxl.CellType;
 import jxl.Range;
 import jxl.format.CellFormat;
@@ -122,6 +123,10 @@
 		public boolean isHidden() {
 			return false;
 		}
+
+        public CellFeatures getCellFeatures() {
+            return null;
+        }
     	
     }
     



More information about the jboss-svn-commits mailing list