1 12 package org.eclipse.core.internal.databinding.conversion; 13 14 import org.eclipse.core.databinding.conversion.IConverter; 15 16 19 public class StringToCharacterConverter implements IConverter { 20 21 26 public Object convert(Object source) { 27 String s = (String ) source; 28 Character result; 29 30 if (s.length() > 1) 31 throw new IllegalArgumentException ( 32 "String2Character: string too long: " + s); 34 try { 35 result = new Character (s.charAt(0)); 36 } catch (Exception e) { 37 throw new IllegalArgumentException ( 38 "String2Character: " + e.getMessage() + ": " + s); } 40 41 return result; 42 } 43 44 public Object getFromType() { 45 return String .class; 46 } 47 48 public Object getToType() { 49 return Character .class; 50 } 51 52 } 53 | Popular Tags |