4 Replies Latest reply on Mar 7, 2013 11:05 AM by 823810

    Appropriate way to transfer data

      I am using below lines to transfer data from LDAP server with JNDI.

      But it is really ugly and i do this for every where i should transfer data.

      I know there is Spring ODM and UnboundID solutions but i do not want to have such contexts.

      Is there an appropriate way in JNDI?

      NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
                     while (answer.hasMore())
                               SearchResult sr = (SearchResult) answer.next();
                               UserPojo userPojo = new UserPojo();
        • 1. Re: Appropriate way to transfer data
          That's it, I'm afraid, except that you can obviously write a method to take care of the parameter in each case.
          • 2. Re: Appropriate way to transfer data
            Indeed. Don't like the low-level API? Wrap something slightly higher level around it and use that.
            • 3. Re: Appropriate way to transfer data
              Thank very much for answers.

              I am happy i could tell what i have problem with.

              I want more configurable and standardized code.

              For example if i want to add some new field to my objects, it should be very small work to change the code.

              If i do like above i must edit all the code where i transfer data.

              I thought to use something like below (inspired from Spring ODM)

              ObjectMetaData metaData=getEntityData(managedClass).metaData;

              try {

              for (Field field : metaData) {
              AttributeMetaData attributeInfo = metaData.getAttribute(field);

              Attribute attribute = attributeValueMap.get(attributeInfo.getName());
              if (attribute != null) {
              Object value = attribute.get();
              if (value != null) {
              field.set(result, value);

              I want some automized code like this, but if i add a field to Java side, the code will fail.

              I thought to put an xml into my Java project, and write some code to update LDAP automatically but can not decide if it is an elegant way.
              • 4. Re: Appropriate way to transfer data
                Is using the code like in my reply appropriate?

                I mean using fields name as equal to attribute types in LDAP object.

                Might it be dangerous in further steps of project development?