use of org.openhab.core.automation.type.ModuleType in project openhab-core by openhab.
the class CommandlineModuleTypeProvider method importModuleTypes.
/**
* This method is responsible for importing a set of ModuleTypes from a specified file or URL resource.
*
* @param parserType is relevant to the format that you need for conversion of the ModuleTypes in text.
* @param url a specified URL for import.
* @throws IOException when I/O operation has failed or has been interrupted.
* @throws ParsingException when parsing of the text fails for some reasons.
* @see AutomationCommandsPluggable#importModuleTypes(String, URL)
*/
public Set<ModuleType> importModuleTypes(String parserType, URL url) throws IOException, ParsingException {
Parser<ModuleType> parser = parsers.get(parserType);
if (parser != null) {
InputStream is = url.openStream();
BufferedInputStream bis = new BufferedInputStream(is);
InputStreamReader inputStreamReader = new InputStreamReader(bis);
try {
return importData(url, parser, inputStreamReader);
} finally {
inputStreamReader.close();
}
} else {
throw new ParsingException(new ParsingNestedException(ParsingNestedException.MODULE_TYPE, null, new IllegalArgumentException("Parser " + parserType + " not available")));
}
}
use of org.openhab.core.automation.type.ModuleType in project openhab-core by openhab.
the class CommandlineModuleTypeProvider method importData.
@Override
protected Set<ModuleType> importData(URL url, Parser<ModuleType> parser, InputStreamReader inputStreamReader) throws ParsingException {
Set<ModuleType> providedObjects = parser.parse(inputStreamReader);
if (providedObjects != null && !providedObjects.isEmpty()) {
String uid = null;
List<String> portfolio = new ArrayList<>();
synchronized (providerPortfolio) {
providerPortfolio.put(url, portfolio);
}
List<ParsingNestedException> importDataExceptions = new ArrayList<>();
for (ModuleType providedObject : providedObjects) {
List<ParsingNestedException> exceptions = new ArrayList<>();
uid = providedObject.getUID();
checkExistence(uid, exceptions);
if (exceptions.isEmpty()) {
portfolio.add(uid);
synchronized (providedObjectsHolder) {
notifyListeners(providedObjectsHolder.put(uid, providedObject), providedObject);
}
} else {
importDataExceptions.addAll(exceptions);
}
}
if (!importDataExceptions.isEmpty()) {
throw new ParsingException(importDataExceptions);
}
}
return providedObjects;
}
use of org.openhab.core.automation.type.ModuleType in project openhab-core by openhab.
the class CompositeModuleHandlerFactory method internalCreate.
@Override
@Nullable
public ModuleHandler internalCreate(Module module, String ruleUID) {
ModuleHandler handler = null;
String moduleType = module.getTypeUID();
ModuleType mt = mtRegistry.get(moduleType);
if (mt instanceof CompositeTriggerType) {
List<Trigger> childModules = ((CompositeTriggerType) mt).getChildren();
LinkedHashMap<Trigger, @Nullable TriggerHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeTriggerHandler((Trigger) module, (CompositeTriggerType) mt, mapModuleToHandler, ruleUID);
}
} else if (mt instanceof CompositeConditionType) {
List<Condition> childModules = ((CompositeConditionType) mt).getChildren();
LinkedHashMap<Condition, @Nullable ConditionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeConditionHandler((Condition) module, (CompositeConditionType) mt, mapModuleToHandler, ruleUID);
}
} else if (mt instanceof CompositeActionType) {
List<Action> childModules = ((CompositeActionType) mt).getChildren();
LinkedHashMap<Action, @Nullable ActionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeActionHandler((Action) module, (CompositeActionType) mt, mapModuleToHandler, ruleUID);
}
}
if (handler != null) {
logger.debug("Set module handler: {} -> {} of rule {}.", module.getId(), handler.getClass().getSimpleName() + "(" + moduleType + ")", ruleUID);
} else {
logger.debug("Not found module handler {} for moduleType {} of rule {}.", module.getId(), moduleType, ruleUID);
}
return handler;
}
use of org.openhab.core.automation.type.ModuleType in project openhab-core by openhab.
the class AnnotatedActionModuleTypeProvider method removeActionProvider.
public void removeActionProvider(AnnotatedActions actionProvider, Map<String, Object> properties) {
Collection<ModuleInformation> moduleInformations = helper.parseAnnotations(actionProvider);
String configName = getConfigNameFromService(properties);
for (ModuleInformation mi : moduleInformations) {
mi.setConfigName(configName);
ModuleType oldType = null;
Set<ModuleInformation> availableModuleConfigs = moduleInformation.get(mi.getUID());
if (availableModuleConfigs != null) {
if (availableModuleConfigs.size() > 1) {
oldType = helper.buildModuleType(mi.getUID(), moduleInformation);
availableModuleConfigs.remove(mi);
} else {
moduleInformation.remove(mi.getUID());
}
ModuleType mt = helper.buildModuleType(mi.getUID(), moduleInformation);
// localize moduletype -> remove from map
if (mt != null) {
for (ProviderChangeListener<ModuleType> l : changeListeners) {
if (oldType != null) {
l.updated(this, oldType, mt);
} else {
l.removed(this, mt);
}
}
}
}
}
}
use of org.openhab.core.automation.type.ModuleType in project openhab-core by openhab.
the class AnnotatedActionModuleTypeProvider method localizeModuleType.
@Nullable
private ModuleType localizeModuleType(String uid, @Nullable Locale locale) {
Set<ModuleInformation> mis = moduleInformation.get(uid);
if (mis != null && !mis.isEmpty()) {
ModuleInformation mi = mis.iterator().next();
Bundle bundle = FrameworkUtil.getBundle(mi.getActionProvider().getClass());
ModuleType mt = helper.buildModuleType(uid, moduleInformation);
ModuleType localizedModuleType = moduleTypeI18nService.getModuleTypePerLocale(mt, locale, bundle);
return localizedModuleType;
}
return null;
}
Aggregations