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


Java KieFileSystem.write方法代码示例

本文整理汇总了Java中org.kie.api.builder.KieFileSystem.write方法的典型用法代码示例。如果您正苦于以下问题:Java KieFileSystem.write方法的具体用法?Java KieFileSystem.write怎么用?Java KieFileSystem.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.kie.api.builder.KieFileSystem的用法示例。


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

示例1: loadContainerFromString

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
private  KieContainer loadContainerFromString(List<Rule> rules) {
    long startTime = System.currentTimeMillis();
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieFileSystem kfs = ks.newKieFileSystem();

    for (Rule rule:rules) {
        String  drl=rule.getContent();
        kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl);
    }

    KieBuilder kb = ks.newKieBuilder(kfs);

    kb.buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
    }
    long endTime = System.currentTimeMillis();
    System.out.println("Time to build rules : " + (endTime - startTime)  + " ms" );
    startTime = System.currentTimeMillis();
    KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    endTime = System.currentTimeMillis();
    System.out.println("Time to load container: " + (endTime - startTime)  + " ms" );
    return kContainer;
}
 
开发者ID:ityouknow,项目名称:drools-examples,代码行数:26,代码来源:ReloadDroolsRulesService.java

示例2: buildRelease

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
private static void buildRelease(ReleaseId releaseId, Resource pomResource, Resource kmodule, String... resources) {
    if (releases.contains(releaseId)) {
        ks.getRepository().removeKieModule(releaseId);
    }
    KieServices kieServices = KieServices.Factory.get();

    KieFileSystem kfs = kieServices.newKieFileSystem();

    kfs.write("pom.xml", pomResource);

    kfs.write("src/main/resources/META-INF/kmodule.xml", kmodule);

    for (String res : resources) {
        Resource resource = new ClassPathResource(res);
        kfs.write("src/main/resources/" + res, resource);
    }

    hasErrors(kieServices.newKieBuilder(kfs).buildAll().getResults());

    releases.add(releaseId);
}
 
开发者ID:redhat-italy,项目名称:hacep,代码行数:22,代码来源:KieAPITestUtils.java

示例3: createKieContainer

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
private KieContainer createKieContainer(String... ruleFiles) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);

    for (String ruleFile : ruleFiles) {
        InputStream ruleFileIs = DroolsTestSupport.class.getResourceAsStream("/" + ruleFile);
        Assert.assertNotNull("Can't open stream for rule file. Does it exist?", ruleFileIs);
        kfs.write(ks.getResources().newInputStreamResource(ruleFileIs).setSourcePath(ruleFile));
        try {
            ruleFileIs.close();
        } catch (IOException e) {
            throw new RuntimeException("InputStream of rule file could not be closed.");
        }
    }
    kieBuilder.buildAll();

    StringBuilder message = new StringBuilder();
    List<Message> messages = kieBuilder.getResults().getMessages();
    for (Message m : messages) {
        message.append(m.toString()).append("\n");
    }
    Assert.assertEquals(message.toString(), 0, messages.size());
    return ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
}
 
开发者ID:jeichler,项目名称:junit-drools,代码行数:26,代码来源:DroolsTestSupport.java

示例4: getKieSession

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
/** create empty knowledge base */
private KieSession getKieSession() {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieResources kieResources = ks.getResources();

    kfs.write(kieResources.newClassPathResource("getOlder.drl", getClass()).setResourceType(ResourceType.DRL));

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:18,代码来源:JsonQueryTest.java

示例5: registerKnowledgeRuntime

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
protected KieSession registerKnowledgeRuntime(String identifier, String rule) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieResources kieResources = ks.getResources();

    if (rule != null && rule.length() > 0) {
        kfs.write("src/main/resources/rule.drl", rule);
    }

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();

    try {
        jndiContext.bind(identifier, ksession);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }

    return ksession;
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:27,代码来源:KieCamelTestSupport.java

示例6: initKieJar

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
/** 
 * 初始化一个kjar:把原有的drl包含进新建的kjar中 
 * 
 * @param ks 
 * @param releaseId 
 * @return 
 * @throws IOException 
 */  
public static InternalKieModule initKieJar(KieServices ks, ReleaseId releaseId) throws IOException {  
    KieFileSystem kfs = createKieFileSystemWithKProject(ks, true);  
    kfs.writePomXML(getPom(releaseId));  
    for (File file : getRuleFiles()) {  
        kfs.write("src/main/resources/" + file.getName(),  
                ResourceFactory.newClassPathResource(RULES_PATH + File.separator + file.getName(), "UTF-8"));  
    }  
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);  
    if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {  
        throw new IllegalStateException("Error creating KieBuilder.");  
    }  
    return (InternalKieModule) kieBuilder.getKieModule();  
}
 
