• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PackageBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: initialize

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
/**
 * <p>initialize</p>
 *
 * @throws java.lang.Exception if any.
 */
public void initialize() throws Exception {
	final Properties props = new Properties();
    props.setProperty("drools.dialect.java.compiler.lnglevel", "1.6");
    final PackageBuilderConfiguration conf = new PackageBuilderConfiguration(props);
    final PackageBuilder builder = new PackageBuilder( conf );
    
    loadRules(builder);

    final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( builder.getPackage() );

    m_workingMemory = ruleBase.newStatefulSession();
    m_workingMemory.setGlobal("engine", this);
    
    for (final Map.Entry<String, Object> entry : m_globals.entrySet()) {
        m_workingMemory.setGlobal(entry.getKey(), entry.getValue());
    }

}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:25,代码来源:DroolsCorrelationEngine.java


示例2: syncNow

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
private void syncNow() {
	LOG.debug("Initiating new synchornization");
	Date previousLastDate = lastDeploymentDate;
	LOG.debug("Previous deployment last date '{}'", previousLastDate);

	LOG.debug("Creating package builder and configuring it");
	PackageBuilder builder = new PackageBuilder();
	BPMN2ProcessFactory.configurePackageBuilder(builder);
	List<WorkflowDefinition> allDefs = workflowService.getAllWorkflowDefinition();
	int installed = 0;
	LOG.debug("Checking {} workflow definitions", allDefs.size());
	for (WorkflowDefinition def : allDefs) {
		Deployment deployment = workflowService.getDeployment(def.getDeploymemtId());
		LOG.debug("Check if deployment must be sincronized, deployment date: {} ", deployment.getDeploymentDate());
		if (deployment.getDeploymentDate().compareTo(previousLastDate) > 0) {
			try {
				LOG.debug("Need to deploy to kbase, building process for Workflow,  Id: {}, Key: {}, Version: {}",
						new Object[] { def.getId(), def.getKey(), def.getVersion() });
				builder.addProcessFromXml(getResourceFromDefinition(def));
				installed++;
				Date deploymentDate = deployment.getDeploymentDate();
				lastDeploymentDate = deploymentDate.compareTo(lastDeploymentDate) > 0 ? deploymentDate : lastDeploymentDate;
			} catch (Exception e) {
				LOG.error(String.format("Cant register process %s becouse has thorwn an exception", def.getKey()), e);
			}
		}
	}
	if (installed > 0 && builder.getPackage() != null) {
		LOG.debug("Total process builts: {}", installed);
		kbase.addKnowledgePackages(Arrays.asList((KnowledgePackage) new KnowledgePackageImp(builder.getPackage())));
	}
}
 
开发者ID:frincon,项目名称:openeos,代码行数:33,代码来源:JbpmSynchronizer.java


示例3: initialize

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
/**
 * <p>initialize</p>
 *
 * @throws java.lang.Exception if any.
 */
public void initialize() throws Exception {
	final Properties props = new Properties();
    props.setProperty("drools.dialect.java.compiler.lnglevel", "1.6");

    final PackageBuilderConfiguration conf = new PackageBuilderConfiguration(props);
    final PackageBuilder builder = new PackageBuilder( conf );
    
    loadRules(builder);
    
    AssertBehaviour behaviour = AssertBehaviour.determineAssertBehaviour(m_assertBehaviour);
    RuleBaseConfiguration config = new RuleBaseConfiguration();
    config.setAssertBehaviour(behaviour);

    final RuleBase ruleBase = RuleBaseFactory.newRuleBase( config );

    if (builder.hasErrors()) {
        LogUtils.warnf(this, "Unable to initialize Drools engine: %s", builder.getErrors());
        throw new IllegalStateException("Unable to initialize Drools engine: " + builder.getErrors());
    }

    ruleBase.addPackage( builder.getPackage() );

    m_workingMemory = ruleBase.newStatefulSession();
    m_workingMemory.setGlobal("engine", this);
    
    for (final Map.Entry<String, Object> entry : m_globals.entrySet()) {
        m_workingMemory.setGlobal(entry.getKey(), entry.getValue());
    }

}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:36,代码来源:DroolsCorrelationEngine.java


