001/****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one   *
003 * or more contributor license agreements.  See the NOTICE file *
004 * distributed with this work for additional information        *
005 * regarding copyright ownership.  The ASF licenses this file   *
006 * to you under the Apache License, Version 2.0 (the            *
007 * "License"); you may not use this file except in compliance   *
008 * with the License.  You may obtain a copy of the License at   *
009 *                                                              *
010 *   http://www.apache.org/licenses/LICENSE-2.0                 *
011 *                                                              *
012 * Unless required by applicable law or agreed to in writing,   *
013 * software distributed under the License is distributed on an  *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015 * KIND, either express or implied.  See the License for the    *
016 * specific language governing permissions and limitations      *
017 * under the License.                                           *
018 ****************************************************************/
019package org.apache.james.domainlist.lib;
020
021import java.util.List;
022
023import javax.inject.Inject;
024import javax.management.NotCompliantMBeanException;
025import javax.management.StandardMBean;
026
027import org.apache.james.domainlist.api.DomainList;
028import org.apache.james.domainlist.api.DomainListException;
029import org.apache.james.domainlist.api.DomainListManagementMBean;
030
031import com.google.common.collect.ImmutableList;
032
033public class DomainListManagement extends StandardMBean implements DomainListManagementMBean {
034
035    private DomainList domainList;
036
037    public DomainListManagement() throws NotCompliantMBeanException {
038        super(DomainListManagementMBean.class);
039    }
040
041    @Inject
042    public void setDomainList(DomainList domainList) {
043        this.domainList = domainList;
044    }
045
046    @Override
047    public void addDomain(String domain) throws Exception {
048        try {
049            domainList.addDomain(domain);
050        }
051        catch (DomainListException e) {
052            throw new Exception(e.getMessage());
053        }
054    }
055
056    @Override
057    public boolean containsDomain(String domain) throws Exception {
058        try {
059            return domainList.containsDomain(domain);
060        }
061        catch (DomainListException e) {
062            throw new Exception(e.getMessage());
063        }
064    }
065
066    @Override
067    public List<String> getDomains() throws Exception {
068        try {
069            return ImmutableList.copyOf(domainList.getDomains());
070        }
071        catch (DomainListException e) {
072            throw new Exception(e.getMessage());
073        }
074    }
075
076    @Override
077    public void removeDomain(String domain) throws Exception {
078        try {
079            domainList.removeDomain(domain);
080        }
081        catch (DomainListException e) {
082            throw new Exception(e.getMessage());
083        }
084    }
085
086    @Override
087    public String getDefaultDomain() throws Exception {
088        try {
089            return domainList.getDefaultDomain();
090        }
091        catch (DomainListException e) {
092            throw new Exception(e.getMessage());
093        }
094
095    }
096
097}