blob: cdf53d0053c0a2672d9d9a3962069ecf32b56e8f [file] [log] [blame]
Sean Condond911af92017-07-19 18:05:27 +01001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.yang;
17
18import org.onosproject.drivers.microsemi.yang.MicrosemiModelRegistrator;
19import org.onosproject.yang.compiler.datamodel.YangNode;
20import org.onosproject.yang.compiler.datamodel.utils.DataModelUtils;
21import org.onosproject.yang.runtime.DefaultModelRegistrationParam;
22import org.onosproject.yang.runtime.ModelRegistrationParam;
23import org.onosproject.yang.runtime.YangModelRegistry;
24import org.onosproject.yang.runtime.helperutils.YangApacheUtils;
25import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry;
26
27import java.io.File;
28import java.io.IOException;
29import java.util.ArrayList;
30import java.util.List;
31
32public class MockMicrosemiRegistrator extends MicrosemiModelRegistrator {
33 private static final String FS = File.separator;
34 private static final String PATH = System.getProperty("user.dir") +
35 FS + "buck-out" + FS + "gen" +
36 FS + "models" + FS + "microsemi" + FS + "onos-models-microsemi-schema" + FS;
37 private static final String SER_FILE_PATH = "yang" + FS + "resources" +
38 FS + "YangMetaData.ser";
39 private static final String META_PATH =
40 PATH.replace("drivers/microsemi", "")
41 + SER_FILE_PATH;
42
43 @Override
44 public void activate() {
45 modelRegistry = new DefaultYangModelRegistry();
46 List<YangNode> nodes = new ArrayList<>();
47 try {
48 nodes.addAll(DataModelUtils.deSerializeDataModel(META_PATH));
49
50 model = YangApacheUtils.processYangModel(META_PATH, nodes);
51 ModelRegistrationParam.Builder b =
52 DefaultModelRegistrationParam.builder().setYangModel(model);
53 b.setYangModel(model);
54
55 ModelRegistrationParam registrationParam = getAppInfo(b).setYangModel(model).build();
56 modelRegistry.registerModel(registrationParam);
57 } catch (IOException ioe) {
58 ioe.printStackTrace();
59 }
60 }
61
62 public YangModelRegistry registry() {
63 return modelRegistry;
64 }
65}