Skip to content

Commit

Permalink
Deprecate ConverterManager
Browse files Browse the repository at this point in the history
Closes gh-1004
  • Loading branch information
jzheaux committed Feb 12, 2025
1 parent 30efe4e commit 763ee4b
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ldap.convert;

import org.springframework.core.convert.converter.ConverterRegistry;

/**
* A utility class for working with Spring LDAP converters
*
* @author Josh Cummings
* @since 3.3
*/
public final class ConverterUtils {

/**
* Register Spring LDAP's default converters to the given {@link ConverterRegistry}.
* @param registry the {@link ConverterRegistry} to configure
*/
public static void addDefaultConverters(ConverterRegistry registry) {
registry.addConverter(new StringToNameConverter());
registry.addConverter(new NameToStringConverter());
}

private ConverterUtils() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ldap.convert;

import javax.naming.Name;

import org.springframework.core.convert.converter.Converter;

/**
* A converer from {@link Name} to {@link String}.
*
* <p>
* Helpful for {@link org.springframework.ldap.odm.core.ObjectDirectoryMapper} for
* converting fields. Also helpful when working with {@link Name} instances in Spring MVC
* applications.
*
* @author Josh Cummings
* @since 3.3
*/
public final class NameToStringConverter implements Converter<Name, String> {

@Override
public String convert(Name source) {
if (source == null) {
return null;
}

return source.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ldap.convert;

import javax.naming.Name;

import org.springframework.core.convert.converter.Converter;
import org.springframework.ldap.support.LdapUtils;

/**
* A converer from {@link String} to {@link Name}.
*
* <p>
* Helpful for {@link org.springframework.ldap.odm.core.ObjectDirectoryMapper} for
* converting fields. Also helpful when working with {@link Name} instances in Spring MVC
* applications.
*
* @author Josh Cummings
* @since 3.3
*/
public final class StringToNameConverter implements Converter<String, Name> {

@Override
public Name convert(String source) {
if (source == null) {
return null;
}

return LdapUtils.newLdapName(source);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@
import org.slf4j.LoggerFactory;

import org.springframework.LdapDataEntry;
import org.springframework.core.SpringVersion;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.ldap.convert.ConverterUtils;
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.ldap.filter.Filter;
import org.springframework.ldap.odm.annotations.DnAttribute;
import org.springframework.ldap.odm.core.ObjectDirectoryMapper;
import org.springframework.ldap.odm.typeconversion.ConverterManager;
import org.springframework.ldap.odm.typeconversion.impl.ConversionServiceConverterManager;
import org.springframework.ldap.odm.typeconversion.impl.ConverterManagerImpl;
import org.springframework.ldap.support.LdapNameBuilder;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -77,24 +78,29 @@ public DefaultObjectDirectoryMapper() {
}

private static ConverterManager createDefaultConverterManager() {
String springVersion = SpringVersion.getVersion();
if (springVersion == null) {
LOG.debug(
"Could not determine the Spring Version. Guessing > Spring 3.0. If this does not work, please ensure to explicitly set converterManager");
return new ConversionServiceConverterManager();
}
else if (springVersion.compareTo("3.0") > 0) {
return new ConversionServiceConverterManager();
}
else {
return new ConverterManagerImpl();
}
GenericConversionService conversionService = new GenericConversionService();
ConverterUtils.addDefaultConverters(conversionService);
return new ConversionServiceConverterManager(conversionService);
}

/**
* @deprecated please use {@link #setConversionService} instead
*/
@Deprecated(since = "3.3")
public void setConverterManager(ConverterManager converterManager) {
this.converterManager = converterManager;
}

/**
* Use this {@link ConversionService}
* @param conversionService
* @since 3.3
* @see ConverterUtils for converters helpful to {@link ObjectDirectoryMapper}
*/
public void setConversionService(ConversionService conversionService) {
this.converterManager = new ConversionServiceConverterManager(conversionService);
}

// A map of managed classes to to meta data about those classes
private final ConcurrentMap<Class<?>, EntityData> metaDataMap = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,9 @@
* type conversion.
*
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
* @deprecated please use {@link org.springframework.core.convert.ConversionException}
*/
@Deprecated
@SuppressWarnings("serial")
public final class ConverterException extends NamingException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,11 +16,15 @@

package org.springframework.ldap.odm.typeconversion;

import org.springframework.core.convert.ConversionService;

/**
* A simple interface to be implemented to provide type conversion functionality.
*
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
* @deprecated please use {@link ConversionService} directly
*/
@Deprecated
public interface ConverterManager {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,9 @@

import javax.naming.Name;

import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.ldap.convert.ConverterUtils;
import org.springframework.ldap.odm.typeconversion.ConverterManager;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.util.ClassUtils;
Expand All @@ -27,37 +29,37 @@
/**
* @author Mattias Hellborg Arthursson
* @since 2.0
* @deprecated Please use {@link ConversionService} directly and with
* {@link ConverterUtils} to add Spring LDAP converters
*/
@Deprecated
public class ConversionServiceConverterManager implements ConverterManager {

private GenericConversionService conversionService;
private ConversionService conversionService;

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

public ConversionServiceConverterManager(ConversionService conversionService) {
this.conversionService = conversionService;
}

public ConversionServiceConverterManager(GenericConversionService conversionService) {
this.conversionService = conversionService;
}

public ConversionServiceConverterManager() {
GenericConversionService genericConversionService = new GenericConversionService();
ClassLoader defaultClassLoader = ClassUtils.getDefaultClassLoader();
if (ClassUtils.isPresent(DEFAULT_CONVERSION_SERVICE_CLASS, defaultClassLoader)) {
try {
Class<?> clazz = ClassUtils.forName(DEFAULT_CONVERSION_SERVICE_CLASS, defaultClassLoader);
this.conversionService = (GenericConversionService) clazz.newInstance();
genericConversionService = (GenericConversionService) clazz.newInstance();
}
catch (Exception ex) {
ReflectionUtils.handleReflectionException(ex);
}
}
else {
this.conversionService = new GenericConversionService();
}

prePopulateWithNameConverter();
}

private void prePopulateWithNameConverter() {
this.conversionService.addConverter(new StringToNameConverter());
genericConversionService.addConverter(new StringToNameConverter());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,10 @@
* Interface specifying the conversion between two classes
*
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
* @deprecated please use {@link org.springframework.core.convert.converter.Converter} and
* {@link org.springframework.core.convert.ConversionService} directly
*/
@Deprecated
public interface Converter {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@
* parameter to allow an LDAP syntax to be defined.
*
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
* @deprecated please use {@link org.springframework.core.convert.ConversionService}
* directly
*/
@Deprecated
public final class ConverterManagerFactoryBean implements FactoryBean {

private static final Logger LOG = LoggerFactory.getLogger(ConverterManagerFactoryBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
* </ol>
*
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
* @deprecated please use {@link org.springframework.core.convert.ConversionService}
* directly
*/
@Deprecated
public final class ConverterManagerImpl implements ConverterManager {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2023 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
/**
* @author Mattias Hellborg Arthursson
*/
@Deprecated
public class StringConverter {

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,10 @@
* This should only be used as a fall-back converter, as a last attempt.
*
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
* @deprecated please use {@link org.springframework.core.convert.converter.Converter}
* directly
*/
@Deprecated
public final class FromStringConverter implements Converter {

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,10 @@
* This should only be used as a fall-back converter, as a last attempt.
*
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk&gt;
* @deprecated please use {@link org.springframework.core.convert.converter.Converter} and
* {@link org.springframework.core.convert.ConversionService} directly
*/
@Deprecated
public final class ToStringConverter implements Converter {

/*
Expand Down
Loading

0 comments on commit 763ee4b

Please sign in to comment.