diff --git a/CHANGELOG.md b/CHANGELOG.md
index 455248b..8b15478 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
## Unreleased
+## [1.1.5] - 2021-01-31
+### Changed
+- Removed clone() from DataType objects
+- Simplified EbusConfigurationReader methods
+### Fixed
+- Fix NPE for NestedValues
+
## [1.1.4] - 2020-12-27
### Changed
- Enhanced the internal ThreadPool from 30 to 60 to prevent issues on startup
diff --git a/pom.xml b/pom.xml
index 54369ef..ff8a96b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
eBUS core library - This library handles the communication with heating engineering via the BUS specification. This protocol is used by many heating manufacturers in Europe.
de.cs-dev.ebus
ebus-core
- 1.1.4
+ 1.1.5
https://github.com/csowada/ebus
bundle
diff --git a/src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java b/src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java
index 244b981..18bb83c 100644
--- a/src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java
+++ b/src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java
@@ -164,8 +164,8 @@ public EBusConfigurationReader() {
// add md5 hash
commandCollection.setIdentification(collection.getIdentification());
- // parse the template block
- parseTemplateConfiguration(collection);
+ // parse the template list block
+ parseTemplateListConfiguration(collection);
List commands = collection.getCommands();
if (commands != null) {
@@ -179,7 +179,7 @@ public EBusConfigurationReader() {
return commandCollection;
}
- protected void parseTemplateConfiguration(@NonNull EBusCollectionDTO collection)
+ protected void parseTemplateListConfiguration(@NonNull EBusCollectionDTO collection)
throws EBusConfigurationReaderException {
Objects.requireNonNull(collection, "collection");
@@ -188,36 +188,42 @@ protected void parseTemplateConfiguration(@NonNull EBusCollectionDTO collection)
List templateSection = collection.getTemplates();
if (templateSection != null) {
for (EBusCommandTemplatesDTO templates : templateSection) {
- List templateValues = templates.getTemplate();
- if (templateValues != null) {
+ parseTemplateBlockConfiguration(templates.getTemplate(), collection, templates);
+ }
+ }
+ }
- Collection blockList = new ArrayList<>();
+ protected void parseTemplateBlockConfiguration(@Nullable List templateValues, @NonNull EBusCollectionDTO collection, @NonNull EBusCommandTemplatesDTO templates)
+ throws EBusConfigurationReaderException {
- for (EBusValueDTO value : templateValues) {
- if (value != null) {
- Collection<@NonNull EBusCommandValue> pv = parseValueConfiguration(value, null, null, null);
+ if (templateValues == null) {
+ return;
+ }
- if (pv != null && !pv.isEmpty()) {
- blockList.addAll(pv);
+ Collection blockList = new ArrayList<>();
- // global id
- String id = collection.getId() + "." + templates.getName() + "." + value.getName();
- logger.trace("Add template with global id {} to registry ...", id);
- templateValueRegistry.put(id, pv);
- }
- }
- }
+ for (EBusValueDTO value : templateValues) {
+ if (value != null) {
+ Collection<@NonNull EBusCommandValue> pv = parseValueConfiguration(value, null, null, null);
- if (!blockList.isEmpty()) {
- String id = collection.getId() + "." + templates.getName();
+ if (!pv.isEmpty()) {
+ blockList.addAll(pv);
- // global id
- logger.trace("Add template block with global id {} to registry ...", id);
- templateBlockRegistry.put(id, blockList);
- }
+ // global id
+ String id = collection.getId() + "." + templates.getName() + "." + value.getName();
+ logger.trace("Add template with global id {} to registry ...", id);
+ templateValueRegistry.put(id, pv);
}
}
}
+
+ if (!blockList.isEmpty()) {
+ String id = collection.getId() + "." + templates.getName();
+
+ // global id
+ logger.trace("Add template block with global id {} to registry ...", id);
+ templateBlockRegistry.put(id, blockList);
+ }
}
/**
@@ -255,18 +261,13 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
Byte source = EBusUtils.toByte(commandElement.getSrc());
// read in template block
- List templates = commandElement.getTemplate();
- if (templates != null) {
- for (EBusValueDTO template : templates) {
- if (template != null) {
- for (EBusCommandValue templateCfg : parseValueConfiguration(template, null, null, null)) {
- if (StringUtils.isEmpty(templateCfg.getName())) {
- templateMap.put(templateCfg.getName(), templateCfg);
- }
-
- templateList.add(templateCfg);
- }
+ for (EBusValueDTO template : checkedList(commandElement.getTemplate())) {
+ for (EBusCommandValue templateCfg : parseValueConfiguration(template, null, null, null)) {
+ if (StringUtils.isEmpty(templateCfg.getName())) {
+ templateMap.put(templateCfg.getName(), templateCfg);
}
+
+ templateList.add(templateCfg);
}
}
@@ -315,28 +316,16 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
commandMethod.setDestinationAddress(destination);
commandMethod.setSourceAddress(source);
- List master = commandMethodElement.getMaster();
- if (master != null) {
- for (EBusValueDTO template : master) {
- if (template != null) {
- for (EBusCommandValue ev : parseValueConfiguration(template, templateMap, templateList,
- commandMethod)) {
- commandMethod.addMasterValue(ev);
- }
+ for (EBusValueDTO template : checkedList(commandMethodElement.getMaster())) {
+ for (EBusCommandValue ev : parseValueConfiguration(template, templateMap, templateList, commandMethod)) {
+ commandMethod.addMasterValue(ev);
}
- }
}
- List slave = commandMethodElement.getSlave();
- if (slave != null) {
- for (EBusValueDTO template : slave) {
- if (template != null) {
- for (EBusCommandValue ev : parseValueConfiguration(template, templateMap, templateList,
- commandMethod)) {
- commandMethod.addSlaveValue(ev);
- }
+ for (EBusValueDTO template : checkedList(commandMethodElement.getSlave())) {
+ for (EBusCommandValue ev : parseValueConfiguration(template, templateMap, templateList, commandMethod)) {
+ commandMethod.addSlaveValue(ev);
}
- }
}
// default type is always master-slave if not explicit set or a broadcast
@@ -363,6 +352,23 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
return cfg;
}
+ /**
+ * Helper function to work with a secure non null list
+ * @param master
+ * @return
+ */
+ protected @NonNull List<@NonNull EBusValueDTO> checkedList(List master) {
+ List templates = new ArrayList<>();
+ if (master != null) {
+ for (EBusValueDTO template : master) {
+ if (template != null) {
+ templates.add(template);
+ }
+ }
+ }
+ return templates;
+ }
+
/**
* @param valueDto
* @param templateMap
@@ -447,7 +453,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
} else if (typeStr != null && typeStr.equals("template")) {
String id = (String) valueDto.getProperty("id");
- String globalId = collectionId + "." + id;
+ String globalId = collectionId != null ? collectionId + "." + id : null;
Collection<@NonNull EBusCommandValue> templateCollection = null;
if (StringUtils.isEmpty(id)) {
@@ -457,7 +463,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
if (templateValueRegistry.containsKey(id)) {
templateCollection = templateValueRegistry.get(id);
- } else if (templateValueRegistry.containsKey(globalId)) {
+ } else if (globalId != null && templateValueRegistry.containsKey(globalId)) {
templateCollection = templateValueRegistry.get(globalId);
} else if (templateMap != null && templateMap.containsKey(id)) {
diff --git a/src/main/java/de/csdev/ebus/command/EBusCommandNestedValue.java b/src/main/java/de/csdev/ebus/command/EBusCommandNestedValue.java
index db4dab2..16002ef 100644
--- a/src/main/java/de/csdev/ebus/command/EBusCommandNestedValue.java
+++ b/src/main/java/de/csdev/ebus/command/EBusCommandNestedValue.java
@@ -25,13 +25,12 @@ public class EBusCommandNestedValue extends EBusCommandValue implements IEBusNes
@Override
public void setParent(@Nullable EBusCommandMethod parent) {
+ if (parent != null) {
+ super.setParent(parent);
- Objects.requireNonNull(parent, "parent");
-
- super.setParent(parent);
-
- for (IEBusValue value : list) {
- ((EBusCommandValue) value).setParent(parent);
+ for (IEBusValue value : list) {
+ ((EBusCommandValue) value).setParent(parent);
+ }
}
}