All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jbpm.process.ProcessBaseImpl Maven / Gradle / Ivy

There is a newer version: 7.74.1.Final
Show newest version
/**
 * Copyright 2010 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jbpm.process;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.drools.RuleBase;
import org.drools.SessionConfiguration;
import org.drools.definition.KnowledgePackage;
import org.drools.definition.process.Process;
import org.drools.definition.rule.Query;
import org.drools.definition.rule.Rule;
import org.drools.definition.type.FactType;
import org.drools.event.knowledgebase.KnowledgeBaseEventListener;
import org.drools.impl.EnvironmentFactory;
import org.drools.impl.InternalKnowledgeBase;
import org.drools.runtime.Environment;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.StatelessKnowledgeSession;

public class ProcessBaseImpl implements InternalKnowledgeBase {
    
	private Map processes = new HashMap();
	private Map packages = new HashMap();
	private List listeners = new ArrayList();

	public void addEventListener(KnowledgeBaseEventListener listener) {
        listeners.add(listener);
    }

    public void removeEventListener(KnowledgeBaseEventListener listener) {
        listeners.remove(listener);
    }
    
    public Collection getKnowledgeBaseEventListeners() {
        return listeners;
    }

    public void addKnowledgePackage(KnowledgePackage knowledgePackage) {
    	packages.put(knowledgePackage.getName(), knowledgePackage);
    	for (Process process: knowledgePackage.getProcesses()) {
    		processes.put(process.getId(), process);
    	}
    }

    public void addKnowledgePackages(Collection knowledgePackages) {
        for ( KnowledgePackage knowledgePackage : knowledgePackages ) {
            addKnowledgePackage(knowledgePackage);
        }
    }

    public Collection getKnowledgePackages() {
        return packages.values();
    }

    public StatefulKnowledgeSession newStatefulKnowledgeSession() {
    	return newStatefulKnowledgeSession(new SessionConfiguration(), EnvironmentFactory.newEnvironment());
    }
    
    public StatefulKnowledgeSession newStatefulKnowledgeSession(KnowledgeSessionConfiguration conf, Environment environment) {
        return new StatefulProcessSession(this, conf, environment);
    }  
    
    public Collection getStatefulKnowledgeSessions() {
        throw new UnsupportedOperationException("Getting stateful sessions not supported");
    }
    
    public StatelessKnowledgeSession newStatelessKnowledgeSession() {
        throw new UnsupportedOperationException("Stateless sessions not supported");
    }
    
    public StatelessKnowledgeSession newStatelessKnowledgeSession(KnowledgeSessionConfiguration conf) {        
        throw new UnsupportedOperationException("Stateless sessions not supported");
    } 

    public void removeKnowledgePackage(String packageName) {
    	packages.remove(packageName);
    }

    public void removeRule(String packageName, String ruleName) {
        throw new UnsupportedOperationException();
    }
    
    public void removeQuery(String packageName, String queryName) {
        throw new UnsupportedOperationException();
    }    

    public void removeFunction(String packageName, String ruleName) {
        throw new UnsupportedOperationException();
    }

    public void removeProcess(String processId) {
    	processes.remove(processId);
    }
    
    public FactType getFactType(String packageName, String typeName) {
        throw new UnsupportedOperationException();
    }

    public KnowledgePackage getKnowledgePackage(String packageName) {
        return packages.get(packageName);
    }

    public Process getProcess(String processId) {
    	return processes.get(processId);
    }
    
    public Collection getProcesses() {
    	return processes.values();
    }

    public Rule getRule(String packageName, String ruleName) {
        throw new UnsupportedOperationException();
    }
    
    public Query getQuery(String packageName, String queryName) {
        throw new UnsupportedOperationException();
    }

	public RuleBase getRuleBase() {
		return null;
	}

	public Set getEntryPointIds() {
		throw new UnsupportedOperationException("Entry points not supported");
	}
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy