001: /*
002: * Copyright (c) 2001 - 2005 ivata limited.
003: * All rights reserved.
004: * -----------------------------------------------------------------------------
005: * ivata masks may be redistributed under the GNU General Public
006: * License as published by the Free Software Foundation;
007: * version 2 of the License.
008: *
009: * These programs are free software; you can redistribute them and/or
010: * modify them under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; version 2 of the License.
012: *
013: * These programs are distributed in the hope that they will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: *
017: * See the GNU General Public License in the file LICENSE.txt for more
018: * details.
019: *
020: * If you would like a copy of the GNU General Public License write to
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place - Suite 330
024: * Boston, MA 02111-1307, USA.
025: *
026: *
027: * To arrange commercial support and licensing, contact ivata at
028: * http://www.ivata.com/contact.jsp
029: * -----------------------------------------------------------------------------
030: * $Log: ValueObjectFieldValueConvertor.java,v $
031: * Revision 1.4 2005/10/02 14:06:32 colinmacleod
032: * Added/improved log4j logging.
033: *
034: * Revision 1.3 2005/09/14 12:51:52 colinmacleod
035: * Added serialVersionUID.
036: *
037: * Revision 1.2 2005/04/09 18:04:15 colinmacleod
038: * Changed copyright text to GPL v2 explicitly.
039: *
040: * Revision 1.1 2005/01/19 12:32:24 colinmacleod
041: * First version. Extracts id for hidden fields.
042: *
043: * -----------------------------------------------------------------------------
044: */
045: package com.ivata.mask.field.valueobject;
046:
047: import org.apache.log4j.Logger;
048:
049: import com.ivata.mask.field.FieldValueConvertor;
050: import com.ivata.mask.valueobject.ValueObject;
051:
052: /**
053: * Write out the id field of a value object for hidden fields.
054: *
055: * @since ivata masks 0.5 (2005-01-14)
056: * @author Colin MacLeod
057: * <a href="mailto:colin.macleod@ivata.com">colin.macleod@ivata.com</a>
058: * @version $Revision: 1.4 $
059: */
060:
061: public class ValueObjectFieldValueConvertor extends FieldValueConvertor {
062: /**
063: * Logger for this class.
064: */
065: private static final Logger logger = Logger
066: .getLogger(ValueObjectFieldValueConvertor.class);
067:
068: /**
069: * Serialization version (for <code>Serializable</code> interface).
070: */
071: private static final long serialVersionUID = 1L;
072:
073: /**
074: * Overridden to get the id string of a value object for hidden fields.
075: *
076: * @param valueObjectParam value object for which to get the id string.
077: * @return id string of the value object provided.
078: */
079: protected String toString(final Object valueObjectParam) {
080: if (logger.isDebugEnabled()) {
081: logger.debug("toString(Object valueObjectParam = "
082: + valueObjectParam + ") - start");
083: }
084:
085: if (valueObjectParam == null) {
086: if (logger.isDebugEnabled()) {
087: logger.debug("toString(Object) - end - return value = "
088: + null);
089: }
090: return null;
091: }
092: // if we got a value object, put that out
093: if (valueObjectParam instanceof ValueObject) {
094: // TODO: for now, it only handles a single value object - it should
095: // also handle a collection
096: String returnString = ((ValueObject) valueObjectParam)
097: .getIdString();
098: if (logger.isDebugEnabled()) {
099: logger.debug("toString(Object) - end - return value = "
100: + returnString);
101: }
102: return returnString;
103: } else {
104: // otherwise, assume it maps to an id
105: String returnString = valueObjectParam.toString();
106: if (logger.isDebugEnabled()) {
107: logger.debug("toString(Object) - end - return value = "
108: + returnString);
109: }
110: return returnString;
111: }
112: }
113: }
|