KickJava   Java API By Example, From Geeks To Geeks.

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


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  * StringToCharacterConverter.
18  */

19 public class StringToCharacterConverter implements IConverter {
20
21     /*
22      * (non-Javadoc)
23      *
24      * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
25      */

26     public Object JavaDoc convert(Object JavaDoc source) {
27         String JavaDoc s = (String JavaDoc) source;
28         Character JavaDoc result;
29
30         if (s.length() > 1)
31             throw new IllegalArgumentException JavaDoc(
32                     "String2Character: string too long: " + s); //$NON-NLS-1$
33

34         try {
35             result = new Character JavaDoc(s.charAt(0));
36         } catch (Exception JavaDoc e) {
37             throw new IllegalArgumentException JavaDoc(
38                     "String2Character: " + e.getMessage() + ": " + s); //$NON-NLS-1$ //$NON-NLS-2$
39
}
40
41         return result;
42     }
43
44     public Object JavaDoc getFromType() {
45         return String JavaDoc.class;
46     }
47
48     public Object JavaDoc getToType() {
49         return Character JavaDoc.class;
50     }
51
52 }
53
Popular Tags