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>> {
17 default T getSingleton() {
18 // return this.singleton
19 Class<?> cls = getClass();
21 Field field = cls.getDeclaredField("singleton");
22 @SuppressWarnings("unchecked")
23 T value = (T) field.get(this);
25 } catch (IllegalAccessException | NoSuchFieldException e) {
26 throw new IllegalArgumentException(e);
30 default boolean isSingleton() {
31 return getSingleton() != null;
34 default List<T> getBulk() {
35 // return this.bulkRequest
36 Class<?> cls = getClass();
38 Field field = cls.getDeclaredField("bulkRequest");
39 @SuppressWarnings("unchecked")
40 List<T> value = (List<T>) field.get(this);
42 } catch (IllegalAccessException | NoSuchFieldException e) {
43 throw new IllegalArgumentException(e);