01: /* StringPropertyEditor.java
02: *
03: * DDSteps - Data Driven JUnit Test Steps
04: * Copyright (C) 2005 Jayway AB
05: * www.ddsteps.org
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License version 2.1 as published by the Free Software Foundation.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, visit
18: * http://www.opensource.org/licenses/lgpl-license.php
19: */
20:
21: package org.ddsteps.beans;
22:
23: import java.beans.PropertyEditorSupport;
24:
25: /**
26: * Property Editor for String that handles Object to String conversions too.
27: *
28: * @author adam
29: * @version $Id: StringPropertyEditor.java,v 1.1 2005/12/03 12:51:41 adamskogman Exp $
30: */
31: public class StringPropertyEditor extends PropertyEditorSupport {
32:
33: /**
34: * @see PropertyEditorSupport#PropertyEditorSupport()
35: */
36: public StringPropertyEditor() {
37: super ();
38: }
39:
40: /**
41: * @param source
42: * @see PropertyEditorSupport#PropertyEditorSupport(java.lang.Object)
43: */
44: public StringPropertyEditor(Object source) {
45: super (source);
46: }
47:
48: /**
49: * Overrides this method with special handling in case the object passed in
50: * is not a string, as to handle Object to String conversions.
51: * <p>
52: * Spring says to override this method to do just that.
53: * <p>
54: * If the value argument is no a String, it will simply use toString() to
55: * make it a String.
56: *
57: * @see java.beans.PropertyEditor#setValue(java.lang.Object)
58: */
59: public void setValue(Object value) {
60:
61: if (value != null && !(value instanceof String)) {
62: value = value.toString();
63: }
64:
65: super .setValue(value);
66: }
67:
68: /**
69: * Overrides and replaces setAsTest, because of a BUG in the superclass...
70: *
71: * @see java.beans.PropertyEditor#setAsText(java.lang.String)
72: */
73: public void setAsText(String text) throws IllegalArgumentException {
74: setValue(text);
75: }
76:
77: }
|