/** * Prints the usage screen and exits the process. * * @param opts * If the parsing of options have started, set a partly populated * {@link Options} object. */ public static void usage( @Nullable Options opts, boolean privateUsage ) { if( privateUsage ) { System.out.println(Messages.format(Messages.DRIVER_PRIVATE_USAGE)); } else { System.out.println(Messages.format(Messages.DRIVER_PUBLIC_USAGE)); } if( opts!=null && opts.getAllPlugins().size()!=0 ) { System.out.println(Messages.format(Messages.ADDON_USAGE)); for (Plugin p : opts.getAllPlugins()) { System.out.println(p.getUsage()); } } }
@Test public void testGlobal() throws Exception { Options xjcOpts = new Options(); xjcOpts.setSchemaLanguage(Language.XMLSCHEMA); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); JaxbConfiguration jaxbConf = KnowledgeBuilderFactory.newJaxbConfiguration(xjcOpts, "xsd"); kbuilder.add( ResourceFactory.newClassPathResource("order.xsd", getClass()), ResourceType.XSD, jaxbConf); assertFalse(kbuilder.hasErrors()); kbuilder.add( ResourceFactory.newClassPathResource("test_Jaxb.drl", getClass()), ResourceType.DRL); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); assertFalse(kbuilder.hasErrors()); assertFalse(kbuilder.hasErrors()); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeCommand setGlobalStage = PipelineFactory.newStatefulKnowledgeSessionSetGlobal("order"); JAXBContext jaxbCtx = KnowledgeBuilderHelper.newJAXBContext( jaxbConf.getClasses().toArray(new String[jaxbConf.getClasses().size()]), kbase); Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller(); Transformer transformer = PipelineFactory.newJaxbFromXmlTransformer(unmarshaller); transformer.setReceiver(setGlobalStage); Pipeline pipeline = PipelineFactory.newStatefulKnowledgeSessionPipeline(ksession); pipeline.setReceiver(transformer); String xml = StringUtils.readFileAsString( new InputStreamReader(getClass().getResourceAsStream("order.xml"))); ResultHandlerImpl resultHandler = new ResultHandlerImpl(); pipeline.insert(xml, resultHandler); // now round trip that global Action executeResult = PipelineFactory.newExecuteResultHandler(); Action assignAsResult = PipelineFactory.newAssignObjectAsResult(); assignAsResult.setReceiver(executeResult); // transformer = PipelineFactory.newXStreamToXmlTransformer( xstream ); Marshaller marshaller = jaxbCtx.createMarshaller(); transformer = PipelineFactory.newJaxbToXmlTransformer(marshaller); transformer.setReceiver(assignAsResult); KnowledgeRuntimeCommand getGlobalStage = PipelineFactory.newStatefulKnowledgeSessionGetGlobal(); getGlobalStage.setReceiver(transformer); pipeline = PipelineFactory.newStatefulKnowledgeSessionPipeline(ksession); pipeline.setReceiver(getGlobalStage); resultHandler = new ResultHandlerImpl(); pipeline.insert("order", resultHandler); assertEqualsIgnoreWhitespace(xml, (String) resultHandler.getObject()); }