private static void appendURLs(List<URL> urls, File f) throws MalformedURLException { for (File file : f.listFiles()) { if (file.getName().toUpperCase().endsWith(".JAR")) { urls.add(file.toURI().toURL()); } else if (file.isDirectory()) { appendURLs(urls, file); } } }
/** * Extracts RA Bean properties via reflection. * * @param raClassName The RA Bean class name. * @param classLoader the classloader to use to find the class. */ private static Map extractRABeanProps(String raClassName, ClassLoader classLoader) throws ClassNotFoundException { Map hMap = new HashMap(); //Only if RA is a 1.5 RAR, we need to get RA JavaBean properties, else //return an empty map. if(raClassName.trim().length() != 0) { Class c = classLoader.loadClass(raClassName); if(_logger.isLoggable(Level.FINER)) printClassDetails(c); hMap = getJavaBeanProperties(c); } return hMap; }
public static Class loadClassFromRar(String rarName, String beanClassName) throws ConnectorRuntimeException{ String rarLocation = getRarLocation(rarName); return loadClass(rarLocation, beanClassName); }
ClassLoader cl = null; File f = new File(file); validateRARLocation(f); try { ClassLoader commonClassLoader = List<URL> urls = new ArrayList<URL>(); urls.add(f.toURI().toURL()); appendURLs(urls, f); cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), commonClassLoader); } else {
/** * Checks whether the property is valid or not. */ private boolean isValid(Method setMethod, Class loadedClass) { Method getMethod = correspondingGetMethod( setMethod, loadedClass); if (getMethod != null) { return RARUtils.isValidRABeanConfigProperty(getMethod.getReturnType()); } else { return false; } }
/** * A valid resource adapter java bean property should either be one of the * following * 1. A Java primitive or a primitve wrapper * 2. A String */ public static boolean isValidRABeanConfigProperty(Class clz) { return (clz.isPrimitive() || clz.equals(String.class) || isPrimitiveWrapper(clz)); }
/** * given the location of .rar (archive / exploded dir), the specified class will be loaded * @param pathToDeployableUnit location of .rar (archive / exploded dir) * @param beanClassName class that has to be loaded * @return loaded class * @throws ConnectorRuntimeException when unable to load the class */ private static Class loadClass(String pathToDeployableUnit, String beanClassName) throws ConnectorRuntimeException { Class cls = null; ClassLoader cl = getClassLoader(pathToDeployableUnit); try { //Only if RA is a 1.5 RAR, we need to get RA JavaBean properties, else //return an empty map. if (beanClassName != null && beanClassName.trim().length() != 0) { cls = cl.loadClass(beanClassName); } return cls; } catch (ClassNotFoundException e) { _logger.info(e.getMessage()); if(_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE, "Unable to find class while trying to read connector" + "descriptor to get resource-adapter properties", e); } ConnectorRuntimeException cre = new ConnectorRuntimeException("unable to find class : " + beanClassName); cre.setStackTrace(e.getStackTrace()); throw cre; } }
" from server instance, trying other instances' deployments"); loadedClass = RARUtils.loadClassFromRar(resourceAdapterName, className); }else{ loadedClass = app.getClassLoader().loadClass(className);
RARUtils.getMergedActivationConfigProperties(descriptor);
private static Map getJavaBeanProperties(Class c) { Method[] m = c.getMethods(); Map hMap = new HashMap(); for (int i = 0; i < m.length; i++) { if(_logger.isLoggable(Level.FINER)) { _logger.finer(m[i].getName()); } if(m[i].getName().startsWith("get") && isValidRABeanConfigProperty(m[i].getReturnType())) { hMap.put(m[i].getName().substring(3), m[i].getReturnType()); } } //remove Object's Class attribute. hMap.remove("Class"); return hMap; }