1 23 24 37 package com.sun.enterprise.resource; 38 39 import com.sun.enterprise.server.ResourceDeployer; 40 import com.sun.enterprise.config.serverbeans.PersistenceManagerFactoryResource; 41 import com.sun.enterprise.config.serverbeans.Resources; 42 import com.sun.enterprise.config.serverbeans.JdbcResource; 43 import com.sun.enterprise.config.ConfigBean; 44 import com.sun.enterprise.connectors.ConnectorAdminServiceUtils; 45 import com.sun.enterprise.connectors.ConnectorConstants; 46 47 import com.sun.enterprise.Switch; 48 import com.sun.enterprise.NamingManager; 49 import com.sun.enterprise.resource.ResourceInstaller; 50 import com.sun.enterprise.repository.IASJ2EEResourceFactoryImpl; 51 import com.sun.enterprise.repository.J2EEResource; 52 import com.sun.enterprise.repository.PMFResource; 53 54 import java.util.logging.Logger ; 55 import java.util.logging.Level ; 56 import com.sun.logging.LogDomains; 57 import com.sun.enterprise.util.i18n.StringManager; 58 59 import javax.naming.InitialContext ; 60 61 69 70 public class PersistenceManagerFactoryResourceDeployer implements ResourceDeployer { 71 72 73 private static final StringManager localStrings = 74 StringManager.getManager("com.sun.enterprise.resource"); 75 76 77 private static Logger _logger=LogDomains.getLogger(LogDomains.CORE_LOGGER); 78 79 81 public synchronized void deployResource(Object resource) throws Exception { 82 PersistenceManagerFactoryResource configPMFRes = 83 (PersistenceManagerFactoryResource)resource; 84 85 if (configPMFRes.isEnabled()) { 86 loadJdbcResource(configPMFRes); 88 89 PMFResource j2eeResource = (PMFResource) 90 IASJ2EEResourceFactoryImpl.toPMFJ2EEResource(configPMFRes); 91 92 ResourceInstaller installer = 93 Switch.getSwitch().getResourceInstaller(); 94 installer.installPersistenceManagerResource(j2eeResource); 95 96 installer.addResource(j2eeResource); 97 } else { 98 _logger.log(Level.INFO, "core.resource_disabled", 99 new Object [] {configPMFRes.getJndiName(), 100 IASJ2EEResourceFactoryImpl.PMF_RES_TYPE}); 101 } 102 } 103 104 public synchronized void undeployResource(Object resource) 105 throws Exception { 106 NamingManager namingMgr = Switch.getSwitch().getNamingManager(); 107 PersistenceManagerFactoryResource configPMFRes = 108 (PersistenceManagerFactoryResource)resource; 109 namingMgr.unpublishObject(configPMFRes.getJndiName()); 110 111 ResourceInstaller installer = Switch.getSwitch().getResourceInstaller(); 112 installer.removeResource((PMFResource) 113 IASJ2EEResourceFactoryImpl.toPMFJ2EEResource(configPMFRes)); 114 } 115 116 public synchronized void redeployResource(Object resource) 117 throws Exception { 118 undeployResource(resource); 119 deployResource(resource); 120 } 121 122 public synchronized void enableResource(Object resource) throws Exception { 123 deployResource(resource); 124 } 125 126 public synchronized void disableResource(Object resource) throws Exception { 127 undeployResource(resource); 128 } 129 130 138 public Object getResource(String name, Resources rbeans) throws Exception { 139 Object res = rbeans.getPersistenceManagerFactoryResourceByJndiName(name); 140 if (res == null) { 141 String msg = localStrings.getString("resource.no_resource",name); 142 throw new Exception (msg); 143 } 144 return res; 145 } 146 147 private void loadJdbcResource(PersistenceManagerFactoryResource cr) 148 throws Exception { 149 150 String resName = cr.getJdbcResourceJndiName(); 151 Resources resources = (Resources) cr.parent(); 152 ConfigBean cb = resources.getJdbcResourceByJndiName(resName); 153 if (cb != null) { 154 try { 155 InitialContext ic = new InitialContext (); 156 ic.lookup(resName); 157 } catch (Exception e) { 158 JdbcResourceDeployer deployer = 160 new JdbcResourceDeployer(); 161 deployer.deployResource( 162 (com.sun.enterprise.config.serverbeans.JdbcResource) cb); 163 } 164 } 165 } 166 167 } 169 | Popular Tags |