1 16 package org.outerj.daisy.repository; 17 18 import java.util.Map ; 19 import java.util.HashMap ; 20 21 24 public class CollectionNotFoundException extends RepositoryException { 25 private long id; 26 private String name; 27 28 private static final String ID_KEY = "id"; 29 private static final String NAME_KEY = "name"; 30 31 public CollectionNotFoundException(long id) { 32 this.id = id; 33 } 34 35 public CollectionNotFoundException(String name) { 36 this.name = name; 37 } 38 39 public CollectionNotFoundException(Map params) { 40 if (params.containsKey(ID_KEY)) { 41 this.id = Long.parseLong((String )params.get(ID_KEY)); 42 } else { 43 this.name = (String )params.get(NAME_KEY); 44 } 45 } 46 47 public Map getState() { 48 HashMap map = new HashMap (1); 49 if (name == null) 50 map.put(ID_KEY, String.valueOf(id)); 51 else 52 map.put(NAME_KEY, name); 53 return map; 54 } 55 56 public String getMessage() { 57 if (name == null) 58 return "The collection with ID " + id + " does not exist."; 59 else 60 return "The collection named \"" + name + "\" does not exist."; 61 } 62 } 63 | Popular Tags |