1 23 24 package com.sun.enterprise.connectors; 25 26 import java.util.Hashtable ; 27 import java.util.logging.*; 28 import javax.naming.*; 29 30 import com.sun.enterprise.*; 31 import com.sun.enterprise.deployment.*; 32 import com.sun.enterprise.server.*; 33 34 39 40 41 public class ConnectorResourceAdminServiceImpl extends 42 ConnectorServiceImpl implements ConnectorAdminService { 43 44 47 48 public ConnectorResourceAdminServiceImpl() { 49 super(); 50 } 51 52 59 60 public void createConnectorResource(String jndiName, String poolName, 61 String resourceType) throws ConnectorRuntimeException 62 { 63 64 String errMsg = "rardeployment.jndi_lookup_failed"; 65 String name = poolName; 66 try { 67 ConnectorConnectionPool connectorConnectionPool = null; 68 String jndiNameForPool = ConnectorAdminServiceUtils. 69 getReservePrefixedJNDINameForPool(poolName); 70 InitialContext ic = new InitialContext(); 71 try { 72 connectorConnectionPool = 73 (ConnectorConnectionPool) ic.lookup(jndiNameForPool); 74 } catch(NamingException ne) { 75 checkAndLoadPoolResource(poolName); 76 } 77 78 connectorConnectionPool = 79 (ConnectorConnectionPool) ic.lookup(jndiNameForPool); 80 ConnectorDescriptorInfo cdi = connectorConnectionPool. 81 getConnectorDescriptorInfo(); 82 83 javax.naming.Reference ref=new javax.naming.Reference ( 84 connectorConnectionPool.getConnectorDescriptorInfo(). 85 getConnectionFactoryClass(), 86 "com.sun.enterprise.naming.factory.ConnectorObjectFactory", 87 null); 88 StringRefAddr addr = new StringRefAddr("poolName",poolName); 89 ref.add(addr); 90 addr = new StringRefAddr("rarName", cdi.getRarName() ); 91 ref.add(addr); 92 93 errMsg = "Failed to bind connector resource in JNDI"; 94 name = jndiName; 95 Switch.getSwitch().getNamingManager().publishObject( 96 jndiName,ref,true); 97 ConnectorResourceNamingEventNotifier.getInstance(). 99 notifyListeners( 100 new ConnectorNamingEvent( 101 jndiName,ConnectorNamingEvent.EVENT_OBJECT_REBIND)); 102 103 } catch(NamingException ne) { 104 ConnectorRuntimeException cre = 105 new ConnectorRuntimeException(errMsg); 106 cre.initCause(ne); 107 _logger.log(Level.SEVERE,errMsg, name); 108 _logger.log(Level.SEVERE,"", cre); 109 throw cre; 110 } 111 } 112 113 118 119 public void deleteConnectorResource(String jndiName) 120 throws ConnectorRuntimeException 121 { 122 123 try { 124 InitialContext ic = new InitialContext(); 125 ic.unbind(jndiName); 126 } catch(NamingException ne) { 127 ResourcesUtil resUtil = ResourcesUtil.getInstance(); 128 if(resUtil.resourceBelongsToSystemRar(jndiName)) { 129 return; 130 } 131 if(ne instanceof NameNotFoundException){ 132 _logger.log(Level.FINE, 133 "rardeployment.connectorresource_removal_from_jndi_error", 134 jndiName); 135 _logger.log(Level.FINE,"", ne); 136 return; 137 } 138 ConnectorRuntimeException cre = new ConnectorRuntimeException( 139 "Failed to delete connector resource from jndi"); 140 cre.initCause(ne); 141 _logger.log(Level.SEVERE, 142 "rardeployment.connectorresource_removal_from_jndi_error", 143 jndiName); 144 _logger.log(Level.SEVERE,"", cre); 145 throw cre; 146 } 147 } 148 149 153 public boolean isValidJndiSuffix(String suffix) { 154 if (suffix != null) { 155 for (String validSuffix : ConnectorConstants.JNDI_SUFFIX_VALUES) { 156 if (validSuffix.equals(suffix)) { 157 return true; 158 } 159 } 160 } 161 162 return false; 163 } 164 165 169 public Object lookup(String name) throws NamingException { 170 Hashtable ht = null; 171 String suffix = getValidSuffix(name); 172 if (suffix != null) { 173 ht = new Hashtable (); 174 ht.put(ConnectorConstants.JNDI_SUFFIX_PROPERTY, suffix); 175 name = name.substring(0, name.lastIndexOf(suffix)); 176 } 177 InitialContext ic = new InitialContext(ht); 178 return ic.lookup(name); 179 } 180 181 185 public ConnectorNamingEventNotifier getResourceRebindEventNotifier(){ 186 return ConnectorResourceNamingEventNotifier.getInstance(); 187 } 188 189 private String getValidSuffix(String name) { 190 if (name != null) { 191 for (String validSuffix : ConnectorConstants.JNDI_SUFFIX_VALUES) { 192 if (name.endsWith(validSuffix)) { 193 return validSuffix; 194 } 195 } 196 } 197 return null; 198 } 199 } 200 | Popular Tags |