Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 17707 invoked from network); 6 Nov 2003 17:45:09 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 6 Nov 2003 17:45:09 -0000 Received: (qmail 22775 invoked by uid 500); 6 Nov 2003 17:43:42 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 22742 invoked by uid 500); 6 Nov 2003 17:43:42 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@cocoon.apache.org Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 22709 invoked from network); 6 Nov 2003 17:43:40 -0000 Received: from unknown (HELO mail.cbim.it) (212.131.130.82) by daedalus.apache.org with SMTP; 6 Nov 2003 17:43:40 -0000 Received: from cuprouter.cbim.it (cuprouter.cbim.it [192.168.4.10]) by mail.cbim.it (8.11.6/8.11.0) with ESMTP id hA6I94M27351 for ; Thu, 6 Nov 2003 19:09:04 +0100 Received: from cbim.it (caterina.cbim.it [192.168.4.42]) by cuprouter.cbim.it (8.9.3/8.9.3) with ESMTP id SAA23480 for ; Thu, 6 Nov 2003 18:44:15 +0100 Message-ID: <3FAA8857.7010100@cbim.it> Date: Thu, 06 Nov 2003 18:43:51 +0100 From: Ugo Cei Organization: C.B.I.M. User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030314 X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: [Proposal] Add "enum" basetype and convertor to Woody Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I'd like to add an "enum" basetype and "enum" convertor to Woody. Those would work with types implementing Joshua Bloch's "typesafe enum" pattern [1]. The reason for this is as follows: when representing business entities with Java objects, I always try to assign a significant type to fields that can assume a value taken from a list, e.g. package com.example; public class Person { private Sex sex; ... } public class Sex { public static final Sex MALE = new Sex("M"); public static final Sex FEMALE = new Sex("F"); private String code; private Sex(String code) { this.code = code; } public String toString() { return code; // Will probably have some i18n support here } } ... person.setSex(Sex.FEMALE); ... Currently, in Woody we cannot directly bind form fields to objects of type "Sex" and it would be cumbersome to add a datatype and convertor for every possible enum (there could be many in even a small application) in cocoon.xconf. So we have to resort to manually converting to and from enums and strings (or integers). I am thinking about adding something that might allow to specify: com.example.Sex Maybe we could also generate a selection list from the enum type. One possible problem could be that the enum type must implement an interface providing methods for converting to/from strings or integers. This could be impossible or problematic when dealing with existing classes. However, I haven't really thought about the implementation, yet. WDYT? Ugo [1]: http://developer.java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums -- Ugo Cei - Consorzio di Bioingegneria e Informatica Medica P.le Volontari del Sangue, 2 - 27100 Pavia - Italy Phone: +39.0382.525100 - E-mail: u.cei@cbim.it