1 18 package org.objectweb.speedo.lib; 19 20 import java.util.Locale ; 21 import java.util.StringTokenizer ; 22 23 import org.objectweb.speedo.api.UserFieldMapping; 24 25 29 public class LocaleFieldMapping implements UserFieldMapping { 30 31 35 public Class getStorageType() { 36 return String .class; 37 } 38 39 43 public Class getMemoryType() { 44 return Locale .class; 45 } 46 47 52 public Object toMemory(Object storagevalue) { 53 if (storagevalue == null) { 54 return null; 55 } 56 57 if (storagevalue instanceof Locale ) { 58 return storagevalue; 59 } else { 60 StringTokenizer tokenizer = new StringTokenizer ((String )storagevalue, "_"); 61 String [] names = new String [3]; 62 int max = tokenizer.countTokens(); 63 for (int i=0; i<3; i++) { 64 names[i] = ""; 65 } 66 for (int i=0; i<max; i++) { 67 String token = tokenizer.nextToken(); 68 names[i] = token; 69 } 70 71 Locale locale; 72 locale = new Locale (names[0], names[1], names[2]); 73 return locale; 74 } 75 } 76 77 82 public Object toStorage(Object memoryvalue) { 83 if (memoryvalue == null) { 84 return null; 85 } 86 return ((Locale )memoryvalue).toString(); 87 } 88 } 89 | Popular Tags |