2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.hueemulation.internal.automation;
15 import java.util.Arrays;
16 import java.util.Collection;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.core.automation.Action;
21 import org.openhab.core.automation.Module;
22 import org.openhab.core.automation.RuleRegistry;
23 import org.openhab.core.automation.handler.BaseModuleHandlerFactory;
24 import org.openhab.core.automation.handler.ModuleHandler;
25 import org.openhab.core.automation.handler.ModuleHandlerFactory;
26 import org.openhab.core.io.net.http.HttpClientFactory;
27 import org.osgi.service.component.annotations.Component;
28 import org.osgi.service.component.annotations.Deactivate;
29 import org.osgi.service.component.annotations.Reference;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * This factory is responsible for rule and http related module types.
36 * @author David Graeff - Initial contribution
39 @Component(service = ModuleHandlerFactory.class)
40 public class RulesHandlerFactory extends BaseModuleHandlerFactory {
42 private final Logger logger = LoggerFactory.getLogger(RulesHandlerFactory.class);
44 private static final Collection<String> TYPES = Arrays
45 .asList(new String[] { RemoveRuleActionHandler.MODULE_TYPE_ID, HttpActionHandler.MODULE_TYPE_ID });
48 protected @NonNullByDefault({}) RuleRegistry ruleRegistry;
51 protected @NonNullByDefault({}) HttpClientFactory httpFactory;
55 public void deactivate() {
60 public Collection<String> getTypes() {
65 protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
66 logger.trace("create {} -> {}", module.getId(), module.getTypeUID());
67 String moduleTypeUID = module.getTypeUID();
68 if (RemoveRuleActionHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Action) {
69 return new RemoveRuleActionHandler((Action) module, ruleRegistry);
70 } else if (HttpActionHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Action) {
71 return new HttpActionHandler((Action) module, httpFactory);
73 logger.error("The module handler type '{}' is not supported.", moduleTypeUID);