Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * 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.
  */
 
 package org.drools.osgi.api;
 
 
 
 public class Activator
     implements
     BundleActivator {
 
     protected static final transient Logger logger = LoggerFactory.getLogger(Activator.class);
 
     private ServiceTracker      registryTracker;
 
     public void start(BundleContext bcthrows Exception {
         .info"registering api services" );
 
         this. = bc.registerServiceServiceRegistry.class.getName(),
                                                    ServiceRegistryImpl.getInstance(),
                                                    new Hashtable() );
 
         this. = new ServiceTrackerbc,
                                                    Service.class.getName(),
                                                    new DroolsServiceTrackerbc,
                                                                              this ) );
         
         .open();
         
         this. = new ServiceTrackerbc,
                 MarshallerProvider.class.getName(),
                 new DroolsServiceTrackerbc,
                                           this) );
         
         this..open();
 
         .info"api drools services registered" );
     }
 
     public void stop(BundleContext bcthrows Exception {
         this..unregister();
         this..close();
         this..close();
     }
 
     public static class DroolsServiceTracker
         implements
         ServiceTrackerCustomizer {
 
         protected static final transient Logger logger = LoggerFactory.getLogger(DroolsServiceTracker.class);
 
         private BundleContext bc;
         private Activator     activator;
 
         public DroolsServiceTracker(BundleContext bc,
                                     Activator activator) {
             this. = bc;
             this. = activator;
         }
 
         public Object addingService(ServiceReference ref) {
             Service service = (Servicethis..getServiceref );
             .info"registering api : " + service + " : " + service.getClass().getInterfaces()[0] );
 
             Dictionary dic = new Hashtable();
             ServiceReference regServiceRef = this...getReference();
             for ( String key : regServiceRef.getPropertyKeys() ) {
                 dic.putkey,
                          regServiceRef.getPropertykey ) );
            }
            dic.putservice.getClass().getInterfaces()[0].getName(),
                     "true" );
            ..setPropertiesdic );
            ((ServiceRegistryImpl.getServiceregServiceRef )).registerLocatorservice.getClass().getInterfaces()[0],
                                                                                    new BundleContextInstantiatorthis.,
                                                                                                                   ref ) );
            return service;
        }
        public void modifiedService(ServiceReference arg0,
                                    Object arg1) {
        }
        public void removedService(ServiceReference ref,
                                   Object arg1) {
            Service service = (Servicethis..getServiceref );
            .info"unregistering : " + service + " : " + service.getClass().getInterfaces()[0] );
            Dictionary dic = new Hashtable();
            ServiceReference regServiceRef = this...getReference();
            ((ServiceRegistryImpl.getServiceregServiceRef )).unregisterLocatorservice.getClass().getInterfaces()[0] );
            for ( String key : regServiceRef.getPropertyKeys() ) {
                if ( !key.equalsservice.getClass().getInterfaces()[0].getName() ) ) {
                    dic.putkey,
                             regServiceRef.getPropertykey ) );
                }
            }
            ..setPropertiesdic );
        }
    }
    public static class BundleContextInstantiator<V>
        implements
        Callable<V> {
        private BundleContext    bc;
        private ServiceReference ref;
        public BundleContextInstantiator(BundleContext bc,
                                         ServiceReference ref) {
            this. = bc;
            this. = ref;
        }
        public V call() throws Exception {
            return (V) this..getServicethis. );
        }
    }
New to GrepCode? Check out our FAQ X