Perhaps I should show you how the Composite is declared too:

@Concerns(MessageConcern.class)
@Mixins([SubjectMixin.class,ContentMixin.class])
@SideEffects(MessageSideEffect.class)
interface MessageEntity extends MessageBehaviour, Composite {}

And here's the test:

SingletonAssembler assembler = new MySingletonAssembler()
CompositeBuilder<MessageEntity> builder =
assembler.compositeBuilderFactory().newCompositeBuilder(MessageEntity.class)
builder.stateFor(MessageState.class).subject().set "shout"
builder.stateFor(MessageState.class).content().set "speak"
MessageEntity me = builder.newInstance()
println me.giveMeContent()
println me.giveMeSubject()

>> abstract class MessageConcern extends ConcernOf<MessageBehaviour>
>> implements MessageBehaviour {
>>    String giveMeContent() {
>>        return 'concern for ' + next.giveMeContent()
>>    }
>> }
>
> The above also contains the 'next' member, so are you sure it works?

Yes, it works.

>> abstract class MessageSideEffect extends ConcernOf<MessageBehaviour>
>> implements MessageBehaviour {
>>    String giveMeContent() {
>>        println "sideeffect in action " + next
>>        return null
>>    }
>> }
>>
>> It gives the result:
>>
>> sideeffect in action concern for speak
>> concern for speak
>> shout
>
> Very strange. I presume that you have concern, sideeffect and mixin
> doing output.

That is correct.

> The client programmer will not see that only the reference is saved,
> and as a few other things, (Many)Associations are lazy-loaded, i.e. if
> not traversed it won't be read from storage.

But it means that I exlicitly have to save each entity, even though
is's referenced by another one being saved? Just double checking to
see if I understand you correctly. When I save an object graph, each
object (or composite) needs to be saved explicity. When I access them
again, they will be lazy loaded from the store. Do I understand you
correctly?

> As for your Groovy experiments, you are pretty much on your own, we
> won't be able to support you much, since we don't even know if it is
> supposed to work at all. Further, we have Groovy support at Mixin
> level, i.e. letting you easily implement Mixin code in Groovy. Perhaps
> that is good enough. I guess similar support can be done for both
> Concerns and SideEffects...

Ok, I understand. Perhaps this is an error for the Groovy team.

Btw, Rickard spotted an error in my SideEffect declaration. It
inherited from ConcernOf instead of SideEffectOf. I changed that but
the same error occurs. And the order of execution didn't change.

I have a Java example which is almost identical. And it seems I get
the same problem with the order of execution. Here's the composite
declaration:

@Concerns(MessageConcern.class)
@Mixins(MessageMixin.class)
@SideEffects(MessageSideEffect.class)
public interface MessageEntity extends MessageBehaviour, Composite {}

And mixin, concern and sideeffect:

public abstract class MessageMixin implements MessageEntity {
    @This MessageState state;
    public String giveMeContent( ) {
        return state.content().get();
    }
}

public abstract class MessageConcern extends
ConcernOf<MessageBehaviour> implements MessageBehaviour {
    public String giveMeContent() {
        return "Concern for " + next.giveMeContent();
    }
}

public abstract class MessageSideEffect extends
SideEffectOf<MessageBehaviour> implements MessageBehaviour {
    public String giveMeContent() {
        String s = next.giveMeContent();
        System.out.println("sideeffect for " + s);
        return null;
    }
}

And the test:

CompositeBuilder<MessageEntity> builder =
assembler.compositeBuilderFactory().newCompositeBuilder(MessageEntity.class);
builder.stateFor(MessageState.class).subject().set("Subject");
builder.stateFor(MessageState.class).content().set("Content");
MessageEntity me = builder.newInstance();
System.out.println(me.giveMeContent());

The result:

sideeffect for Concern for Content
Concern for Content

It appears like the SideEffect is executed first.

One other question: If the SideEffect is to be executed last, what
will "next" refer to? Other sideeffects later in the chain?

Best regards,
Pelle P

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to