2 * Copyright (c) 2014, 2015 Red Hat, Inc. 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
9 package org.opendaylight.neutron.northbound.api;
11 import java.lang.reflect.Field;
12 import java.util.List;
13 import org.opendaylight.neutron.spi.INeutronObject;
15 public interface INeutronRequest<T extends INeutronObject<T>> {
16 default T getSingleton() {
17 // return this.sinleton
18 Class<?> cls = getClass();
20 Field field = cls.getDeclaredField("singleton");
21 @SuppressWarnings("unchecked")
22 T value = (T) field.get(this);
24 } catch (IllegalAccessException | NoSuchFieldException e) {
25 throw new IllegalArgumentException(e);
29 default boolean isSingleton() {
30 // return this.sinleton != null
31 Class<?> cls = getClass();
33 Field field = cls.getDeclaredField("singleton");
34 return field.get(this) != null;
35 } catch (IllegalAccessException | NoSuchFieldException e) {
36 throw new IllegalArgumentException(e);
40 default List<T> getBulk() {
41 // return this.bulkRequest
42 Class<?> cls = getClass();
44 Field field = cls.getDeclaredField("bulkRequest");
45 @SuppressWarnings("unchecked")
46 List<T> value = (List<T>) field.get(this);
48 } catch (IllegalAccessException | NoSuchFieldException e) {
49 throw new IllegalArgumentException(e);