@Override public List<ActionService> get() { return this.scriptServiceUtil.getActionServiceInstances(); } }
public static List<ThingActions> getThingActions() { return getInstance().thingActions; }
@Override public void configure(Binder binder) { binder.bind(ItemRegistry.class).toInstance(scriptServiceUtil.getItemRegistryInstance()); binder.bind(ThingRegistry.class).toInstance(scriptServiceUtil.getThingRegistryInstance()); binder.bind(ModelRepository.class).toInstance(scriptServiceUtil.getModelRepositoryInstance()); binder.bind(ScriptEngine.class).toInstance(scriptEngine); binder.bind(IActionServiceProvider.class) .toInstance(new ServiceTrackerActionServiceProvider(scriptServiceUtil)); binder.bind(IThingActionsProvider.class).toInstance(new ServiceTrackerThingActionsProvider(scriptServiceUtil)); binder.bind(Script.class).to(ScriptImpl.class); }
/** * Sends a command for a specified item to the event bus. * * @param itemName the name of the item to send the command to * @param commandString the command to send */ static public Object sendCommand(String itemName, String commandString) { ItemRegistry registry = ScriptServiceUtil.getItemRegistry(); EventPublisher publisher = ScriptServiceUtil.getEventPublisher(); if (publisher != null && registry != null) { try { Item item = registry.getItem(itemName); Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandString); if (command != null) { publisher.post(ItemEventFactory.createCommandEvent(itemName, command)); } else { LoggerFactory.getLogger(BusEvent.class).warn( "Cannot convert '{}' to a command type which item '{}' accepts: {}.", commandString, itemName, getAcceptedCommandNames(item)); } } catch (ItemNotFoundException e) { LoggerFactory.getLogger(BusEvent.class).warn("Item '{}' does not exist.", itemName); } } return null; }
@Override public Class<?> loadClass(String name) throws ClassNotFoundException { try { Class<?> clazz = getParent().loadClass(name); return clazz; } catch (ClassNotFoundException e) { for (ActionService actionService : ScriptServiceUtil.getActionServices()) { if (actionService.getActionClassName().equals(name)) { return actionService.getActionClass(); } } for (ThingActions actions : ScriptServiceUtil.getThingActions()) { if (actions.getClass().getName().equals(name)) { return actions.getClass(); } } } throw new ClassNotFoundException(); } }
ModelRepository repo = ScriptServiceUtil.getModelRepository(); if (repo != null) { String scriptNameWithExt = scriptName; ScriptEngine scriptEngine = ScriptServiceUtil.getScriptEngine(); if (scriptEngine != null) { Script script = scriptEngine.newScriptFromXExpression(expr);
/** * Sends a command for a specified item to the event bus. * * @param item the item to send the command to * @param command the command to send */ static public Object sendCommand(Item item, Command command) { EventPublisher publisher = ScriptServiceUtil.getEventPublisher(); if (publisher != null && item != null) { publisher.post(ItemEventFactory.createCommandEvent(item.getName(), command)); } return null; }
/** * Posts a status update for a specified item to the event bus. * * @param itemName the name of the item to send the status update for * @param stateAsString the new state of the item */ static public Object postUpdate(String itemName, String stateString) { ItemRegistry registry = ScriptServiceUtil.getItemRegistry(); EventPublisher publisher = ScriptServiceUtil.getEventPublisher(); if (publisher != null && registry != null) { try { Item item = registry.getItem(itemName); State state = TypeParser.parseState(item.getAcceptedDataTypes(), stateString); if (state != null) { publisher.post(ItemEventFactory.createStateEvent(itemName, state)); } else { LoggerFactory.getLogger(BusEvent.class).warn( "Cannot convert '{}' to a state type which item '{}' accepts: {}.", stateString, itemName, getAcceptedDataTypeNames(item)); } } catch (ItemNotFoundException e) { LoggerFactory.getLogger(BusEvent.class).warn("Item '{}' does not exist.", itemName); } } return null; }
/** * Posts a status update for a specified item to the event bus. * t * * @param item the item to send the status update for * @param state the new state of the item */ static public Object postUpdate(Item item, State state) { EventPublisher publisher = ScriptServiceUtil.getEventPublisher(); if (publisher != null && item != null) { publisher.post(ItemEventFactory.createStateEvent(item.getName(), state)); } return null; }
public static EventPublisher getEventPublisher() { return getInstance().eventPublisher; }
public static ModelRepository getModelRepository() { return getInstance().modelRepository; }
public static List<ActionService> getActionServices() { return getInstance().actionServices; }
public static ItemRegistry getItemRegistry() { return getInstance().itemRegistry; }
public static ScriptEngine getScriptEngine() { return getInstance().scriptEngine.get(); }