/** Creates DOM Element which represents all the instances defined. called by saveInstances(). */ private static Element createInstancesElement(Document document) { Element instancesRoot = document.createElement(SEQUOYAH_XML_INSTANCES); InstanceRegistry registry = InstanceRegistry.getInstance(); Iterator<IInstance> iterator = registry.getInstances().iterator(); while (iterator.hasNext()) { IInstance iIInst = iterator.next(); IDeviceType device = DeviceTypeRegistry.getInstance().getDeviceTypeById(iIInst.getDeviceTypeId()); /* * Check if this instance should be persisted * If device == null, it means that this particular instance does not * have a plug-in that declares its device, so we persist it anyway. */ if (device == null || device.isPersistent()) { Element element = document.createElement(SEQUOYAH_XML_INSTANCE); element.setAttribute(SEQUOYAH_XML_INSTANCE_NAME, iIInst.getName()); String xml_device_id = iIInst.getDeviceTypeId(); element.setAttribute(SEQUOYAH_XML_INSTANCE_DEVICE_ID, xml_device_id); if (element != null) instancesRoot.appendChild(element); Properties propProp = iIInst.getProperties(); for (Enumeration<?> e = propProp.keys(); e.hasMoreElements(); ) { String propStr = (String) e.nextElement(); String propValStr = propProp.getProperty(propStr); Element propElement = document.createElement(propStr); Text propNode = document.createTextNode(propValStr); propElement.appendChild(propNode); element.appendChild(propElement); } } } return instancesRoot; }
@Override public IStatus runService(IInstance instance, Map<Object, Object> arg1, IProgressMonitor arg2) { if (instance instanceof ISerialNumbered) { final String serialNumber = ((ISerialNumbered) instance).getSerialNumber(); final String deviceName = instance.getName(); Job job = new Job(ServicesNLS.JOB_Name_Monkey) { @Override protected IStatus run(IProgressMonitor monitor) { DDMSUtils.runMonkey(serialNumber, deviceName); return Status.OK_STATUS; } }; job.schedule(); } return Status.OK_STATUS; }