- /**
- * Returns the Yang Module from specified Schema Context in which the TypeDefinition is declared. If the
- * TypeDefinition si not present in Schema Context then the method will return <code>null</code>
- *
- * If Schema Context or TypeDefinition contains <code>null</code> references the method will throw IllegalArgumentException
- *
- * @throws IllegalArgumentException
- *
- * @param context Schema Context
- * @param type Type Definition
- * @return Yang Module in which the TypeDefinition is declared, if is not present, returns <code>null</code>.
- */
- public static Module findParentModuleForTypeDefinition(final SchemaContext context, final TypeDefinition<?> type) {
- final SchemaPath schemaPath = type.getPath();
- if (schemaPath == null) {
- throw new IllegalArgumentException("Schema Path reference cannot be NULL");
- }
- final List<QName> qnamedPath = schemaPath.getPath();
- if (qnamedPath == null || qnamedPath.isEmpty()) {
- throw new IllegalStateException("Schema Path contains invalid state of path parts."
- + "The Schema Path MUST contain at least ONE QName which defines namespace and Local name"
- + "of path.");
- }
-
- if (type instanceof ExtendedType) {
- final QName qname = qnamedPath.get(qnamedPath.size() - 1);
- if ((qname != null) && (qname.getNamespace() != null)) {
- return context.findModuleByNamespace(qname.getNamespace());
- }
- } else {
- final QName qname = qnamedPath.get(qnamedPath.size() - 2);
- if ((qname != null) && (qname.getNamespace() != null)) {
- return context.findModuleByNamespace(qname.getNamespace());
- }
- }
- return null;
- }
-