示例4: loadRules

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
private void loadRules(final PackageBuilder builder) throws DroolsParserException, IOException {
    
    for (final Resource rulesFile : m_rules) {
        Reader rdr = null;
        try {
            LogUtils.debugf(this, "Loading rules file: %s", rulesFile);
            rdr = new InputStreamReader( rulesFile.getInputStream(), "UTF-8" );
            builder.addPackageFromDrl( rdr );
        } finally {
            IOUtils.closeQuietly(rdr);
        }
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:14,代码来源:DroolsCorrelationEngine.java


示例5: main

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
/**
 * <p>main</p>
 *
 * @param args an array of {@link java.lang.String} objects.
 * @throws java.lang.Exception if any.
 */
public static void main(final String[] args) throws Exception {

    final PackageBuilder builder = new PackageBuilder();
    builder.addPackageFromDrl( new InputStreamReader( CorrelationExample.class.getResourceAsStream( "CorrelationExample.drl" ), "UTF-8" ) );

    final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( builder.getPackage() );

    final WorkingMemory workingMemory = ruleBase.newStatefulSession();

    final WorkingMemoryFileLogger logger = new WorkingMemoryFileLogger( workingMemory );
    logger.setFileName( "log/correlation" );
    
    final InputStream in = CorrelationExample.class.getResourceAsStream("simulation");
    try {
    	final Simulation simulation = new Simulation();
    	System.out.println("Loading Simulation");
    	simulation.load(in);
    	System.out.println("Executing Simulation");
    	simulation.simulate(workingMemory);
    	
    } finally {
    	if (in != null) in.close();
    }
    
    	
    logger.writeToDisk();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:35,代码来源:CorrelationExample.java


示例6: doInit

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
/**
 * Drools initialization
 */
protected void doInit() {
    // Workaround for https://issues.jboss.org/browse/DROOLS-329 TODO: Remove when not needed or move to better place
    System.setProperty("drools.dialect.java.compiler", "JANINO");

    RuleBaseConfiguration ruleBaseConfig = new RuleBaseConfiguration(DroolsPolicy.class.getClassLoader());
    this.ruleBase = RuleBaseFactory.newRuleBase(ruleBaseConfig);
    this.packageBuilder = new PackageBuilder(this.ruleBase);

    // Add DRL with functions
    InputStream functionsFileStream = DroolsPolicy.class.getClassLoader().getResourceAsStream("templates/DroolsPolicyFunctions.drl");
    Reader functionsFileReader = new InputStreamReader(functionsFileStream);
    addPackage(functionsFileReader);
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:17,代码来源:DroolsPolicyConfigurator.java


示例7: loadRules

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
private void loadRules(final PackageBuilder builder) throws DroolsParserException, IOException {
    
    for (final Resource rulesFile : m_rules) {
        Reader rdr = null;
        try {
            rdr = new InputStreamReader( rulesFile.getInputStream(), "UTF-8" );
            builder.addPackageFromDrl( rdr );
        } finally {
            IOUtils.closeQuietly(rdr);
        }
    }
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:13,代码来源:DroolsCorrelationEngine.java


示例8: compileRules

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
@Override
    public void compileRules(InputStream fichero) throws Exception {
        PackageBuilder builder = new PackageBuilder();
        try {
              KnowledgeBuilder Kbuild = KnowledgeBuilderFactory.newKnowledgeBuilder();
              Resource rsc = ResourceFactory.newInputStreamResource( fichero );
              Kbuild.add( rsc,ResourceType.DRL );
              if ( Kbuild.hasErrors() ) {
                  System.out.println("Problemas con el fichero : "+ fichero.toString());
                   System.err.println( Kbuild.getErrors().toString() );
                   throw new RuntimeException( "Unable to compile");
              }

              //FRAGMENTO NUEVO
              KnowledgeBaseConfiguration kbaseconfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    //          kbaseconfiguration.setProperty(AssertBehaviorOption.PROPERTY_NAME, "equality");
              
              System.out.println("\n\n\n\n");
              System.out.println("\nLISTADO DE LAS PROPIEDADES UTILIZADAS PARA LA CONFIGURACION DEL MOTOR DEL AGENTE " + this.agent.getIdentAgente() + "......\n");
              System.out.println("----------------------------------------------------------------");
              
              System.out.println("AssertBehaviorOption->" + kbaseconfiguration.getProperty(org.drools.conf.AssertBehaviorOption.PROPERTY_NAME));              
              System.out.println("EventProcessingOption->" + kbaseconfiguration.getProperty(org.drools.conf.EventProcessingOption.PROPERTY_NAME));              
              System.out.println("IndexLeftBetaMemoryOption->" + kbaseconfiguration.getProperty(org.drools.conf.IndexLeftBetaMemoryOption.PROPERTY_NAME));
              System.out.println("IndexRightBetaMemoryOption->" + kbaseconfiguration.getProperty(org.drools.conf.IndexRightBetaMemoryOption.PROPERTY_NAME));
              System.out.println("LogicalOverrideOption->" + kbaseconfiguration.getProperty(org.drools.conf.LogicalOverrideOption.PROPERTY_NAME));              
              System.out.println("MaintainTMSOption->" + kbaseconfiguration.getProperty(org.drools.conf.MaintainTMSOption.PROPERTY_NAME));              
              System.out.println("MBeansOption->" + kbaseconfiguration.getProperty(org.drools.conf.MBeansOption.PROPERTY_NAME));              
              System.out.println("MultithreadEvaluationOption->" + kbaseconfiguration.getProperty(org.drools.conf.MultithreadEvaluationOption.PROPERTY_NAME));              
              System.out.println("RemoveIdentitiesOption->" + kbaseconfiguration.getProperty(org.drools.conf.RemoveIdentitiesOption.PROPERTY_NAME));
              System.out.println("SequentialAgendaOption->" + kbaseconfiguration.getProperty(org.drools.conf.SequentialAgendaOption.PROPERTY_NAME));
              System.out.println("SequentialOption->" + kbaseconfiguration.getProperty(org.drools.conf.SequentialOption.PROPERTY_NAME));
              System.out.println("ShareAlphaNodesOption->" + kbaseconfiguration.getProperty(org.drools.conf.ShareAlphaNodesOption.PROPERTY_NAME));
              System.out.println("ShareBetaNodesOption->" + kbaseconfiguration.getProperty(org.drools.conf.ShareBetaNodesOption.PROPERTY_NAME));
              System.out.println("----------------------------------------------------------------\n\n\n\n");
                                                         
              
              KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseconfiguration);            	                
              //FIN FRAGMENTO NUEVO        
//              KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
              kbase.addKnowledgePackages( Kbuild.getKnowledgePackages() );
              kSesion = kbase.newStatefulKnowledgeSession();
              entrypoint = kSesion.getWorkingMemoryEntryPoint("DEFAULT");
              if (depuracionActivationRulesDebugging)trazarRuleActivation();
              

//////////////////////////////////////////////////              if (ConfigDebugging.WORKINGMEMORY_DEBUGGING==1){
              if (depuracionWorkingMemoryDebugging)trazarWorkingMemory ();//fin del if depuracion working memory
                trazas.aceptaNuevaTraza(new InfoTraza(agentId,"RuleEngine: Rules compiled successfully. ",
                                                    InfoTraza.NivelTraza.debug));
        } catch (Exception e) {
             trazas.aceptaNuevaTraza(new InfoTraza(agentId,"RuleEngine: ERROR compiling the rules. " + e,
                                                   InfoTraza.NivelTraza.error));
             e.printStackTrace();
        }
    }
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:57,代码来源:MotorDeReglasDroolsImp5.java


示例9: buildPackage

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
private static Package buildPackage() throws DroolsParserException, IOException {
	
	final Reader rule = new InputStreamReader( XpsUtil.getRuleAsStream(RULE_FILE));
	final Reader dsl = new InputStreamReader( XpsUtil.getRuleAsStream(DSL_FILE));
	
	final PackageBuilder builder = new PackageBuilder();

	
	builder.addPackageFromDrl( rule,dsl );
	
	// Check the builder for errors
       if ( builder.hasErrors() ) {
           log.severe("Compilation Errors in rule : " + builder.getErrors().toString() );
           throw new AstrosoftException( "Compilation Errors in " + RULE_FILE);
       }

       return builder.getPackage();
}
 
开发者ID:erajasekar,项目名称:Astrosoft,代码行数:19,代码来源:YogaFinder.java


示例10: buildPackage

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
private static Package buildPackage() throws DroolsParserException, IOException {
	
	final Reader rule = new InputStreamReader( XpsUtil.getRuleAsStream(RULE_FILE));
	final Reader dsl = new InputStreamReader( XpsUtil.getRuleAsStream(DSL_FILE));
	
	final PackageBuilder builder = new PackageBuilder();

	//builder.addPackageFromDrl( rule );
	
	builder.addPackageFromDrl( rule,dsl );
	
	// Check the builder for errors
       if ( builder.hasErrors() ) {
           System.out.println( builder.getErrors().toString() );
           throw new RuntimeException( "Compilation Errors in " + RULE_FILE);
       }

       return builder.getPackage();
       
}
 
开发者ID:erajasekar,项目名称:Astrosoft,代码行数:21,代码来源:YogasTest.java


示例11: buildPackage

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
public static Package buildPackage() throws DroolsParserException, IOException {
	
	final Reader rule = new InputStreamReader( XpsUtil.getRuleAsStream(RULE_FILE));
	final Reader dsl = new InputStreamReader( XpsUtil.getRuleAsStream(DSL_FILE));
	
	final PackageBuilder builder = new PackageBuilder();

	
	//builder.addPackageFromDrl( rule );
	
	builder.addPackageFromDrl( rule,dsl );
	
	// Check the builder for errors
    if ( builder.hasErrors() ) {
        System.out.println( builder.getErrors().toString() );
        throw new RuntimeException( "Compilation Errors in " + RULE_FILE);
    }

    return builder.getPackage();
    
}
 
开发者ID:erajasekar,项目名称:Astrosoft,代码行数:22,代码来源:YogaAnalysisTestHelper.java


示例12: main

import org.drools.compiler.PackageBuilder; //导入依赖的package包/类
public static final void main(final String[] args) throws Exception {
	
	//read in the source
    final Reader source = new InputStreamReader( HelloWorldExample.class.getResourceAsStream( "/resources/rules/test.drl" ) );

    Properties properties = new Properties();
    properties.setProperty( "drools.dialect.java.languageLevel",
                            "1.5" );
    
    PackageBuilderConfiguration cfg = new PackageBuilderConfiguration( properties );
    
    JavaDialectConfiguration javaConf = (JavaDialectConfiguration) cfg.getDialectConfiguration( "java" );
    System.out.println(javaConf.getJavaLanguageLevel());
    
    final PackageBuilder builder = new PackageBuilder(cfg);

    
    //this wil parse and compile in one step
    builder.addPackageFromDrl( source );
    
    // Check the builder for errors
    if ( builder.hasErrors() ) {
        System.out.println( builder.getErrors().toString() );
        throw new RuntimeException( "Unable to compile \"HelloWorld.drl\".");
    }

    //get the compiled package (which is serializable)
    final Package pkg = builder.getPackage();

    //add the package to a rulebase (deploy the rule package).
    final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );

    final StatefulSession session = ruleBase.newStatefulSession();
    
    session.addEventListener( new DebugAgendaEventListener() );
    session.addEventListener( new DebugWorkingMemoryEventListener() );
    
    final WorkingMemoryFileLogger logger = new WorkingMemoryFileLogger( session );
    logger.setFileName( "C:/Astrosoft/helloworld" );        

    /*final Message message = new Message();
    message.setMessage( "Hello World" );
    message.setStatus( Message.STATUSVALS.HELLO );
    session.insert( message );*/
    
    List<String> l = new ArrayList<String>();
    
    l.add("a");
    l.add("b");
    l.add("c");
    
    session.insert(l);
    
    session.insert(Planet.Sun);
    
    /*Map<Planet, Integer> m = new EnumMap<Planet, Integer>(Planet.class);
    
    Map<Planet,Integer> m = new HashMap<Planet,Integer>();
    m.put(Planet.Sun, 1);
    m.put(Planet.Moon, 2);
    m.put(Planet.Mars, 3);
    
    session.insert(m);*/
    
    PlanetLocation p1 = new PlanetLocation(Planet.Sun, 1);
    PlanetLocation p2 = new PlanetLocation(Planet.Moon, 2);
    PlanetLocation p3 = new PlanetLocation(Planet.Mars, 3);
    
    session.insert(p1);
    session.insert(p2);
    session.insert(p3);
    
    
    session.fireAllRules();
    
    logger.writeToDisk();
    
    session.dispose();
}
 
开发者ID:erajasekar,项目名称:Astrosoft,代码行数:81,代码来源:HelloWorldExample.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ErrorHandler类代码示例发布时间:2022-05-23
下一篇:
Java PluginManager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap