added location item support in config reader delegate

Signed-off-by: Kai Kreuzer <kai@openhab.org>
pull/18/head
Kai Kreuzer 2016-02-16 18:27:00 +01:00
parent c7c6e2965f
commit 6d04f2d042
1 changed files with 59 additions and 50 deletions

View File

@ -22,8 +22,7 @@ public class BindingConfigReaderDelegate implements BindingConfigReader {
private org.openhab.model.item.binding.BindingConfigReader reader; private org.openhab.model.item.binding.BindingConfigReader reader;
public BindingConfigReaderDelegate( public BindingConfigReaderDelegate(org.openhab.model.item.binding.BindingConfigReader reader) {
org.openhab.model.item.binding.BindingConfigReader reader) {
this.reader = reader; this.reader = reader;
} }
@ -33,8 +32,7 @@ public class BindingConfigReaderDelegate implements BindingConfigReader {
} }
@Override @Override
public void validateItemType(String itemType, String bindingConfig) public void validateItemType(String itemType, String bindingConfig) throws BindingConfigParseException {
throws BindingConfigParseException {
try { try {
reader.validateItemType(getOpenHABItem(itemType), bindingConfig); reader.validateItemType(getOpenHABItem(itemType), bindingConfig);
} catch (org.openhab.model.item.binding.BindingConfigParseException e) { } catch (org.openhab.model.item.binding.BindingConfigParseException e) {
@ -44,8 +42,8 @@ public class BindingConfigReaderDelegate implements BindingConfigReader {
} }
@Override @Override
public void processBindingConfiguration(String context, String itemType, String itemName, public void processBindingConfiguration(String context, String itemType, String itemName, String bindingConfig)
String bindingConfig) throws BindingConfigParseException { throws BindingConfigParseException {
try { try {
reader.processBindingConfiguration(context, getOpenHABItem(itemType, itemName), bindingConfig); reader.processBindingConfiguration(context, getOpenHABItem(itemType, itemName), bindingConfig);
} catch (org.openhab.model.item.binding.BindingConfigParseException e) { } catch (org.openhab.model.item.binding.BindingConfigParseException e) {
@ -58,19 +56,30 @@ public class BindingConfigReaderDelegate implements BindingConfigReader {
return getOpenHABItem(itemType, "itemName"); return getOpenHABItem(itemType, "itemName");
} }
private org.openhab.core.items.Item getOpenHABItem(String itemType, private org.openhab.core.items.Item getOpenHABItem(String itemType, String itemName)
String itemName) throws BindingConfigParseException { throws BindingConfigParseException {
switch (itemType) { switch (itemType) {
case "Switch" : return new org.openhab.core.library.items.SwitchItem(itemName); case "Switch":
case "Dimmer" : return new org.openhab.core.library.items.DimmerItem(itemName); return new org.openhab.core.library.items.SwitchItem(itemName);
case "Color" : return new org.openhab.core.library.items.ColorItem(itemName); case "Dimmer":
case "String" : return new org.openhab.core.library.items.StringItem(itemName); return new org.openhab.core.library.items.DimmerItem(itemName);
case "Number" : return new org.openhab.core.library.items.NumberItem(itemName); case "Color":
case "Contact" : return new org.openhab.core.library.items.ContactItem(itemName); return new org.openhab.core.library.items.ColorItem(itemName);
case "Rollershutter" : return new org.openhab.core.library.items.RollershutterItem(itemName); case "String":
case "DateTime" : return new org.openhab.core.library.items.DateTimeItem(itemName); return new org.openhab.core.library.items.StringItem(itemName);
case "Call" : return new org.openhab.library.tel.items.CallItem(itemName); case "Number":
return new org.openhab.core.library.items.NumberItem(itemName);
case "Contact":
return new org.openhab.core.library.items.ContactItem(itemName);
case "Rollershutter":
return new org.openhab.core.library.items.RollershutterItem(itemName);
case "DateTime":
return new org.openhab.core.library.items.DateTimeItem(itemName);
case "Location":
return new org.openhab.core.library.items.LocationItem(itemName);
case "Call":
return new org.openhab.library.tel.items.CallItem(itemName);
} }
throw new BindingConfigParseException("cannot process unknown item type " + itemType); throw new BindingConfigParseException("cannot process unknown item type " + itemType);
} }