View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
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   ****************************************************************/
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   * Provide management class for DomainLists
37   */
38  public class DomainListManagement implements DomainListManagementService,DomainListManagementMBean,Serviceable {
39      private DomainList domList;
40      
41      /**
42       * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
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       * @see org.apache.james.management.DomainListManagementService#addDomain(java.lang.String)
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                  //TODO: Remove later. Temporary fix
61                  throw new DomainListManagementException(e);
62              } 
63          } else {
64              throw new DomainListManagementException("Used DomainList implementation not support management");
65          }
66      }
67  
68      /**
69       * @see org.apache.james.management.DomainListManagementService#removeDomain(java.lang.String)
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                  //TODO: Remove later. Temporary fix
77                  throw new DomainListManagementException(e);
78              }
79          } else {
80             throw new DomainListManagementException("Used DomainList implementation not support management");
81          }
82      }
83  
84      /**
85       * @see org.apache.james.management.DomainListManagementService#containsDomain(java.lang.String)
86       */
87      public boolean containsDomain(String domain) {
88          return domList.containsDomain(domain);
89      }
90  
91      /**
92       * @see org.apache.james.management.DomainListManagementService#getDomains()
93       */
94      public List getDomains() {
95          return domList.getDomains();
96      }
97  }