val basePackageName = moduleNamespaceToPackageName(module);
for (usesNode : node.uses) {
for (augment : usesNode.augmentations) {
- augmentationToGenTypes(basePackageName, augment, module, usesNode);
+ usesAugmentationToGenTypes(basePackageName, augment, module, usesNode, node);
processUsesAugments(augment, module);
}
}
val basePackageName = moduleNamespaceToPackageName(module);
val List<AugmentationSchema> augmentations = resolveAugmentations(module);
for (augment : augmentations) {
- augmentationToGenTypes(basePackageName, augment, module, null);
+ augmentationToGenTypes(basePackageName, augment, module);
}
}
* <li>if target path of <code>augSchema</code> equals null</li>\r
* </ul>\r
*/
- private def void augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module,
- UsesNode parentUsesNode) {
+ private def void augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module) {
checkArgument(augmentPackageName !== null, "Package Name cannot be NULL.");
checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL.");
checkState(augSchema.targetPath !== null,
"Augmentation Schema does not contain Target Path (Target Path is NULL).");
- processUsesAugments(augSchema, module);\r
+ processUsesAugments(augSchema, module);
val targetPath = augSchema.targetPath;
- var targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);\r
+ var SchemaNode targetSchemaNode = null
+
+ targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
if (targetSchemaNode instanceof DataSchemaNode && (targetSchemaNode as DataSchemaNode).isAddedByUses()) {
- if (parentUsesNode == null) {
- targetSchemaNode = findOriginal(targetSchemaNode as DataSchemaNode);
- } else {
- targetSchemaNode = findOriginalTargetFromGrouping(targetSchemaNode.QName.localName, parentUsesNode);
- }
+ targetSchemaNode = findOriginal(targetSchemaNode as DataSchemaNode);
if (targetSchemaNode == null) {
throw new NullPointerException(
- "Failed to find target node from grouping for augmentation " + augSchema + " in module " +
+ "Failed to find target node from grouping in augmentation " + augSchema + " in module " +
module.name);
}
+ }
+ if (targetSchemaNode == null) {
+ throw new IllegalArgumentException("augment target not found: " + targetPath)
+ }
+
+ var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path)
+ if (targetTypeBuilder === null) {
+ targetTypeBuilder = findCaseByPath(targetSchemaNode.path)
+ }
+ if (targetTypeBuilder === null) {
+ throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
}\r
+
+ if (!(targetSchemaNode instanceof ChoiceNode)) {
+ var packageName = augmentPackageName;
+ val augTypeBuilder = addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,
+ targetTypeBuilder.toInstance, augSchema);
+ genCtx.get(module).addAugmentType(augTypeBuilder)
+ genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema);
+ } else {
+ generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance,
+ targetSchemaNode as ChoiceNode, augSchema.childNodes);
+ }
+ }
\r
- if (targetSchemaNode == null) {\r
- throw new IllegalArgumentException("augment target not found: " + targetPath)\r
+ private def void usesAugmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module,
+ UsesNode usesNode, DataNodeContainer usesNodeParent) {
+ checkArgument(augmentPackageName !== null, "Package Name cannot be NULL.");
+ checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL.");
+ checkState(augSchema.targetPath !== null,
+ "Augmentation Schema does not contain Target Path (Target Path is NULL).");
+
+ processUsesAugments(augSchema, module);
+ val targetPath = augSchema.targetPath;
+ var SchemaNode targetSchemaNode = null
+ targetSchemaNode = findOriginalTargetFromGrouping(targetPath, usesNode);
+ if (targetSchemaNode == null) {
+ throw new IllegalArgumentException("augment target not found: " + targetPath)
+ }
+
+ var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path)
+ if (targetTypeBuilder === null) {
+ targetTypeBuilder = findCaseByPath(targetSchemaNode.path)
+ }
+ if (targetTypeBuilder === null) {
+ throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
}\r
- if (targetSchemaNode !== null) {
- var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path)
- if (targetTypeBuilder === null) {
- targetTypeBuilder = findCaseByPath(targetSchemaNode.path)
- }
- if (targetTypeBuilder === null) {
- throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
- }
- if (!(targetSchemaNode instanceof ChoiceNode)) {
- var packageName = augmentPackageName;
- if (parentUsesNode != null) {
- packageName = packageNameForGeneratedType(augmentPackageName, augSchema.targetPath);
- }
- val augTypeBuilder = addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,
- targetTypeBuilder.toInstance, augSchema);
- genCtx.get(module).addAugmentType(augTypeBuilder)\r
- genCtx.get(module).addTypeToAugmentation(augTypeBuilder,augSchema);
- } else {
- generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance,
- targetSchemaNode as ChoiceNode, augSchema.childNodes);
+ if (!(targetSchemaNode instanceof ChoiceNode)) {
+ var packageName = augmentPackageName;
+ if (usesNodeParent instanceof SchemaNode) {
+ packageName = packageNameForGeneratedType(augmentPackageName, (usesNodeParent as SchemaNode).path, true)
}
+ val augTypeBuilder = addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,
+ targetTypeBuilder.toInstance, augSchema);
+ genCtx.get(module).addAugmentType(augTypeBuilder)
+ genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema);
+ } else {
+ generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance,
+ targetSchemaNode as ChoiceNode, augSchema.childNodes);
}
- }
+ }\r
/**\r
* Utility method which search for original node defined in grouping.\r
/**\r
* Convenient method to find node added by uses statement.\r
*/
- private def DataSchemaNode findOriginalTargetFromGrouping(String targetSchemaNodeName, UsesNode parentUsesNode) {
+ private def DataSchemaNode findOriginalTargetFromGrouping(SchemaPath targetPath, UsesNode parentUsesNode) {
var SchemaNode targetGrouping = findNodeInSchemaContext(schemaContext, parentUsesNode.groupingPath.path);
if (!(targetGrouping instanceof GroupingDefinition)) {
throw new IllegalArgumentException("Failed to generate code for augment in " + parentUsesNode);
}
- var grouping = targetGrouping as GroupingDefinition;
- var result = grouping.getDataChildByName(targetSchemaNodeName);
+ var grouping = targetGrouping as GroupingDefinition;\r
+ var SchemaNode result = grouping;\r
+ val List<QName> path = targetPath.path\r
+ for (node : path) {
+ // finding by local name is valid, grouping cannot contain nodes with same name and different namespace\r
+ if (result instanceof DataNodeContainer) {
+ result = (result as DataNodeContainer).getDataChildByName(node.localName)
+ } else if (result instanceof ChoiceNode) {
+ result = (result as ChoiceNode).getCaseNodeByName(node.localName)
+ }
+ }
if (result == null) {
return null;
- }
- var boolean fromUses = result.addedByUses;
-
+ }\r
+\r
+ val String targetSchemaNodeName = result.QName.localName;
+ var boolean fromUses = (result as DataSchemaNode).addedByUses
var Iterator<UsesNode> groupingUses = grouping.uses.iterator;
while (fromUses) {
if (groupingUses.hasNext()) {
grouping = findNodeInSchemaContext(schemaContext, groupingUses.next().groupingPath.path) as GroupingDefinition;
result = grouping.getDataChildByName(targetSchemaNodeName);
- fromUses = result.addedByUses;
+ fromUses = (result as DataSchemaNode).addedByUses;
} else {
throw new NullPointerException("Failed to generate code for augment in " + parentUsesNode);
}
}
- return result;
+ return result as DataSchemaNode
}
/**\r
// Test if all sources were generated from 'module foo'
File parent = new File(sourcesOutputDir, NS_FOO);
assertTrue(new File(parent, "Object.java").exists());
+ assertTrue(new File(parent, "ClosedObject.java").exists());
assertTrue(new File(parent, "OpenObject.java").exists());
assertTrue(new File(parent, "ExplicitRouteObject.java").exists());
assertTrue(new File(parent, "PathKeySubobject.java").exists());
- assertFilesCount(parent, 7);
+ assertFilesCount(parent, 9);
parent = new File(parent, "object");
assertTrue(new File(parent, "Nodes.java").exists());
assertTrue(new File(parent, "NodesBuilder.java").exists());
assertFilesCount(parent, 2);
+ parent = new File(sourcesOutputDir, NS_FOO + FS + "closed");
+ assertFilesCount(parent, 1);
+
+ parent = new File(parent, "object");
+ assertTrue(new File(parent, "Link1.java").exists());
+ assertTrue(new File(parent, "Link1Builder.java").exists());
+ assertFilesCount(parent, 2);
+
parent = new File(sourcesOutputDir, NS_FOO + FS + "open");
assertFilesCount(parent, 1);
parent = new File(sourcesOutputDir, NS_BAR);
assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists());
assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists());
- assertFilesCount(parent, 3);
+ assertTrue(new File(parent, "RouteSubobjects.java").exists());
+ assertFilesCount(parent, 5);
- parent = new File(parent, "basic");
+ parent = new File(parent, "route");
+ assertFilesCount(parent, 1);
+ parent = new File(new File(sourcesOutputDir, NS_BAR), "basic");
assertFilesCount(parent, 1);
parent = new File(parent, "explicit");
assertFilesCount(parent, 1);