1 /*
2 * Copyright (c) 2001 - 2005 ivata limited.
3 * All rights reserved.
4 * -----------------------------------------------------------------------------
5 * ivata masks may be redistributed under the GNU General Public
6 * License as published by the Free Software Foundation;
7 * version 2 of the License.
8 *
9 * These programs are free software; you can redistribute them and/or
10 * modify them under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; version 2 of the License.
12 *
13 * These programs are distributed in the hope that they will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * See the GNU General Public License in the file LICENSE.txt for more
18 * details.
19 *
20 * If you would like a copy of the GNU General Public License write to
21 *
22 * Free Software Foundation, Inc.
23 * 59 Temple Place - Suite 330
24 * Boston, MA 02111-1307, USA.
25 *
26 *
27 * To arrange commercial support and licensing, contact ivata at
28 * http://www.ivata.com/contact.jsp
29 * -----------------------------------------------------------------------------
30 * $Log: ValueObjectFieldValueConvertor.java,v $
31 * Revision 1.2 2005/04/09 18:04:15 colinmacleod
32 * Changed copyright text to GPL v2 explicitly.
33 *
34 * Revision 1.1 2005/01/19 12:32:24 colinmacleod
35 * First version. Extracts id for hidden fields.
36 *
37 * -----------------------------------------------------------------------------
38 */
39 package com.ivata.mask.field.valueobject;
40
41 import com.ivata.mask.field.FieldValueConvertor;
42 import com.ivata.mask.valueobject.ValueObject;
43
44 /***
45 * Write out the id field of a value object for hidden fields.
46 *
47 * @since ivata masks 0.5 (2005-01-14)
48 * @author Colin MacLeod
49 * <a href="mailto:colin.macleod@ivata.com">colin.macleod@ivata.com</a>
50 * @version $Revision: 1.2 $
51 */
52
53 public class ValueObjectFieldValueConvertor extends FieldValueConvertor {
54 /***
55 * Overridden to get the id string of a value object for hidden fields.
56 *
57 * @param valueObjectParam value object for which to get the id string.
58 * @return id string of the value object provided.
59 */
60 protected String toString(final Object valueObjectParam) {
61 if (valueObjectParam == null) {
62 return null;
63 }
64 // if we got a value object, put that out
65 if (valueObjectParam instanceof ValueObject) {
66 // TODO: for now, it only handles a single value object - it should
67 // also handle a collection
68 return ((ValueObject) valueObjectParam).getIdString();
69 } else {
70 // otherwise, assume it maps to an id
71 return valueObjectParam.toString();
72 }
73 }
74 }