11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2013 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -72,16 +72,15 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
7272
7373 public static final String RESOURCE_ATTRIBUTE = "resource" ;
7474
75- /** @see org.springframework.context.annotation.Profile */
7675 public static final String PROFILE_ATTRIBUTE = "profile" ;
7776
7877
7978 protected final Log logger = LogFactory .getLog (getClass ());
8079
81- private XmlReaderContext readerContext ;
82-
8380 private Environment environment ;
8481
82+ private XmlReaderContext readerContext ;
83+
8584 private BeanDefinitionParserDelegate delegate ;
8685
8786
@@ -104,13 +103,12 @@ public void setEnvironment(Environment environment) {
104103 */
105104 public void registerBeanDefinitions (Document doc , XmlReaderContext readerContext ) {
106105 this .readerContext = readerContext ;
107-
108106 logger .debug ("Loading bean definitions" );
109107 Element root = doc .getDocumentElement ();
110-
111108 doRegisterBeanDefinitions (root );
112109 }
113110
111+
114112 /**
115113 * Register each bean definition within the given root {@code <beans/>} element.
116114 * @throws IllegalStateException if {@code <beans profile="..."} attribute is present
@@ -120,21 +118,22 @@ public void registerBeanDefinitions(Document doc, XmlReaderContext readerContext
120118 protected void doRegisterBeanDefinitions (Element root ) {
121119 String profileSpec = root .getAttribute (PROFILE_ATTRIBUTE );
122120 if (StringUtils .hasText (profileSpec )) {
123- Assert .state (this .environment != null , "environment property must not be null" );
124- String [] specifiedProfiles = StringUtils .tokenizeToStringArray (profileSpec , BeanDefinitionParserDelegate .MULTI_VALUE_ATTRIBUTE_DELIMITERS );
121+ Assert .state (this .environment != null , "Environment must be set for evaluating profiles" );
122+ String [] specifiedProfiles = StringUtils .tokenizeToStringArray (
123+ profileSpec , BeanDefinitionParserDelegate .MULTI_VALUE_ATTRIBUTE_DELIMITERS );
125124 if (!this .environment .acceptsProfiles (specifiedProfiles )) {
126125 return ;
127126 }
128127 }
129128
130- // any nested <beans> elements will cause recursion in this method. In
129+ // Any nested <beans> elements will cause recursion in this method. In
131130 // order to propagate and preserve <beans> default-* attributes correctly,
132131 // keep track of the current (parent) delegate, which may be null. Create
133132 // the new (child) delegate with a reference to the parent for fallback purposes,
134133 // then ultimately reset this.delegate back to its original (parent) reference.
135134 // this behavior emulates a stack of delegates without actually necessitating one.
136135 BeanDefinitionParserDelegate parent = this .delegate ;
137- this .delegate = createHelper (readerContext , root , parent );
136+ this .delegate = createHelper (this . readerContext , root , parent );
138137
139138 preProcessXml (root );
140139 parseBeanDefinitions (root , this .delegate );
@@ -143,7 +142,9 @@ protected void doRegisterBeanDefinitions(Element root) {
143142 this .delegate = parent ;
144143 }
145144
146- protected BeanDefinitionParserDelegate createHelper (XmlReaderContext readerContext , Element root , BeanDefinitionParserDelegate parentDelegate ) {
145+ protected BeanDefinitionParserDelegate createHelper (
146+ XmlReaderContext readerContext , Element root , BeanDefinitionParserDelegate parentDelegate ) {
147+
147148 BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate (readerContext , environment );
148149 delegate .initDefaults (root , parentDelegate );
149150 return delegate ;
0 commit comments