当前位置: 首页>>代码示例>>Java>>正文


Java KnowledgeBuilderFactory类代码示例

本文整理汇总了Java中org.kie.internal.builder.KnowledgeBuilderFactory的典型用法代码示例。如果您正苦于以下问题:Java KnowledgeBuilderFactory类的具体用法?Java KnowledgeBuilderFactory怎么用?Java KnowledgeBuilderFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KnowledgeBuilderFactory类属于org.kie.internal.builder包,在下文中一共展示了KnowledgeBuilderFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadDrools

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
private void loadDrools() {
	try {
		logger.info("Initializing Drools rule engine");
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

		addDrls(kbuilder);

		KieSessionConfiguration config = KieServices.Factory.get().newKieSessionConfiguration();
		config.setOption(ClockTypeOption.get("pseudo"));

		logger.debug("Compiling rules");
		kSession = kbuilder.newKieBase().newKieSession(config, null);
		homeioSessionClock = new HomeioSessionClock(kSession.getSessionClock());

		initGlobals();

		droolsInitialized = true;

		logger.debug("Successfully initialized Drools rule engine");

	} catch (Exception e) {
		logger.error("Exiting because of an exception during the Drools initialization ", e);
		new RuntimeException("Exiting because of an exception during the Drools initialization");
	}
}
 
开发者ID:IncQueryLabs,项目名称:smarthome-cep-demonstrator,代码行数:26,代码来源:DroolsEventBusClient.java

示例2: loadDrools

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
private void loadDrools() {
	try {
		logger.info("Initializing Drools rule engine");
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

		addDrls(kbuilder);

		logger.debug("Compiling rules");
		kSession = kbuilder.newKieBase().newKieSession();
		initGlobals();

		droolsInitialized = true;

		logger.info("Successfully initialized Drools rule engine");

	} catch (Exception e) {
		logger.error("Exiting because of an exception during the Drools initialization ", e);
		new RuntimeException("Exiting because of an exception during the Drools initialization");
	}
}
 
开发者ID:IncQueryLabs,项目名称:smarthome-cep-demonstrator,代码行数:21,代码来源:DroolsEventBusClient.java

示例3: addRule

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
/**
 * 单一规则上线
 *
 * @param packageName
 * @param ruleName
 */
public void addRule(String packageName, String ruleName) {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + ruleName + ".drl"), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        logger.error("Unable to compile drl. " + packageName + ruleName + ".drl");
        return;
    } else {
        if (kbase.getRule(packageName, ruleName) != null) {
            logger.info("update rule: " + packageName + "." + ruleName);
        } else {
            logger.info("add rule: " + packageName + "." + ruleName);
        }
    }

    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    kieSession = kbase.newStatelessKieSession();
    setGlobal();
    printRules();
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:26,代码来源:KieService.java

示例4: testCallService

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
@Test
public void testCallService() throws Exception {
    final Holder holder = new Holder();
    serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            holder.setValue("message handled");
        }
    });
    serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    ksession.startProcess("CallService");
    ksession.halt();
    ksession.dispose();
    Assert.assertEquals("message handled", holder.getValue());
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:23,代码来源:BPMServiceTests.java

示例5: runFaultBoundaryProcess

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
    String output = (String)wpi.getVariable("TestOutput");
    Assert.assertEquals(bomb ? "Failure" : "Success", output);
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:24,代码来源:BPMServiceTests.java

示例6: testCallService

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
@Test
public void testCallService() throws Exception {
    final Holder holder = new Holder();
    serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            holder.setValue("message handled");
        }
    });
    serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    ksession.startProcess("CallService");
    ksession.halt();
    ksession.dispose();
    Assert.assertEquals("message handled", holder.getValue());
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:23,代码来源:BPMServiceTests.java

示例7: runFaultBoundaryProcess

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
    String output = (String)wpi.getVariable("TestOutput");
    Assert.assertEquals(bomb ? "Failure" : "Success", output);
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:24,代码来源:BPMServiceTests.java

示例8: testNamedWorksheet

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
/**
 * Test named worksheet.
 *
 * @throws Exception the exception
 */
@Test
public void testNamedWorksheet() throws Exception {
    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.XLS);
    dtconf.setWorksheetName("Tables");

    Resource dt = ResourceFactory.newClassPathResource("/data/IntegrationExampleTest.xls", getClass()).setConfiguration(
            dtconf);
    KieSession ksession = getKieSession(dt);

    // ASSERT AND FIRE
    ksession.insert(new Cheese("cheddar", 42));
    ksession.insert(new Person("michael", "stilton", 21));
    final List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals("Young man cheddar", list.get(0));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:25,代码来源:SpreadsheetIntegrationExampleTest.java

示例9: addPackage

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
/**
 * 规则集上线
 *
 * @param packageName
 */
