KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > databinding > conversion > ObjectToStringConverter


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.core.internal.databinding.conversion;
13
14 import org.eclipse.core.databinding.conversion.IConverter;
15
16 /**
17  * Converts any object to a string by calling its toString() method.
18  */

19 public class ObjectToStringConverter implements IConverter {
20     private final Class JavaDoc fromClass;
21
22     /**
23      *
24      */

25     public ObjectToStringConverter() {
26         this(Object JavaDoc.class);
27     }
28
29     /**
30      * @param fromClass
31      */

32     public ObjectToStringConverter(Class JavaDoc fromClass) {
33         this.fromClass = fromClass;
34     }
35
36     /*
37      * (non-Javadoc)
38      *
39      * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
40      */

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