Java Code Examples for org.drools.builder.KnowledgeBuilderFactory#newKnowledgeBuilder()
The following examples show how to use
org.drools.builder.KnowledgeBuilderFactory#newKnowledgeBuilder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RulesDeployer.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) { log.debug("Processing deployment {}", deployment.getName()); KnowledgeBuilder knowledgeBuilder = null; DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager(); Map<String, ResourceEntity> resources = deployment.getResources(); for (String resourceName : resources.keySet()) { log.info("Processing resource {}", resourceName); if (resourceName.endsWith(".drl")) { // is only parsing .drls sufficient? what about other rule dsl's? (@see ResourceType) if (knowledgeBuilder == null) { knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); } ResourceEntity resourceEntity = resources.get(resourceName); byte[] resourceBytes = resourceEntity.getBytes(); Resource droolsResource = ResourceFactory.newByteArrayResource(resourceBytes); knowledgeBuilder.add(droolsResource, ResourceType.DRL); } } if (knowledgeBuilder != null) { KnowledgeBase knowledgeBase = knowledgeBuilder.newKnowledgeBase(); deploymentManager.getKnowledgeBaseCache().add(deployment.getId(), knowledgeBase); } }
Example 2
Source File: RulesDeployer.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) { log.debug("Processing deployment {}", deployment.getName()); KnowledgeBuilder knowledgeBuilder = null; DeploymentManager deploymentManager = Context .getProcessEngineConfiguration() .getDeploymentManager(); Map<String, ResourceEntity> resources = deployment.getResources(); for (String resourceName : resources.keySet()) { log.info("Processing resource {}", resourceName); if (resourceName.endsWith(".drl")) { // is only parsing .drls sufficient? what about other rule dsl's? (@see ResourceType) if (knowledgeBuilder==null) { knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); } ResourceEntity resourceEntity = resources.get(resourceName); byte[] resourceBytes = resourceEntity.getBytes(); Resource droolsResource = ResourceFactory.newByteArrayResource(resourceBytes); knowledgeBuilder.add(droolsResource, ResourceType.DRL); } } if (knowledgeBuilder!=null) { KnowledgeBase knowledgeBase = knowledgeBuilder.newKnowledgeBase(); deploymentManager.getKnowledgeBaseCache().add(deployment.getId(), knowledgeBase); } }
Example 3
Source File: RulesExecutorData.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void initializeRules() { // To ensure the plugin classloader use for dependency resolution ClassLoader orig = Thread.currentThread().getContextClassLoader(); ClassLoader loader = getClass().getClassLoader(); Thread.currentThread().setContextClassLoader( loader ); Resource ruleSet = null; if ( ruleString != null ) { ruleSet = ResourceFactory.newReaderResource( new StringReader( ruleString ) ); } else { ruleSet = ResourceFactory.newFileResource( ruleFilePath ); } kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ruleSet, ResourceType.DRL ); if ( kbuilder.hasErrors() ) { System.out.println( kbuilder.getErrors().toString() ); throw new RuntimeException( BaseMessages.getString( PKG, "RulesData.Error.CompileDRL" ) ); } Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages(); kbase = KnowledgeBaseFactory.newKnowledgeBase(); // Cache the knowledge base as its creation is intensive kbase.addKnowledgePackages( pkgs ); // reset classloader back to original Thread.currentThread().setContextClassLoader( orig ); }
Example 4
Source File: RulesAccumulatorData.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void initializeRules() { // To ensure the plugin classloader use for dependency resolution ClassLoader orig = Thread.currentThread().getContextClassLoader(); ClassLoader loader = getClass().getClassLoader(); Thread.currentThread().setContextClassLoader( loader ); Resource ruleSet = null; if ( ruleString != null ) { ruleSet = ResourceFactory.newReaderResource( new StringReader( ruleString ) ); } else { ruleSet = ResourceFactory.newFileResource( ruleFilePath ); } kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ruleSet, ResourceType.DRL ); if ( kbuilder.hasErrors() ) { System.out.println( kbuilder.getErrors().toString() ); throw new RuntimeException( BaseMessages.getString( PKG, "RulesData.Error.CompileDRL" ) ); } Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages(); kbase = KnowledgeBaseFactory.newKnowledgeBase(); // Cache the knowledge base as its creation is intensive kbase.addKnowledgePackages( pkgs ); // reset classloader back to original Thread.currentThread().setContextClassLoader( orig ); }