blob: 4ba48581e99b70d4278108dd414e7dc40472d419 [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;
Bharat saraswal33dfa012016-05-17 19:59:16 +053022import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053023
24/**
25 * Represents java information corresponding to the YANG type.
Bharat saraswalab4c6ba2016-05-17 14:19:38 +053026 *
27 * @param <T> generic parameter for YANG java type
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053028 */
29public class YangJavaType<T>
30 extends YangType<T>
31 implements JavaQualifiedTypeResolver {
32
33 private JavaQualifiedTypeInfo javaQualifiedAccess;
34
35 /**
36 * Create a YANG leaf object with java qualified access details.
37 */
38 public YangJavaType() {
39 super();
40 setJavaQualifiedInfo(new JavaQualifiedTypeInfo());
41 }
42
43 @Override
Bharat saraswal33dfa012016-05-17 19:59:16 +053044 public void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil confilictResolver) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053045 JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo();
46
47 /*
48 * Type is added as an attribute in the class.
49 */
Bharat saraswal33dfa012016-05-17 19:59:16 +053050 String className = AttributesJavaDataType.getJavaImportClass(this, false, confilictResolver);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053051 if (className != null) {
52 /*
53 * Corresponding to the attribute type a class needs to be imported,
54 * since it can be a derived type or a usage of wrapper classes.
55 */
56 importInfo.setClassInfo(className);
57 String classPkg = AttributesJavaDataType.getJavaImportPackage(this,
58 false, className);
59 if (classPkg == null) {
60 throw new TranslatorException("import package cannot be null when the class is used");
61 }
62 importInfo.setPkgInfo(classPkg);
63 } else {
64 /*
65 * The attribute does not need a class to be imported, for example
66 * built in java types.
67 */
68 String dataTypeName = AttributesJavaDataType.getJavaDataType(this);
69 if (dataTypeName == null) {
70 throw new TranslatorException("not supported data type");
71 }
72 importInfo.setClassInfo(dataTypeName);
73 }
Bharat saraswalc0e04842016-05-12 13:16:57 +053074 setJavaQualifiedInfo(importInfo);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053075 }
76
77 @Override
78 public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
79 return javaQualifiedAccess;
80 }
81
82 @Override
83 public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
84 javaQualifiedAccess = typeInfo;
85 }
86}