}
public void doServiceUpdating(String udn,String serviceType){
Activator.logger.DEBUG("[Importer] check for service updating");
OSGiDeviceInfo deviceinfo = (OSGiDeviceInfo) devices.get(udn);
UPnPDeviceImpl device = deviceinfo.getOSGiDevice();
boolean isSerPresent = device.existServiceType(serviceType);
if (!isSerPresent) {
/*
* The serivice doesn't exist so it's new.
* Find the udn of owner device and re-register the owner
*/
ServiceRegistration registar =
((OSGiDeviceInfo) devices.remove(udn)).getRegistration();
String[] oldServicesID =
(String[]) device.getDescriptions(null).get(UPnPServiceImpl.ID);
String[] oldServicesType =
(String[]) device.getDescriptions(null).get(UPnPServiceImpl.TYPE);
//to handle multiple instance of a serivice of the same type
Device cyberDevice = findDeviceCtrl(this, udn);
ServiceList serviceList = cyberDevice.getServiceList();
ArrayList newServicesID = new ArrayList();
for (int i = 0; i < serviceList.size(); i++) {
if (serviceList.getService(i).getServiceType()
.equals(serviceType))
{
newServicesID.add(serviceList.getService(i).getServiceID());
}
}
//adding the new servicesID
String[] currentServicesID =
new String[(oldServicesID.length + newServicesID.size())];
int endOld = 1;
for (int i = 0; i < oldServicesID.length; i++) {
currentServicesID[i] = oldServicesID[i];
endOld++;
}
int j = 0;
for (; endOld < currentServicesID.length; endOld++) {
currentServicesID[endOld] = (String) newServicesID.get(j);
j++;
}
//adding the new ServiceType
String[] currentServicesType = new String[oldServicesType.length + 1];
for (int i = 0; i < oldServicesType.length; i++) {
currentServicesType[i] = oldServicesType[i];
}
currentServicesType[currentServicesType.length - 1] = serviceType;
// unregistring the OSGi Device
// and setting new properties
unregisterUPnPDevice(registar);
device.setProperty(UPnPService.ID, currentServicesID);
device.setProperty(UPnPServiceImpl.TYPE,currentServicesType);
//registering the service with the updated properties
//TODO Check if null to the first paramaters is correct or it requires the reference to the cyberdomo upnp device
registerUPnPDevice(null, device, device.getDescriptions(null));
searchForListener(cyberDevice);
}
}