- if ((qname != null) && (qname.getNamespace() != null)) {
- return context.findModuleByNamespace(qname.getNamespace());
+ if ((qname != null) && (qname.getNamespace() != null)) {
+ return context.findModuleByNamespace(qname.getNamespace());
+ }
+ }
+ }
+ return null;
+ }
+
+ public static Module findParentModuleForTypeDefinition(
+ final SchemaContext context, final TypeDefinition<?> type) {
+ final SchemaPath schemaPath = type.getPath();
+ if ((schemaPath != null) && (schemaPath.getPath() != null)) {
+ if(type instanceof ExtendedType) {
+ List<QName> path = schemaPath.getPath();
+ final QName qname = path.get(path.size() - 1);
+
+ if ((qname != null) && (qname.getNamespace() != null)) {
+ return context.findModuleByNamespace(qname.getNamespace());
+ }
+ } else {
+ List<QName> path = schemaPath.getPath();
+ final QName qname = path.get(path.size() - 2);
+
+ if ((qname != null) && (qname.getNamespace() != null)) {
+ return context.findModuleByNamespace(qname.getNamespace());
+ }