[ONOS-3904] Derived data type and formatting fixes
Change-Id: I1d68899e0056fa0db6322e83f7e9d3ff9b3b1ee0
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java b/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
index 0ce074e..f1250a2 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
@@ -54,10 +54,6 @@
*/
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
- /**
- * Name of derived data type.
- */
- private String derivedName;
/**
* Default value in string, needs to be converted to the target object,
@@ -81,14 +77,9 @@
private YangStatusType status;
/**
- * Derived data type. The type will be set when the parser detects the type
- * parsing. Hence it is of raw type and it not know at the time of creation
- * of the object. i.e. in entry parse, it will not be know, in the exit
- * parse we may know the type implicitly based on the restriction. We must
- * know and validate the base built in type, by the linking phase. It is a
- * RAW type and it usage needs to be validate in linking phase.
+ * Maintain the derived type information.
*/
- private YangType<?> derivedType;
+ private YangType<YangDerivedType> derivedType;
/**
* Units of the data type.
@@ -96,11 +87,6 @@
private String units;
/**
- * YANG base built in data type.
- */
- private YangDataTypes baseBuiltInType;
-
- /**
* package of the generated java code.
*/
private String pkg;
@@ -112,23 +98,7 @@
super(YangNodeType.TYPEDEF_NODE);
}
- /**
- * Get the data type name.
- *
- * @return the data type name.
- */
- public String getDerivedName() {
- return derivedName;
- }
- /**
- * Set the data type name.
- *
- * @param derrivedName data type name.
- */
- public void setDerivedName(String derrivedName) {
- derivedName = derrivedName;
- }
/**
* Get the default value.
@@ -209,20 +179,20 @@
}
/**
- * Get the referenced type.
+ * Get the derived type.
*
- * @return the referenced type.
+ * @return the derived type.
*/
- public YangType<?> getDerivedType() {
+ public YangType<YangDerivedType> getDerivedType() {
return derivedType;
}
/**
- * Get the referenced type.
+ * Set the derived type.
*
- * @param derivedType the referenced type.
+ * @param derivedType the derived type.
*/
- public void setDerivedType(YangType<?> derivedType) {
+ public void setDerivedType(YangType<YangDerivedType> derivedType) {
this.derivedType = derivedType;
}
@@ -245,24 +215,6 @@
}
/**
- * Get the base built in YANG data type.
- *
- * @return base built in YANG data type.
- */
- public YangDataTypes getBaseBuiltInType() {
- return baseBuiltInType;
- }
-
- /**
- * Set the base built in YANG data type.
- *
- * @param baseBuiltInType base built in YANG data type.
- */
- public void setBaseBuiltInType(YangDataTypes baseBuiltInType) {
- this.baseBuiltInType = baseBuiltInType;
- }
-
- /**
* Returns the type of the data.
*
* @return returns TYPEDEF_DATA
@@ -289,7 +241,34 @@
*/
@Override
public void validateDataOnExit() throws DataModelException {
- // TODO auto-generated method stub, to be implemented by parser
+ YangType<YangDerivedType> type = getDerivedType();
+ if (type == null) {
+ throw new DataModelException("Typedef does not have type info.");
+ }
+ if ((type.getDataType() != YangDataTypes.DERIVED)
+ || (type.getDataTypeName() == null)) {
+ throw new DataModelException("Typedef type is not derived.");
+ }
+
+ YangDerivedType derivedTypeInfo = type.getDataTypeExtendedInfo();
+ if (derivedTypeInfo == null) {
+ throw new DataModelException("derrived type does not have derived info.");
+ }
+
+ YangType<?> baseType = derivedTypeInfo.getBaseType();
+ if (baseType == null) {
+ throw new DataModelException("Base type of a derived type is missing.");
+ }
+
+ if (derivedTypeInfo.getEffectiveYangBuiltInType() == null) {
+ /* resolve the effective type from the data tree. */
+ /*
+ * TODO: try to resolve the nested reference, if possible in the
+ * partial tree, otherwise we need to resolve finally when the
+ * complete module is created.
+ */
+ YangModule.addToResolveList(this);
+ }
}
/**
@@ -299,7 +278,10 @@
*/
@Override
public String getName() {
- return derivedName;
+ if (getDerivedType() != null) {
+ return getDerivedType().getDataTypeName();
+ }
+ return null;
}
/**
@@ -309,8 +291,12 @@
*/
@Override
public void setName(String name) {
- // TODO Auto-generated method stub
-
+ if (getDerivedType() == null) {
+ throw new RuntimeException(
+ "Derrived Type info needs to be set in parser when the typedef listner is processed");
+ }
+ getDerivedType().setDataTypeName(name);
+ getDerivedType().setDataType(YangDataTypes.DERIVED);
}
/**