|
61 | 61 | import org.springframework.lang.Nullable; |
62 | 62 | import org.springframework.util.Assert; |
63 | 63 | import org.springframework.util.ClassUtils; |
| 64 | +import org.springframework.util.ObjectUtils; |
64 | 65 | import org.springframework.util.StringUtils; |
65 | 66 | import org.springframework.util.xml.DomUtils; |
66 | 67 |
|
@@ -97,8 +98,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) { |
97 | 98 | String id = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE); |
98 | 99 | id = StringUtils.hasText(id) ? id : DEFAULT_CONVERTER_BEAN_NAME; |
99 | 100 |
|
100 | | - String autoIndexCreation = element.getAttribute("auto-index-creation"); |
101 | | - boolean autoIndexCreationEnabled = StringUtils.hasText(autoIndexCreation) && Boolean.valueOf(autoIndexCreation); |
| 101 | + boolean autoIndexCreationEnabled = isAutoIndexCreationEnabled(element); |
102 | 102 |
|
103 | 103 | parserContext.pushContainingComponent(new CompositeComponentDefinition("Mapping Mongo Converter", element)); |
104 | 104 |
|
@@ -199,11 +199,33 @@ private RuntimeBeanReference getValidator(Object source, ParserContext parserCon |
199 | 199 | return new RuntimeBeanReference(validatorName); |
200 | 200 | } |
201 | 201 |
|
| 202 | + private static boolean isAutoIndexCreationEnabled(Element element) { |
| 203 | + |
| 204 | + String autoIndexCreation = element.getAttribute("auto-index-creation"); |
| 205 | + return StringUtils.hasText(autoIndexCreation) && Boolean.parseBoolean(autoIndexCreation); |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * Create and register the {@link BeanDefinition} for a {@link MongoMappingContext} if not explicitly referenced by a |
| 210 | + * given {@literal mapping-context-ref} {@link Element#getAttribute(String) attribuite}. |
| 211 | + * |
| 212 | + * @return the mapping context bean name. |
| 213 | + * @deprecated since 4.3. Use |
| 214 | + * {@link #potentiallyCreateMappingContext(Element, ParserContext, BeanDefinition, String, boolean)} |
| 215 | + * instead. |
| 216 | + */ |
| 217 | + @Deprecated(since = "4.3", forRemoval = true) |
202 | 218 | public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext, |
203 | 219 | @Nullable BeanDefinition conversionsDefinition, @Nullable String converterId) { |
204 | 220 | return potentiallyCreateMappingContext(element, parserContext, conversionsDefinition, converterId, false); |
205 | 221 | } |
206 | 222 |
|
| 223 | + /** |
| 224 | + * Create and register the {@link BeanDefinition} for a {@link MongoMappingContext} if not explicitly referenced by a |
| 225 | + * given {@literal mapping-context-ref} {@link Element#getAttribute(String) attribuite}. |
| 226 | + * |
| 227 | + * @return the mapping context bean name. |
| 228 | + */ |
207 | 229 | public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext, |
208 | 230 | @Nullable BeanDefinition conversionsDefinition, @Nullable String converterId, boolean autoIndexCreation) { |
209 | 231 |
|
@@ -283,8 +305,10 @@ private BeanDefinition getCustomConversions(Element element, ParserContext parse |
283 | 305 | ManagedList<BeanMetadataElement> converterBeans = new ManagedList<>(); |
284 | 306 | List<Element> converterElements = DomUtils.getChildElementsByTagName(customerConvertersElement, "converter"); |
285 | 307 |
|
286 | | - for (Element listenerElement : converterElements) { |
287 | | - converterBeans.add(parseConverter(listenerElement, parserContext)); |
| 308 | + if (!ObjectUtils.isEmpty(converterElements)) { |
| 309 | + for (Element listenerElement : converterElements) { |
| 310 | + converterBeans.add(parseConverter(listenerElement, parserContext)); |
| 311 | + } |
288 | 312 | } |
289 | 313 |
|
290 | 314 | // Scan for Converter and GenericConverter beans in the given base-package |
|
0 commit comments