Merge pull request #18 from kaikreuzer/loc

added location item support in config reader delegate
This commit is contained in:
Kai Kreuzer 2016-02-16 18:27:55 +01:00
commit ab2eebdbd7

View File

@ -14,70 +14,79 @@ import org.eclipse.smarthome.model.item.BindingConfigReader;
/** /**
* This class serves as a mapping from the "old" org.openhab namespace to the new org.eclipse.smarthome * This class serves as a mapping from the "old" org.openhab namespace to the new org.eclipse.smarthome
* namespace for the binding config readers. It wraps an instance with the old interface * namespace for the binding config readers. It wraps an instance with the old interface
* into a class with the new interface. * into a class with the new interface.
* *
* @author Kai Kreuzer - Initial contribution and API * @author Kai Kreuzer - Initial contribution and API
*/ */
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 }
public void processBindingConfiguration(String context, String itemType, String itemName,
String bindingConfig) throws BindingConfigParseException {
try {
reader.processBindingConfiguration(context, getOpenHABItem(itemType, itemName), bindingConfig);
} catch (org.openhab.model.item.binding.BindingConfigParseException e) {
throw new BindingConfigParseException(e.getMessage());
}
}
private org.openhab.core.items.Item getOpenHABItem(String itemType) throws BindingConfigParseException { @Override
return getOpenHABItem(itemType, "itemName"); public void processBindingConfiguration(String context, String itemType, String itemName, String bindingConfig)
} throws BindingConfigParseException {
try {
reader.processBindingConfiguration(context, getOpenHABItem(itemType, itemName), bindingConfig);
} catch (org.openhab.model.item.binding.BindingConfigParseException e) {
throw new BindingConfigParseException(e.getMessage());
}
private org.openhab.core.items.Item getOpenHABItem(String itemType, }
String itemName) throws BindingConfigParseException {
switch(itemType) { private org.openhab.core.items.Item getOpenHABItem(String itemType) throws BindingConfigParseException {
case "Switch" : return new org.openhab.core.library.items.SwitchItem(itemName); return getOpenHABItem(itemType, "itemName");
case "Dimmer" : return new org.openhab.core.library.items.DimmerItem(itemName); }
case "Color" : return new org.openhab.core.library.items.ColorItem(itemName);
case "String" : return new org.openhab.core.library.items.StringItem(itemName); private org.openhab.core.items.Item getOpenHABItem(String itemType, String itemName)
case "Number" : return new org.openhab.core.library.items.NumberItem(itemName); throws BindingConfigParseException {
case "Contact" : return new org.openhab.core.library.items.ContactItem(itemName);
case "Rollershutter" : return new org.openhab.core.library.items.RollershutterItem(itemName); switch (itemType) {
case "DateTime" : return new org.openhab.core.library.items.DateTimeItem(itemName); case "Switch":
case "Call" : return new org.openhab.library.tel.items.CallItem(itemName); return new org.openhab.core.library.items.SwitchItem(itemName);
} case "Dimmer":
throw new BindingConfigParseException("cannot process unknown item type " + itemType); return new org.openhab.core.library.items.DimmerItem(itemName);
} case "Color":
return new org.openhab.core.library.items.ColorItem(itemName);
case "String":
return new org.openhab.core.library.items.StringItem(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);
}
@Override @Override
public void startConfigurationUpdate(String context) { public void startConfigurationUpdate(String context) {
reader.removeConfigurations(context); reader.removeConfigurations(context);
} }
@Override @Override