public ServiceRegistrationImpl(
      BundleImpl bundle,
      long serviceId,
      String[] classNames,
      Object service,
      Dictionary<String, ?> properties) {
    this.bundle = bundle;
    this.serviceId = serviceId;
    this.classNames = classNames;
    this.service = service;

    if ((properties == null) || properties.isEmpty()) this.properties = EMPTY_PROPERTIES;
    else {
      Enumeration<String> keys = properties.keys();
      Map<String, Object> thisProperties = newCaseInsensitiveMapInstance();

      while (keys.hasMoreElements()) {
        String key = keys.nextElement();

        if (Constants.OBJECTCLASS.equalsIgnoreCase(key)
            || Constants.SERVICE_ID.equalsIgnoreCase(key)) continue;
        else if (thisProperties.containsKey(key)) throw new IllegalArgumentException(key);
        else thisProperties.put(key, properties.get(key));
      }

      this.properties = thisProperties.isEmpty() ? EMPTY_PROPERTIES : thisProperties;
    }
  }
示例#2
0
    /** @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary) */
    @Override
    public Dictionary invoke(Dictionary _args) throws Exception {

      FloatHolder currentValue = new FloatHolder();
      FloatHolder currentError = new FloatHolder();
      StringHolder unit = new StringHolder();
      DateHolder timestamp = new DateHolder();

      // invoke model

      model.getCurrentValue(currentValue, currentError, unit, timestamp);

      // build returned Dictionary
      Dictionary _result = new Hashtable();

      _result.put("CurrentValue", currentValue.getObject());
      // java.lang.Float
      _result.put("CurrentError", currentError.getObject());
      // java.lang.Float
      _result.put("Unit", unit.getObject());
      // java.lang.String
      _result.put("Timestamp", timestamp.getObject());
      // java.util.Date
      return _result.isEmpty() ? null : _result;
    }
 public boolean isEmpty() {
   java.util.Dictionary dict = getDictionaryValue();
   if (dict != null) {
     return dict.isEmpty();
   } else {
     return true;
   }
 }
示例#4
0
    /** @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary) */
    @Override
    public Dictionary invoke(Dictionary _args) throws Exception {

      java.lang.Float newHighValueThreshold = (java.lang.Float) _args.get("NewHighValueThreshold");

      // invoke model

      model.setLowValueThreshold(FloatHolder.toValue(newHighValueThreshold));

      // build returned Dictionary
      Dictionary _result = new Hashtable();

      return _result.isEmpty() ? null : _result;
    }
示例#5
0
  /**
   * Try ro load a config from properties, then parse into a array of configuration string
   *
   * @param props Configuration collection
   * @param key Configuration key
   * @return Configuration String
   */
  public static String loadConfiguration(Dictionary props, String key) {
    // This should be checked, before passed to this method
    if (props != null && !props.isEmpty()) {
      // Read config string from property
      Object config = props.get(key);
      // It config string is not null or empty
      if (config != null && StringUtils.isNotBlank(String.valueOf(config))) {
        return String.valueOf(config);
      }
    }

    // Return null when parse failed
    return null;
  }
示例#6
0
  /**
   * Try ro load a config from properties, then parse into a array of configuration string
   *
   * @param props Configuration collection
   * @param key Configuration key
   * @return Configuration Array
   */
  public static List<String> loadConfigurations(Dictionary props, String key) {
    // This should be checked, before passed to this method
    if (props != null && !props.isEmpty()) {
      // Read config string from property
      Object configs = props.get(key);
      // It config string is not null or empty
      if (configs != null && StringUtils.isNotBlank(String.valueOf(configs))) {
        // Split into several configurations
        return Arrays.asList(ConfigSplitPattern.split(StringUtils.trim(String.valueOf(configs))));
      }
    }

    // Return null when parse failed
    return null;
  }
示例#7
0
    /** @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary) */
    @Override
    public Dictionary invoke(Dictionary _args) throws Exception {

      FloatHolder currentLowValueThreshold = new FloatHolder();

      // invoke model

      model.getLowValueThreshold(currentLowValueThreshold);

      // build returned Dictionary
      Dictionary _result = new Hashtable();

      _result.put("CurrentLowValueThreshold", currentLowValueThreshold.getObject());
      // java.lang.Float
      return _result.isEmpty() ? null : _result;
    }