开发者ID:lansheng228,项目名称:kie-dynamic-rule,代码行数:22,代码来源:DroolsUtils.java

示例7: createKieJar

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
public static InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, ResourceWrapper resourceWrapper) {  
    KieFileSystem kfs = createKieFileSystemWithKProject(ks, true);  
    kfs.writePomXML(getPom(releaseId));  
    kfs.write("src/main/resources/" + resourceWrapper.getTargetResourceName(), resourceWrapper.getResource());  
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);  
    if (!kieBuilder.getResults().getMessages().isEmpty()) {  
        System.out.println(kieBuilder.getResults().getMessages());  
        throw new IllegalStateException("Error creating KieBuilder.");  
    }  
    return (InternalKieModule) kieBuilder.getKieModule();  
}
 
开发者ID:lansheng228,项目名称:kie-dynamic-rule,代码行数:12,代码来源:DroolsUtils.java

示例8: getStatelessKieSessionFromResource

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
private StatelessKieSession getStatelessKieSessionFromResource(Resource resource) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();

    kfs.write(resource);

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newStatelessKieSession();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:16,代码来源:XStreamBatchExecutionTest.java

示例9: getKieSessionFromResource

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
private KieSession getKieSessionFromResource(Resource resource) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();

    kfs.write(resource);

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:16,代码来源:XStreamBatchExecutionTest.java

示例10: registerKnowledgeRuntime

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
@Override
protected KieSession registerKnowledgeRuntime(String identifier, String rule) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieResources kieResources = ks.getResources();

    Options xjcOpts = new Options();
    xjcOpts.setSchemaLanguage(Language.XMLSCHEMA);

    JaxbConfiguration jaxbConfiguration = KnowledgeBuilderFactory.newJaxbConfiguration(xjcOpts, "xsd");

    kfs.write(kieResources.newClassPathResource("person.xsd", getClass()).setResourceType(ResourceType.XSD).setConfiguration(jaxbConfiguration));

    if (rule != null && rule.length() > 0) {
        kfs.write("src/main/resources/rule.drl", rule);
    }

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
    classLoader = ((KnowledgeBaseImpl)ksession.getKieBase()).getRootClassLoader();

    try {
        jndiContext.bind(identifier, ksession);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }

    return ksession;
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:36,代码来源:CamelEndpointWithJaxbXSDModelTest.java

示例11: registerKnowledgeRuntime

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
@Override
protected KieSession registerKnowledgeRuntime(String identifier, String rule) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieResources kieResources = ks.getResources();

    Options xjcOpts = new Options();
    xjcOpts.setSchemaLanguage(Language.XMLSCHEMA);

    JaxbConfiguration jaxbConfiguration = KnowledgeBuilderFactory.newJaxbConfiguration(xjcOpts, "xsd");

    kfs.write(kieResources.newClassPathResource("person.xsd", getClass()).setResourceType(ResourceType.XSD).setConfiguration(jaxbConfiguration));

    if (rule != null && rule.length() > 0) {
        kfs.write("src/main/resources/rule.drl", rule);
    }

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();

    try {
        jndiContext.bind(identifier, ksession);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }

    return ksession;
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:35,代码来源:CamelEndpointWithJaxWrapperCollectionTest.java

示例12: getStatelessKieSessionFromResource

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
private StatelessKieSession getStatelessKieSessionFromResource(Resource resource) throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();

    kfs.write(resource);

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newStatelessKieSession();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:16,代码来源:BatchTest.java

示例13: getKieSessionFromResource

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
private KieSession getKieSessionFromResource(Resource resource) throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();

    kfs.write(resource);

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:16,代码来源:BatchTest.java

