public class DrlConfiguration {
	protected final InputStream drl;
	protected final String path;
	
	public DrlConfiguration(InputStream drl, String path) {
		this.drl = drl;
		this.path = path;
	}

	public InputStream getDrl() {
		return drl;
	}

	public String getPath() {
		return path;
	}
} public class DtableConfiguration {
	protected final InputStream dtable;
	protected final String path;

	public DtableConfiguration(InputStream dtable, String path) {
		this.dtable = dtable;
		this.path = path;
	}

	public InputStream getDtable() {
		return dtable;
	}

	public String getPath() {
		return path;
	}
} public interface IEventPublisher {
    public void postCommand(String itemName, Command command);

    public void postCommand(Item item, Command command);

    public void startComplexCommand(IComplexCommand complexCommand);

    public void stopComplexCommand(String itemName);

    public void stopComplexCommand(Item item);
} public interface IEventSubscriber {
	public void stateUpdated(ItemStateEvent event);
	
    public void stateChanged(ItemStateChangedEvent event);
    
    public void groupStateChanged(GroupItemStateChangedEvent event);

    public void commandReceived(ItemCommandEvent event);

    public void initItems(Collection<Item> items);

    public void itemAdded(ItemAddedEvent event);

    public void itemRemoved(ItemRemovedEvent event);

    public void itemUpdated(ItemUpdatedEvent event);

    public String getSubscriberName();
} public interface IRuleLoader {
    public List<DrlConfiguration> getDrls();
    public List<DtableConfiguration> getDtables();
    public List<RuleTemplateConfiguration> getRuleTemplates();
} public class RuleTemplateConfiguration {
	// Table of data
	protected final InputStream templateData;
	protected final String path;
	protected final String worksheetName;

	//parameters where the data starts in the table
	protected final int startRow;
	protected final int startColumn;
	
	// The template data can be applied on many template rules
	protected final List<DrlConfiguration> templateRules;

	public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow,
			int startColumn, List<DrlConfiguration> templateRules) {
		this.templateData = templateData;
		this.path = path;
		this.worksheetName = worksheetName;
		this.startRow = startRow;
		this.startColumn = startColumn;
		this.templateRules = templateRules;
	}

	public InputStream getTemplateData() {
		return templateData;
	}

	public String getPath() {
		return path;
	}
	
	public String getWorksheetName() {
		return worksheetName;
	}

	public int getStartRow() {
		return startRow;
	}

	public int getStartColumn() {
		return startColumn;
	}

	public List<DrlConfiguration> getTemplateRules() {
		return templateRules;
	}
} public class GroupItemStateChangedEvent extends ItemStateChangedEvent {

	public GroupItemStateChangedEvent(Item item, State newState, State oldState) {
		super(item, newState, oldState);
	}
	
    @Override
    public String toString() {
        return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState);
    }
} public class ItemAddedEvent implements ItemEvent {
    protected final Item item;

	public ItemAddedEvent(Item item) {
		super();
		this.item = item;
	}

	public Item getItem() {
		return item;
	}
	
	public String getName() {
		return item.getName();
	}
	
    @Override
    public String toString() {
        return "Item '" + item.getName() + "' has been added.";
    }
} public class ItemCommandEvent extends ItemCommandBase implements ItemEvent {

	public ItemCommandEvent(Item item, Command command) {
		super(item, command);
	}
} public class ItemCommandHistory extends ItemCommandBase implements ItemEventHistory {

    public ItemCommandHistory(Item item, Command command) {
        super(item, command);
    }

    public ItemCommandHistory(ItemCommandEvent event) {
        super(event.getItem(), event.getCommand());
    }
} public class ItemRemovedEvent implements ItemEvent {
    protected final String itemName;

	public ItemRemovedEvent(String itemName) {
		super();
		this.itemName = itemName;
	}
	
	public String getName() {
		return itemName;
	}
	
    @Override
    public String toString() {
        return "Item '" + itemName + "' has been removed.";
    }
} public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent {

    public ItemStateChangedEvent(Item item, State newState, State oldState) {
        super(item, newState, oldState);
    }
} public class ItemStateChangedHistory extends ItemStateChangedBase implements ItemEventHistory {

    public ItemStateChangedHistory(Item item, State newState, State oldState) {
        super(item, newState, oldState);
    }

    public ItemStateChangedHistory(ItemStateChangedEvent event) {
        super(event.getItem(), event.getNewState(), event.getOldState());
    }
} public class ItemStateEvent implements ItemEvent {
    protected final Item item;
    protected final State itemState;

	public ItemStateEvent(Item item, State itemState) {
		super();
		this.item = item;
		this.itemState = itemState;
	}

	public Item getItem() {
		return item;
	}
	
    public String getName() {
        return this.item.getName();
    }

	public State getItemState() {
		return itemState;
	}
	
    @Override
    public String toString() {
        return String.format("%s updated to %s", item.getName(), itemState);
    }
} public class ItemUpdatedEvent {
    protected final Item newItem;
    protected final String oldItemName;
	
	public ItemUpdatedEvent(Item newItem, String oldItemName) {
		super();
		this.newItem = newItem;
		this.oldItemName = oldItemName;
	}

	public Item getNewItem() {
		return newItem;
	}

	public String getOldItemName() {
		return oldItemName;
	}
	
    @Override
    public String toString() {
        return "Item '" + oldItemName + "' has been updated.";
    }
}
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.smarthome.core.items.Item;
import org.eclipse.smarthome.core.library.types.IncreaseDecreaseType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
import org.kie.internal.builder.DecisionTableConfiguration;
import org.kie.internal.builder.DecisionTableInputType;
import org.kie.internal.builder.KnowledgeBuilder;
import org.kie.internal.builder.KnowledgeBuilderFactory;
import org.kie.internal.io.ResourceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration;
import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration;
import com.incquerylabs.smarthome.eventbus.api.IEventPublisher;
import com.incquerylabs.smarthome.eventbus.api.IEventSubscriber;
import com.incquerylabs.smarthome.eventbus.api.IRuleLoader;
import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration;
import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent;
import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent;
import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent;
import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandHistory;
import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent;
import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent;
import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedHistory;
import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent;
import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent;
package com.incquerylabs.smarthome.eventbus.ruleengine.drools;




public class DroolsEventBusClient implements IEventSubscriber {
	private static class DroolsLogger {}
	static Logger logger = LoggerFactory.getLogger(DroolsEventBusClient.class);
	static Logger droolsLogger = LoggerFactory.getLogger(DroolsLogger.class);
	private static final String subscriberName = "Drools event bus client";

	private ConcurrentHashMap<String, FactHandle> addedItems = new ConcurrentHashMap<String, FactHandle>();
	private IRuleLoader ruleLoader = null;

	private KieSession kSession;
	private volatile boolean droolsInitialized = false;

	private IEventPublisher eventPublisher = null;

	@Override
	public void stateUpdated(ItemStateEvent itemStateEvent) {