public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cri) throws javax.resource.ResourceException { if (xadsSelector == null) { return getXAManagedConnection(subject, cri); } // try to get a connection as many times as many urls we have in the list for (int i = 0; i < xadsSelector.getCustomSortedUrls().size(); ++i) { XAData xaData = (XAData) xadsSelector.getUrlObject(); if (log.isTraceEnabled()) { log.trace("Trying to create an XA connection to " + xaData.url); } try { return getXAManagedConnection(subject, cri); } catch (ResourceException e) { log.warn("Failed to create an XA connection to " + xaData.url + ": " + e.getMessage()); xadsSelector.failedUrlObject(xaData); } } // we have supposedly tried all the urls throw new JBossResourceException( "Could not create connection using any of the URLs: " + xadsSelector.getAllUrlObjects()); }
protected synchronized XADataSource getXADataSource() throws ResourceException { if (xadsSelector != null) { XAData xada = (XAData) xadsSelector.getUrlObject(); return xada.xads; } if (xads == null) { if (xaDataSourceClass == null) throw new JBossResourceException("No XADataSourceClass supplied!"); try { Class clazz = Thread.currentThread().getContextClassLoader().loadClass(xaDataSourceClass); xads = (XADataSource) clazz.newInstance(); Class[] NOCLASSES = new Class[] {}; for (Iterator i = xaProps.keySet().iterator(); i.hasNext(); ) { String name = (String) i.next(); String value = xaProps.getProperty(name); char firstCharName = Character.toUpperCase(name.charAt(0)); if (name.length() > 1) name = firstCharName + name.substring(1); else name = "" + firstCharName; // This is a bad solution. On the other hand the only known example // of a setter with no getter is for Oracle with password. // Anyway, each xadatasource implementation should get its // own subclass of this that explicitly sets the // properties individually. Class type = null; try { Method getter = clazz.getMethod("get" + name, NOCLASSES); type = getter.getReturnType(); } catch (NoSuchMethodException e) { try { // HACK for now until we can rethink the XADataSourceProperties variable and pass type // information Method isMethod = clazz.getMethod("is" + name, NOCLASSES); type = isMethod.getReturnType(); } catch (NoSuchMethodException nsme) { type = String.class; } } Method setter = clazz.getMethod("set" + name, new Class[] {type}); PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor == null) throw new JBossResourceException("No property editor found for type: " + type); editor.setAsText(value); setter.invoke(xads, new Object[] {editor.getValue()}); } } catch (ClassNotFoundException cnfe) { throw new JBossResourceException( "Class not found for XADataSource " + xaDataSourceClass, cnfe); } catch (InstantiationException ie) { throw new JBossResourceException("Could not create an XADataSource: ", ie); } catch (IllegalAccessException iae) { throw new JBossResourceException("Could not set a property: ", iae); } catch (IllegalArgumentException iae) { throw new JBossResourceException("Could not set a property: ", iae); } catch (InvocationTargetException ite) { throw new JBossResourceException("Could not invoke setter on XADataSource: ", ite); } catch (NoSuchMethodException nsme) { throw new JBossResourceException("Could not find accessor on XADataSource: ", nsme); } } return xads; }