Exercise 4 solution | page 4 of 6 |
//Exercise 4 builds from Exercise 3
Lab3 lab3 = new Lab3();
XSDSchema schema = lab3.createSchema(xsdFile); //Schema from lab 3
//Create global complex type with name = "PurchaseOrderType"
XSDComplexTypeDefinition complexType = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
complexType.setName("PurchaseOrderType");
XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
//Create a sequence model group
XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
//Add the model group to the particle
particle.setContent(modelGroup);
//Set the contents of the complex type to be the particle
complexType.setContent(particle);
//Add the complex type to the root schema
schema.getContents().add(complexType);
// Save the contents of the resource to the file system.
schema.eResource().save(Collections.EMPTY_MAP);
|