KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > provisional > conversion > ToStringConverter


1 /*
2  * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * db4objects - Initial API and implementation
11  */

12 package org.eclipse.jface.internal.databinding.provisional.conversion;
13
14 /**
15  * Converts any object to a string by calling its toString() method.
16  */

17 public class ToStringConverter implements IConverter {
18
19     /**
20      * A singleton for the toString() converter function
21      */

22     public static final ToStringConverter TOSTRINGFUNCTION = new ToStringConverter();
23
24     private final Class JavaDoc fromClass;
25
26     /**
27      *
28      */

29     public ToStringConverter() {
30         this(Object JavaDoc.class);
31     }
32
33     /**
34      * @param fromClass
35      */

36     public ToStringConverter(Class JavaDoc fromClass) {
37         this.fromClass = fromClass;
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
44      */

45     public Object JavaDoc convert(Object JavaDoc source) {
46         if (source == null) {
47             return ""; //$NON-NLS-1$
48
}
49         return source.toString();
50     }
51
52     public Object JavaDoc getFromType() {
53         return fromClass;
54     }
55
56     public Object JavaDoc getToType() {
57         return String JavaDoc.class;
58     }
59
60 }
61
Popular Tags