Source:
public void execute(JobExecutionContext context) throws JobExecutionException { String content = (String) context.getJobDetail().getJobDataMap().get(JOB_DATA_CONTENT_KEY); ItemRegistry registry = GCalActivator.itemRegistryTracker.getService(); EventPublisher publisher = GCalActivator.eventPublisherTracker.getService(); if (registry == null) { logger.warn("Sorry, no item registry service available!"); return; } if (publisher == null) { logger.warn("Sorry, no event publisher service available!"); return; } if (content.startsWith("[PresenceSimulation]")) { try { Item item = registry.getItem("PresenceSimulation"); if (item.getState() != OnOffType.ON) { logger.info( "Presence Simulation job detected, but PresenceSimulation is not in ON state. Job is not executed"); return; } } catch (ItemNotFoundException e) { logger.error( "Presence Simulation job detected, but PresenceSimulation item does not exists. Check configuration"); return; } } if (StringUtils.isNotBlank(content)) { String[] commands = parseCommands(content); for (String command : commands) { String[] args = parseCommand(command); try { if (args[0].equals("send")) { if (args.length > 2) { Item item = registry.getItem(args[1]); Command cmd = TypeParser.parseCommand(item.getAcceptedCommandTypes(), args[2]); if (cmd != null) { publisher.sendCommand(item.getName(), cmd); logger.debug("Command has been sent", Arrays.asList(args)); } else { logger.warn("Command is not valid for item {}", args[2], args[1]); } } } else if (args[0].equals("update")) { if (args.length > 2) { Item item = registry.getItem(args[1]); State state = TypeParser.parseState(item.getAcceptedDataTypes(), args[2]); publisher.postUpdate(item.getName(), state); logger.debug("Published update {}", Arrays.asList(args)); } } else { logger.warn("Command not supported", args[0]); } } catch (ItemNotFoundException e) { logger.warn("Executing command failed. Item not found", args[1]); } } } }

Target:
public void execute(JobExecutionContext context) throws JobExecutionException { String content = (String) context.getJobDetail().getJobDataMap().get(JOB_DATA_CONTENT_KEY); ItemRegistry registry = GCalActivator.itemRegistryTracker.getService(); EventPublisher publisher = GCalActivator.eventPublisherTracker.getService(); if (registry == null) { logger.warn("Sorry, no item registry service available!"); return; } if (publisher == null) { logger.warn("Sorry, no event publisher service available!"); return; } if (content.startsWith("[PresenceSimulation]")) { try { Item item = registry.getItem("PresenceSimulation"); if (item.getState() != OnOffType.ON) { logger.debug( "Presence Simulation job detected, but PresenceSimulation is not in ON state. Job is not executed"); return; } } catch (ItemNotFoundException e) { logger.warn( "Presence Simulation job detected, but PresenceSimulation item does not exists. Check configuration"); return; } } if (StringUtils.isNotBlank(content)) { String[] commands = parseCommands(content); for (String command : commands) { String[] args = parseCommand(command); try { if (args[0].equals("send")) { if (args.length > 2) { Item item = registry.getItem(args[1]); Command cmd = TypeParser.parseCommand(item.getAcceptedCommandTypes(), args[2]); if (cmd != null) { publisher.sendCommand(item.getName(), cmd); logger.debug("Command has been sent", Arrays.asList(args)); } else { logger.warn("Command '{}' is not valid. Command not sent.", Arrays.asList(args)); } } } else if (args[0].equals("update")) { if (args.length > 2) { Item item = registry.getItem(args[1]); State state = TypeParser.parseState(item.getAcceptedDataTypes(), args[2]); publisher.postUpdate(item.getName(), state); logger.debug("Published update {}", Arrays.asList(args)); } else { logger.warn("Command '{}' is not valid. Update not sent.", Arrays.asList(args)); } } else { logger.warn("Command not supported", args[0]); } } catch (ItemNotFoundException e) { logger.warn("Executing command failed. Item not found", args[1]); } } } }