Search in sources :

Example 1 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.

the class OWServerBinding method updated.

/**
     * {@inheritDoc}
     */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        Enumeration<String> keys = config.keys();
        if (serverList == null) {
            serverList = new HashMap<String, OWServerConfig>();
        }
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }
            Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
            if (!matcher.matches()) {
                continue;
            }
            matcher.reset();
            matcher.find();
            String serverId = matcher.group(1);
            OWServerConfig deviceConfig = serverList.get(serverId);
            if (deviceConfig == null) {
                deviceConfig = new OWServerConfig();
                serverList.put(serverId, deviceConfig);
            }
            String configKey = matcher.group(2);
            String value = (String) config.get(key);
            if ("host".equals(configKey)) {
                deviceConfig.host = value;
            } else if ("user".equals(configKey)) {
                deviceConfig.user = value;
            } else if ("password".equals(configKey)) {
                deviceConfig.password = value;
            } else {
                throw new ConfigurationException(configKey, "The given OWServer configKey '" + configKey + "' is unknown");
            }
        }
        String timeoutString = (String) config.get("timeout");
        if (StringUtils.isNotBlank(timeoutString)) {
            timeout = Integer.parseInt(timeoutString);
        }
        String granularityString = (String) config.get("granularity");
        if (StringUtils.isNotBlank(granularityString)) {
            granularity = Integer.parseInt(granularityString);
        }
        String cacheString = (String) config.get("cache");
        if (StringUtils.isNotBlank(cacheString)) {
            cacheDuration = Integer.parseInt(cacheString);
        }
        setProperlyConfigured(true);
    }
}
Also used : Matcher(java.util.regex.Matcher) ConfigurationException(org.osgi.service.cm.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.

the class PioneerAvrBinding method updated.

/**
     * @{inheritDoc
     */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("Configuration updated, config {}", config != null ? true : false);
    if (config != null) {
        Enumeration<String> keys = config.keys();
        if (deviceConfigCache == null) {
            deviceConfigCache = new HashMap<String, DeviceConfig>();
        }
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }
            Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
            if (!matcher.matches()) {
                logger.debug("given config key '" + key + "' does not follow the expected pattern '<id>.<host|port|checkconn>'");
                continue;
            }
            matcher.reset();
            matcher.find();
            String deviceId = matcher.group(1);
            DeviceConfig deviceConfig = deviceConfigCache.get(deviceId);
            if (deviceConfig == null) {
                deviceConfig = new DeviceConfig(deviceId);
                deviceConfigCache.put(deviceId, deviceConfig);
            }
            String configKey = matcher.group(2);
            String value = (String) config.get(key);
            if ("host".equals(configKey)) {
                deviceConfig.host = value;
            } else if ("port".equals(configKey)) {
                deviceConfig.port = Integer.valueOf(value);
            } else if ("checkconn".equals(configKey)) {
                if (value.equals("0")) {
                    deviceConfig.connectionCheckActive = false;
                } else {
                    deviceConfig.connectionCheckActive = true;
                }
            } else {
                throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
            }
        }
        // open connection to all receivers
        for (String device : deviceConfigCache.keySet()) {
            PioneerAvrConnection connection = deviceConfigCache.get(device).getConnection();
            if (connection != null) {
                connection.openConnection();
                connection.addEventListener(this);
            }
        }
        for (PioneerAvrBindingProvider provider : this.providers) {
            for (String itemName : provider.getItemNames()) {
                initializeItem(itemName);
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ConfigurationException(org.osgi.service.cm.ConfigurationException) PioneerAvrBindingProvider(org.openhab.binding.pioneeravr.PioneerAvrBindingProvider)

Example 3 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.

the class PLCLogoBinding method updated.

@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    Boolean configured = false;
    if (config != null) {
        String refreshIntervalString = Objects.toString(config.get("refresh"), null);
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }
        if (controllers == null) {
            controllers = new HashMap<String, PLCLogoConfig>();
        }
        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }
            Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
            if (!matcher.matches()) {
                continue;
            }
            matcher.reset();
            matcher.find();
            String controllerName = matcher.group(1);
            PLCLogoConfig deviceConfig = controllers.get(controllerName);
            if (deviceConfig == null) {
                deviceConfig = new PLCLogoConfig();
                controllers.put(controllerName, deviceConfig);
                logger.info("Create new config for {}", controllerName);
            }
            if (matcher.group(2).equals("host")) {
                String ip = config.get(key).toString();
                deviceConfig.setIP(ip);
                logger.info("Set host of {}: {}", controllerName, ip);
                configured = true;
            }
            if (matcher.group(2).equals("remoteTSAP")) {
                String tsap = config.get(key).toString();
                deviceConfig.setRemoteTSAP(Integer.decode(tsap));
                logger.info("Set remote TSAP for {}: {}", controllerName, tsap);
            }
            if (matcher.group(2).equals("localTSAP")) {
                String tsap = config.get(key).toString();
                deviceConfig.setLocalTSAP(Integer.decode(tsap));
                logger.info("Set local TSAP for {}: {}", controllerName, tsap);
            }
            if (matcher.group(2).equals("model")) {
                PLCLogoModel model = null;
                String modelName = config.get(key).toString();
                if (modelName.equalsIgnoreCase("0BA7")) {
                    model = PLCLogoModel.LOGO_MODEL_0BA7;
                } else if (modelName.equalsIgnoreCase("0BA8")) {
                    model = PLCLogoModel.LOGO_MODEL_0BA8;
                } else {
                    logger.info("Found unknown model for {}: {}", controllerName, modelName);
                }
                if (model != null) {
                    deviceConfig.setModel(model);
                    logger.info("Set model for {}: {}", controllerName, modelName);
                }
            }
        }
        // while
        Iterator<Entry<String, PLCLogoConfig>> entries = controllers.entrySet().iterator();
        while (entries.hasNext()) {
            Entry<String, PLCLogoConfig> thisEntry = entries.next();
            String controllerName = thisEntry.getKey();
            PLCLogoConfig deviceConfig = thisEntry.getValue();
            S7Client LogoS7Client = deviceConfig.getS7Client();
            if (LogoS7Client == null) {
                LogoS7Client = new Moka7.S7Client();
            } else {
                LogoS7Client.Disconnect();
            }
            LogoS7Client.SetConnectionParams(deviceConfig.getlogoIP(), deviceConfig.getlocalTSAP(), deviceConfig.getremoteTSAP());
            logger.info("About to connect to {}", controllerName);
            if ((LogoS7Client.Connect() == 0) && LogoS7Client.Connected) {
                logger.info("Connected to PLC LOGO! device {}", controllerName);
            } else {
                logger.error("Could not connect to PLC LOGO! device {} : {}", controllerName, S7Client.ErrorText(LogoS7Client.LastError));
                throw new ConfigurationException("Could not connect to PLC LOGO! device ", controllerName + " " + deviceConfig.getlogoIP());
            }
            deviceConfig.setS7Client(LogoS7Client);
        }
        setProperlyConfigured(configured);
    } else {
        logger.info("No configuration for PLCLogoBinding");
    }
}
Also used : Matcher(java.util.regex.Matcher) S7Client(Moka7.S7Client) Entry(java.util.Map.Entry) ConfigurationException(org.osgi.service.cm.ConfigurationException) S7Client(Moka7.S7Client)

