else if (svcObj == null)
{
throw new IllegalArgumentException("Service object cannot be null.");
}
ServiceRegistration reg = null;
// Check to make sure that the service object is
// an instance of all service classes; ignore if
// service object is a service factory.
if (!(svcObj instanceof ServiceFactory))
{
for (int i = 0; i < classNames.length; i++)
{
Class clazz = Util.loadClassUsingClass(svcObj.getClass(), classNames[i], m_secureAction);
if (clazz == null)
{
throw new IllegalArgumentException(
"Cannot cast service: " + classNames[i]);
}
else if (!clazz.isAssignableFrom(svcObj.getClass()))
{
throw new IllegalArgumentException(
"Service object is not an instance of \""
+ classNames[i] + "\".");
}
}
}
reg = m_registry.registerService(context, classNames, svcObj, dict);
// Check to see if this a listener hook; if so, then we need
// to invoke the callback with all existing service listeners.
if (ServiceRegistry.isHook(
classNames, org.osgi.framework.hooks.service.ListenerHook.class, svcObj))
{
org.osgi.framework.hooks.service.ListenerHook lh =
(org.osgi.framework.hooks.service.ListenerHook)
getService(this, reg.getReference(), false);
if (lh != null)
{
try
{
m_secureAction.invokeServiceListenerHookAdded(
lh, m_dispatcher.getAllServiceListeners());
}
catch (Throwable th)
{
m_logger.log(reg.getReference(), Logger.LOG_WARNING,
"Problem invoking service registry hook", th);
}
finally
{
m_registry.ungetService(this, reg.getReference(), null);
}
}
}
// Fire service event.
fireServiceEvent(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()), null);
return reg;
}