Spring ldap 2.0.1替换不​​推荐使用的OdmManager [英] spring ldap 2.0.1 replacing deprecated OdmManager

查看:81
本文介绍了Spring ldap 2.0.1替换不​​推荐使用的OdmManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring LDAP 2.x中,似乎不赞成使用OdmManager工具,因为大多数类似odm的事情都可以通过ldapTemplate完成.但是OdmManager可以注入一个ConverterManager,可以告诉您有关自定义类型转换的信息.将ldapTemplate用于类似odm(ConverterManager)操作的等效方法是什么?

It seems in Spring LDAP 2.x, that the OdmManager facility is deprecated, as most odm-like things can be done by ldapTemplate, which is true. But the OdmManager has the ability to inject a ConverterManager which can be told about your custom type conversions. What is the equivalent method for using ldapTemplate for odm-like (ConverterManager) operations ?

如果ldapTemplate中没有等效的系统,则应该:

If there is not an equivalent system in ldapTemplate, should it :

  1. 使用单个字符串构造函数和String toString()类方法隐式检测自定义类,前提是它们作为要映射到ldap属性或从ldap属性映射的属性而存在.

  1. implicitly detect custom classes with single string constructors and String toString() class methods, iff they exist as properties to be mapped to/from ldap attributes.

隐式允许使用Bean编辑器,以从文本映射到特定类型

implicitly allow the use of bean editors, to map from text to the specific type

具有类似Converter Converter的功能,您可以在其中进行配置.

explicitly have some facility like a Converter manager, in which you can configure this.

作为一个例子,考虑简单的类(我想将其作为bean属性的类型,它将被映射到ldap时间戳记)

As an example, consider the simple class (which i would like to be the type of a bean property, which will be mapped to a ldap timestamp)

公共类LdapTimestamp {

public class LdapTimestamp {

static private Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Australia/Brisbane"));
static private DateFormat toStringFormat;
static {
    toStringFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    toStringFormat.setCalendar(cal);
}
static private DateFormat nativeLdapFormat = new SimpleDateFormat("yyyyMMddHHmmssZ"); 

private Date dateTime; // GMT time

public LdapTimestamp(String ldapDateTimeString) throws ParseException {
    this.dateTime = nativeLdapFormat.parse(ldapDateTimeString);
}

public LdapTimestamp() {
    super();
}

public Date getDateTime() {
    return dateTime;
}

public void setDateTime(Date dateTimeObject) {
    this.dateTime = dateTimeObject;
}

public void setDateTime(String ldapDateTimeString) throws ParseException {
    this.dateTime = nativeLdapFormat.parse(ldapDateTimeString);
}

public String toStringShort() {
    return toStringFormat.format(dateTime);
}

public String toString() {
    return nativeLdapFormat.format(dateTime);
}

}

目的是该bean本地存储一个Date对象,该对象可用于日期范围比较等,同时将ldap日期字符串以toString()的形式返回到bean的外部,并以返回值的形式返回给bean一个String参数.

The intent is that the bean natively store a Date object, which can be used for date range comparisons and the like, while returning the ldap date string outwards of the bean as toString() and inward to the bean, as constructor with a single String argument.

这似乎是ConverterManager的建议,但这是新代码,因此,如果可以避免的话,我宁愿不使用不推荐使用的OdmManager接口. ConverterManager尚未弃用,但我看不到将其链接到ldapTemplate以便使用的明显方法.

This seems to be what is suggested with ConverterManager, but this is new code, so i'd rather not use the deprecated OdmManager interface if i can avoid it. ConverterManager is not deprecated, but i can't see an obvious way of linking it to ldapTemplate to use.

任何想法都会受到欢迎.

Any thoughts would be welcome.

推荐答案

LdapTemplate具有setObjectDirectoryMapper方法,使您可以注入已配置的ObjectDirectoryMapper(与以前版本中的OdmManager相对应). DefaultObjectDirectoryMapper可以配置为ConverterManager,所以我认为您应该已经准备就绪.

LdapTemplate has a setObjectDirectoryMapper method, which enables you to inject a configured ObjectDirectoryMapper (which corresponds to the OdmManager in previous versions). DefaultObjectDirectoryMapper can be configured with a ConverterManager, so I think you should be all set.

这篇关于Spring ldap 2.0.1替换不​​推荐使用的OdmManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