示例14: initKieSession

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
private void initKieSession(String... resourceNames) {
    final KieServices kieServices = KieServices.Factory.get();
    final KieModuleModel kieModuleModel = kieServices.newKieModuleModel();
    final KieBaseModel kieBaseModel = kieModuleModel.newKieBaseModel("defaultKieBase")
            .setDefault(true)
            .setEqualsBehavior(EqualityBehaviorOption.EQUALITY)
            .setEventProcessingMode(EventProcessingOption.STREAM);

    kieBaseModel.newKieSessionModel("defaultKieSession")
            .setDefault(true)
            .setType(KieSessionModel.KieSessionType.STATEFUL)
            .setClockType(ClockTypeOption.get("pseudo"))
            .newWorkItemHandlerModel("Rest", "org.drools.workbench.screens.testscenario.backend.server.GithubContributorsWIH");

    final KieFileSystem kfs = kieServices.newKieFileSystem();
    kfs.writeKModuleXML(kieModuleModel.toXML());
    for (String resource : resourceNames) {
        kfs.write(ResourceFactory.newUrlResource(this.getClass()
                                                         .getResource(resource)
                                                         .toString()));
    }

    kieServices.newKieBuilder(kfs).buildAll();

    kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
    kieSession = kieContainer.newKieSession();
    doReturn(kieSession).when(sessionService).newDefaultKieSessionWithPseudoClock(any(KieModule.class));
}
 
开发者ID:kiegroup,项目名称:drools-wb,代码行数:29,代码来源:ScenarioRunnerServiceTest.java

示例15: createAndBuildKieServices

import org.kie.api.builder.KieFileSystem; //导入方法依赖的package包/类
/**
 * Creates a new {@link KieServices} using a collection of resources. It
 * does this by creating a new virtual file system and adding the resources
 * to it.
 * 
 * @param resources
 *            An array of {@link DroolsResource} indicating where the
 *            various resources should be loaded from. These could be
 *            classpath, file or URL resources.
 * @return A new {@link KieServices}.
 * @throws KieBuildException I there are errors whilst building the {@link KieServices}.
 */
public static KieServices createAndBuildKieServices(DroolsResource[] resources) throws KieBuildException {
    KieServices kieServices = KieServices.Factory.get();
    KieFileSystem kfs = kieServices.newKieFileSystem();
    
    for (DroolsResource resource : resources) {
        log.info("Resource: " + resource.getType() + ", path type="
                + resource.getPathType() + ", path=" + resource.getPath());
        switch (resource.getPathType()) {
        case CLASSPATH:
            kfs.write(ResourceFactory.newClassPathResource(resource.getPath()));
            break;
        case FILE:
            kfs.write(ResourceFactory.newFileResource(resource.getPath()));
            break;
        case URL:
            UrlResource urlResource = (UrlResource) ResourceFactory
                    .newUrlResource(resource.getPath());
            
            if (resource.getUsername() != null) {
                log.info("Setting authentication for: " + resource.getUsername());
                urlResource.setBasicAuthentication("enabled");
                urlResource.setUsername(resource.getUsername());
                urlResource.setPassword(resource.getPassword());
            }
            
            kfs.write(urlResource);
            
            break;
        default:
            throw new IllegalArgumentException(
                    "Unable to build this resource path type.");
        }
    }
    
    KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll();
    
    // The KieBuilder contains a collection of messages, which is built up
    // as it does its job. If any of these have a level of 'ERROR', then the
    // rules did not compile correctly. Therefore we log such messages and 
    // throw an exception to indicate failure.
    if (kieBuilder.getResults().hasMessages(Level.ERROR)) {
        List<Message> errors = kieBuilder.getResults().getMessages(Level.ERROR);
        StringBuilder sb = new StringBuilder("Errors:");
        for (Message msg : errors) {
            sb.append("\n  " + prettyBuildMessage(msg));
        }
        throw new KieBuildException(sb.toString());
    }
    
    return kieServices;
}
 
开发者ID:gratiartis,项目名称:qzr,代码行数:64,代码来源:DroolsUtil.java


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