Entry encode(final T o, final String parentDN) throws LDAPPersistException { // Get the attributes that should be included in the entry. final LinkedHashMap<String, Attribute> attrMap = new LinkedHashMap<String, Attribute>(); attrMap.put("objectClass", objectClassAttribute); for (final Map.Entry<String, FieldInfo> e : fieldMap.entrySet()) { final FieldInfo i = e.getValue(); if (!i.includeInAdd()) { continue; } final Attribute a = i.encode(o, false); if (a != null) { attrMap.put(e.getKey(), a); } } for (final Map.Entry<String, GetterInfo> e : getterMap.entrySet()) { final GetterInfo i = e.getValue(); if (!i.includeInAdd()) { continue; } final Attribute a = i.encode(o); if (a != null) { attrMap.put(e.getKey(), a); } } final String dn = constructDN(o, parentDN, attrMap); final Entry entry = new Entry(dn, attrMap.values()); if (postEncodeMethod != null) { try { postEncodeMethod.invoke(o, entry); } catch (Throwable t) { debugException(t); if (t instanceof InvocationTargetException) { t = ((InvocationTargetException) t).getTargetException(); } throw new LDAPPersistException( ERR_OBJECT_HANDLER_ERROR_INVOKING_POST_ENCODE_METHOD.get( postEncodeMethod.getName(), type.getName(), getExceptionMessage(t)), t); } } setDNAndEntryFields(o, entry); if (superclassHandler != null) { final Entry e = superclassHandler.encode(o, parentDN); for (final Attribute a : e.getAttributes()) { entry.addAttribute(a); } } return entry; }
void decode(final T o, final Entry e) throws LDAPPersistException { if (superclassHandler != null) { superclassHandler.decode(o, e); } setDNAndEntryFields(o, e); final ArrayList<String> failureReasons = new ArrayList<String>(5); boolean successful = true; for (final FieldInfo i : fieldMap.values()) { successful &= i.decode(o, e, failureReasons); } for (final SetterInfo i : setterMap.values()) { successful &= i.invokeSetter(o, e, failureReasons); } Throwable cause = null; if (postDecodeMethod != null) { try { postDecodeMethod.invoke(o); } catch (final Throwable t) { debugException(t); if (t instanceof InvocationTargetException) { cause = ((InvocationTargetException) t).getTargetException(); } else { cause = t; } successful = false; failureReasons.add( ERR_OBJECT_HANDLER_ERROR_INVOKING_POST_DECODE_METHOD.get( postDecodeMethod.getName(), type.getName(), getExceptionMessage(t))); } } if (!successful) { throw new LDAPPersistException(concatenateStrings(failureReasons), o, cause); } }