+
+ TypeDefinition<?> result = null;
+ QName qname = new QName(namespace, revision, prefix, typeName);
+ ExtendedType.Builder typeBuilder = null;
+
+ SchemaPath schemaPath = createTypeSchemaPath(actualPath, namespace,
+ revision, prefix, typeName, false, false);
+ typeBuilder = new ExtendedType.Builder(qname, baseType, "", "",
+ schemaPath);
+
+ typeBuilder.ranges(rangeStatements);
+ typeBuilder.lengths(lengthStatements);
+ typeBuilder.patterns(patternStatements);
+ typeBuilder.fractionDigits(fractionDigits);
+
+ result = typeBuilder.build();
+ return result;
+ }
+
+ /**
+ * Create SchemaPath object from given path list with namespace, revision
+ * and prefix based on given values.
+ *
+ * @param actualPath
+ * current position in model
+ * @param namespace
+ * @param revision
+ * @param prefix
+ * @param typeName
+ * @param isBaseYangType
+ * if this is base yang type
+ * @param isBaseYangTypeFinal
+ * if this is base yang type without restrictions
+ * @return SchemaPath object.
+ */
+ private static SchemaPath createTypeSchemaPath(
+ final List<String> actualPath, final URI namespace,
+ final Date revision, final String prefix, final String typeName,
+ final boolean isBaseYangType, final boolean isBaseYangTypeFinal) {
+ List<String> typePath = new ArrayList<String>(actualPath);
+ if (isBaseYangType && !isBaseYangTypeFinal) {
+ typePath.add(typeName);
+ }
+
+ final List<QName> path = new ArrayList<QName>();
+ QName qname;
+ // start from index 1 -> module name omited
+ for (int i = 1; i < typePath.size(); i++) {
+ qname = new QName(namespace, revision, prefix, typePath.get(i));
+ path.add(qname);
+ }
+ QName typeQName;
+ if (isBaseYangType) {
+ typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName);
+ } else {
+ typeQName = new QName(namespace, revision, prefix, typeName);
+ }
+ path.add(typeQName);
+ return new SchemaPath(path, true);