1 19 20 21 22 package org.apache.james.test.mock.avalon; 23 24 import org.apache.avalon.cornerstone.services.store.Store; 25 import org.apache.avalon.framework.configuration.Configuration; 26 import org.apache.avalon.framework.configuration.ConfigurationException; 27 import org.apache.avalon.framework.service.ServiceException; 28 29 import java.util.HashMap ; 30 import java.util.Map ; 31 32 public class MockStore implements Store { 33 34 Map m_storedObjectMap = new HashMap (); 35 36 public void add(Object key, Object obj) { 37 m_storedObjectMap.put(key, obj); 38 } 39 40 public Object select(Object object) throws ServiceException { 41 Object result = get(object); 42 return result; 43 } 44 45 private Object get(Object object) { 46 Object key = extractKeyObject(object); 47 System.err.println(key); 48 return m_storedObjectMap.get(key); 49 } 50 51 private Object extractKeyObject(Object object) { 52 if (object instanceof Configuration) { 53 Configuration repConf = (Configuration) object; 54 try { 55 String type = repConf.getAttribute("type"); 56 String prefix = ""; 57 if (!"MAIL".equals(type) && !"SPOOL".equals(type)) { 58 prefix = type+"."; 59 } 60 String attribute = repConf.getAttribute("destinationURL"); 61 String [] strings = attribute.split("/"); 62 if (strings.length > 0) { 63 return prefix+strings[strings.length-1]; 64 } 65 } catch (ConfigurationException e) { 66 throw new RuntimeException ("test configuration setup failed"); 67 } 68 69 } 70 return object; 71 } 72 73 public boolean isSelectable(Object object) { 74 return get(object) != null; 75 } 76 77 public void release(Object object) { 78 } 80 } 81 | Popular Tags |