*/
package org.opendaylight.mdsal.binding.dom.codec.impl;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.Throwables;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;
import org.opendaylight.mdsal.binding.dom.codec.impl.ValueTypeCodec.SchemaUnawareCodec;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
/**
* Derived YANG types are just immutable value holders for simple value
private EncapsulatedValueCodec(final Class<?> typeClz, final MethodHandle constructor, final MethodHandle getter,
final Class<?> valueType) {
super(typeClz);
- this.constructor = Preconditions.checkNotNull(constructor);
- this.getter = Preconditions.checkNotNull(getter);
- this.valueType = Preconditions.checkNotNull(valueType);
+ this.constructor = requireNonNull(constructor);
+ this.getter = requireNonNull(getter);
+ this.valueType = requireNonNull(valueType);
}
- static Callable<EncapsulatedValueCodec> loader(final Class<?> typeClz, TypeDefinition<?> typeDef) {
+ static Callable<EncapsulatedValueCodec> loader(final Class<?> typeClz, final TypeDefinition<?> typeDef) {
return () -> {
- final Method m;
- if (typeDef instanceof BooleanTypeDefinition || typeDef instanceof EmptyTypeDefinition) {
- m = typeClz.getMethod("isValue");
- } else {
- m = typeClz.getMethod("getValue");
- }
+ final Method m = typeClz.getMethod(BindingMapping.SCALAR_TYPE_OBJECT_GET_VALUE_NAME);
final MethodHandle getter = LOOKUP.unreflect(m).asType(OBJ_METHOD);
final Class<?> valueType = m.getReturnType();
-
final MethodHandle constructor = LOOKUP.findConstructor(typeClz,
MethodType.methodType(void.class, valueType)).asType(OBJ_METHOD);
return new EncapsulatedValueCodec(typeClz, constructor, getter, valueType);
return constructor.invokeExact(input);
} catch (Throwable e) {
Throwables.throwIfUnchecked(e);
- throw new RuntimeException(e);
+ throw new IllegalStateException(e);
}
}
return getter.invokeExact(input);
} catch (Throwable e) {
Throwables.throwIfUnchecked(e);
- throw new RuntimeException(e);
+ throw new IllegalStateException(e);
}
}
}
\ No newline at end of file