/** * Attempts to load the class on the current thread context class loader or * the class loader which loaded us */ protected Class loadClass(String name) throws ClassNotFoundException { ClassLoader beanClassLoader = getBeanDefinitionReader().getBeanClassLoader(); if (beanClassLoader != null) { try { return beanClassLoader.loadClass(name); } catch (ClassNotFoundException e) { } } ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); if (contextClassLoader != null) { try { return contextClassLoader.loadClass(name); } catch (ClassNotFoundException e) { } } return getClass().getClassLoader().loadClass(name); }
/** * Loads the resource from the given URI */ protected InputStream loadResource(String uri) { if (System.getProperty("xbean.dir") != null) { File f = new File(System.getProperty("xbean.dir") + uri); try { return new FileInputStream(f); } catch (FileNotFoundException e) { // Ignore } } // lets try the thread context class loader first InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uri); if (in == null) { ClassLoader cl = getBeanDefinitionReader().getBeanClassLoader(); if (cl != null) { in = cl.getResourceAsStream(uri); } if (in == null) { in = getClass().getClassLoader().getResourceAsStream(uri); if (in == null) { logger.debug("Could not find resource: " + uri); } } } return in; }
String name = ele.getAttribute(NAME_ATTRIBUTE); String alias = ele.getAttribute(ALIAS_ATTRIBUTE); getBeanDefinitionReader().getBeanFactory().registerAlias(name, alias); BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getBeanDefinitionReader() .getBeanFactory()); if (bdHolder != null) { beanDefinitionCount++; BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getBeanDefinitionReader() .getBeanFactory()); if (bdHolder != null) { beanDefinitionCount++; BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getBeanDefinitionReader() .getBeanFactory());
/** * Parse an "import" element and load the bean definitions * from the given resource into the bean factory. */ protected void importBeanDefinitionResource(Element ele) throws BeanDefinitionStoreException { String location = ele.getAttribute(RESOURCE_ATTRIBUTE); // Resolve system properties: e.g. "${user.dir}" location = SystemPropertyUtils.resolvePlaceholders(location); if (ResourcePatternUtils.isUrl(location)) { int importCount = getBeanDefinitionReader().loadBeanDefinitions(location); if (logger.isDebugEnabled()) { logger.debug("Imported " + importCount + " bean definitions from URL location [" + location + "]"); } } else { // No URL -> considering resource location as relative to the current file. try { Resource relativeResource = getResource().createRelative(location); int importCount = getBeanDefinitionReader().loadBeanDefinitions(relativeResource); if (logger.isDebugEnabled()) { logger.debug("Imported " + importCount + " bean definitions from relative location [" + location + "]"); } } catch (IOException ex) { throw new BeanDefinitionStoreException( "Invalid relative resource location [" + location + "] to import bean definitions from", ex); } } }
className, parent, cargs, pvs, getBeanDefinitionReader().getBeanClassLoader());