// set the component for the services object
services.setComponent(component);
// retrieve the ComponentID for this component
if (!(services.getComponentID() instanceof MobileComponentIDServerImpl))
throw new NonstandardException("ComponentID not an instance of MobileComponentIDServerImpl");
MobileComponentIDServerImpl cid =
(MobileComponentIDServerImpl) services.getComponentID();
// set the GSH for this ComponentID
cid.setGSH(instanceHandle);
// Add a reference to this ComponentID into the Handle Resolver
HandleResolver.addReference(instanceHandle, cid);
// if this component has been migrated, return here
if (isMigrated) {
logger.finest("Component is migrated, setServices will not be invoked");
return;
}
// invoke the setServices method on the component
try {
component.setServices(services);
} catch (Exception e) {
logger.severe("Can't invoke setServices on component", e);
throw new NonstandardException("Can't invoke setServices on component", e);
}
// add some SDEs to the Component
logger.finest("adding default Service Data Elements");
ServiceDataManagerInterface sdm =
cid.getServiceDataManager();
ServiceDataElementFactory sdeFactory =
ServiceDataElementFactory.getDefault();
// an SDE for the name of the Component
XmlQName serviceQName = XmlQName.Factory.newInstance();
serviceQName.setQNameValue(new QName("http://www.extreme.indiana.edu/xcat/ccacore/componentID",
instanceName));
ServiceDataElement serviceNameSDE =
sdeFactory.newServiceDataElement(new QName(OGSI.OGSI_NS,
"instanceName"),
serviceQName);
sdm.addServiceData(serviceNameSDE);
// add SDEs for GSH's of each of the ports
String[] portNames = services.getProvidedPortNames();
for (int i = 0; i < portNames.length; i++) {
String portHandle = services.getPortHandle(portNames[i]);
String handleXMLString =
"<tns:providesPortHandle " +
"xmlns:tns=\"http://www.extreme.indiana.edu/xcat/ccacore/componentID\" " +
"name=\"" + portNames[i] + "\">" +
portHandle +
"</tns:providesPortHandle>";
ServiceDataElement handleSDE =
sdeFactory.newServiceDataElement(handleXMLString);
sdm.addServiceData(handleSDE);
}
String handleXMLString =
"<tns:componentHandle " +
"xmlns:tns=\"http://www.extreme.indiana.edu/xcat/ccacore/componentID\" " +
"name=\"" + instanceName + "\">" +
instanceHandle +
"</tns:componentHandle>";
ServiceDataElement handleSDE =
sdeFactory.newServiceDataElement(handleXMLString);
sdm.addServiceData(handleSDE);
} catch (ClassNotFoundException cnfe) {
logger.severe("Can't find class " + className + " for component", cnfe);
throw new NonstandardException("Can't find class " + className +
" for component", cnfe);
} catch(InstantiationException ie) {
logger.severe("Can't instantiate class " + className, ie);
throw new NonstandardException("Can't instantiate class " + className,
ie);
} catch (IllegalAccessException iae) {
logger.severe("Can't instantiate class " + className, iae);
throw new NonstandardException("Can't instantiate class " + className,
iae);
} catch (ServiceDataManagerException sdme) {
logger.severe("Can't create ServiceDataManager for ComponentID", sdme);
throw new NonstandardException("Can't create ServiceDataManager for ComponentID",
sdme);
} catch (ServiceDataElementException sdee) {
logger.severe("Can't add service data to ComponentID", sdee);
throw new NonstandardException("Can't add service data to ComponentID",
sdee);
}
}