1 26 27 package com.opensugar.cube; 28 29 import com.opensugar.cube.serviceRegistry.ServiceRegistryEntry; 30 31 import org.osgi.framework.ServiceRegistration; 32 import org.osgi.framework.ServiceReference; 33 import org.osgi.framework.Bundle; 34 import org.osgi.framework.ServiceEvent; 35 36 import java.util.Dictionary ; 37 38 public class ServiceRegistrationImpl implements ServiceRegistration { 40 41 private ServiceReferenceImpl reference; 43 private boolean registered; 45 46 public ServiceRegistrationImpl( Bundle bundle, String [] classNames, Dictionary properties ) { 47 reference = new ServiceReferenceImpl( bundle, classNames, properties ); 48 registered = true; 49 } 50 51 public ServiceReference getReference() { 54 checkStillRegistered(); 56 57 return reference; 58 } 59 60 public void setProperties( Dictionary properties ) { 63 65 checkStillRegistered(); 67 68 reference.setProperties( properties ); 70 71 ( (BundleImpl)reference.getBundle() ).getCube().fireServiceEvent( ServiceEvent.MODIFIED, reference ); 73 } 74 75 public void unregister() { 76 checkStillRegistered(); 78 79 registered = false; 80 83 BundleImpl bundle = (BundleImpl)reference.getBundle(); 85 Object serviceClass = reference.getProperty( "objectClass" ); 86 if ( serviceClass instanceof Object [] ) { 87 serviceClass = ( (Object [])serviceClass )[ 0 ]; 88 } 89 ( bundle.getCube() ).log( AbstractCube.LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " unregistering " + serviceClass ); 90 bundle.getCube().fireServiceEvent( ServiceEvent.UNREGISTERING, reference ); 91 92 reference.serviceUnregistered(); 95 96 ServiceRegistryEntry serviceRegistryEntry = bundle.getCube().getServiceRegistry().getServiceRegistryEntry( this ); 101 serviceRegistryEntry.serviceUnregistered(); 102 } 103 104 106 private void checkStillRegistered() { 108 if ( !registered ) { 109 throw new IllegalStateException ( "Service has already been unregistered" ); 110 } 111 } 112 113 } | Popular Tags |