From b97463d792458aa6cba0db7d236e117768ac6e78 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Mon, 13 Oct 2014 15:09:07 +0000
Subject: [PATCH] OPENDJ-1551 checkpoint : apply patch to ensure compatibility with sdk new Function API and prevents circular dependency problem
---
opendj3-server-dev/src/server/org/opends/server/types/AttributeParser.java | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 56 insertions(+), 1 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/AttributeParser.java b/opendj3-server-dev/src/server/org/opends/server/types/AttributeParser.java
index 91718f9..8665574 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/AttributeParser.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/AttributeParser.java
@@ -25,6 +25,8 @@
*/
package org.opends.server.types;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.*;
import org.forgerock.opendj.ldap.ByteString;
@@ -118,14 +120,67 @@
* The default value to return if the attribute is empty.
* @return The first value decoded as a {@code T}.
*/
+ @SuppressWarnings("unchecked")
public <T> T as(final Function<ByteString, ? extends T, Void> f, final T defaultValue) {
if (!isEmpty(attribute)) {
- return f.apply(attribute.iterator().next(), null);
+ ByteString value = attribute.iterator().next();
+ try
+ {
+ // use existing already committed code
+ return f.apply(value, null);
+ }
+ catch (NoSuchMethodError e1)
+ {
+ try
+ {
+ // use the new code that is not yet committed and compiled (with Void parameter)
+ final Method method = f.getClass().getMethod("apply", Object.class, Void.class);
+ return (T) method.invoke(f, value, null);
+ }
+ catch (NoSuchMethodException e2)
+ {
+ return invokeForgerockUtilFunctionApply(f, value);
+ }
+ catch (SecurityException e2)
+ {
+ return invokeForgerockUtilFunctionApply(f, value);
+ }
+ catch (IllegalAccessException e)
+ {
+ return invokeForgerockUtilFunctionApply(f, value);
+ }
+ catch (InvocationTargetException e)
+ {
+ return invokeForgerockUtilFunctionApply(f, value);
+ }
+ catch (RuntimeException e2)
+ {
+ throw e2;
+ }
+ }
} else {
return defaultValue;
}
}
+ private <T> T invokeForgerockUtilFunctionApply(final Function<ByteString, ? extends T, Void> f, ByteString value)
+ {
+ try
+ {
+ // use forgerock util Function
+ final Method method = f.getClass().getMethod("apply", Object.class);
+ return (T) method.invoke(f, value);
+ }
+ catch (RuntimeException e3)
+ {
+ throw e3;
+ }
+ catch (Exception e3)
+ {
+ throw new RuntimeException(e3);
+ }
+ }
+
/**
* Returns the first value decoded as a boolean, or {@code null} if the
* attribute does not contain any values.
--
Gitblit v1.10.0