blob: 8367f9f0e50400b58a590aa4511e51db506cc7a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.mso.yangDecoder.transform.impl;
import javassist.ClassPool;
import org.openecomp.mso.yangDecoder.base.TYangJsonXmlBase;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
/**
* Created by 10112215 on 2017/3/26.
*/
public class TransformJava2JsonFactory extends TYangJsonXmlBase {
BindingToNormalizedNodeCodec mappingservice;
ModuleInfoBackedContext moduleInfoBackedContext;
protected final static ControllerContext controllerContext = ControllerContext.getInstance();
public TransformJava2JsonServiceImpl getJava2jsonService() {
if (java2jsonService == null) {
try {
setup2();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
return java2jsonService;
}
TransformJava2JsonServiceImpl java2jsonService;
@Override
protected void setupWithDataBroker(final DataBroker dataBroker) {
// Intentionally left No-op, subclasses may customize it
mappingservice = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(),
new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
moduleInfoBackedContext = ModuleInfoBackedContext.create();
// moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(SncTunnels.class));
try {
for (YangModuleInfo yangModuleInfo : getModuleInfos()) {
moduleInfoBackedContext.registerModuleInfo(yangModuleInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
schemaContext = moduleInfoBackedContext.tryToCreateSchemaContext().get();
mappingservice.onGlobalContextUpdated(schemaContext);
controllerContext.setSchemas(schemaContext);
}
public final void setup2() throws Exception {
super.setup();
if(java2jsonService==null)
java2jsonService = new TransformJava2JsonServiceImpl(mappingservice, schemaContext);
}
}
|