2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
10 import static java.util.Objects.requireNonNull;
12 import java.lang.reflect.InvocationHandler;
13 import java.lang.reflect.Method;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
16 import org.opendaylight.yangtools.yang.binding.AbstractOpaqueObject;
17 import org.opendaylight.yangtools.yang.binding.OpaqueData;
18 import org.opendaylight.yangtools.yang.binding.OpaqueObject;
21 * Proxy support for an OpaqueObject.
23 * @param <T> OpaqueObject type
25 // FIXME: MDSAL-442: this class has no run-time dependencies on other generated types, hence is a prime candidate for
26 // becoming a prototype instantiated in a separate ClassLoader (see MDSAL-401) and not being a proxy at all.
27 final class ForeignOpaqueObject<T extends OpaqueObject<T>> extends AbstractOpaqueObject<T>
28 implements InvocationHandler {
29 private final @NonNull Class<T> implementedInterface;
30 private final @NonNull ForeignOpaqueData<?> value;
32 ForeignOpaqueObject(final Class<T> implementedInterface, final ForeignOpaqueData<?> value) {
33 this.implementedInterface = requireNonNull(implementedInterface);
34 this.value = requireNonNull(value);
38 public Class<T> implementedInterface() {
39 return implementedInterface;
43 public OpaqueData<?> getValue() {
48 public Object invoke(final Object proxy, final Method method, final Object[] args) {
49 switch (method.getName()) {
51 return equals(args[0]);
58 case BindingMapping.DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME:
59 return implementedInterface;
61 throw new NoSuchMethodError("Unknown method " + method);