protected Object parsePropertySubElement(Element valueElement, String beanName) { if (valueElement.getTagName().equals(VALUE_ELEMENT)) { for (Node nd = valueElement.getFirstChild(); nd != null; nd = nd.getNextSibling()) { if (Node.ELEMENT_NODE == nd.getNodeType()) { return nd; } } } return super.parsePropertySubElement(valueElement, beanName); } }
/** * 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); }
protected BeanDefinitionHolder parseBeanDefinitionElement(Element ele, boolean isInnerBean) throws BeanDefinitionStoreException { BeanDefinitionHolder bdh = super.parseBeanDefinitionElement(ele, isInnerBean); coerceNamespaceAwarePropertyValues(bdh, ele); return bdh; }
/** * Parses bean definitions according to the "spring-beans" DTD. * <p>Opens a DOM Document; then initializes the default settings * specified at <code><beans></code> level; then parses * the contained bean definitions. */ public int registerBeanDefinitions(BeanDefinitionReader reader, Document doc, Resource resource) throws BeanDefinitionStoreException { this.beanDefinitionReader = reader; this.resource = resource; logger.debug("Loading bean definitions"); Element root = doc.getDocumentElement(); initDefaults(root); if (logger.isDebugEnabled()) { logger.debug("Default lazy init '" + getDefaultLazyInit() + "'"); logger.debug("Default autowire '" + getDefaultAutowire() + "'"); logger.debug("Default dependency check '" + getDefaultDependencyCheck() + "'"); } preProcessXml(root); int beanDefinitionCount = parseBeanDefinitions(root); if (logger.isDebugEnabled()) { logger.debug("Found " + beanDefinitionCount + " <bean> elements in " + resource); } postProcessXml(root); return beanDefinitionCount; }
/** * Parse a key sub-element of a map element. */ protected Object parseKeyElement(Element keyEle, String beanName) throws BeanDefinitionStoreException { NodeList nl = keyEle.getChildNodes(); Element subElement = null; for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof Element) { Element candidateEle = (Element) nl.item(i); // Child element is what we're looking for. if (subElement != null) { throw new BeanDefinitionStoreException( getResource(), beanName, "<key> must not contain more than one value sub-element"); } subElement = candidateEle; } } return parsePropertySubElement(subElement, beanName); }
ConstructorArgumentValues cargs = parseConstructorArgElements(ele, beanName); MutablePropertyValues pvs = parsePropertyElements(ele, beanName); className, parent, cargs, pvs, getBeanDefinitionReader().getBeanClassLoader()); dependencyCheck = getDefaultDependencyCheck(); bd.setDependencyCheck(getDependencyCheck(dependencyCheck)); autowire = getDefaultAutowire(); bd.setAutowireMode(getAutowireMode(autowire)); parseLookupOverrideSubElements(ele, beanName, bd.getMethodOverrides()); parseReplacedMethodSubElements(ele, beanName, bd.getMethodOverrides()); bd.setResourceDescription(getResource().getDescription()); if (DEFAULT_VALUE.equals(lazyInit) && bd.isSingleton()) { lazyInit = getDefaultLazyInit(); getResource(), beanName, "Bean class [" + className + "] not found", ex); getResource(), beanName, "Class that bean class [" + className + "] depends on not found", err);
return parseBeanDefinitionElement(ele, true); if (!StringUtils.hasLength(beanRef)) { throw new BeanDefinitionStoreException( getResource(), beanName, "'bean', 'local' or 'parent' is required for a reference"); if (!StringUtils.hasLength(beanRef)) { throw new BeanDefinitionStoreException( getResource(), beanName, "Either 'bean' or 'local' is required for an idref"); getResource(), beanName, "Value type class [" + typeClassName + "] not found", ex); return parseListElement(ele, beanName); return parseSetElement(ele, beanName); return parseMapElement(ele, beanName); return parsePropsElement(ele, beanName); getResource(), beanName, "Unknown property sub-element: <" + ele.getTagName() + ">");
if (keyEle != null) { throw new BeanDefinitionStoreException( getResource(), beanName, "<entry> is only allowed to contain one <key> sub-element"); getResource(), beanName, "<entry> must not contain more than one value sub-element"); ((hasKeyAttribute || hasKeyRefAttribute)) && keyEle != null) { throw new BeanDefinitionStoreException( getResource(), beanName, "<entry> is only allowed to contain either " + "a 'key' attribute OR a 'key-ref' attribute OR a <key> sub-element"); key = parseKeyElement(keyEle, beanName); getResource(), beanName, "<entry> must specify a key"); ((hasValueAttribute || hasValueRefAttribute)) && valueEle != null) { throw new BeanDefinitionStoreException( getResource(), beanName, "<entry> is only allowed to contain either " + "a 'value' attribute OR a 'value-ref' attribute OR a value sub-element"); value = parsePropertySubElement(valueEle, beanName); getResource(), beanName, "<entry> must specify a value");
/** * Parse the elements at the root level in the document: * "import", "alias", "bean". * @param root the DOM root element of the document * @return the number of bean definitions found */ protected int parseBeanDefinitions(Element root) throws BeanDefinitionStoreException { NodeList nl = root.getChildNodes(); int beanDefinitionCount = 0; for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element) { Element ele = (Element) node; if (IMPORT_ELEMENT.equals(node.getNodeName())) { importBeanDefinitionResource(ele); } else if (ALIAS_ELEMENT.equals(node.getNodeName())) { String name = ele.getAttribute(NAME_ATTRIBUTE); String alias = ele.getAttribute(ALIAS_ATTRIBUTE); this.beanDefinitionReader.getBeanFactory().registerAlias(name, alias); } else if (BEAN_ELEMENT.equals(node.getNodeName())) { beanDefinitionCount++; BeanDefinitionHolder bdHolder = parseBeanDefinitionElement(ele, false); BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, this.beanDefinitionReader.getBeanFactory()); } } } return beanDefinitionCount; }
Element ele = (Element) node; if (IMPORT_ELEMENT.equals(node.getNodeName())) { importBeanDefinitionResource(ele); 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); } } }
/** * Attempts to use introspection to parse the nested property element. */ private Object parseNestedPropertyViaIntrospection(MappingMetaData metadata, Element element, String propertyName, Class propertyType) { if (isMap(propertyType)) { return parseCustomMapElement(metadata, element, propertyName); } else if (isCollection(propertyType)) { return parseListElement(element, propertyName); } else { return parseChildExtensionBean(element); } }
getResource(), beanName, elementName + " must not contain more than one sub-element"); ((hasRefAttribute || hasValueAttribute)) && subElement != null) { throw new BeanDefinitionStoreException( getResource(), beanName, elementName + " is only allowed to contain either a 'ref' attribute OR a 'value' attribute OR a sub-element"); getResource(), beanName, elementName + " must specify a ref or value"); return parsePropertySubElement(subElement, beanName);
String propertyName = metadata.getNestedListProperty(getLocalName(element), localName); if (propertyName != null) { value = parseListElement(childElement, propertyName);
/** * Parse a list element. */ protected List parseListElement(Element collectionEle, String beanName) throws BeanDefinitionStoreException { NodeList nl = collectionEle.getChildNodes(); ManagedList list = new ManagedList(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof Element) { Element ele = (Element) nl.item(i); list.add(parsePropertySubElement(ele, beanName)); } } return list; }
BeanDefinition beanDefinition = parseBeanDefinitionElement(ele, beanName);
/** * 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; }
/** * Parse a set element. */ protected Set parseSetElement(Element collectionEle, String beanName) throws BeanDefinitionStoreException { NodeList nl = collectionEle.getChildNodes(); ManagedSet set = new ManagedSet(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof Element) { Element ele = (Element) nl.item(i); set.add(parsePropertySubElement(ele, beanName)); } } return set; }
protected Object parsePropertySubElement(Element element, String beanName) throws BeanDefinitionStoreException { String uri = element.getNamespaceURI(); String localName = getLocalName(element); if ((!isEmpty(uri) && !(uri.equals(SPRING_SCHEMA) || uri.equals(SPRING_SCHEMA_COMPAT))) || !reservedElementNames.contains(localName)) { Object answer = parseBeanFromExtensionElement(element); if (answer != null) { return answer; } } if (QNAME_ELEMENT.equals(localName) && isQnameIsOnClassPath()) { Object answer = parseQNameElement(element); if (answer != null) { return answer; } } return super.parsePropertySubElement(element, beanName); }