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.PCEPMessage;
18 import org.opendaylight.protocol.pcep.impl.message.PCEPRawMessage;
20 import com.google.common.base.Preconditions;
23 * A PCEP message parser which also does validation.
25 public final class PCEPMessageFactory implements ProtocolMessageFactory<PCEPMessage> {
26 private static final RawPCEPMessageFactory rawFactory = new RawPCEPMessageFactory();
29 public List<PCEPMessage> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
30 final List<PCEPMessage> parsed = rawFactory.parse(bytes);
31 final List<PCEPMessage> validated = new ArrayList<>(parsed.size());
33 for (PCEPMessage msg : parsed) {
34 Preconditions.checkState(msg instanceof PCEPRawMessage);
35 final PCEPRawMessage raw = (PCEPRawMessage) 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 PCEPMessage msg) {
52 return rawFactory.put(msg);