* @param schemaCount
* @param properties
* @return
*/
protected Schema buildNewSchema(String uri, NamespaceResolver nr, int schemaCount, SchemaModelGeneratorProperties properties) {
Schema schema = new Schema();
schema.setName(SCHEMA_FILE_NAME + schemaCount + SCHEMA_FILE_EXT);
schemaCount++;
String defaultNamespace = null;
if (nr != null) {
defaultNamespace = nr.getDefaultNamespaceURI();
if (defaultNamespace != null) {
schema.setDefaultNamespace(defaultNamespace);
schema.getNamespaceResolver().setDefaultNamespaceURI(defaultNamespace);
}
}
if (!uri.equals(XMLConstants.EMPTY_STRING)) {
schema.setTargetNamespace(uri);
String prefix = null;
if (nr != null) {
prefix = nr.resolveNamespaceURI(uri);
}
if (prefix == null && !uri.equals(defaultNamespace)) {
prefix = schema.getNamespaceResolver().generatePrefix();
schema.getNamespaceResolver().put(prefix, uri);
}
}
if (properties != null) {
// set elementFormDefault and attributeFormDefault to qualified if necessary
Properties props = properties.getProperties(uri);
if (props != null) {
if (props.containsKey(SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY)) {
schema.setElementFormDefault((Boolean) props.get(SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY));
}
if (props.containsKey(SchemaModelGeneratorProperties.ATTRIBUTE_FORM_QUALIFIED_KEY)) {
schema.setAttributeFormDefault((Boolean) props.get(SchemaModelGeneratorProperties.ATTRIBUTE_FORM_QUALIFIED_KEY));
}
}
}
return schema;
}