On 2010-01-18 15.11, Stanislav Muhametsin wrote:
Sounds good. I hope the core-team approves this and it will get
implemented soon! :)

For method-constraints, I'm dabbling with a Concern that implements the check Right Now. Reasonably easy to implement, and works well. The only missing point is that I can't ensure that it runs before all other concerns, but for now that's acceptable to me at least.

Here's what I got in my test. Entity method looks like this:
   @Assigned(false)
   void assignTo( Assignee assignee );

Annotation is:
@ConstraintDeclaration
@Retention(RetentionPolicy.RUNTIME)
@Constraints(Assigned.Constraint.class)
public @interface Assigned
{
   public abstract boolean value() default true;

   public class Constraint
implements org.qi4j.api.constraint.Constraint<Assigned, Assignable.Data>
   {
      public boolean isValid( Assigned assigned, Assignable.Data value )
      {
         Assignee assignee = value.assignedTo().get();

         return assigned.value() == (assignee != null);
      }
   }
}
--
Assignable.Data is an internal mixin that has the assignedTo() association.

The concern simply looks up annotations with @ConstraintDeclaration, instantiates the constraint, and runs it on method invocation. Very very simple!

But like I said, this code will pretty much never be executed. What I'm primarily after is to let my clients find the @Assigned annotation and run it with the constraint on an entity, so that I can automatically see what operations are valid and update my client UI accordingly.

/Rickard

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

Reply via email to