@SuppressWarnings("unchecked") public void run() throws JsonParseException, JsonMappingException, IOException { final File currentDir = new File("").getAbsoluteFile(); final ObjectMapper mapper = new ObjectMapper(); List<Map<String, ?>> configurationMap = new ArrayList<Map<String, ?>>(); File folder = new File(currentDir, "src/main/resources/"); File[] listOfFiles = folder.listFiles(); PrintStream out = null; PrintStream mainOut = new PrintStream(new File(currentDir, "docs/json-configs.md")); mainOut.println("# JSON configuration files"); mainOut.println(); mainOut.println("This is an automatic created list of all included configuration files."); mainOut.println(); EBusConfigurationProvider ebuscfg = new EBusConfigurationProvider(); for (File file : listOfFiles) { if (file.getName().endsWith("configuration.json")) { String string = StringUtils.substringBefore(file.getName(), "-configuration.json"); out = new PrintStream(new File(currentDir, "docs/json-files/" + string + ".md")); out.println("# JSON configuration for _" + string + "_"); out.println(); ebuscfg.loadConfigurationFile(file.toURI().toURL()); List<Map<String, ?>> readValue = mapper.readValue(file, List.class); writeMarkdownIdTable(readValue, out); out.println(); out.println("_bold part is the command-id part_"); out.println(); configurationMap.addAll(readValue); out.flush(); out.close(); mainOut.println("* [" + string + "](./json-files/" + string + ".md)"); } } mainOut.println(); mainOut.flush(); mainOut.close(); checkConfiguration(configurationMap); }
/* (non-Javadoc) * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ @Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { logger.info("Update eBus Binding configuration ..."); try { // stop last thread if active if (connector != null && connector.isAlive()) { connector.interrupt(); } // check to ensure that it is available checkConfigurationProvider(); // clear current configuration configurationProvider.clear(); // load parser from default url parser = new EBusTelegramParser(configurationProvider); URL configurationUrl = null; String parsers = (String) properties.get("parsers"); if (StringUtils.isEmpty(parsers)) { // set to current stable configurations as default parsers = "common,wolf"; } for (String elem : parsers.split(",")) { configurationUrl = null; // check for keyword custom to load custom configuration if (elem.trim().equals("custom")) { String parserUrl = (String) properties.get("parserUrl"); if (parserUrl != null) { logger.debug("Load custom eBus Parser with url {}", parserUrl); configurationUrl = new URL(parserUrl); } } else { logger.debug("Load eBus Parser Configuration \"{}\" ...", elem.trim()); configurationUrl = this.getClass().getResource("/" + elem.trim() + "-configuration.json"); } if (configurationUrl != null) { configurationProvider.loadConfigurationFile(configurationUrl); } } // check minimal config if (properties.get("serialPort") != null && properties.get("hostname") != null) { throw new ConfigurationException( "hostname", "Set property serialPort or hostname, not both!"); } if (StringUtils.isNotEmpty((String) properties.get("serialPort"))) { // use the serial connector connector = new EBusSerialConnector((String) properties.get("serialPort")); } else if (StringUtils.isNotEmpty((String) properties.get("hostname"))) { // use the tcp-ip connector connector = new EBusTCPConnector( (String) properties.get("hostname"), Integer.parseInt((String) properties.get("port"))); } // Set eBus sender id or default 0xFF if (StringUtils.isNotEmpty((String) properties.get("senderId"))) { connector.setSenderId(EBusUtils.toByte((String) properties.get("senderId"))); } // add event listener connector.addEBusEventListener(this); // start thread connector.start(); // set the new connector commandProcessor.setConnector(connector); commandProcessor.setConfigurationProvider(configurationProvider); } catch (MalformedURLException e) { logger.error(e.toString(), e); } catch (IOException e) { throw new ConfigurationException("general", e.toString(), e); } }