On 30-okt-05, at 18:35, JR Boyens wrote:

I think this is fine. While I don't know if I would ever use it (I suspect I would) I think it fills a void.

I think the implementation that Geert suggested is perfect (except that his POJO extends something, but I'm sure that is a typo).

Blergh, it is :-/
Did it too fast, it should be like this of course:

Traditional method
==================

public class Blog extends CmfValidation
{
    private int     mId = -1;
    private Date    mMoment = Calendar.getInstance().getTime();
    private byte[]  mImage = null;
    private String  mTitle = null;
    private String  mBody = null;
    private boolean mDraft = false;

    protected void activateValidation()
    {
        addConstraint(new ConstrainedBean()
            .defaultOrder("moment", ConstrainedBean.DESC)
            .defaultOrder("title"));

        addConstraint(new CmfProperty("id")
            .editable(false)
            .identifier(true));
        addConstraint(new CmfProperty("moment")
            .listed(true)
            .notNull(true));
        addConstraint(new CmfProperty("image")
            .listed(true)
            .mimeType(MimeType.IMAGE_PNG)
            .contentAttribute("width", 150)
            .notNull(true)
            .file(true));
        addConstraint(new CmfProperty("title")
            .listed(true)
            .notNull(true)
            .notEmpty(true)
            .maxLength(100));
        addConstraint(new CmfProperty("body")
            .mimeType(MimeType.APPLICATION_XHTML)
            .autoRetrieved(true)
            .fragment(true)
            .notNull(true)
            .notEmpty(true));
        addConstraint(new CmfProperty("draft")
            .notNull(true)
            .defaultValue(false));
    }

    // accessors omitted
}

True POJO method
================

public class Blog
{
    private int     mId = -1;
    private Date    mMoment = Calendar.getInstance().getTime();
    private byte[]  mImage = null;
    private String  mTitle = null;
    private String  mBody = null;
    private boolean mDraft = false;

    // accessors omitted
}

public class BlogMetaData extends CmfValidation
{
    protected void activateValidation()
    {
        addConstraint(new ConstrainedBean()
            .defaultOrder("moment", ConstrainedBean.DESC)
            .defaultOrder("title"));

        addConstraint(new CmfProperty("id")
            .editable(false)
            .identifier(true));
        addConstraint(new CmfProperty("moment")
            .listed(true)
            .notNull(true));
        addConstraint(new CmfProperty("image")
            .listed(true)
            .mimeType(MimeType.IMAGE_PNG)
            .contentAttribute("width", 150)
            .notNull(true)
            .file(true));
        addConstraint(new CmfProperty("title")
            .listed(true)
            .notNull(true)
            .notEmpty(true)
            .maxLength(100));
        addConstraint(new CmfProperty("body")
            .mimeType(MimeType.APPLICATION_XHTML)
            .autoRetrieved(true)
            .fragment(true)
            .notNull(true)
            .notEmpty(true));
        addConstraint(new CmfProperty("draft")
            .notNull(true)
            .defaultValue(false));
    }
}

--
Geert Bevin                       Uwyn bvba
"Use what you need"               Avenue de Scailmont 34
http://www.uwyn.com               7170 Manage, Belgium
gbevin[remove] at uwyn dot com    Tel +32 64 84 80 03

PGP Fingerprint : 4E21 6399 CD9E A384 6619  719A C8F4 D40D 309F D6A9
Public PGP key  : available at servers pgp.mit.edu, wwwkeys.pgp.net


_______________________________________________
Rife-users mailing list
Rife-users@uwyn.com
http://www.uwyn.com/mailman/listinfo/rife-users

Reply via email to