org.drools.builder.KnowledgeBuilder Java Examples
The following examples show how to use
org.drools.builder.KnowledgeBuilder.
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); } }