String multivalAttr = modelElement.getDefaultValue();
if(modelAttrName == null) {
final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.nullAttrError"); //$NON-NLS-1$
throw new TranslatorException(msg);
}
Attribute resultAttr = attrs.get(modelAttrName);
// If the attribute is not present, we return NULL.
if(resultAttr == null) {
// MPW - 2-20-07 - Changed from returning empty string to returning null.
//row.add("");
//logger.logTrace("Did not find a match for attribute named: " + modelAttrName);
// GHH 20080326 - return DN from input parameter
// if DN attribute is not present in search result
if (modelAttrName.toUpperCase().equals("DN")) { //$NON-NLS-1$
row.add(resultDistinguishedName);
}
else {
row.add(null);
}
return;
}
Object objResult = null;
try {
if(TypeFacility.RUNTIME_TYPES.STRING.equals(modelAttrClass) && "multivalued-concat".equalsIgnoreCase(multivalAttr)) { //$NON-NLS-1$
// mpw 5/09
// Order the multi-valued attrs alphabetically before creating a single string,
// using the delimiter to separate each token
ArrayList<String> multivalList = new ArrayList<String>();
NamingEnumeration<?> attrNE = resultAttr.getAll();
int length = 0;
while(attrNE.hasMore()) {
String val = (String)attrNE.next();
multivalList.add(val);
length += ((val==null?0:val.length()) + 1);
}
Collections.sort(multivalList);
StringBuilder multivalSB = new StringBuilder(length);
Iterator<String> itr = multivalList.iterator();
while(itr.hasNext()) {
multivalSB.append(itr.next());
if (itr.hasNext()) {
multivalSB.append(delimiter);
}
}
row.add(multivalSB.toString());
return;
}
//just a single value
objResult = resultAttr.get();
} catch (NamingException ne) {
final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.attrValueFetchError",modelAttrName) +" : "+ne.getExplanation(); //$NON-NLS-1$m//$NON-NLS-2$
LogManager.logWarning(LogConstants.CTX_CONNECTOR, msg);
throw new TranslatorException(msg);
}
// GHH 20080326 - if attribute is not a string or empty, just
// return null.
// TODO - allow return of non-strings (always byte[]) as
// MM object (or blob). Perhaps also add directory-specific logic
// to deserialize byte[] attributes into Java objects
// when appropriate
if (objResult instanceof String) {
strResult = (String)objResult;
// MPW - 3.9.07 - Also return NULL when attribute is unset or empty string.
// There is no way to differentiate between being unset and being the empty string.
if(strResult.equals("")) { //$NON-NLS-1$
strResult = null;
}
}
// MPW: 3-11-07: Added support for java.lang.Integer conversion.
if(TypeFacility.RUNTIME_TYPES.TIMESTAMP.equals(modelAttrClass)) {
Map<String, String> p = modelElement.getProperties();
String timestampFormat = p.get("Format"); //$NON-NLS-1$
SimpleDateFormat dateFormat;
if(timestampFormat == null) {
timestampFormat = LDAPConnectorConstants.ldapTimestampFormat;
}
dateFormat = new SimpleDateFormat(timestampFormat);
try {
if(strResult != null) {
Date dateResult = dateFormat.parse(strResult);
Timestamp tsResult = new Timestamp(dateResult.getTime());
row.add(tsResult);
} else {
row.add(null);
}
} catch(ParseException pe) {
throw new TranslatorException(pe, LDAPPlugin.Util.getString("LDAPSyncQueryExecution.timestampParseFailed", modelAttrName)); //$NON-NLS-1$
}
// TODO: Extend support for more types in the future.
// Specifically, add support for byte arrays, since that's actually supported
// in the underlying data source.