Quoting Stanislav Muhametsin <[email protected]>:
I dug this email out from naphtaline, as I kinda run into a problem
with Lifecycle. I implemented the code example shown in Lifecycle's
javadoc (and fixed numerous typos and errors). I ran the test, and
it didn't call the create() method. As a consequence, it threw
ConstaintViolationException, as the admin() property was never set.
Then I search my mail folder and found this mail. Niclas mentioned
searching methods of private mixins, and I thought he meant to add
something like this into SystemAdminMixin:
@This private Dummy _dummy;
public static interface Dummy
{
public void dummy();
}
public static class DummyMixin
implements Dummy
{
public void dummy() {}
}
But, alas, it still didn't work. Even adding Lifecycle to
implementation list of DummyMixin didn't work. In fact, I could
leave out the whole DummyMixin from @Mixins-list of SystemEntity and
Qi4j runtime would still start up. It seems that it doesn't scan
these private mixins anymore?
Since I've misunderstood this issue before, I rather ask here first
than create JIRA issue. So, the question: how do I implement
Lifecycle functionality for role-interfaces, which are empty or have
only Property/Association/ManyAssociation methods?
Well, I found a work-around. In SystemAdminMixin, make it implement
Identity, and do
@State StateHolder _state;
// Just a call-through to return actual identity.
public Property<String> identity()
{
return this._state.getProperty( QualifiedName.fromClass(
Identity.class, "identity" ) );
}
This way, you create "own implementation" for Identity role, and that
triggers addition of this mixin to composite's mixin list. Still, is a
bit of a hacky. Alternative, but equally hacky way is to make @State
annotation to EntityStateHolder, and override admin() association
method in System interface. However, only overriding identity() works
for adding Lifecycle functionality to empty role interfaces. And even
with this 'solution', only one empty role for each entity type is
supported, since only one identity() method implementation will get
picked by Qi4j runtime (AFAIK).
Looking at all this, I think it would be nice to have a good, robust,
and most importantly, clear, way of implementing Lifecycle
functionality, without private-mixin- or
overriding-property-method-hacks. Maybe a separate @LifeCycle
annotation, in style of @Mixins.
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev