2 * Copyright (c) 2013 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
8 package org.opendaylight.protocol.pcep.impl.message;
10 import io.netty.buffer.ByteBuf;
12 import java.util.List;
14 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
15 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
16 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
25 * Parser for {@link OpenMessage}
27 public class PCEPOpenMessageParser extends AbstractMessageParser {
29 public static final int TYPE = 1;
31 public PCEPOpenMessageParser(final ObjectHandlerRegistry registry) {
36 public void serializeMessage(final Message message, final ByteBuf buffer) {
37 if (!(message instanceof OpenMessage)) {
38 throw new IllegalArgumentException("Wrong instance of Message. Passed instance " + message.getClass() + ". Needed OpenMessage.");
40 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage open = ((OpenMessage) message).getOpenMessage();
42 if (open.getOpen() == null) {
43 throw new IllegalArgumentException("Open Object must be present in Open Message.");
46 buffer.writeBytes(serializeObject(open.getOpen()));
50 protected org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
51 if (objects == null) {
52 throw new IllegalArgumentException("Passed list can't be null.");
55 if (objects.isEmpty() || !(objects.get(0) instanceof Open)) {
56 throw new PCEPDeserializerException("Open message doesn't contain OPEN object.");
59 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage msg = new OpenMessageBuilder().setOpen(
60 (Open) objects.get(0)).build();
64 if (!objects.isEmpty()) {
65 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
68 return new OpenBuilder().setOpenMessage(msg).build();
72 public int getMessageType() {