示例#8
0
    /** @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary) */
    @Override
    public Dictionary invoke(Dictionary _args) throws Exception {

      StringHolder currentApplication = new StringHolder();

      // invoke model

      model.getApplication(currentApplication);

      // build returned Dictionary
      Dictionary _result = new Hashtable();

      _result.put("CurrentApplication", currentApplication.getObject());
      // java.lang.String
      return _result.isEmpty() ? null : _result;
    }
  /** @{inheritDoc */
  @Override
  public void updated(Dictionary<String, ?> config) throws ConfigurationException {

    if (config == null || config.isEmpty()) {
      logger.warn("Empty or null configuration. Ignoring.");
      return;
    }

    Set<String> names = getNames(config);

    for (String name : names) {

      String value = (String) config.get(name + ".serialPort");
      String serialPort = value != null ? value : MeterConfig.DEFAULT_SERIAL_PORT;

      value = (String) config.get(name + ".baudRateChangeDelay");
      int baudRateChangeDelay =
          value != null ? Integer.valueOf(value) : MeterConfig.DEFAULT_BAUD_RATE_CHANGE_DELAY;

      value = (String) config.get(name + ".echoHandling");
      boolean echoHandling =
          value != null ? Boolean.valueOf(value) : MeterConfig.DEFAULT_ECHO_HANDLING;

      Meter meterConfig =
          createIec6205621MeterConfig(
              name, new MeterConfig(serialPort, baudRateChangeDelay, echoHandling));

      if (meterDeviceConfigurtions.put(meterConfig.getName(), meterConfig) != null) {
        logger.info(
            "Recreated reader {} with  {}!", meterConfig.getName(), meterConfig.getConfig());
      } else {
        logger.info("Created reader {} with  {}!", meterConfig.getName(), meterConfig.getConfig());
      }
    }

    if (config != null) {
      // to override the default refresh interval one has to add a
      // parameter to openhab.cfg like
      // <bindingName>:refresh=<intervalInMs>
      if (StringUtils.isNotBlank((String) config.get("refresh"))) {
        refreshInterval = Long.parseLong((String) config.get("refresh"));
      }
      setProperlyConfigured(true);
    }
  }
示例#10
0
 public void createOrUpdateDataStoreConfig(CreateEnsembleOptions options) throws IOException {
   Configuration config = configAdmin.get().getConfiguration(Constants.DATASTORE_PID, null);
   Dictionary<String, Object> properties = config.getProperties();
   if (properties == null || properties.isEmpty()) {
     boolean updateConfig = false;
     properties = new Hashtable<String, Object>();
     Map<String, String> dataStoreProperties = options.getDataStoreProperties();
     for (Map.Entry<String, String> entry : dataStoreProperties.entrySet()) {
       String key = entry.getKey();
       String value = entry.getValue();
       Object oldval = properties.put(key, value);
       updateConfig = updateConfig || !value.equals(oldval);
     }
     if (updateConfig) {
       config.update(properties);
     }
   }
 }
