final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(context, caseNode);
caseTypeBuilder.addImplementsType(targetType);
- SchemaNode parent;
- final SchemaPath nodeSp = targetNode.getPath();
- parent = findDataSchemaNode(schemaContext, nodeSp.getParent());
-
- GeneratedTypeBuilder childOfType = null;
- if (parent instanceof Module) {
- childOfType = moduleContext(((Module) parent).getQNameModule()).getModuleNode();
- } else if (parent instanceof CaseSchemaNode) {
- childOfType = findCaseByPath(parent.getPath());
- } else if (parent instanceof DataSchemaNode || parent instanceof NotificationDefinition) {
- childOfType = findChildNodeByPath(parent.getPath());
- } else if (parent instanceof GroupingDefinition) {
- childOfType = findGroupingByPath(parent.getPath());
- }
-
- if (childOfType == null) {
- throw new IllegalArgumentException("Failed to find parent type of choice " + targetNode);
- }
-
+ GeneratedTypeBuilder childOfType = findChildOfType(targetNode);
CaseSchemaNode node = null;
final String caseLocalName = caseNode.getQName().getLocalName();
if (caseNode instanceof CaseSchemaNode) {
}
}
+ private GeneratedTypeBuilder findChildOfType(final ChoiceSchemaNode targetNode) {
+ final SchemaPath nodePath = targetNode.getPath();
+ final SchemaPath parentSp = nodePath.getParent();
+ if (parentSp.getParent() == null) {
+ return moduleContext(nodePath.getLastComponent().getModule()).getModuleNode();
+ }
+
+ final SchemaNode parent = findDataSchemaNode(schemaContext, parentSp);
+ GeneratedTypeBuilder childOfType = null;
+ if (parent instanceof CaseSchemaNode) {
+ childOfType = findCaseByPath(parent.getPath());
+ } else if (parent instanceof DataSchemaNode || parent instanceof NotificationDefinition) {
+ childOfType = findChildNodeByPath(parent.getPath());
+ } else if (parent instanceof GroupingDefinition) {
+ childOfType = findGroupingByPath(parent.getPath());
+ }
+
+ if (childOfType == null) {
+ throw new IllegalArgumentException("Failed to find parent type of choice " + targetNode);
+ }
+
+ return childOfType;
+ }
+
private static CaseSchemaNode findNamedCase(final ChoiceSchemaNode choice, final String caseName) {
final List<CaseSchemaNode> cases = choice.findCaseNodes(caseName);
return cases.isEmpty() ? null : cases.get(0);