public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) { ActionNode actionNode = ( ActionNode ) node; DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction(); ActionDescr actionDescr = new ActionDescr(); actionDescr.setText( action.getConsequence() ); actionDescr.setResource(processDescr.getResource()); ProcessDialect dialect = ProcessDialectRegistry.getDialect( action.getDialect() ); dialect.getActionBuilder().build( context, action, actionDescr, (NodeImpl) node ); }
StringUtils.ucFirst(context.getProcessDescr().getClassName())); context.getProcessDescr().getClassName() + StringUtils.ucFirst(className) + "Invoker");
PackageRegistry pkgRegistry = this.knowledgeBuilder.getOrCreatePackageRegistry(new PackageDescr(process.getPackageName())); if (pkgRegistry != null) { InternalKnowledgePackage p = pkgRegistry.getPackage(); ProcessDescr processDescr = new ProcessDescr(); processDescr.setName(process.getPackageName() + "." + process.getName()); processDescr.setResource( resource ); processDescr.setProcessId( process.getId() ); DialectCompiletimeRegistry dialectRegistry = pkgRegistry.getDialectCompiletimeRegistry(); Dialect dialect = dialectRegistry.getDialect( "java" );
final InternalKnowledgePackage pkg = new KnowledgePackageImpl( "pkg1" ); ActionDescr actionDescr = new ActionDescr(); actionDescr.setText( "list.add( \"hello world\" );" ); JavaDialect javaDialect = ( JavaDialect ) dialectRegistry.getDialect( "java" ); ProcessDescr processDescr = new ProcessDescr(); processDescr.setClassName( "Process1" ); processDescr.setName( "Process1" );
@Test public void testRuleFlow() throws Exception { InputStream in = this.getClass().getResourceAsStream( "/org/jbpm/integrationtests/ruleflow.rfm" ); assertNotNull( in ); builder.addPackage( new PackageDescr( "com.sample" ) ); builder.addRuleFlow( new InputStreamReader( in ) ); InternalKnowledgePackage pkg = builder.getPackage("com.sample"); assertNotNull( pkg ); Map<String, Process> flows = pkg.getRuleFlows(); assertNotNull( flows ); assertEquals( 1, flows.size() ); assertTrue( flows.containsKey( "0" ) ); Process p = (Process) flows.get( "0" ); assertTrue( p instanceof WorkflowProcessImpl ); //now serialization InternalKnowledgePackage pkg2 = (InternalKnowledgePackage) DroolsStreamUtils.streamIn( DroolsStreamUtils.streamOut( pkg ) ); assertNotNull( pkg2 ); flows = pkg2.getRuleFlows(); assertNotNull( flows ); assertEquals( 1, flows.size() ); assertTrue( flows.containsKey( "0" ) ); p = (Process) flows.get( "0" ); assertTrue( p instanceof WorkflowProcessImpl ); }
@Test public void testReturnValueDescrCreation() throws Exception { TestJavaProcessDialect javaProcessDialect = new TestJavaProcessDialect(); ProcessDialectRegistry.setDialect("java", javaProcessDialect); String filename = "BPMN2-GatewaySplit-SequenceConditions.bpmn2"; KieBase kbase = createKnowledgeBase(filename); assertFalse( "No " + ActionDescr.class.getSimpleName() + " instances caught for testing!", javaProcessDialect.getActionDescrs().isEmpty() ); for( BaseDescr descr : javaProcessDialect.getActionDescrs() ) { assertNotNull( descr.getClass().getSimpleName() +" has a null resource field", descr.getResource() ); } assertFalse( "No " + ReturnValueDescr.class.getSimpleName() + " instances caught for testing!", javaProcessDialect.getReturnValueDescrs().isEmpty() ); for( BaseDescr descr : javaProcessDialect.getReturnValueDescrs() ) { assertNotNull( descr.getClass().getSimpleName() +" has a null resource field", descr.getResource() ); } }
returnValueDescr.setResource(processDescr.getResource());
final InternalKnowledgePackage pkg = new KnowledgePackageImpl("pkg1"); ActionDescr actionDescr = new ActionDescr(); actionDescr.setText( "var testString; print('Hello')" ); ProcessDescr processDescr = new ProcessDescr(); processDescr.setClassName("Process1"); processDescr.setName("Process1");
protected void buildAction(DroolsAction droolsAction, ProcessBuildContext context, NodeImpl node) { DroolsConsequenceAction action = (DroolsConsequenceAction) droolsAction; ActionDescr actionDescr = new ActionDescr(); actionDescr.setText( action.getConsequence() ); actionDescr.setResource(context.getProcessDescr().getResource()); ProcessDialect dialect = ProcessDialectRegistry.getDialect( action.getDialect() ); dialect.getActionBuilder().build( context, action, actionDescr, node); }
assertNotNull( in ); builder.addPackage( new PackageDescr( "com.sample" ) );
public void build(final PackageBuildContext context, final DroolsAction action, final ActionDescr actionDescr, final ContextResolver contextResolver) { String text = actionDescr.getText(); JavaScriptAction expr = new JavaScriptAction(text); action.setMetaData("Action", expr ); }
buffer.append( "public class " + StringUtils.ucFirst( processDescr.getClassName() ) + " {" + lineSeparator ); buffer.append( " private static final long serialVersionUID = 510l;" + lineSeparator );
public void buildContexts(ContextContainer contextContainer, ProcessBuildContext buildContext) { List<Context> exceptionScopes = contextContainer.getContexts(ExceptionScope.EXCEPTION_SCOPE); if (exceptionScopes != null) { for (Context context: exceptionScopes) { // TODO: OCRAM: add compensation scope to process builder???? ExceptionScope exceptionScope = (ExceptionScope) context; for (ExceptionHandler exceptionHandler: exceptionScope.getExceptionHandlers().values()) { if (exceptionHandler instanceof ActionExceptionHandler) { DroolsConsequenceAction action = (DroolsConsequenceAction) ((ActionExceptionHandler) exceptionHandler).getAction(); ActionDescr actionDescr = new ActionDescr(); actionDescr.setText( action.getConsequence() ); actionDescr.setResource(buildContext.getProcessDescr().getResource()); ProcessDialect dialect = ProcessDialectRegistry.getDialect( action.getDialect() ); dialect.getActionBuilder().build( buildContext, action, actionDescr, (ProcessImpl) buildContext.getProcess() ); } } } } }
protected AnalysisResult getAnalysis(final PackageBuildContext context, final ActionDescr actionDescr) { JavaDialect dialect = (JavaDialect) context.getDialect( "java" ); Map<String, Class<?>> variables = new HashMap<String,Class<?>>(); BoundIdentifiers boundIdentifiers = new BoundIdentifiers(variables, context); AnalysisResult analysis = dialect.analyzeBlock( context, actionDescr, actionDescr.getText(), boundIdentifiers); return analysis; }
public void generateTemplates(final String ruleTemplate, final String invokerTemplate, final ProcessBuildContext context, final String className, final Map vars, final Object invokerLookup, final BaseDescr descrLookup) { TemplateRegistry registry = getRuleTemplateRegistry(); context.getMethods().add((String) TemplateRuntime.execute(registry.getNamedTemplate(ruleTemplate), null, new MapVariableResolverFactory(vars), registry) ); registry = getInvokerTemplateRegistry(); final String invokerClassName = context.getPkg().getName() + "." + context.getProcessDescr().getClassName() + StringUtils.ucFirst(className) + "Invoker"; context.getInvokers().put(invokerClassName, (String)TemplateRuntime.execute(registry.getNamedTemplate(invokerTemplate), null, new MapVariableResolverFactory(vars), registry) ); context.addInvokerLookup(invokerClassName, invokerLookup); context.addDescrLookups(invokerClassName, descrLookup); }
public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) { super.build(process, processDescr, context, node); ActionNode actionNode = ( ActionNode ) node; DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction(); ActionDescr actionDescr = new ActionDescr(); actionDescr.setText( action.getConsequence() ); actionDescr.setResource(processDescr.getResource()); ProcessDialect dialect = ProcessDialectRegistry.getDialect( action.getDialect() ); dialect.getActionBuilder().build( context, action, actionDescr, (NodeImpl) node ); Transformation transformation = (Transformation) node.getMetaData().get("Transformation"); if (transformation != null) { WorkflowProcess wfProcess = (WorkflowProcess) process; Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("imports", wfProcess.getImports()); parameters.put("classloader", context.getConfiguration().getClassLoader()); DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage()); transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters)); } }
protected void buildAction(final PackageBuildContext context, final DroolsAction action, final ActionDescr actionDescr, final ContextResolver contextResolver, String className, AnalysisResult analysis) { Set<String> identifiers = analysis.getBoundIdentifiers().getGlobals().keySet(); final Map map = createVariableContext( className, actionDescr.getText(), (ProcessBuildContext) context, (String[]) identifiers.toArray( new String[identifiers.size()] ), analysis.getNotBoundedIdentifiers(), contextResolver); map.put( "text", ProcessKnowledgeHelperFixer.fix( actionDescr.getText() )); generateTemplates( "actionMethod", "actionInvoker", (ProcessBuildContext)context, className, map, action, actionDescr ); collectTypes("JavaDialect", analysis, (ProcessBuildContext)context); }
context.getPkg().getName() + "." + processDescr.getClassName(), processDescr, processClass,
public void build(final PackageBuildContext context, final DroolsAction action, final ActionDescr actionDescr, final ContextResolver contextResolver) { String text = processMacros( actionDescr.getText() ); Map<String, Class<?>> variables = new HashMap<String,Class<?>>(); try { MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" ); MVELAnalysisResult analysis = getAnalysis(context, actionDescr, dialect, text, variables); if ( analysis == null ) { // not possible to get the analysis results return; } buildAction(context, action, actionDescr, contextResolver, dialect, analysis, text, variables); } catch ( final Exception e ) { context.getErrors().add( new DescrBuildError( context.getParentDescr(), actionDescr, null, "Unable to build expression for action '" + actionDescr.getText() + "' :" + e ) ); } }