Package org.openhab.model.item.binding

Examples of org.openhab.model.item.binding.BindingConfigParseException


  /**
   * {@inheritDoc}
   */
  public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
    if (!(item instanceof SwitchItem || item instanceof StringItem)) {
      throw new BindingConfigParseException("item '" + item.getName()
          + "' is of type '" + item.getClass().getSimpleName()
          + "', only Switch- and StringItems are allowed - please check your *.items configuration");
    }
  }
View Full Code Here


      serialDevice = new SerialDevice(port);
      serialDevice.setEventPublisher(eventPublisher);
      try {
        serialDevice.initialize();
      } catch (InitializationException e) {
        throw new BindingConfigParseException(
            "Could not open serial port " + port + ": "
                + e.getMessage());
      } catch (Throwable e) {
        throw new BindingConfigParseException(
            "Could not open serial port " + port + ": "
                + e.getMessage());
      }
      itemMap.put(item.getName(), port);
      serialDevices.put(port, serialDevice);
    }
    if (item instanceof StringItem) {
      if (serialDevice.getStringItemName() == null) {
        serialDevice.setStringItemName(item.getName());
      } else {
        throw new BindingConfigParseException(
            "There is already another StringItem assigned to serial port "
                + port);
      }
    } else { // it is a SwitchItem
      if (serialDevice.getSwitchItemName() == null) {
        serialDevice.setSwitchItemName(item.getName());
      } else {
        throw new BindingConfigParseException(
            "There is already another SwitchItem assigned to serial port "
                + port);
      }
    }
    Set<String> itemNames = contextMap.get(context);
View Full Code Here

  @Override
  public void validateItemType(Item item, String bindingConfig)
      throws BindingConfigParseException {
    if (!(item instanceof SwitchItem) && !(item instanceof NumberItem)
        && !(item instanceof StringItem)) {
      throw new BindingConfigParseException(
          "item '"
              + item.getName()
              + "' is of type '"
              + item.getClass().getSimpleName()
              + "', only Switch or Number Items are allowed - please check your *.items configuration");
View Full Code Here

    } else if (bindingConfig.equalsIgnoreCase("source_number")) {
      config.mode = BenqProjectorItemMode.SOURCE_NUMBER;
    } else if (bindingConfig.equalsIgnoreCase("source_string")) {
      config.mode = BenqProjectorItemMode.SOURCE_STRING;
    } else {
      throw new BindingConfigParseException("Unable to parse '"
          + bindingConfig + "' to create a valid item binding.");
    }
    logger.debug("Adding " + item.getName() + " as " + config.mode);
    addBindingConfig(item, config);
  }
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
    if (!(item instanceof NumberItem)) {
      throw new BindingConfigParseException("item '" + item.getName()
          + "' is of type '" + item.getClass().getSimpleName()
          + "', only NumberItems are allowed - please check your *.items configuration");
    }
  }
View Full Code Here

    config.printerName = parts[0];
    if (parts.length==2) {
      try {
        config.whichJobs = WhichJobsEnum.valueOf(WhichJobsEnum.class, parts[1].toUpperCase());
      } catch (IllegalArgumentException e) {
        throw new BindingConfigParseException("WhichJobs-Part "+parts[1]+" is unknown (use one of "+StringUtils.join(WhichJobsEnum.values(),", ")+")");
      } catch (NullPointerException e) {
        // empty WhichJobs-Part -> use default
        config.whichJobs = WhichJobsEnum.NOT_COMPLETED;
      }
    }
View Full Code Here

    AstroBindingConfigHelper helper = new AstroBindingConfigHelper();

    for (String entry : entries) {
      String[] entryParts = StringUtils.trimToEmpty(entry).split("[=]");
      if (entryParts.length != 2) {
        throw new BindingConfigParseException("A bindingConfig must have a key and a value");
      }
      String key = StringUtils.trim(entryParts[0]);

      String value = StringUtils.trim(entryParts[1]);
      value = StringUtils.removeStart(value, "\"");
      value = StringUtils.removeEnd(value, "\"");

      try {
        if ("offset".equalsIgnoreCase(key)) {
          helper.getClass().getDeclaredField(key).set(helper, Integer.valueOf(value.toString()));
        } else {
          helper.getClass().getDeclaredField(key).set(helper, value);
        }
      } catch (Exception e) {
        throw new BindingConfigParseException("Could not set value " + value + " for attribute " + key);
      }
    }

    if (helper.isOldStyle()) {
      logger.warn(
          "Old Astro binding style for item {}, please see Wiki page for new style: https://github.com/openhab/openhab/wiki/Astro-binding",
          item.getName());
      return getOldAstroBindingConfig(helper);
    }

    if (!helper.isValid()) {
      throw new BindingConfigParseException("Invalid binding: " + bindingConfig);
    }

    PlanetName planetName = getPlanetName(helper);
    if (planetName == null) {
      throw new BindingConfigParseException("Invalid binding, unknown planet: " + bindingConfig);
    }

    AstroBindingConfig astroConfig = new AstroBindingConfig(planetName, helper.type, helper.property, helper.offset);

    if (!PropertyUtils.hasProperty(context.getPlanet(astroConfig.getPlanetName()), astroConfig.getPlanetProperty())) {
      throw new BindingConfigParseException("Invalid binding, unknown type or property: " + bindingConfig);
    }
    return astroConfig;
  }
View Full Code Here

    if (item.getClass() == ContactItem.class)
      return;
    if (item.getClass() == NumberItem.class)
      return;

    throw new BindingConfigParseException("item '" + item.getName()
        + "' is of type '" + item.getClass().getSimpleName()
        + "', only Switch, Contact or Number are allowed - please check your *.items configuration");
  }
View Full Code Here

          writeRegister = Integer.valueOf(items[1]);
        } else if (items.length == 3) {
          assignRegisters(items[1]);
          assignRegisters(items[2]);
        } else {
          throw new BindingConfigParseException("Invalid number of registers in item configuration");
        }
      } catch (Exception e) {
        throw new BindingConfigParseException(e.getMessage());
      }
    }
View Full Code Here

      if (item.startsWith("<")) {
        readRegister = Integer.valueOf(item.substring(1, item.length()));
      } else if (item.startsWith(">")) {
        writeRegister = Integer.valueOf(item.substring(1, item.length()));
      } else {
        throw new BindingConfigParseException("Register references should be either :X or :<X:>Y");     
      }
    }
View Full Code Here

TOP

Related Classes of org.openhab.model.item.binding.BindingConfigParseException

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.