private NeutralSchema parseSimpleType( XmlSchemaSimpleType schemaSimpleType, XmlSchema schema, String name) { NeutralSchema ns = recursiveParseSimpleType(schemaSimpleType, schema); if (schemaSimpleType.getName() == null) { // Type defined in-line. Need to capture it in the element schema set. int i = 1; NeutralSchema existing = elementSchemas.get(name + i); while (existing != null && !schemasEqual(ns, existing)) { i++; existing = schemas.get(name + i); } ns.setType(name + i); elementSchemas.put(name + i, ns); } return ns; }
private NeutralSchema recursiveParseSimpleType( XmlSchemaSimpleType schemaSimpleType, XmlSchema schema) { NeutralSchema simpleSchema = null; String simpleTypeName = schemaSimpleType.getName(); if (NeutralSchemaType.isPrimitive(schemaSimpleType.getQName())) { simpleSchema = getSchemaFactory().createSchema(schemaSimpleType.getQName()); } else if (NeutralSchemaType.exists(schemaSimpleType.getBaseSchemaTypeName())) { if (NeutralSchemaType.isPrimitive(schemaSimpleType.getBaseSchemaTypeName())) { simpleSchema = getSchemaFactory().createSchema(schemaSimpleType.getBaseSchemaTypeName()); } else { XmlSchemaSimpleType simpleBaseType = getSimpleBaseType(schemaSimpleType.getBaseSchemaTypeName(), schema); if (simpleBaseType != null) { if (simpleTypeName == null) { simpleTypeName = simpleBaseType.getName(); } simpleSchema = getSchemaFactory().createSchema(simpleTypeName); } } } else if (schemaSimpleType.getContent() != null && schemaSimpleType.getContent() instanceof XmlSchemaSimpleTypeList) { ListSchema listSchema = (ListSchema) getSchemaFactory().createSchema("list"); XmlSchemaSimpleTypeList content = (XmlSchemaSimpleTypeList) schemaSimpleType.getContent(); NeutralSchema listContentSchema = null; if (content.getItemType() != null) { listContentSchema = parseSimpleType(content.getItemType(), schema, null); } else { QName itemTypeName = content.getItemTypeName(); listContentSchema = getSchemaFactory().createSchema(itemTypeName.getLocalPart()); } listSchema.getList().add(listContentSchema); listSchema.updateAnnotations(); return listSchema; } else if (getSimpleContentTypeName(schemaSimpleType) != null) { if (NeutralSchemaType.isPrimitive(getSimpleContentTypeName(schemaSimpleType))) { simpleSchema = getSchemaFactory().createSchema(getSimpleContentTypeName(schemaSimpleType)); } else { XmlSchemaSimpleType simpleBaseType = getSimpleBaseType(getSimpleContentTypeName(schemaSimpleType), schema); simpleSchema = recursiveParseSimpleType(simpleBaseType, schema); } } if (simpleSchema != null && schemaSimpleType.getContent() != null) { if (schemaSimpleType.getContent() instanceof XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction simpleRestrictedContent = (XmlSchemaSimpleTypeRestriction) schemaSimpleType.getContent(); XmlSchemaObjectCollection facets = simpleRestrictedContent.getFacets(); List<String> tokens = new ArrayList<String>(); for (int i = 0; i < facets.getCount(); i++) { XmlSchemaObject facetObject = facets.getItem(i); if (facetObject instanceof XmlSchemaEnumerationFacet) { XmlSchemaEnumerationFacet enumerationFacet = (XmlSchemaEnumerationFacet) facetObject; tokens.add(enumerationFacet.getValue().toString()); } else if (facetObject instanceof XmlSchemaFacet) { XmlSchemaFacet facet = (XmlSchemaFacet) facetObject; String facetPropertyName = NeutralSchemaType.lookupPropertyName(facet); simpleSchema.getProperties().put(facetPropertyName, facet.getValue().toString()); } } if (tokens.size() > 0) { // Token Schema Collections.sort(tokens); // sort so we can binary search simpleSchema.getProperties().put(TokenSchema.TOKENS, tokens); } } } parseAnnotations(simpleSchema, schemaSimpleType); if ((simpleSchema != null) && (simpleTypeName != null)) { simpleSchema.setType(simpleTypeName); } return simpleSchema; }