Package org.openhab.core.scriptengine

Examples of org.openhab.core.scriptengine.Script


  public static void handleScript(String[] args, Console console) {
    ScriptEngine scriptEngine = ConsoleActivator.scriptEngineTracker.getService();
    if(scriptEngine!=null) {
      String scriptString = Joiner.on(" ").join(args);
      Script script;
      try {
        script = scriptEngine.newScriptFromString(scriptString);
        Object result = script.execute();
       
        if(result!=null) {
          console.println(result.toString());
        } else {
          console.println("OK");
View Full Code Here


      }
      XExpression expr = (XExpression) repo.getModel(scriptNameWithExt);
      if(expr!=null) {
        ScriptEngine scriptEngine = ScriptActivator.scriptEngineTracker.getService();
        if(scriptEngine!=null) {
          Script script = scriptEngine.newScriptFromXExpression(expr);
          return script.execute();
        } else {
          throw new ScriptExecutionException("Script engine is not available.");
        }
      } else {
        throw new ScriptExecutionException("Script '" + scriptName + "' cannot be found.");
View Full Code Here

        Iterable<Rule> startupRules = triggerManager.getRules(STARTUP);
        List<Rule> executedRules = Lists.newArrayList();
       
        for(Rule rule : startupRules) {
          try {
            Script script = scriptEngine.newScriptFromXExpression(rule.getScript());           
            logger.debug("Executing startup rule '{}'", rule.getName());
            RuleEvaluationContext context = new RuleEvaluationContext();
            context.setGlobalContext(RuleContextHelper.getContext(rule));
            script.execute(context);
            executedRules.add(rule);
          } catch (ScriptExecutionException e) {
            if(e.getCause() instanceof ItemNotFoundException || e.getCause().getMessage().contains("cannot be resolved to an item or type")) {
              // we do not seem to have all required items in place yet
              // so we keep the rule in the list and try it again later
View Full Code Here

    protected synchronized void executeRule(Rule rule) {
      executeRule(rule, new RuleEvaluationContext());
    }
     
    protected synchronized void executeRule(Rule rule, RuleEvaluationContext context) {
      Script script = scriptEngine.newScriptFromXExpression(rule.getScript());
     
      logger.debug("Executing rule '{}'", rule.getName());
     
      context.setGlobalContext(RuleContextHelper.getContext(rule));
     
View Full Code Here

      EObject model = modelRepository.getModel(modelName);
      if (model instanceof RuleModel) {
        RuleModel ruleModel = (RuleModel) model;
        Rule rule = getRule(ruleModel, ruleName);
        if(rule!=null) {
          Script script = scriptEngine.newScriptFromXExpression(rule.getScript());
          logger.debug("Executing scheduled rule '{}'", rule.getName());
          try {
            script.execute(RuleContextHelper.getContext(rule));
          } catch (ScriptExecutionException e) {
            logger.error("Error during the execution of rule {}", rule.getName(), e.getCause());
          }
        } else {
          logger.debug("Scheduled rule '{}' does not exist", ruleName);
View Full Code Here

TOP

Related Classes of org.openhab.core.scriptengine.Script

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.