On Fri, Jun 26, 2009 at 4:56 AM, Thiago Souza<[email protected]> wrote:

>     BTW, does qi4j supports some sort of abstract mixins (or even purely
> dynamic ones) so there is no need to implement dummy getter/setter method
> implementions?

Let me answer this part first, and I'll get back to the 'engineering'
question later;

The answer is YES to both. For the "abstract mixin", this is an example;

@Mixins( { Habba1Mixin.class, Habba2Mixin.class } )
public interface Habba extends ValueComposite
{
    void doSomething1();
    void doSomething2();
}

public abstract class Habba1Mixin
    implements Habba
{
    public void doSomething1()
    {
        //
    }
}

public abstract class Habba2Mixin
    implements Habba
{
    public void doSomething2()
    {
        //
    }
}

The above will work.

And if you implement InvocationHandler, it will be used. Typically
that is done in conjunction with @AppliesTo to selective figure out
exactly which methods are mapped to which mixins. So for instance,
look at PropertyMixin, which takes care of all the Property methods
and is 'hardcoded' into the Composite interface;

@AppliesTo( { PropertyMixin.PropertyFilter.class } )
public class PropertyMixin
    implements InvocationHandler
{
    @State private StateHolder state;

    public Object invoke( Object proxy, Method method, Object[] args )
        throws Throwable
    {
        return state.getProperty( method );
    }

    public static class PropertyFilter
        implements AppliesToFilter, Serializable
    {
        public boolean appliesTo( Method method, Class<?> mixin,
Class<?> compositeType, Class<?> modifierClass )
        {
            return Property.class.isAssignableFrom( method.getReturnType() );
        }
    }
}

The AppliesToFilter is evaluated at assembly time, before the
application is activated, and determines which mixin is bound to which
method. The above is all there is to handling the Property methods,
such as;

   Property<String> name();

You can use exactly the same approach for your generic mixins. The
@AppliesTo can contain 3 things; AppliesToFilter, Annotation or Class.
So the first one you see an example of above. The annotation means
that "Use this mixin for methods that are annotated with the given
annotation.", and finally the Class is "Use this mixin when the
composite interface is of this class".


Cheers
-- 
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