2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.yangDecoder.transform.impl;
23 import javassist.ClassPool;
24 import org.openecomp.mso.yangDecoder.base.TYangJsonXmlBase;
25 import org.opendaylight.mdsal.binding.api.DataBroker;
26 import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec;
27 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
28 import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
29 import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
30 import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
31 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
32 import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
33 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
36 * Created by 10112215 on 2017/3/26.
38 public class TransformJava2XMLFactory extends TYangJsonXmlBase {
39 BindingToNormalizedNodeCodec mappingservice;
40 ModuleInfoBackedContext moduleInfoBackedContext;
41 protected final static ControllerContext controllerContext = ControllerContext.getInstance();
43 public TransformJava2XMLServiceImpl getJava2xmlService() {
44 if (java2xmlService == null) {
47 } catch (Exception e) {
52 return java2xmlService;
55 TransformJava2XMLServiceImpl java2xmlService;
58 protected void setupWithDataBroker(final DataBroker dataBroker) {
59 // Intentionally left No-op, subclasses may customize it
61 // moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(SncTunnels.class));
63 mappingservice = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(),
64 new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
65 moduleInfoBackedContext = ModuleInfoBackedContext.create();
67 for (YangModuleInfo yangModuleInfo : getModuleInfos()) {
68 moduleInfoBackedContext.registerModuleInfo(yangModuleInfo);
71 schemaContext = moduleInfoBackedContext.tryToCreateSchemaContext().get();
72 mappingservice.onGlobalContextUpdated(schemaContext);
73 controllerContext.setSchemas(schemaContext);
74 } catch (Exception e) {
77 if(null != mappingservice){
78 mappingservice.close();
85 public final void setup2() throws Exception {
87 if(java2xmlService==null)
88 java2xmlService = new TransformJava2XMLServiceImpl(mappingservice, schemaContext);