1 23 24 31 package com.sun.enterprise.resource; 32 33 import com.sun.enterprise.server.ResourceDeployer; 34 import com.sun.enterprise.config.serverbeans.Resources; 35 36 import com.sun.enterprise.NamingManager; 37 import com.sun.enterprise.resource.ResourceInstaller; 38 import com.sun.enterprise.repository.J2EEResource; 39 import com.sun.enterprise.repository.MailResource; 40 import com.sun.enterprise.repository.IASJ2EEResourceFactoryImpl; 41 42 import java.util.logging.Logger ; 43 import java.util.logging.Level ; 44 import com.sun.logging.LogDomains; 45 import com.sun.enterprise.util.i18n.StringManager; 46 import com.sun.enterprise.ManagementObjectManager; 47 48 60 public class MailResourceDeployer extends GlobalResourceDeployer 61 implements ResourceDeployer { 62 63 64 private static final StringManager localStrings = 65 StringManager.getManager("com.sun.enterprise.resource"); 66 67 68 private static Logger _logger=LogDomains.getLogger(LogDomains.CORE_LOGGER); 69 70 76 public synchronized void deployResource(Object resource) throws Exception { 77 78 com.sun.enterprise.config.serverbeans.MailResource mailRes = 79 (com.sun.enterprise.config.serverbeans.MailResource) resource; 80 81 if(mailRes == null) { 82 _logger.log(Level.INFO, "core.resourcedeploy_error"); 83 } else { 84 if (mailRes.isEnabled()) { 85 ManagementObjectManager mgr = 87 getAppServerSwitchObject().getManagementObjectManager(); 88 mgr.registerJavaMailResource(mailRes.getJndiName()); 89 installResource(mailRes); 90 } else { 91 _logger.log(Level.INFO, "core.resource_disabled", 92 new Object [] {mailRes.getJndiName(), 93 IASJ2EEResourceFactoryImpl.MAIL_RES_TYPE}); 94 } 95 } 96 } 97 98 104 void installResource(com.sun.enterprise.config.serverbeans.MailResource 105 mailResource) throws Exception { 106 J2EEResource j2eeRes = 110 IASJ2EEResourceFactoryImpl.toMailJ2EEResource(mailResource); 111 ResourceInstaller installer = 112 getAppServerSwitchObject().getResourceInstaller(); 113 installer.installMailResource((MailResource) j2eeRes); 114 installer.addResource(j2eeRes); 115 } 116 117 123 public synchronized void undeployResource(Object resource) 124 throws Exception { 125 126 NamingManager namingMgr = getAppServerSwitchObject().getNamingManager(); 128 129 com.sun.enterprise.config.serverbeans.MailResource mailRes = 130 (com.sun.enterprise.config.serverbeans.MailResource) resource; 131 132 J2EEResource j2eeResource = 134 IASJ2EEResourceFactoryImpl.toMailJ2EEResource(mailRes); 135 136 namingMgr.unpublishObject(j2eeResource.getName()); 138 139 ResourceInstaller installer = getAppServerSwitchObject().getResourceInstaller(); 141 142 installer.removeResource(j2eeResource); 144 145 ManagementObjectManager mgr = 146 getAppServerSwitchObject().getManagementObjectManager(); 147 mgr.unregisterJavaMailResource(mailRes.getJndiName()); 148 } 149 150 156 public synchronized void redeployResource(Object resource) 157 throws Exception { 158 159 undeployResource(resource); 160 deployResource(resource); 161 } 162 163 169 public synchronized void enableResource(Object resource) throws Exception { 170 deployResource(resource); 171 } 172 173 179 public synchronized void disableResource(Object resource) throws Exception { 180 undeployResource(resource); 181 } 182 183 184 192 public Object getResource(String name, Resources rbeans) throws Exception { 193 194 Object res = rbeans.getMailResourceByJndiName(name); 195 196 if (res == null) { 197 String msg = localStrings.getString("resource.no_resource",name); 198 throw new Exception (msg); 199 } 200 201 return res; 202 } 203 } 204 | Popular Tags |