in rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java [213:249]
private ExportRegistration exportService(
final List<String> interfaceNames,
final ServiceReference<?> serviceReference,
final Map<String, Object> serviceProperties) {
LOG.info("interfaces selected for export: " + interfaceNames);
try {
checkPermission(new EndpointPermission("*", EndpointPermission.EXPORT));
Bundle serviceBundle = serviceReference.getBundle();
if (serviceBundle == null) {
throw new IllegalStateException("Service is already unregistered");
}
final BundleContext serviceContext = serviceBundle.getBundleContext();
final Object serviceO = serviceContext.getService(serviceReference);
if (serviceO == null) {
throw new IllegalStateException("service object is null (service was unregistered?)");
}
final Class<?>[] interfaces = getInterfaces(serviceO, interfaceNames);
final Map<String, Object> eprops = createEndpointProps(serviceProperties, interfaces);
// TODO unget service when export is destroyed
Endpoint endpoint = AccessController.doPrivileged(new PrivilegedAction<Endpoint>() {
public Endpoint run() {
return provider.exportService(serviceO, serviceContext, eprops, interfaces);
}
});
if (endpoint == null) {
return null;
}
return new ExportRegistrationImpl(serviceReference, endpoint, closeHandler, eventProducer);
} catch (IllegalArgumentException e) {
// TCK expects this for garbage input
throw e;
} catch (Exception e) {
return new ExportRegistrationImpl(e, closeHandler, eventProducer);
}
}