use of org.eclipse.smarthome.core.persistence.config.SimpleAllConfig in project smarthome by eclipse.
the class PersistenceManagerImpl method appliesToItem.
/**
* Checks if a given persistence configuration entry is relevant for an item
*
* @param config the persistence configuration entry
* @param item to check if the configuration applies to
* @return true, if the configuration applies to the item
*/
private boolean appliesToItem(SimpleItemConfiguration config, Item item) {
for (SimpleConfig itemCfg : config.getItems()) {
if (itemCfg instanceof SimpleAllConfig) {
return true;
}
if (itemCfg instanceof SimpleItemConfig) {
SimpleItemConfig singleItemConfig = (SimpleItemConfig) itemCfg;
if (item.getName().equals(singleItemConfig.getItem())) {
return true;
}
}
if (itemCfg instanceof SimpleGroupConfig) {
SimpleGroupConfig groupItemCfg = (SimpleGroupConfig) itemCfg;
String groupName = groupItemCfg.getGroup();
try {
Item gItem = itemRegistry.getItem(groupName);
if (gItem instanceof GroupItem) {
GroupItem groupItem = (GroupItem) gItem;
if (groupItem.getAllMembers().contains(item)) {
return true;
}
}
} catch (Exception e) {
}
}
}
return false;
}
use of org.eclipse.smarthome.core.persistence.config.SimpleAllConfig in project smarthome by eclipse.
the class PersistenceManagerImpl method getAllItems.
/**
* Retrieves all items for which the persistence configuration applies to.
*
* @param config the persistence configuration entry
* @return all items that this configuration applies to
*/
Iterable<Item> getAllItems(SimpleItemConfiguration config) {
// first check, if we should return them all
for (Object itemCfg : config.getItems()) {
if (itemCfg instanceof SimpleAllConfig) {
return itemRegistry.getItems();
}
}
// otherwise, go through the detailed definitions
Set<Item> items = new HashSet<Item>();
for (Object itemCfg : config.getItems()) {
if (itemCfg instanceof SimpleItemConfig) {
SimpleItemConfig singleItemConfig = (SimpleItemConfig) itemCfg;
try {
Item item = itemRegistry.getItem(singleItemConfig.getItem());
items.add(item);
} catch (ItemNotFoundException e) {
logger.debug("Item '{}' does not exist.", singleItemConfig.getItem());
}
}
if (itemCfg instanceof SimpleGroupConfig) {
SimpleGroupConfig groupItemCfg = (SimpleGroupConfig) itemCfg;
String groupName = groupItemCfg.getGroup();
try {
Item gItem = itemRegistry.getItem(groupName);
if (gItem instanceof GroupItem) {
GroupItem groupItem = (GroupItem) gItem;
items.addAll(groupItem.getAllMembers());
}
} catch (ItemNotFoundException e) {
logger.debug("Item group '{}' does not exist.", groupName);
}
}
}
return items;
}
Aggregations