Search in sources :

Example 1 with DefaultName

use of org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.DefaultName in project onos by opennetworkinglab.

the class TapiGlobalClassUtil method addNameList.

/**
 * Add key-value to the ModelObject as "name-and-value" list.
 *
 * @param obj ModelObject
 * @param kvs Key-value map
 * @param <T> Type of ModelObject
 */
public static <T extends ModelObject> void addNameList(T obj, Map<String, String> kvs) {
    @SuppressWarnings("unchecked") Class<T> cls = (Class<T>) obj.getClass();
    try {
        Method method = cls.getMethod("addToName", Name.class);
        for (Entry<String, String> kv : kvs.entrySet()) {
            DefaultName prop = new DefaultName();
            prop.valueName(kv.getKey());
            prop.value(kv.getValue());
            method.invoke(obj, prop);
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        log.error("Exception thrown", e);
    }
}
Also used : DefaultName(org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.DefaultName) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with DefaultName

use of org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.DefaultName in project onos by opennetworkinglab.

the class TapiLocalClassUtil method addNameList.

/**
 * Add key-value to the ModelObject as "name-and-value" list.
 *
 * @param obj ModelObject
 * @param kvs Key-value map
 * @param <T> Type of ModelObject
 */
public static <T extends ModelObject> void addNameList(T obj, Map<String, String> kvs) {
    @SuppressWarnings("unchecked") Class<T> cls = (Class<T>) obj.getClass();
    try {
        Method method = cls.getMethod("addToName", Name.class);
        for (Entry<String, String> kv : kvs.entrySet()) {
            DefaultName prop = new DefaultName();
            prop.valueName(kv.getKey());
            prop.value(kv.getValue());
            method.invoke(obj, prop);
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        log.error("Exception thrown", e);
    }
}
Also used : DefaultName(org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.DefaultName) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 DefaultName (org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.DefaultName)2