blob: 39b622038dbe469b0f7dfc5a18144f7566504013 [file] [log] [blame]
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301/*
2 * Copyright 2016-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.yangutils.translator.tojava.javamodel;
17
18import org.onosproject.yangutils.datamodel.YangType;
19import org.onosproject.yangutils.translator.exception.TranslatorException;
20import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
21import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
22
23/**
24 * Represents java information corresponding to the YANG type.
25 */
26public class YangJavaType<T>
27 extends YangType<T>
28 implements JavaQualifiedTypeResolver {
29
30 private JavaQualifiedTypeInfo javaQualifiedAccess;
31
32 /**
33 * Create a YANG leaf object with java qualified access details.
34 */
35 public YangJavaType() {
36 super();
37 setJavaQualifiedInfo(new JavaQualifiedTypeInfo());
38 }
39
40 @Override
41 public void updateJavaQualifiedInfo() {
42 JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo();
43
44 /*
45 * Type is added as an attribute in the class.
46 */
47 String className = AttributesJavaDataType.getJavaImportClass(this, false);
48 if (className != null) {
49 /*
50 * Corresponding to the attribute type a class needs to be imported,
51 * since it can be a derived type or a usage of wrapper classes.
52 */
53 importInfo.setClassInfo(className);
54 String classPkg = AttributesJavaDataType.getJavaImportPackage(this,
55 false, className);
56 if (classPkg == null) {
57 throw new TranslatorException("import package cannot be null when the class is used");
58 }
59 importInfo.setPkgInfo(classPkg);
60 } else {
61 /*
62 * The attribute does not need a class to be imported, for example
63 * built in java types.
64 */
65 String dataTypeName = AttributesJavaDataType.getJavaDataType(this);
66 if (dataTypeName == null) {
67 throw new TranslatorException("not supported data type");
68 }
69 importInfo.setClassInfo(dataTypeName);
70 }
Bharat saraswalc0e04842016-05-12 13:16:57 +053071 setJavaQualifiedInfo(importInfo);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053072 }
73
74 @Override
75 public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
76 return javaQualifiedAccess;
77 }
78
79 @Override
80 public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
81 javaQualifiedAccess = typeInfo;
82 }
83}