e7a5917d6c42e214f4704fbb140d49ee85ccc7ee
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / mapping / ExiEncoderHandler.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.controller.netconf.impl.mapping;\r
9 \r
10 import io.netty.buffer.ByteBuf;\r
11 import io.netty.channel.ChannelHandlerContext;\r
12 import io.netty.handler.codec.MessageToByteEncoder;\r
13 \r
14 import org.opendaylight.controller.netconf.util.xml.ExiParameters;\r
15 import org.opendaylight.controller.netconf.util.xml.ExiUtil;\r
16 \r
17 public class ExiEncoderHandler extends MessageToByteEncoder<Object> {\r
18 \r
19     public static final String HANDLER_NAME;\r
20     static {\r
21         HANDLER_NAME = "exiEncoder";\r
22     }\r
23 \r
24     private ExiParameters parameters;\r
25 \r
26     public ExiEncoderHandler(ExiParameters parameters) {\r
27         this.parameters = parameters;\r
28     }\r
29 \r
30     @Override\r
31     protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out)\r
32             throws Exception {\r
33         try {\r
34             ExiUtil.encode(msg, out, this.parameters);\r
35         } catch (Exception e) {\r
36             throw new IllegalStateException("Unable to encode exi message.");\r
37         }\r
38     }\r
39 }\r