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;
11 import io.netty.buffer.Unpooled;
13 import java.util.List;
15 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
16 import org.opendaylight.protocol.pcep.spi.MessageUtil;
17 import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
18 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
27 * Parser for {@link OpenMessage}
29 public class PCEPOpenMessageParser extends AbstractMessageParser {
31 public static final int TYPE = 1;
33 public PCEPOpenMessageParser(final ObjectRegistry registry) {
38 public void serializeMessage(final Message message, final ByteBuf out) {
39 if (!(message instanceof OpenMessage)) {
40 throw new IllegalArgumentException("Wrong instance of Message. Passed instance " + message.getClass() + ". Needed OpenMessage.");
42 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage open = ((OpenMessage) message).getOpenMessage();
44 if (open.getOpen() == null) {
45 throw new IllegalArgumentException("Open Object must be present in Open Message.");
47 ByteBuf buffer = Unpooled.buffer();
48 buffer.writeBytes(serializeObject(open.getOpen()));
49 MessageUtil.formatMessage(TYPE, buffer, out);
53 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 {
54 if (objects == null) {
55 throw new IllegalArgumentException("Passed list can't be null.");
58 if (objects.isEmpty() || !(objects.get(0) instanceof Open)) {
59 throw new PCEPDeserializerException("Open message doesn't contain OPEN object.");
62 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage msg = new OpenMessageBuilder().setOpen(
63 (Open) objects.get(0)).build();
67 if (!objects.isEmpty()) {
68 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
71 return new OpenBuilder().setOpenMessage(msg).build();
75 public int getMessageType() {