Are you talking about LifeCycle or Initializable??

They are handled slightly differently. First of all, LifeCycle methods
are only called upon creation/deletion of the Entity, not the instance
representing the entity in memory. Also, I vaguely recall that for
non-Entities, LifeCycle has no meaning.

I also recall that unlike other methods, LifeCycle methods are called
on ALL mixins of the Entity (need to verify this, since *I* normally
limit LifeCycle to a single Mixin.).

On the other hand, Initializable is called (if defined) when a Mixin
(that implements it) is instantiated.


Does that help??


On Sat, Oct 23, 2010 at 4:30 AM, Stanislav Muhametsin
<[email protected]> wrote:
> 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
>



-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

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

Reply via email to