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.management.impl;
23
24 import java.util.List;
25
26 import org.apache.avalon.framework.service.ServiceException;
27 import org.apache.avalon.framework.service.ServiceManager;
28 import org.apache.avalon.framework.service.Serviceable;
29 import org.apache.james.api.domainlist.DomainList;
30 import org.apache.james.api.domainlist.ManageableDomainList;
31 import org.apache.james.management.DomainListManagementException;
32 import org.apache.james.management.DomainListManagementMBean;
33 import org.apache.james.management.DomainListManagementService;
34
35
36
37
38 public class DomainListManagement implements DomainListManagementService,DomainListManagementMBean,Serviceable {
39 private DomainList domList;
40
41
42
43
44 public void service(ServiceManager arg0) throws ServiceException {
45 setDomainList((DomainList) arg0.lookup(DomainList.ROLE));
46 }
47
48 public void setDomainList(DomainList domList) {
49 this.domList = domList;
50 }
51
52
53
54
55 public boolean addDomain(String domain) throws DomainListManagementException {
56 if (domList instanceof ManageableDomainList) {
57 try {
58 return ((ManageableDomainList)domList).addDomain(domain);
59 } catch (UnsupportedOperationException e) {
60
61 throw new DomainListManagementException(e);
62 }
63 } else {
64 throw new DomainListManagementException("Used DomainList implementation not support management");
65 }
66 }
67
68
69
70
71 public boolean removeDomain(String domain) throws DomainListManagementException {
72 if (domList instanceof ManageableDomainList) {
73 try {
74 return ((ManageableDomainList)domList).removeDomain(domain);
75 } catch (UnsupportedOperationException e) {
76
77 throw new DomainListManagementException(e);
78 }
79 } else {
80 throw new DomainListManagementException("Used DomainList implementation not support management");
81 }
82 }
83
84
85
86
87 public boolean containsDomain(String domain) {
88 return domList.containsDomain(domain);
89 }
90
91
92
93
94 public List getDomains() {
95 return domList.getDomains();
96 }
97 }