private void dispatchBindingsPerType(BindingConfigReader reader, String[] bindingTypes) { if (modelRepository != null) { for (String modelName : modelRepository.getAllModelNamesOfType("items")) { ItemModel model = (ItemModel) modelRepository.getModel(modelName); if (model != null) { for (ModelItem modelItem : model.getItems()) { for (ModelBinding modelBinding : modelItem.getBindings()) { for (String bindingType : bindingTypes) { if (bindingType.equals(modelBinding.getType())) { Item item = createItemFromModelItem(modelItem); if (item != null) { internalDispatchBindings(reader, modelName, item, modelItem.getBindings()); } } } } } } else { logger.debug("Model repository returned NULL for model named '{}'", modelName); } } } else { logger.warn("ModelRepository is NULL > dispatch bindings aborted!"); } }
private void processBindingConfigsFromModel(String modelName) { logger.debug("Processing binding configs for items from model '{}'", modelName); if (modelRepository != null) { ItemModel model = (ItemModel) modelRepository.getModel(modelName); if (model == null) { return; } // start binding configuration processing for (BindingConfigReader reader : bindingConfigReaders.values()) { reader.startConfigurationUpdate(modelName); } // create items and read new binding configuration for (ModelItem modelItem : model.getItems()) { Item item = createItemFromModelItem(modelItem); if (item != null) { internalDispatchBindings(modelName, item, modelItem.getBindings()); } } // end binding configuration processing for (BindingConfigReader reader : bindingConfigReaders.values()) { reader.stopConfigurationUpdate(modelName); } } }
private Collection<Item> getItemsFromModel(String modelName) { logger.debug("Read items from model '{}'", modelName); List<Item> items = new ArrayList<Item>(); if (modelRepository != null) { ItemModel model = (ItemModel) modelRepository.getModel(modelName); if (model != null) { for (ModelItem modelItem : model.getItems()) { Item item = createItemFromModelItem(modelItem); if (item != null) { for (String groupName : modelItem.getGroups()) { ((GenericItem) item).addGroupName(groupName); } items.add(item); } } } } return items; }
private Item createItemFromModelItem(ModelItem modelItem) { GenericItem item = null; if (modelItem instanceof ModelGroupItem) { ModelGroupItem modelGroupItem = (ModelGroupItem) modelItem; String baseItemType = modelGroupItem.getType(); GenericItem baseItem = createItemOfType(baseItemType, modelGroupItem.getName()); if (baseItem != null) { ModelGroupFunction function = modelGroupItem.getFunction(); if (function == null) { item = new GroupItem(modelGroupItem.getName(), baseItem); } else { item = applyGroupFunction(baseItem, modelGroupItem, function); } } else { item = new GroupItem(modelGroupItem.getName()); } } else { ModelNormalItem normalItem = (ModelNormalItem) modelItem; String itemName = normalItem.getName(); item = createItemOfType(normalItem.getType(), itemName); } if (item != null) { String label = modelItem.getLabel(); String format = StringUtils.substringBetween(label, "[", "]"); if (format != null) { label = StringUtils.substringBefore(label, "[").trim(); stateDescriptions.put( modelItem.getName(), new StateDescription(null, null, null, format, false, null)); } item.setLabel(label); item.setCategory(modelItem.getIcon()); assignTags(modelItem, item); return item; } else { return null; } }
private void assignTags(ModelItem modelItem, GenericItem item) { List<String> tags = modelItem.getTags(); for (String tag : tags) { item.addTag(tag); } }