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.rrt.lib; 020 021import java.util.Map; 022 023import javax.inject.Inject; 024import javax.management.NotCompliantMBeanException; 025import javax.management.StandardMBean; 026 027import org.apache.james.rrt.api.RecipientRewriteTable; 028import org.apache.james.rrt.api.RecipientRewriteTableException; 029import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean; 030 031import com.google.common.collect.ImmutableMap; 032 033/** 034 * Management for RecipientRewriteTables 035 */ 036public class RecipientRewriteTableManagement extends StandardMBean implements RecipientRewriteTableManagementMBean { 037 038 private RecipientRewriteTable rrt; 039 040 protected RecipientRewriteTableManagement() throws NotCompliantMBeanException { 041 super(RecipientRewriteTableManagementMBean.class); 042 } 043 044 @Inject 045 public void setManageableRecipientRewriteTable(RecipientRewriteTable rrt) { 046 this.rrt = rrt; 047 } 048 049 /** 050 * @see 051 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean#addRegexMapping 052 * (java.lang.String, java.lang.String, java.lang.String) 053 */ 054 public void addRegexMapping(String user, String domain, String regex) throws Exception { 055 try { 056 rrt.addRegexMapping(user, domain, regex); 057 } catch (RecipientRewriteTableException e) { 058 throw new Exception(e.getMessage()); 059 } 060 } 061 062 /** 063 * @see 064 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean#removeRegexMapping 065 * (java.lang.String, java.lang.String, java.lang.String) 066 */ 067 public void removeRegexMapping(String user, String domain, String regex) throws Exception { 068 try { 069 rrt.removeRegexMapping(user, domain, regex); 070 } catch (RecipientRewriteTableException e) { 071 throw new Exception(e.getMessage()); 072 } 073 } 074 075 /** 076 * @see 077 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean#addAddressMapping 078 * (java.lang.String, java.lang.String, java.lang.String) 079 */ 080 public void addAddressMapping(String user, String domain, String address) throws Exception { 081 try { 082 rrt.addAddressMapping(user, domain, address); 083 } catch (RecipientRewriteTableException e) { 084 throw new Exception(e.getMessage()); 085 } 086 } 087 088 /** 089 * @see 090 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean#removeAddressMapping 091 * (java.lang.String, java.lang.String, java.lang.String) 092 */ 093 public void removeAddressMapping(String user, String domain, String address) throws Exception { 094 try { 095 rrt.removeAddressMapping(user, domain, address); 096 } catch (RecipientRewriteTableException e) { 097 throw new Exception(e.getMessage()); 098 } 099 } 100 101 /** 102 * @see 103 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean#addErrorMapping 104 * (java.lang.String, java.lang.String, java.lang.String) 105 */ 106 public void addErrorMapping(String user, String domain, String error) throws Exception { 107 try { 108 rrt.addErrorMapping(user, domain, error); 109 } catch (RecipientRewriteTableException e) { 110 throw new Exception(e.getMessage()); 111 } 112 } 113 114 /** 115 * @see 116 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean#removeErrorMapping 117 * (java.lang.String, java.lang.String, java.lang.String) 118 */ 119 public void removeErrorMapping(String user, String domain, String error) throws Exception { 120 try { 121 rrt.removeErrorMapping(user, domain, error); 122 } catch (RecipientRewriteTableException e) { 123 throw new Exception(e.getMessage()); 124 } 125 } 126 127 public void addDomainMapping(String domain, String targetDomain) throws Exception { 128 try { 129 rrt.addAliasDomainMapping(domain, targetDomain); 130 } catch (RecipientRewriteTableException e) { 131 throw new Exception(e.getMessage()); 132 } 133 } 134 135 public void removeDomainMapping(String domain, String targetDomain) throws Exception { 136 try { 137 rrt.removeAliasDomainMapping(domain, targetDomain); 138 } catch (RecipientRewriteTableException e) { 139 throw new Exception(e.getMessage()); 140 } 141 } 142 143 /** 144 * @see org.apache.james.rrt.api.RecipientRewriteTableManagementMBean 145 * #getUserDomainMappings(java.lang.String, java.lang.String) 146 */ 147 public Mappings getUserDomainMappings(String user, String domain) throws Exception { 148 try { 149 return rrt.getUserDomainMappings(user, domain); 150 } catch (RecipientRewriteTableException e) { 151 throw new Exception(e.getMessage()); 152 } 153 } 154 155 /** 156 * @see 157 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean 158 * #addMapping(java.lang.String, java.lang.String, java.lang.String) 159 */ 160 public void addMapping(String user, String domain, String mapping) throws Exception { 161 try { 162 rrt.addMapping(user, domain, mapping); 163 } catch (RecipientRewriteTableException e) { 164 throw new Exception(e.getMessage()); 165 } 166 } 167 168 /** 169 * @see 170 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean#removeMapping 171 * (java.lang.String, java.lang.String, java.lang.String) 172 */ 173 public void removeMapping(String user, String domain, String mapping) throws Exception { 174 try { 175 rrt.removeMapping(user, domain, mapping); 176 } catch (RecipientRewriteTableException e) { 177 throw new Exception(e.getMessage()); 178 } 179 } 180 181 /** 182 * @see 183 * org.apache.james.rrt.api.RecipientRewriteTableManagementMBean#getAllMappings() 184 */ 185 public Map<String, Mappings> getAllMappings() throws Exception { 186 try { 187 return ImmutableMap.copyOf(rrt.getAllMappings()); 188 } catch (RecipientRewriteTableException e) { 189 throw new Exception(e.getMessage()); 190 } 191 } 192 193}