From 2014f1ab10ab06c312f2d6c82eecfb9c593f7f74 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Mon, 15 Nov 2010 16:36:04 +0000 Subject: [PATCH] Final touch on the examples. --- src/docbkx/ldif-parsing.xml | 6 +- src/docbkx/odm.xml | 212 ++++++++++++++++++------------------ 2 files changed, 105 insertions(+), 113 deletions(-) diff --git a/src/docbkx/ldif-parsing.xml b/src/docbkx/ldif-parsing.xml index 1e86a554..90262775 100644 --- a/src/docbkx/ldif-parsing.xml +++ b/src/docbkx/ldif-parsing.xml @@ -1,6 +1,4 @@ - LDIF Parsing @@ -8,7 +6,7 @@ Introduction LDAP Directory Interchange Format (LDIF) files are the standard - medium for describing directoy data in a flat file format. The most common + medium for describing directory data in a flat file format. The most common uses of this format include information transfer and archival. However, the standard also defines a way to describe modifications to stored data in a flat file format. LDIFs of this later type are typically referred to @@ -49,7 +47,7 @@ LdapAttribute objects represent options as a Set<String>. The DN support added to the LdapAttributes object employs the - org.springframework.ldap.core.DistuishedName class. + org.springframework.ldap.core.DistinguishedName class.
diff --git a/src/docbkx/odm.xml b/src/docbkx/odm.xml index ea728671..bebd65d5 100644 --- a/src/docbkx/odm.xml +++ b/src/docbkx/odm.xml @@ -1,6 +1,4 @@ - Object-Directory Mapping (ODM) @@ -17,13 +15,12 @@ OdmManager - The - org.springframework.ldap.odm.OdmManager - interface, and its implementation, is the central class in the ODM - package. The OdmManager orchestrates the - process of reading objects from the directory and mapping the data to - annotated Java object classes. This interface provides access to the - underlying directory instance through the following methods: + The org.springframework.ldap.odm.OdmManager interface, + and its implementation, is the central class in the ODM package. The + OdmManager orchestrates the process of reading objects from + the directory and mapping the data to annotated Java object classes. This + interface provides access to the underlying directory instance through the + following methods: @@ -60,38 +57,36 @@ A basic configuration of this factory would be as follows: - Configuring the OdmManager Factory - + Configuring the OdmManager Factory + +<beans> ... - - - - - - com.example.dao.SimplePerson - - - + <bean id="odmManager" class="org.springframework.ldap.odm.core.impl.OdmManagerImplFactoryBean"> + <property name="converterManager" ref="converterManager" /> + <property name="contextSource" ref="contextSource" /> + <property name="managedClasses"> + <set> + <value>com.example.dao.SimplePerson</value> + </set> + </property> + </bean> ... - -]]> +</beans> + The factory requires the list of entity classes to be managed by the - OdmManager to be explicitly declared. These - classes should be properly annotated as defined in the next section. The - converterManager referenced in the above definition - is described in . + OdmManager to be explicitly declared. These classes should be + properly annotated as defined in the next section. The + converterManager referenced in the above definition is + described in . Annotations - Entity classes managed by the - OdmManager are required to be annotated - with the annotations in the + Entity classes managed by the OdmManager are required + to be annotated with the annotations in the org.springframework.ldap.odm.annotations package. The available annotations are: @@ -116,8 +111,7 @@ @Transient - Indicates the field is not persistent - and should be ignored by the - OdmManager. + and should be ignored by the OdmManager. @@ -127,7 +121,7 @@ which fields are mapped are required to be declared. Also, in order for a directory entry to be considered a match to the managed entity, all object classes declared by the directory entry must match be declared by in the - @Entry annotation. + @Entry annotation. The @Id annotation is used to map the distinguished name of the entry to a field. The field must be an instance of @@ -142,8 +136,8 @@ based or string based by the LDAP JNDI provider. The @Transient annotation is used to indicate the - field should be ignored by the OdmManager - and not mapped to an underlying LDAP property. + field should be ignored by the OdmManager and not mapped to + an underlying LDAP property. @@ -154,14 +148,12 @@ convert LDAP attributes to Java fields. The main interface in this class is the org.springframework.ldap.odm.typeconversion.ConverterManager. - The default ConverterManager implementation - uses the following algorithm when parsing objects to convert - fields: + The default ConverterManager implementation uses the + following algorithm when parsing objects to convert fields: - Try to find and use a Converter - registered for the fromClass, - syntax and toClass and use - it. + Try to find and use a Converter registered for + the fromClass, syntax and + toClass and use it. @@ -172,9 +164,9 @@ If this fails try to find and use a - Converter registered for - the fromClass and the - toClass ignoring the syntax. + Converter registered for the + fromClass and the toClass ignoring the + syntax. @@ -183,76 +175,77 @@ - Implementations of the ConverterManager - interface can be obtained from the + Implementations of the ConverterManager interface can + be obtained from the org.springframework.ldap.odm.typeconversion.impl.ConvertManagerFactoryBean. The factory bean requires converter configurations to be declared in the - bean configuration. + bean configuration. The converterConfig property accepts a set of - ConverterConfig classes, each one defining some - conversion logic. A converter config is an instance of + ConverterConfig classes, each one defining some conversion + logic. A converter config is an instance of org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean.ConverterConfig. The config defines a set of source classes, the set of target classes, and an implementation of the com.springframework.ldap.odm.typeconversion.impl.Converter interface which provides the logic to convert from the - fromClass to the toClass. A - sample configuration is provided in the following example: + fromClass to the toClass. A sample configuration + is provided in the following example: Configuring the Converter Manager Factory - - - - - - - - - java.lang.String - - - - - java.lang.Byte - java.lang.Short - java.lang.Integer - java.lang.Long - java.lang.Float - java.lang.Double - java.lang.Boolean - - - - - - - - java.lang.Byte - java.lang.Short - java.lang.Integer - java.lang.Long - java.lang.Float - java.lang.Double - java.lang.Boolean - - - - - java.lang.String - - - - - - - -]]> + + +<bean id="fromStringConverter" + class="org.springframework.ldap.odm.typeconversion.impl.converters.FromStringConverter" /> +<bean id="toStringConverter" + class="org.springframework.ldap.odm.typeconversion.impl.converters.ToStringConverter" /> +<bean id="converterManager" + class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean"> + <property name="converterConfig"> + <set> + <bean class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean$ConverterConfig"> + <property name="fromClasses"> + <set> + <value>java.lang.String</value> + </set> + </property> + <property name="toClasses"> + <set> + <value>java.lang.Byte</value> + <value>java.lang.Short</value> + <value>java.lang.Integer</value> + <value>java.lang.Long</value> + <value>java.lang.Float</value> + <value>java.lang.Double</value> + <value>java.lang.Boolean</value> + </set> + </property> + <property name="converter" ref="fromStringConverter" /> + </bean> + <bean class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean$ConverterConfig"> + <property name="fromClasses"> + <set> + <value>java.lang.Byte</value> + <value>java.lang.Short</value> + <value>java.lang.Integer</value> + <value>java.lang.Long</value> + <value>java.lang.Float</value> + <value>java.lang.Double</value> + <value>java.lang.Boolean</value> + </set> + </property> + <property name="toClasses"> + <set> + <value>java.lang.String</value> + </set> + </property> + <property name="converter" ref="toStringConverter" /> + </bean> + </set> + </property> +</bean> + @@ -260,12 +253,13 @@ Execution After all components are configured, directory interaction can be - acheived through a reference to the - OdmManager as shown in this example: + achieved through a reference to the OdmManager, as shown in + this example: Execution - public class App { private static Log log = LogFactory.getLog(App.class); private static final SearchControls searchControls = @@ -274,7 +268,7 @@ public class App { try { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); OdmManager manager = (OdmManager) context.getBean("odmManager"); - List people = manager.search( + List<SimplePerson> people = manager.search( SimplePerson.class, new DistinguishedName("dc=example,dc=com"), "uid=*", searchControls); log.info("People found: " + people.size()); for (SimplePerson person : people) { @@ -285,7 +279,7 @@ public class App { } } } -]]> +