1 16 package org.outerj.daisy.repository; 17 18 import java.util.Map ; 19 import java.util.HashMap ; 20 import java.util.Locale ; 21 import java.util.ResourceBundle ; 22 import java.text.MessageFormat ; 23 24 public class DocumentNotFoundException extends RepositoryException implements LocalizedException { 25 private long id; 26 27 private static final String ID_KEY = "id"; 28 29 public DocumentNotFoundException(long id) { 30 this.id = id; 31 } 32 33 public DocumentNotFoundException(Map params) { 34 this.id = Long.parseLong((String )params.get(ID_KEY)); 35 } 36 37 public Map getState() { 38 HashMap map = new HashMap (1); 39 map.put(ID_KEY, String.valueOf(id)); 40 return map; 41 } 42 43 public String getMessage() { 44 return getMessage(Locale.US); 45 } 46 47 public String getMessage(Locale locale) { 48 ResourceBundle bundle = ResourceBundle.getBundle("org/outerj/daisy/repository/messages", locale); 49 String message = bundle.getString("document-not-found-exception"); 50 return MessageFormat.format(message, new String [] { String.valueOf(id) }); 51 } 52 } 53 | Popular Tags |