Skip to content

Commit 763ee4b

Browse files
committed
Deprecate ConverterManager
Closes gh-1004
1 parent 30efe4e commit 763ee4b

14 files changed

+212
-32
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2002-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ldap.convert;
18+
19+
import org.springframework.core.convert.converter.ConverterRegistry;
20+
21+
/**
22+
* A utility class for working with Spring LDAP converters
23+
*
24+
* @author Josh Cummings
25+
* @since 3.3
26+
*/
27+
public final class ConverterUtils {
28+
29+
/**
30+
* Register Spring LDAP's default converters to the given {@link ConverterRegistry}.
31+
* @param registry the {@link ConverterRegistry} to configure
32+
*/
33+
public static void addDefaultConverters(ConverterRegistry registry) {
34+
registry.addConverter(new StringToNameConverter());
35+
registry.addConverter(new NameToStringConverter());
36+
}
37+
38+
private ConverterUtils() {
39+
40+
}
41+
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2002-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ldap.convert;
18+
19+
import javax.naming.Name;
20+
21+
import org.springframework.core.convert.converter.Converter;
22+
23+
/**
24+
* A converer from {@link Name} to {@link String}.
25+
*
26+
* <p>
27+
* Helpful for {@link org.springframework.ldap.odm.core.ObjectDirectoryMapper} for
28+
* converting fields. Also helpful when working with {@link Name} instances in Spring MVC
29+
* applications.
30+
*
31+
* @author Josh Cummings
32+
* @since 3.3
33+
*/
34+
public final class NameToStringConverter implements Converter<Name, String> {
35+
36+
@Override
37+
public String convert(Name source) {
38+
if (source == null) {
39+
return null;
40+
}
41+
42+
return source.toString();
43+
}
44+
45+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2002-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ldap.convert;
18+
19+
import javax.naming.Name;
20+
21+
import org.springframework.core.convert.converter.Converter;
22+
import org.springframework.ldap.support.LdapUtils;
23+
24+
/**
25+
* A converer from {@link String} to {@link Name}.
26+
*
27+
* <p>
28+
* Helpful for {@link org.springframework.ldap.odm.core.ObjectDirectoryMapper} for
29+
* converting fields. Also helpful when working with {@link Name} instances in Spring MVC
30+
* applications.
31+
*
32+
* @author Josh Cummings
33+
* @since 3.3
34+
*/
35+
public final class StringToNameConverter implements Converter<String, Name> {
36+
37+
@Override
38+
public Name convert(String source) {
39+
if (source == null) {
40+
return null;
41+
}
42+
43+
return LdapUtils.newLdapName(source);
44+
}
45+
46+
}

core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@
3838
import org.slf4j.LoggerFactory;
3939

4040
import org.springframework.LdapDataEntry;
41-
import org.springframework.core.SpringVersion;
41+
import org.springframework.core.convert.ConversionService;
42+
import org.springframework.core.convert.support.GenericConversionService;
43+
import org.springframework.ldap.convert.ConverterUtils;
4244
import org.springframework.ldap.filter.AndFilter;
4345
import org.springframework.ldap.filter.EqualsFilter;
4446
import org.springframework.ldap.filter.Filter;
4547
import org.springframework.ldap.odm.annotations.DnAttribute;
4648
import org.springframework.ldap.odm.core.ObjectDirectoryMapper;
4749
import org.springframework.ldap.odm.typeconversion.ConverterManager;
4850
import org.springframework.ldap.odm.typeconversion.impl.ConversionServiceConverterManager;
49-
import org.springframework.ldap.odm.typeconversion.impl.ConverterManagerImpl;
5051
import org.springframework.ldap.support.LdapNameBuilder;
5152
import org.springframework.ldap.support.LdapUtils;
5253
import org.springframework.util.Assert;
@@ -77,24 +78,29 @@ public DefaultObjectDirectoryMapper() {
7778
}
7879

7980
private static ConverterManager createDefaultConverterManager() {
80-
String springVersion = SpringVersion.getVersion();
81-
if (springVersion == null) {
82-
LOG.debug(
83-
"Could not determine the Spring Version. Guessing > Spring 3.0. If this does not work, please ensure to explicitly set converterManager");
84-
return new ConversionServiceConverterManager();
85-
}
86-
else if (springVersion.compareTo("3.0") > 0) {
87-
return new ConversionServiceConverterManager();
88-
}
89-
else {
90-
return new ConverterManagerImpl();
91-
}
81+
GenericConversionService conversionService = new GenericConversionService();
82+
ConverterUtils.addDefaultConverters(conversionService);
83+
return new ConversionServiceConverterManager(conversionService);
9284
}
9385

86+
/**
87+
* @deprecated please use {@link #setConversionService} instead
88+
*/
89+
@Deprecated(since = "3.3")
9490
public void setConverterManager(ConverterManager converterManager) {
9591
this.converterManager = converterManager;
9692
}
9793

94+
/**
95+
* Use this {@link ConversionService}
96+
* @param conversionService
97+
* @since 3.3
98+
* @see ConverterUtils for converters helpful to {@link ObjectDirectoryMapper}
99+
*/
100+
public void setConversionService(ConversionService conversionService) {
101+
this.converterManager = new ConversionServiceConverterManager(conversionService);
102+
}
103+
98104
// A map of managed classes to to meta data about those classes
99105
private final ConcurrentMap<Class<?>, EntityData> metaDataMap = new ConcurrentHashMap<>();
100106

core/src/main/java/org/springframework/ldap/odm/typeconversion/ConverterException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2013 the original author or authors.
2+
* Copyright 2005-2025 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.
@@ -23,7 +23,9 @@
2323
* type conversion.
2424
*
2525
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
26+
* @deprecated please use {@link org.springframework.core.convert.ConversionException}
2627
*/
28+
@Deprecated
2729
@SuppressWarnings("serial")
2830
public final class ConverterException extends NamingException {
2931

core/src/main/java/org/springframework/ldap/odm/typeconversion/ConverterManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2013 the original author or authors.
2+
* Copyright 2005-2025 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.
@@ -16,11 +16,15 @@
1616

1717
package org.springframework.ldap.odm.typeconversion;
1818

19+
import org.springframework.core.convert.ConversionService;
20+
1921
/**
2022
* A simple interface to be implemented to provide type conversion functionality.
2123
*
2224
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
25+
* @deprecated please use {@link ConversionService} directly
2326
*/
27+
@Deprecated
2428
public interface ConverterManager {
2529

2630
/**

core/src/main/java/org/springframework/ldap/odm/typeconversion/impl/ConversionServiceConverterManager.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2013 the original author or authors.
2+
* Copyright 2005-2025 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.
@@ -18,7 +18,9 @@
1818

1919
import javax.naming.Name;
2020

21+
import org.springframework.core.convert.ConversionService;
2122
import org.springframework.core.convert.support.GenericConversionService;
23+
import org.springframework.ldap.convert.ConverterUtils;
2224
import org.springframework.ldap.odm.typeconversion.ConverterManager;
2325
import org.springframework.ldap.support.LdapUtils;
2426
import org.springframework.util.ClassUtils;
@@ -27,37 +29,37 @@
2729
/**
2830
* @author Mattias Hellborg Arthursson
2931
* @since 2.0
32+
* @deprecated Please use {@link ConversionService} directly and with
33+
* {@link ConverterUtils} to add Spring LDAP converters
3034
*/
35+
@Deprecated
3136
public class ConversionServiceConverterManager implements ConverterManager {
3237

33-
private GenericConversionService conversionService;
38+
private ConversionService conversionService;
3439

3540
private static final String DEFAULT_CONVERSION_SERVICE_CLASS = "org.springframework.core.convert.support.DefaultConversionService";
3641

42+
public ConversionServiceConverterManager(ConversionService conversionService) {
43+
this.conversionService = conversionService;
44+
}
45+
3746
public ConversionServiceConverterManager(GenericConversionService conversionService) {
3847
this.conversionService = conversionService;
3948
}
4049

4150
public ConversionServiceConverterManager() {
51+
GenericConversionService genericConversionService = new GenericConversionService();
4252
ClassLoader defaultClassLoader = ClassUtils.getDefaultClassLoader();
4353
if (ClassUtils.isPresent(DEFAULT_CONVERSION_SERVICE_CLASS, defaultClassLoader)) {
4454
try {
4555
Class<?> clazz = ClassUtils.forName(DEFAULT_CONVERSION_SERVICE_CLASS, defaultClassLoader);
46-
this.conversionService = (GenericConversionService) clazz.newInstance();
56+
genericConversionService = (GenericConversionService) clazz.newInstance();
4757
}
4858
catch (Exception ex) {
4959
ReflectionUtils.handleReflectionException(ex);
5060
}
5161
}
52-
else {
53-
this.conversionService = new GenericConversionService();
54-
}
55-
56-
prePopulateWithNameConverter();
57-
}
58-
59-
private void prePopulateWithNameConverter() {
60-
this.conversionService.addConverter(new StringToNameConverter());
62+
genericConversionService.addConverter(new StringToNameConverter());
6163
}
6264

6365
@Override

core/src/main/java/org/springframework/ldap/odm/typeconversion/impl/Converter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2013 the original author or authors.
2+
* Copyright 2005-2025 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.
@@ -20,7 +20,10 @@
2020
* Interface specifying the conversion between two classes
2121
*
2222
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
23+
* @deprecated please use {@link org.springframework.core.convert.converter.Converter} and
24+
* {@link org.springframework.core.convert.ConversionService} directly
2325
*/
26+
@Deprecated
2427
public interface Converter {
2528

2629
/**

core/src/main/java/org/springframework/ldap/odm/typeconversion/impl/ConverterManagerFactoryBean.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@
9292
* parameter to allow an LDAP syntax to be defined.
9393
*
9494
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
95+
* @deprecated please use {@link org.springframework.core.convert.ConversionService}
96+
* directly
9597
*/
98+
@Deprecated
9699
public final class ConverterManagerFactoryBean implements FactoryBean {
97100

98101
private static final Logger LOG = LoggerFactory.getLogger(ConverterManagerFactoryBean.class);

core/src/main/java/org/springframework/ldap/odm/typeconversion/impl/ConverterManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@
4040
* </ol>
4141
*
4242
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
43+
* @deprecated please use {@link org.springframework.core.convert.ConversionService}
44+
* directly
4345
*/
46+
@Deprecated
4447
public final class ConverterManagerImpl implements ConverterManager {
4548

4649
/**

core/src/main/java/org/springframework/ldap/odm/typeconversion/impl/StringConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2023 the original author or authors.
2+
* Copyright 2005-2025 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.
@@ -19,6 +19,7 @@
1919
/**
2020
* @author Mattias Hellborg Arthursson
2121
*/
22+
@Deprecated
2223
public class StringConverter {
2324

2425
}

core/src/main/java/org/springframework/ldap/odm/typeconversion/impl/converters/FromStringConverter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2013 the original author or authors.
2+
* Copyright 2005-2025 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.
@@ -27,7 +27,10 @@
2727
* This should only be used as a fall-back converter, as a last attempt.
2828
*
2929
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
30+
* @deprecated please use {@link org.springframework.core.convert.converter.Converter}
31+
* directly
3032
*/
33+
@Deprecated
3134
public final class FromStringConverter implements Converter {
3235

3336
/*

core/src/main/java/org/springframework/ldap/odm/typeconversion/impl/converters/ToStringConverter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2013 the original author or authors.
2+
* Copyright 2005-2025 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.
@@ -25,7 +25,10 @@
2525
* This should only be used as a fall-back converter, as a last attempt.
2626
*
2727
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
28+
* @deprecated please use {@link org.springframework.core.convert.converter.Converter} and
29+
* {@link org.springframework.core.convert.ConversionService} directly
2830
*/
31+
@Deprecated
2932
public final class ToStringConverter implements Converter {
3033

3134
/*

0 commit comments

Comments
 (0)