| |
Exercise 2 solution | page 6 of 10 |
//Exercise 2 builds from Exercise 1
Lab1 lab1 = new Lab1();
XSDSchema schema = lab1.createSchema(xsdFile); //Schema from lab1
//Create global simple type with name="USState"
XSDSimpleTypeDefinition simpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
simpleType.setName("USState");
//Set the base type to be a string
XSDSimpleTypeDefinition stringType = schema.getSchemaForSchema().
resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"string");
simpleType.setBaseTypeDefinition(stringType);
//AK Enumeration
XSDEnumerationFacet akEnum = XSDFactory.eINSTANCE.createXSDEnumerationFacet();
akEnum.setLexicalValue("AK");
simpleType.getFacetContents().add(akEnum);
//AL Enumeration
XSDEnumerationFacet alEnum = XSDFactory.eINSTANCE.createXSDEnumerationFacet();
alEnum.setLexicalValue("AL");
simpleType.getFacetContents().add(alEnum);
//AR Enumeration
XSDEnumerationFacet arEnum = XSDFactory.eINSTANCE.createXSDEnumerationFacet();
arEnum.setLexicalValue("AR");
simpleType.getFacetContents().add(arEnum);
//Add the simple type to the root schema
schema.getContents().add(simpleType);
//Save the contents of the resource to the file system.
schema.eResource().save(Collections.EMPTY_MAP);
|