6e6c6a88f1086370b8a8a4073b361eb3c94310ef
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / schema / provider / impl / YangTextSchemaSourceSerializationProxy.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, 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
9 package org.opendaylight.controller.cluster.schema.provider.impl;
10
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Optional;
13 import com.google.common.io.ByteSource;
14 import java.io.IOException;
15 import java.io.Serializable;
16 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
17 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
18
19 /**
20  * {@link org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource} serialization proxy.
21  */
22 @Beta
23 public class YangTextSchemaSourceSerializationProxy implements Serializable {
24     private static final long serialVersionUID = -6361268518176019477L;
25
26     private final byte[] schemaSource;
27     private final String revision;
28     private final String name;
29
30     public YangTextSchemaSourceSerializationProxy(final YangTextSchemaSource source) throws IOException {
31         this.revision = source.getIdentifier().getRevision();
32         this.name = source.getIdentifier().getName();
33         this.schemaSource = source.read();
34     }
35
36     public YangTextSchemaSource getRepresentation() {
37         return YangTextSchemaSource.delegateForByteSource(RevisionSourceIdentifier.create(name, Optional.of(revision)),
38             ByteSource.wrap(schemaSource));
39     }
40 }