Switch to Objects.requireNonNull
[mdsal.git] / binding2 / mdsal-binding2-dom-codec / src / main / java / org / opendaylight / mdsal / binding / javav2 / dom / codec / impl / AnyxmlCodec.java
1 /*
2  * Copyright (c) 2018 ZTE, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.javav2.dom.codec.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.Preconditions;
14 import javax.xml.transform.dom.DOMSource;
15 import org.opendaylight.mdsal.binding.javav2.runtime.context.BindingRuntimeContext;
16 import org.opendaylight.yangtools.concepts.Codec;
17 import org.w3c.dom.Document;
18
19 /**
20  * Codec for serialize/deserialize anyxml.
21  */
22 @Beta
23 public final class AnyxmlCodec implements Codec<DOMSource, Document> {
24
25     private final BindingRuntimeContext context;
26
27     /**
28      * Prepared binding runtime context for anyxml codec.
29      *
30      * @param context
31      *            - binding runtime context
32      */
33     public AnyxmlCodec(final BindingRuntimeContext context) {
34         this.context = requireNonNull(context);
35     }
36
37     @Override
38     public Document deserialize(final DOMSource input) {
39         Preconditions.checkArgument(input != null, "Input must not be null.");
40         return (Document) input.getNode();
41     }
42
43     @Override
44     public DOMSource serialize(final Document input) {
45         Preconditions.checkArgument(input != null, "Input must not be null.");
46         return new DOMSource(input);
47     }
48 }