BUG-2825: introduce Ipv4 prefix parser for short bytes
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / util / StringValueObjectFactory.java
index 8cf66c2512491ec3b553d0d47afb73ab7c75fc29..0955681442dc9e1bfae79201ffd23bc63f9a0dfd 100644 (file)
@@ -41,9 +41,11 @@ public final class StringValueObjectFactory<T> {
 
     private final MethodHandle constructor;
     private final MethodHandle setter;
+    private final T template;
 
-    private StringValueObjectFactory(final MethodHandle constructor, final MethodHandle setter) {
-        this.constructor = Preconditions.checkNotNull(constructor);
+    private StringValueObjectFactory(final T template, final MethodHandle constructor, final MethodHandle setter) {
+        this.template = Preconditions.checkNotNull(template);
+        this.constructor = constructor.bindTo(template);
         this.setter = Preconditions.checkNotNull(setter);
     }
 
@@ -80,8 +82,8 @@ public final class StringValueObjectFactory<T> {
 
         final StringValueObjectFactory<T> ret;
         try {
-            ret = new StringValueObjectFactory<>(
-                    LOOKUP.unreflectConstructor(copyConstructor).asType(CONSTRUCTOR_METHOD_TYPE).bindTo(template),
+            ret = new StringValueObjectFactory<>(template,
+                    LOOKUP.unreflectConstructor(copyConstructor).asType(CONSTRUCTOR_METHOD_TYPE),
                     LOOKUP.unreflectSetter(f).asType(SETTER_METHOD_TYPE));
         } catch (IllegalAccessException e) {
             throw new IllegalStateException("Failed to instantiate method handles", e);
@@ -123,4 +125,8 @@ public final class StringValueObjectFactory<T> {
             throw Throwables.propagate(e);
         }
     }
+
+    public T getTemplate() {
+        return template;
+    }
 }