2 * Copyright (c) 2016 Cisco Systems, 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.protocol.bgp.rib.spi;
11 import com.google.common.base.Optional;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer;
14 import org.opendaylight.yangtools.yang.binding.BindingMapping;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 public final class PeerRoleUtil {
21 public static final NodeIdentifier PEER_ROLE_NID = new NodeIdentifier(QName.create(Peer.QNAME,
22 "peer-role").intern());
24 private PeerRoleUtil() {
25 throw new UnsupportedOperationException();
28 public static PeerRole roleForChange(final Optional<NormalizedNode<?, ?>> maybePeerRole) {
29 if (maybePeerRole.isPresent()) {
30 final LeafNode<?> peerRoleLeaf = (LeafNode<?>) maybePeerRole.get();
31 return PeerRole.valueOf(BindingMapping.getClassName((String) peerRoleLeaf.getValue()));
36 public static String roleForString(final PeerRole role) {
47 throw new IllegalArgumentException("Unhandled role " + role);