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;
10 import java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.protocol.framework.DeserializerException;
14 import org.opendaylight.protocol.framework.DocumentedException;
15 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
16 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
17 import org.opendaylight.protocol.pcep.spi.RawMessage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
20 import com.google.common.base.Preconditions;
23 * A PCEP message parser which also does validation.
25 public final class PCEPMessageFactory implements ProtocolMessageFactory<Message> {
26 private static final RawPCEPMessageFactory rawFactory = new RawPCEPMessageFactory();
29 public List<Message> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
30 final List<Message> parsed = rawFactory.parse(bytes);
31 final List<Message> validated = new ArrayList<>(parsed.size());
33 for (final Message msg : parsed) {
34 Preconditions.checkState(msg instanceof RawMessage);
35 final RawMessage raw = (RawMessage) msg;
38 validated.addAll(PCEPMessageValidator.getValidator(raw.getMsgType()).validate(raw.getAllObjects()));
39 } catch (final PCEPDeserializerException e) {
40 // FIXME: at validation time we may want to terminate with:
41 // logger.error("Malformed message, terminating. ", e);
42 // this.terminate(Reason.MALFORMED_MSG);
51 public byte[] put(final Message msg) {
52 return rawFactory.put(msg);