org.drools.builder.KnowledgeBuilderFactory Java Examples
The following examples show how to use
org.drools.builder.KnowledgeBuilderFactory.
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: DroolsBlueprintBean.java From servicemix with Apache License 2.0 | 6 votes |
public static KnowledgeBase createKnowledgeBase(GridNode node,String resource,String resourcetype){ if ( node == null ) { node = new GridNodeImpl(); } //kbase configuration PackageBuilderConfiguration kconf = (PackageBuilderConfiguration) KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,DroolsBlueprintBean.class.getClassLoader()); //kbuilder KnowledgeBuilder kbuilder = node.get( KnowledgeBuilderFactoryService.class ).newKnowledgeBuilder( kconf); kbuilder.add(parseResource(resource),ResourceType.getResourceType(resourcetype)); // error handling KnowledgeBuilderErrors errors = kbuilder.getErrors(); if ( !errors.isEmpty() ) { throw new RuntimeException( errors.toString() ); } //KnowledgeBase KnowledgeBaseConfiguration kbaseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, DroolsBlueprintBean.class.getClassLoader()); KnowledgeBase kbase = node.get( KnowledgeBaseFactoryService.class ).newKnowledgeBase(kbaseConfig); kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); return kbase; }
Example #3
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 #4
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 #5
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 ); }