01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
10: * http://www.apache.org/licenses/LICENSE-2.0 *
11: * *
12: * Unless required by applicable law or agreed to in writing, *
13: * software distributed under the License is distributed on an *
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15: * KIND, either express or implied. See the License for the *
16: * specific language governing permissions and limitations *
17: * under the License. *
18: ****************************************************************/package org.apache.james.test.mock.avalon;
19:
20: import org.apache.avalon.cornerstone.services.store.Store;
21: import org.apache.avalon.framework.configuration.Configuration;
22: import org.apache.avalon.framework.configuration.ConfigurationException;
23: import org.apache.avalon.framework.service.ServiceException;
24:
25: import java.util.HashMap;
26: import java.util.Map;
27:
28: public class MockStore implements Store {
29:
30: Map m_storedObjectMap = new HashMap();
31:
32: public void add(Object key, Object obj) {
33: m_storedObjectMap.put(key, obj);
34: }
35:
36: public Object select(Object object) throws ServiceException {
37: Object result = get(object);
38: return result;
39: }
40:
41: private Object get(Object object) {
42: return m_storedObjectMap.get(extractKeyObject(object));
43: }
44:
45: private Object extractKeyObject(Object object) {
46: if (object instanceof Configuration) {
47: Configuration repConf = (Configuration) object;
48: try {
49: String attribute = repConf
50: .getAttribute("destinationURL");
51: String[] strings = attribute.split("/");
52: if (strings.length > 0) {
53: object = strings[strings.length - 1];
54: }
55: } catch (ConfigurationException e) {
56: throw new RuntimeException(
57: "test configuration setup failed");
58: }
59:
60: }
61: return object;
62: }
63:
64: public boolean isSelectable(Object object) {
65: return get(object) != null;
66: }
67:
68: public void release(Object object) {
69: //trivial implementation
70: }
71: }
|