1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.james.impl.vut;
23
24 import java.util.Collection;
25 import java.util.Map;
26
27 import org.apache.avalon.framework.service.ServiceException;
28 import org.apache.avalon.framework.service.ServiceManager;
29 import org.apache.avalon.framework.service.Serviceable;
30 import org.apache.james.api.vut.VirtualUserTable;
31 import org.apache.james.api.vut.VirtualUserTableStore;
32 import org.apache.james.api.vut.management.InvalidMappingException;
33 import org.apache.james.api.vut.management.VirtualUserTableManagementException;
34 import org.apache.james.api.vut.management.VirtualUserTableManagementMBean;
35 import org.apache.james.api.vut.management.VirtualUserTableManagementService;
36
37
38
39
40
41
42 public class VirtualUserTableManagement implements Serviceable, VirtualUserTableManagementService, VirtualUserTableManagementMBean {
43
44 VirtualUserTableStore store;
45 org.apache.james.api.vut.management.VirtualUserTableManagement defaultVUT;
46
47
48
49
50 public void service(ServiceManager arg0) throws ServiceException {
51 setVirtualUserTableStore((VirtualUserTableStore) arg0.lookup(VirtualUserTableStore.ROLE));
52 setDefaultVirtualUserTable((org.apache.james.api.vut.management.VirtualUserTableManagement) arg0.lookup(DefaultVirtualUserTable.ROLE));
53 }
54
55 public void setVirtualUserTableStore(VirtualUserTableStore store) {
56 this.store = store;
57 }
58
59 public void setDefaultVirtualUserTable(org.apache.james.api.vut.management.VirtualUserTableManagement defaultVUT) {
60 this.defaultVUT = defaultVUT;
61 }
62
63
64
65
66
67
68
69
70 private org.apache.james.api.vut.management.VirtualUserTableManagement getTable(String tableName) throws VirtualUserTableManagementException {
71
72 if (tableName == null) {
73 return defaultVUT;
74 } else {
75 VirtualUserTable vut = store.getTable(tableName);
76
77
78 if (vut == null) {
79 throw new VirtualUserTableManagementException("No VirtualUserTable with such name: " + tableName);
80 } else if (!(vut instanceof org.apache.james.api.vut.management.VirtualUserTableManagement)){
81
82 throw new VirtualUserTableManagementException("Used VirtualUserTable implementation not support management");
83 } else {
84 return (org.apache.james.api.vut.management.VirtualUserTableManagement) vut;
85 }
86 }
87 }
88
89
90
91
92 public boolean addAddressMapping(String virtualUserTable, String user, String domain, String address) throws VirtualUserTableManagementException {
93 try {
94 return getTable(virtualUserTable).addAddressMapping(user, domain, address);
95 } catch (InvalidMappingException e) {
96 throw new VirtualUserTableManagementException(e);
97 }
98 }
99
100
101
102
103 public boolean addErrorMapping(String virtualUserTable, String user, String domain, String error) throws VirtualUserTableManagementException {
104 try {
105 return getTable(virtualUserTable).addErrorMapping(user, domain, error);
106 } catch (InvalidMappingException e) {
107 throw new VirtualUserTableManagementException(e);
108 }
109 }
110
111
112
113
114 public boolean addRegexMapping(String virtualUserTable, String user, String domain, String regex) throws VirtualUserTableManagementException {
115 try {
116 return getTable(virtualUserTable).addRegexMapping(user, domain, regex);
117 } catch (InvalidMappingException e) {
118 throw new VirtualUserTableManagementException(e);
119 }
120 }
121
122
123
124
125 public Collection getUserDomainMappings(String virtualUserTable, String user, String domain) throws VirtualUserTableManagementException {
126 try {
127 return getTable(virtualUserTable).getUserDomainMappings(user, domain);
128 } catch (InvalidMappingException e) {
129 throw new VirtualUserTableManagementException(e);
130 }
131 }
132
133
134
135
136 public boolean removeAddressMapping(String virtualUserTable, String user, String domain, String address) throws VirtualUserTableManagementException {
137 try {
138 return getTable(virtualUserTable).removeAddressMapping(user, domain, address);
139 } catch (InvalidMappingException e) {
140 throw new VirtualUserTableManagementException(e);
141 }
142 }
143
144
145
146
147 public boolean removeErrorMapping(String virtualUserTable, String user, String domain, String error) throws VirtualUserTableManagementException {
148 try {
149 return getTable(virtualUserTable).removeErrorMapping(user, domain, error);
150 } catch (InvalidMappingException e) {
151 throw new VirtualUserTableManagementException(e);
152 }
153 }
154
155
156
157
158 public boolean removeRegexMapping(String virtualUserTable, String user, String domain, String regex) throws VirtualUserTableManagementException {
159 try {
160 return getTable(virtualUserTable).removeRegexMapping(user, domain, regex);
161 } catch (InvalidMappingException e) {
162 throw new VirtualUserTableManagementException(e);
163 }
164 }
165
166
167
168
169 public boolean addMapping(String virtualUserTable, String user, String domain, String mapping) throws VirtualUserTableManagementException {
170 try {
171 return getTable(virtualUserTable).addMapping(user, domain, mapping);
172 } catch (InvalidMappingException e) {
173 throw new VirtualUserTableManagementException(e);
174 }
175 }
176
177
178
179
180 public boolean removeMapping(String virtualUserTable, String user, String domain, String mapping) throws VirtualUserTableManagementException {
181 try {
182 return getTable(virtualUserTable).removeMapping(user, domain, mapping);
183 } catch (InvalidMappingException e) {
184 throw new VirtualUserTableManagementException(e);
185 }
186 }
187
188
189
190
191 public Map getAllMappings(String virtualUserTable) throws VirtualUserTableManagementException{
192 return getTable(virtualUserTable).getAllMappings();
193 }
194
195
196
197
198 public boolean addAliasDomainMapping(String virtualUserTable, String aliasDomain, String realDomain) throws VirtualUserTableManagementException {
199 try {
200 return getTable(virtualUserTable).addAliasDomainMapping(aliasDomain, realDomain);
201 } catch (InvalidMappingException e) {
202 throw new VirtualUserTableManagementException(e);
203 }
204 }
205
206
207
208
209 public boolean removeAliasDomainMapping(String virtualUserTable, String aliasDomain, String realDomain) throws VirtualUserTableManagementException {
210 try {
211 return getTable(virtualUserTable).removeAliasDomainMapping(aliasDomain, realDomain);
212 } catch (InvalidMappingException e) {
213 throw new VirtualUserTableManagementException(e);
214 }
215 }
216 }