@@ -52,12 +52,19 @@ public final class MorphBuilder extends AbstractMetamorphDomWalker {
52
52
53
53
private static final class StackFrame {
54
54
55
+ private final NamedValuePipe headPipe ;
56
+
55
57
private NamedValuePipe pipe ;
56
58
private boolean inEntityName ;
57
59
private boolean inCondition ;
58
60
59
- public StackFrame (final NamedValuePipe pipe ) {
60
- this .pipe = pipe ;
61
+ public StackFrame (final NamedValuePipe headPipe ) {
62
+ this .headPipe = headPipe ;
63
+ this .pipe = headPipe ;
64
+ }
65
+
66
+ public NamedValuePipe getHeadPipe () {
67
+ return headPipe ;
61
68
}
62
69
63
70
public void setPipe (final NamedValuePipe pipe ) {
@@ -250,7 +257,8 @@ protected void exitIf(final Node nameNode) {
250
257
@ Override
251
258
protected void enterCollect (final Node node ) {
252
259
final Map <String , String > attributes = resolvedAttributeMap (node );
253
- // must be set after recursive calls to flush descendants before parent
260
+ // flushWith should not be passed to the headPipe object via a
261
+ // setter (see newInstance):
254
262
attributes .remove (AttributeName .FLUSH_WITH .getString ());
255
263
256
264
if (!getCollectFactory ().containsKey (node .getLocalName ())) {
@@ -264,22 +272,24 @@ protected void enterCollect(final Node node) {
264
272
265
273
@ Override
266
274
protected void exitCollect (final Node node ) {
267
- final NamedValuePipe collectPipe = stack .pop ().getPipe ();
275
+ final StackFrame currentCollect = stack .pop ();
276
+ final Collect collector = (Collect ) currentCollect .getHeadPipe ();
277
+ final NamedValuePipe tailPipe = currentCollect .getPipe ();
268
278
269
279
final NamedValuePipe interceptor = interceptorFactory .createNamedValueInterceptor ();
270
280
final NamedValuePipe delegate ;
271
- if (interceptor == null || collectPipe instanceof Entity ) {
281
+ if (interceptor == null || tailPipe instanceof Entity ) {
272
282
// The result of entity collectors cannot be intercepted
273
283
// because they only use the receive/emit interface for
274
284
// signalling while the actual data is transferred using
275
285
// a custom mechanism. In order for this to work the Entity
276
286
// class checks whether source and receiver are an
277
287
// instances of Entity. If an interceptor is inserted between
278
288
// entity elements this mechanism will break.
279
- delegate = collectPipe ;
289
+ delegate = tailPipe ;
280
290
} else {
281
291
delegate = interceptor ;
282
- delegate .addNamedValueSource (collectPipe );
292
+ delegate .addNamedValueSource (tailPipe );
283
293
}
284
294
285
295
final StackFrame parent = stack .peek ();
@@ -296,11 +306,8 @@ protected void exitCollect(final Node node) {
296
306
// must be set after recursive calls to flush descendants before parent
297
307
final String flushWith = resolvedAttribute (node , AttributeName .FLUSH_WITH );
298
308
if (null != flushWith ) {
299
- assert collectPipe instanceof Collect :
300
- "Invokations of enterXXX and exitXXX are not properly balanced" ;
301
-
302
- ((Collect ) collectPipe ).setWaitForFlush (true );
303
- registerFlush (flushWith , ((Collect ) collectPipe ));
309
+ collector .setWaitForFlush (true );
310
+ registerFlush (flushWith , collector );
304
311
}
305
312
}
306
313
0 commit comments