KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConvertString2Character.
16  */

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

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

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