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

@ -20,60 +20,69 @@ import org.eclipse.smarthome.model.item.BindingConfigReader;
*/ */
public class BindingConfigReaderDelegate implements BindingConfigReader { 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; }
}
@Override @Override
public String getBindingType() { public String getBindingType() {
return reader.getBindingType(); return reader.getBindingType();
} }
@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) { throw new BindingConfigParseException(e.getMessage());
throw new BindingConfigParseException(e.getMessage()); }
}
} }
@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) {
throw new BindingConfigParseException(e.getMessage()); throw new BindingConfigParseException(e.getMessage());
} }
} }
private org.openhab.core.items.Item getOpenHABItem(String itemType) throws BindingConfigParseException { private org.openhab.core.items.Item getOpenHABItem(String itemType) throws BindingConfigParseException {
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);
throw new BindingConfigParseException("cannot process unknown item type " + itemType); 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);
}
@Override @Override
public void startConfigurationUpdate(String context) { public void startConfigurationUpdate(String context) {