1 package gboat2.serviceflow; 2 3 import org.drools.KnowledgeBase; 4 import org.drools.KnowledgeBaseConfiguration; 5 import org.drools.KnowledgeBaseFactoryService; 6 import org.drools.builder.KnowledgeBuilder; 7 import org.drools.builder.KnowledgeBuilderConfiguration; 8 import org.drools.builder.KnowledgeBuilderFactoryService; 9 import org.drools.util.ServiceRegistry; 10 11 public final class JBPMHelper { 12 13 private static KnowledgeBase kbase = null; 14 15 private static KnowledgeBuilder kbuilder = null; 16 17 private static ServiceRegistry registry; 18 19 private JBPMHelper() { 20 } 21 22 public static KnowledgeBase getKnowledgeBase() { 23 if (kbase == null) { 24 KnowledgeBaseFactoryService knowledgeBaseFactoryService = (KnowledgeBaseFactoryService) registry.get(KnowledgeBaseFactoryService.class); 25 ClassLoader[] classLoaders = { JBPMHelper.class.getClassLoader() }; 26 KnowledgeBaseConfiguration kbaseConf = knowledgeBaseFactoryService.newKnowledgeBaseConfiguration(null, classLoaders); 27 kbase = knowledgeBaseFactoryService.newKnowledgeBase(kbaseConf); 28 } 29 return JBPMHelper.kbase; 30 } 31 32 public static KnowledgeBuilder getKnowledgeBuilder() { 33 if (kbuilder == null) { 34 ClassLoader[] classLoaders = { JBPMHelper.class.getClassLoader() }; 35 KnowledgeBuilderFactoryService knowledgeBuilderFactoryService = (KnowledgeBuilderFactoryService) registry 36 .get(KnowledgeBuilderFactoryService.class); 37 KnowledgeBuilderConfiguration kbConf = knowledgeBuilderFactoryService.newKnowledgeBuilderConfiguration(null, classLoaders); 38 kbuilder = knowledgeBuilderFactoryService.newKnowledgeBuilder(kbConf); 39 } 40 return JBPMHelper.kbuilder; 41 } 42 43 public static void setServiceRegistry(ServiceRegistry registry) { 44 JBPMHelper.registry = registry; 45 } 46 47 public static ServiceRegistry getServiceRegistry() { 48 return registry; 49 } 50 }