175 if ((id != null) && (!id.equals(OID))) { 176 throw new ConfigurationException( 177 "Start TLS received the following response instead of " + 178 OID + ": " + id); 179 } 180 181 StartTlsResponse resp = null; 182 183 ServiceLoader<StartTlsResponse> sl = ServiceLoader.load( 184 StartTlsResponse.class, getContextClassLoader()); 185 Iterator<StartTlsResponse> iter = sl.iterator(); 186 187 while (resp == null && privilegedHasNext(iter)) { 188 resp = iter.next(); 189 } 190 if (resp != null) { 191 return resp; 192 } 193 try { 194 VersionHelper helper = VersionHelper.getVersionHelper(); 195 Class<?> clas = helper.loadClass( 196 "com.sun.jndi.ldap.ext.StartTlsResponseImpl"); 197 198 resp = (StartTlsResponse) clas.newInstance(); 199 200 } catch (IllegalAccessException e) { 201 throw wrapException(e); 202 203 } catch (InstantiationException e) { 204 throw wrapException(e); 205 206 } catch (ClassNotFoundException e) { 207 throw wrapException(e); 208 } 209 210 return resp; 211 } 212 213 /* 214 * Wrap an exception, thrown while attempting to load the StartTlsResponse 215 * class, in a configuration exception. 216 */ 217 private ConfigurationException wrapException(Exception e) { 218 ConfigurationException ce = new ConfigurationException( 219 "Cannot load implementation of javax.naming.ldap.StartTlsResponse"); 220 221 ce.setRootCause(e); 222 return ce; 223 } 224 225 /* 226 * Acquire the class loader associated with this thread. | 175 if ((id != null) && (!id.equals(OID))) { 176 throw new ConfigurationException( 177 "Start TLS received the following response instead of " + 178 OID + ": " + id); 179 } 180 181 StartTlsResponse resp = null; 182 183 ServiceLoader<StartTlsResponse> sl = ServiceLoader.load( 184 StartTlsResponse.class, getContextClassLoader()); 185 Iterator<StartTlsResponse> iter = sl.iterator(); 186 187 while (resp == null && privilegedHasNext(iter)) { 188 resp = iter.next(); 189 } 190 if (resp != null) { 191 return resp; 192 } 193 try { 194 VersionHelper helper = VersionHelper.getVersionHelper(); 195 @SuppressWarnings("deprecation") 196 Object o = helper.loadClass( 197 "com.sun.jndi.ldap.ext.StartTlsResponseImpl").newInstance(); 198 resp = (StartTlsResponse) o; 199 200 } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) { 201 throw wrapException(e); 202 } 203 204 return resp; 205 } 206 207 /* 208 * Wrap an exception, thrown while attempting to load the StartTlsResponse 209 * class, in a configuration exception. 210 */ 211 private ConfigurationException wrapException(Exception e) { 212 ConfigurationException ce = new ConfigurationException( 213 "Cannot load implementation of javax.naming.ldap.StartTlsResponse"); 214 215 ce.setRootCause(e); 216 return ce; 217 } 218 219 /* 220 * Acquire the class loader associated with this thread. |