示例#11
0
  /**
   * Try ro load a config from properties, then compile into a regexp pattern
   *
   * @param props Configuration collection
   * @param key Configuration key
   * @return Regexp Pattern
   */
  public static Pattern loadPattern(Dictionary props, String key) {
    // This should be checked, before passed to this method
    if (props != null && !props.isEmpty()) {
      // Read config string from property
      Object config = props.get(key);
      // It config string is not null or empty
      if (config != null && StringUtils.isNotBlank(String.valueOf(config))) {
        try {
          return Pattern.compile(
              StringUtils.trim(String.valueOf(config)), Pattern.CASE_INSENSITIVE);
        } catch (PatternSyntaxException e) {
          return null;
        }
      }
    }

    // Return null when parse failed
    return null;
  }
  /**
   * Copies the properties from the <code>source</code> <code>Dictionary</code> into the <code>
   * target</code> <code>Dictionary</code> except for private properties (whose name has a leading
   * dot) which are only copied if the <code>allProps</code> parameter is <code>true</code>.
   *
   * @param target The <code>Dictionary</code> into which to copy the properties. If <code>null
   *     </code> a new <code>Hashtable</code> is created.
   * @param source The <code>Dictionary</code> providing the properties to copy. If <code>null
   *     </code> or empty, nothing is copied.
   * @param allProps Whether all properties (<code>true</code>) or only the public properties (
   *     <code>false</code>) are to be copied.
   * @return The <code>target</code> is returned, which may be empty if <code>source</code> is
   *     <code>null</code> or empty and <code>target</code> was <code>null</code> or all properties
   *     are private and had not to be copied
   */
  protected static Dictionary<String, Object> copyTo(
      Dictionary<String, Object> target,
      final Dictionary<String, Object> source,
      final boolean allProps) {
    if (target == null) {
      target = new Hashtable<String, Object>();
    }

    if (source != null && !source.isEmpty()) {
      for (Enumeration ce = source.keys(); ce.hasMoreElements(); ) {
        // cast is save, because key must be a string as per the spec
        String key = (String) ce.nextElement();
        if (allProps || key.charAt(0) != '.') {
          target.put(key, source.get(key));
        }
      }
    }

    return target;
  }
示例#13
0
  /**
   * Try ro load a config from properties, then compile into a list of regexp pattern
   *
   * @param props Configuration collection
   * @param key Configuration key
   * @return Regexp Pattern List
   */
  public static List<Pattern> loadPatterns(Dictionary props, String key) {
    // This should be checked, before passed to this method
    if (props != null && !props.isEmpty()) {
      // Read config string from property
      Object configs = props.get(key);
      // It config string is not null or empty
      if (configs != null && StringUtils.isNotBlank(String.valueOf(configs))) {
        List<Pattern> patterns = new ArrayList<Pattern>();
        for (String config : ConfigSplitPattern.split(StringUtils.trim(String.valueOf(configs)))) {
          if (StringUtils.isNotBlank(config)) {
            try {
              patterns.add(Pattern.compile(StringUtils.trim(config), Pattern.CASE_INSENSITIVE));
            } catch (PatternSyntaxException e) {
              // Skip Error Pattern
            }
          }
        }
        return patterns;
      }
    }

    // Return null when parse failed
    return null;
  }
 public boolean isEmpty() {
   return headers.isEmpty();
 }
示例#15
0
  @Override
  public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    // disconnect first in case the config has been changed for an existing instance
    disconnect();

    host = null;
    cliPort = DEFAULT_CLI_PORT;
    webPort = DEFAULT_WEB_PORT;

    playersById.clear();
    playersByMacAddress.clear();

    if (config == null || config.isEmpty()) {
      logger.warn("Empty or null configuration. Ignoring.");
      return;
    }

    Enumeration<String> keys = config.keys();
    while (keys.hasMoreElements()) {

      String key = (String) keys.nextElement();

      // the config-key enumeration contains additional keys that we
      // don't want to process here ...
      if ("service.pid".equals(key)) {
        continue;
      }

      Matcher serverMatcher = SERVER_CONFIG_PATTERN.matcher(key);
      Matcher playerMatcher = PLAYER_CONFIG_PATTERN.matcher(key);

      String value = (String) config.get(key);

      if (serverMatcher.matches()) {
        String serverConfig = serverMatcher.group(2);
        if (serverConfig.equals("host")) {
          host = value;
        } else if (serverConfig.equals("cliport")) {
          cliPort = Integer.valueOf(value);
        } else if (serverConfig.equals("webport")) {
          webPort = Integer.valueOf(value);
        }
      } else if (playerMatcher.matches()) {
        String playerId = playerMatcher.group(1);
        String macAddress = value;
        SqueezePlayer player = new SqueezePlayer(playerId, macAddress);

        playersById.put(playerId, player);
        playersByMacAddress.put(macAddress, player);
      } else {
        logger.warn("Unexpected or unsupported configuration: " + key + ". Ignoring.");
      }
    }

    if (StringUtils.isEmpty(host))
      throw new ConfigurationException(
          "host", "No Squeeze Server host specified - this property is mandatory");
    if (playersById.size() == 0)
      throw new ConfigurationException(
          "host", "No Squeezebox players specified - there must be at least one player");

    // attempt to connect using our new config
    connect();
  }