Example 4 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.

the class ZWaveActiveBinding method initialise.

/**
     * Initialises the binding. This is called after the 'updated' method
     * has been called and all configuration has been passed.
     *
     * @throws ConfigurationException
     */
private void initialise() throws ConfigurationException {
    try {
        logger.debug("Initialising zwave binding");
        this.setProperlyConfigured(true);
        this.deactivate();
        this.zController = new ZWaveController(masterController, isSUC, port, timeout, softReset);
        this.converterHandler = new ZWaveConverterHandler(this.zController, this.eventPublisher);
        zController.addEventListener(this);
        // The network monitor service needs to know the controller...
        this.networkMonitor = new ZWaveNetworkMonitor(this.zController);
        if (healtime != null) {
            this.networkMonitor.setHealTime(healtime);
        }
        if (aliveCheckPeriod != null) {
            this.networkMonitor.setPollPeriod(aliveCheckPeriod);
        }
        if (softReset != false) {
            this.networkMonitor.resetOnError(softReset);
        }
        // The config service needs to know the controller and the network monitor...
        this.zConfigurationService = new ZWaveConfiguration(this.zController, this.networkMonitor);
        zController.addEventListener(this.zConfigurationService);
        return;
    } catch (SerialInterfaceException ex) {
        this.setProperlyConfigured(false);
        throw new ConfigurationException("port", ex.getLocalizedMessage(), ex);
    }
}
Also used : ZWaveConverterHandler(org.openhab.binding.zwave.internal.converter.ZWaveConverterHandler) ConfigurationException(org.osgi.service.cm.ConfigurationException) ZWaveController(org.openhab.binding.zwave.internal.protocol.ZWaveController) ZWaveConfiguration(org.openhab.binding.zwave.internal.config.ZWaveConfiguration) SerialInterfaceException(org.openhab.binding.zwave.internal.protocol.SerialInterfaceException)

Example 5 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.

the class MilightBinding method updated.

/**
     * @{inheritDoc}
     */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }
            Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
            if (!matcher.matches()) {
                logger.debug("given config key '" + key + "' does not follow the expected pattern '<id>.<host|port>'");
                continue;
            }
            matcher.reset();
            matcher.find();
            String deviceId = matcher.group(1);
            DeviceConfig deviceConfig = deviceConfigs.get(deviceId);
            if (deviceConfig == null) {
                deviceConfig = new DeviceConfig(deviceId);
                deviceConfigs.put(deviceId, deviceConfig);
            }
            String configKey = matcher.group(2);
            String value = (String) config.get(key);
            if ("host".equals(configKey)) {
                deviceConfig.host = value;
                bridgeIpConfig.put(deviceId, value);
            } else if ("port".equals(configKey)) {
                deviceConfig.port = Integer.valueOf(value);
                bridgePortConfig.put(deviceId, Integer.valueOf(value));
            } else {
                throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Aggregations

ConfigurationException (org.osgi.service.cm.ConfigurationException)190 Activate (org.apache.felix.scr.annotations.Activate)31 ServiceReference (org.osgi.framework.ServiceReference)30 Matcher (java.util.regex.Matcher)28 Hashtable (java.util.Hashtable)26 Properties (java.util.Properties)22 IOException (java.io.IOException)21 Test (org.junit.Test)21 ManagedService (org.osgi.service.cm.ManagedService)20 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)19 HashMap (java.util.HashMap)17 File (java.io.File)11 URISyntaxException (java.net.URISyntaxException)11 Collection (java.util.Collection)11 HashSet (java.util.HashSet)11 ServiceTracker (org.osgi.util.tracker.ServiceTracker)10 URI (java.net.URI)9 Dictionary (java.util.Dictionary)9 Map (java.util.Map)9 NotFoundException (org.opencastproject.util.NotFoundException)9