public Transformed<ElementGraph> performTransform( PlannerContext plannerContext, ElementGraph rootGraph ) { Transformed<ElementGraph> result = new Transformed<>( plannerContext, this, rootGraph ); ElementGraph graphCopy = rootGraph.copyElementGraph(); Transformed<ElementGraph> transformed = graphTransformer.transform( plannerContext, graphCopy ); result.addChildTransform( transformed ); if( transformed.getEndGraph() != null && !rootGraph.equals( transformed.getEndGraph() ) ) result.setEndGraph( transformed.getEndGraph() ); return result; }
@Override public void writeDOTs( String path ) { int count = 0; if( expressionGraph != null ) { String fileName = String.format( "expression-graph-%s.dot", expressionGraph.getClass().getSimpleName() ); expressionGraph.writeDOT( new File( path, fileName ).toString() ); } for( int i = 0; i < getChildTransforms().size(); i++ ) { Transformed transformed = getChildTransforms().get( i ); String name = transformed.getTransformerName(); String pathName = String.format( "%s/child-%d-%s/", path, i, name ); transformed.writeDOTs( pathName ); } count = writeBeginGraph( path, count ); for( ElementGraph recursion : getRecursions() ) { String name = recursion.getClass().getSimpleName(); recursion.writeDOT( new File( path, makeFileName( count++, name, "recursion" ) ).toString() ); } writeEndGraph( path, count ); } }
private void markTransformed( Transformed transformed, Path path ) { if( transformed.getEndGraph() != null && !transformed.getBeginGraph().equals( transformed.getEndGraph() ) ) markFolder( path, GREEN ); }
@Override protected ElementGraph prepareForMatch( ProcessLogger processLogger, Transformed<ElementGraph> transformed, ElementGraph graph ) { if( graphTransformer == null ) return graph; if( processLogger.isDebugEnabled() ) processLogger.logDebug( "transforming with: {}", graphTransformer.getClass().getSimpleName() ); Transformed child = graphTransformer.transform( transformed.getPlannerContext(), graph ); transformed.addChildTransform( child ); return child.getEndGraph(); } }
private ElementGraph transform( ElementGraph flowElementGraph, RuleExpression ruleExpression ) { RuleRegistry ruleRegistry = new RuleRegistry(); ruleRegistry.addElementFactory( NonTapFactory.TEMP_TAP, new NonTapFactory() ); PlannerContext plannerContext = new PlannerContext( ruleRegistry, null, null, null, true ); RuleInsertionTransformer ruleTempTapInsertionTransformer = new RuleInsertionTransformer( PlanPhase.PreResolveAssembly, ruleExpression, IntermediateTapElementFactory.TEMP_TAP ); Transformed<ElementGraph> insertionTransformed = ruleTempTapInsertionTransformer.transform( plannerContext, flowElementGraph ); insertionTransformed.writeDOTs( getPlanPath() ); return insertionTransformed.getEndGraph(); }
public ElementGraph getContractedGraph() { if( contractedGraph == null ) { contractedTransformed = contractedTransformer.transform( plannerContext, elementGraph ); contractedGraph = contractedTransformed.getEndGraph(); } return contractedGraph; }
@Override public void writeDOTs( String path ) { int count = 0; for( int i = 0; i < getChildTransforms().size(); i++ ) { Transformed transformed = getChildTransforms().get( i ); String name = transformed.getTransformerName(); transformed.writeDOTs( path + "/child-" + i + "-" + name + "/" ); } count = writeBeginGraph( path, count ); writeEndGraph( path, count ); } }
@Override public Transformed<E> transform( PlannerContext plannerContext, E rootGraph ) { int maxDepth = plannerContext.getIntProperty( TRANSFORM_RECURSION_DEPTH_MAX, DEFAULT_TRANSFORM_RECURSION_DEPTH_MAX ); Transformed<E> transformed = new Transformed<>( plannerContext, this, expressionGraph, rootGraph ); E result = transform( plannerContext.getLogger(), transformed, rootGraph, maxDepth, 0 ); transformed.setEndGraph( result ); return transformed; }
match = finder.findAllMatches( transformed.getPlannerContext(), prepared, exclusions ); else match = finder.findFirstMatch( transformed.getPlannerContext(), prepared, exclusions ); return graph; transformed.addRecursionTransform( graph );
public String getRuleName() { if( getGraphTransform() instanceof Rule ) return ( (Rule) getGraphTransform() ).getRuleName(); return "none"; }
@Override protected boolean transformGraphInPlaceUsing( Transformed<ElementGraph> transformed, ElementGraph graph, Match match ) { ElementFactory elementFactory = transformed.getPlannerContext().getElementFactoryFor( factoryName ); if( elementFactory == null ) return false; Set<FlowElement> captured = match.getCapturedElements( ElementCapture.Primary ); if( captured.isEmpty() ) return false; else if( captured.size() != 1 ) throw new IllegalStateException( "expected one, but found multiple flow elements in the match expression: " + captured ); FlowElement replace = captured.iterator().next(); FlowElement replaceWith = elementFactory.create( graph, replace ); ElementGraphs.replaceElementWith( graph, replace, replaceWith ); return true; } }
public void addChildTransform( Transformed transformed ) { if( plannerContext.isTransformTracingEnabled() ) getChildTransforms().add( transformed ); }
void addRecursionTransform( ElementGraph transformed ) { recursionCount++; if( plannerContext.isTransformTracingEnabled() ) getRecursions().add( new ElementMultiGraph( transformed ) ); }
@Override protected ElementGraph prepareForMatch( ProcessLogger processLogger, Transformed<ElementGraph> transformed, ElementGraph graph ) { if( graphTransformer == null ) return makeAnnotated( graph ); Transformed child = graphTransformer.transform( transformed.getPlannerContext(), graph ); transformed.addChildTransform( child ); ElementGraph endGraph = child.getEndGraph(); return makeAnnotated( endGraph ); }
transformed.writeDOTs( getPlanPath() + "/transform/" ); result.getEndGraph().writeDOT( getPlanPath() + "/pipeline/" + count + "-cleaned-graph.dot" );
public Asserted assertion( PlannerContext plannerContext, E graph ) { Transformed<E> transform = transform( plannerContext, graph ); if( transform != null && transform.getEndGraph() != null ) graph = transform.getEndGraph(); Match match = finder.findFirstMatch( plannerContext, graph ); Asserted asserted = new Asserted( plannerContext, this, graph, message, assertionType, match ); if( transform != null ) asserted.addChildTransform( transform ); return asserted; } }
public String getTransformerName() { return getGraphTransform().getClass().getSimpleName(); }
return false; ElementFactory elementFactory = transformed.getPlannerContext().getElementFactoryFor( factoryName );
public Transformed<ElementSubGraph> transform( PlannerContext plannerContext, ElementGraph rootGraph ) { Transformed<ElementSubGraph> transformed = new Transformed<>( plannerContext, this, subGraphMatcher, rootGraph ); try { Transformed contractedTransformed = graphTransformer.transform( plannerContext, rootGraph ); // contracted graph transform transformed.addChildTransform( contractedTransformed ); // apply contracted sub-graph matcher to get the bounded sub-graph of the original graph ElementGraph contractedGraph = contractedTransformed.getEndGraph(); Match match = findAllPrimaries ? subGraphFinder.findAllMatches( plannerContext, contractedGraph ) : subGraphFinder.findFirstMatch( plannerContext, contractedGraph ); if( !match.foundMatch() ) return transformed; ElementGraph contractedSubGraph = match.getMatchedGraph(); ElementSubGraph resultSubGraph = asSubGraphOf( rootGraph, contractedSubGraph ); // the bounded sub-graph of the rootGraph transformed.setEndGraph( resultSubGraph ); return transformed; } catch( Throwable throwable ) { throw new TransformException( throwable, transformed ); } }
ElementGraph endGraph = transformed.getEndGraph();