public void addPackage(String packageName) {
    try {
        File path = new File(this.getClass().getClassLoader().getResource(packageName).toURI().getPath());
        if (path.isDirectory()) {
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
            File[] files = path.listFiles();
            for (File file : files) {
                if (file.getName().endsWith(".drl")) {
                    kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + file.getName()), ResourceType.DRL);
                    if (kbuilder.hasErrors()) {
                        logger.error("Unable to compile drl. " + packageName + file.getName());
                        return;
                    } else {
                        String ruleName = file.getName().replace(".drl", "");
                        if (kbase.getRule(packageName, ruleName) != null) {
                            logger.info("update rule: " + packageName + "." + ruleName);
                        } else {
                            logger.info("add rule: " + packageName + "." + ruleName);
                        }
                    }
                }
            }

            kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
            kieSession = kbase.newStatelessKieSession();
            setGlobal();
            printRules();
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:38,代码来源:KieService.java

示例10: runFaultResultProcess

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
private void runFaultResultProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_RESULT_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultResultProcess");
    HandlerException he = (HandlerException)wpi.getVariable("faultResult");
    if (bomb) {
        Assert.assertNotNull(he);
        Assert.assertEquals("BOOM!", he.getMessage());
    } else {
        Assert.assertNull(he);
    }
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:29,代码来源:BPMServiceTests.java

示例11: runFaultEventProcess

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
private void runFaultEventProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_EVENT_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultEventProcess");
    HandlerException he = (HandlerException)wpi.getVariable("faultEvent");
    if (bomb) {
        Assert.assertNotNull(he);
        Assert.assertEquals("BOOM!", he.getMessage());
    } else {
        Assert.assertNull(he);
    }
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:29,代码来源:BPMServiceTests.java

示例12: ResourceBuilder

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
/**
 * Creates a new ResourceBuilder.
 * @param classLoader classLoader
 * @param resourceModel resourceModel
 */
public ResourceBuilder(ClassLoader classLoader, ResourceModel resourceModel) {
    super(classLoader);
    _kieResources = KieServices.Factory.get().getResources();
    if (resourceModel != null) {
        _url = resourceModel.getLocationURL(getClassLoader());
        _resourceType = convertResourceType(resourceModel.getType());
        ResourceDetail syResourceDetail = resourceModel.getDetail();
        if (syResourceDetail != null) {
            if (ResourceType.DTABLE.equals(_resourceType)) {
                String inputType = getInputType(syResourceDetail, DecisionTableInputType.XLS.toString());
                DecisionTableConfiguration dtc = KnowledgeBuilderFactory.newDecisionTableConfiguration();
                dtc.setInputType(DecisionTableInputType.valueOf(inputType));
                dtc.setWorksheetName(getWorksheetName(syResourceDetail));
                //dtc.setUsingExternalTypes(syResourceDetail.isUsingExternalTypes());
                _resourceConfiguration = dtc;
            }
            /* SWITCHYARD-1662
            else if (ResourceType.SCARD.equals(_resourceType)) {
                String inputType = getInputType(syResourceDetail, ScoreCardConfiguration.SCORECARD_INPUT_TYPE.EXCEL.name());
                if ("XLS".equals(inputType)) {
                    inputType = ScoreCardConfiguration.SCORECARD_INPUT_TYPE.EXCEL.name();
                }
                ScoreCardConfiguration scc = KnowledgeBuilderFactory.newScoreCardConfiguration();
                scc.setInputType(ScoreCardConfiguration.SCORECARD_INPUT_TYPE.valueOf(inputType));
                scc.setWorksheetName(getWorksheetName(syResourceDetail));
                //scc.setUsingExternalTypes(syResourceDetail.isUsingExternalTypes());
                _resourceConfiguration = scc;
            }
            */
        }
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:38,代码来源:ResourceBuilder.java

示例13: getDistributeSimplifyKnowledgeBase

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
/**
 * Returns Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
 * 
 * @return Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
 */
public static KnowledgeBase getDistributeSimplifyKnowledgeBase()
{
	if( distributeSimplifyKnowledgeBase == null )
	{
		OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
		
		KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		
		// Load in the reng support as a separate cross-cutting concern.
		builder.add( ResourceFactory.newClassPathResource( "reng.drl" )  , 
				ResourceType.DRL );
		
		builder.add( ResourceFactory.newClassPathResource( "distributeSimplify.drl" )  , 
				ResourceType.DRL );
		
		if( LoggingConfiguration.LOGGING_ON )
		{
			builder.add( ResourceFactory.newClassPathResource( "logging.drl" )  , 
					ResourceType.DRL );
		}
		
		if( builder.hasErrors() )
		{
			throw( new RuntimeException( builder.getErrors().toString() ) );
		}
		distributeSimplifyKnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
		distributeSimplifyKnowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
	}
	
	return( distributeSimplifyKnowledgeBase );
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:37,代码来源:Elem.java

示例14: getDistributeSimplify2KnowledgeBase

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
/**
 * Returns Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
 * 
 * @return Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
 */
public static KnowledgeBase getDistributeSimplify2KnowledgeBase()
{
	if( distributeSimplify2KnowledgeBase == null )
	{
		OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
		
		KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		
		// Load in the reng support as a separate cross-cutting concern.
		builder.add( ResourceFactory.newClassPathResource( "reng.drl" )  , 
				ResourceType.DRL );
		
		builder.add( ResourceFactory.newClassPathResource( "distributeSimplify2.drl" )  , 
				ResourceType.DRL );
		
		if( LoggingConfiguration.LOGGING_ON )
		{
			builder.add( ResourceFactory.newClassPathResource( "logging.drl" )  , 
					ResourceType.DRL );
		}
		
		if( builder.hasErrors() )
		{
			throw( new RuntimeException( builder.getErrors().toString() ) );
		}
		distributeSimplify2KnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
		distributeSimplify2KnowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
	}
	
	return( distributeSimplify2KnowledgeBase );
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:37,代码来源:Elem.java

示例15: runFaultResultProcess

import org.kie.internal.builder.KnowledgeBuilderFactory; //导入依赖的package包/类
private void runFaultResultProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_RESULT_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultResultProcess");
    HandlerException he = (HandlerException)wpi.getVariable("faultResult");
    if (bomb) {
        Assert.assertNotNull(he);
        Assert.assertEquals("BOOM!", he.getMessage());
    } else {
        Assert.assertNull(he);
    }
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:29,代码来源:BPMServiceTests.java


注:本文中的org.kie.internal.builder.KnowledgeBuilderFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。