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