public String constructDN(final T o, final String parentDN) throws LDAPPersistException { final String existingDN = getEntryDN(o); if (existingDN != null) { return existingDN; } final LinkedHashMap<String, Attribute> attrMap = new LinkedHashMap<String, Attribute>(1); for (final FieldInfo i : rdnFields) { final Attribute a = i.encode(o, true); if (a == null) { throw new LDAPPersistException( ERR_OBJECT_HANDLER_RDN_FIELD_MISSING_VALUE.get(type.getName(), i.getField().getName())); } attrMap.put(toLowerCase(i.getAttributeName()), a); } for (final GetterInfo i : rdnGetters) { final Attribute a = i.encode(o); if (a == null) { throw new LDAPPersistException( ERR_OBJECT_HANDLER_RDN_GETTER_MISSING_VALUE.get( type.getName(), i.getMethod().getName())); } attrMap.put(toLowerCase(i.getAttributeName()), a); } return constructDN(o, parentDN, attrMap); }
String constructDN(final T o, final String parentDN, final Map<String, Attribute> attrMap) throws LDAPPersistException { final String existingDN = getEntryDN(o); if (existingDN != null) { return existingDN; } final ArrayList<String> rdnNameList = new ArrayList<String>(1); final ArrayList<byte[]> rdnValueList = new ArrayList<byte[]>(1); for (final FieldInfo i : rdnFields) { final Attribute a = attrMap.get(toLowerCase(i.getAttributeName())); if (a == null) { throw new LDAPPersistException( ERR_OBJECT_HANDLER_RDN_FIELD_MISSING_VALUE.get(type.getName(), i.getField().getName())); } rdnNameList.add(a.getName()); rdnValueList.add(a.getValueByteArray()); } for (final GetterInfo i : rdnGetters) { final Attribute a = attrMap.get(toLowerCase(i.getAttributeName())); if (a == null) { throw new LDAPPersistException( ERR_OBJECT_HANDLER_RDN_GETTER_MISSING_VALUE.get( type.getName(), i.getMethod().getName())); } rdnNameList.add(a.getName()); rdnValueList.add(a.getValueByteArray()); } final String[] rdnNames = new String[rdnNameList.size()]; rdnNameList.toArray(rdnNames); final byte[][] rdnValues = new byte[rdnNames.length][]; rdnValueList.toArray(rdnValues); final RDN rdn = new RDN(rdnNames, rdnValues); if (parentDN == null) { return new DN(rdn, defaultParentDN).toString(); } else { try { final DN parsedParentDN = new DN(parentDN); return new DN(rdn, parsedParentDN).toString(); } catch (LDAPException le) { debugException(le); throw new LDAPPersistException( ERR_OBJECT_HANDLER_INVALID_PARENT_DN.get(type.getName(), parentDN, le.getMessage()), le); } } }