* @param schemas collection of schemas (indexed by systemId)
*
* @return a {@link SchemaModel}
*/
public static final SchemaModel newModel(Map<URI, byte[]> schemas) {
XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
InternalSchemaResolver resolver = new InternalSchemaResolver();
schemaLoader.setEntityResolver(resolver);
schemaLoader.setParameter(Constants.DOM_ERROR_HANDLER, new SchemaErrorHandler());
final String[] uris = new String[schemas.size()];
final byte[][] content = new byte[schemas.size()][];
int idx = 0;
for (Iterator<Map.Entry<URI,byte[]>> i = schemas.entrySet().iterator();i.hasNext();) {
Map.Entry<URI, byte[]> me = i.next();
uris[idx] = me.getKey().toASCIIString();
content[idx] = me.getValue();
resolver.put(me.getKey(), me.getValue());
++idx;
}
LSInputList list = new LSInputList() {
public LSInput item(int index) {
DOMInputImpl input = new DOMInputImpl();
input.setSystemId(uris[index]);
input.setByteStream(new ByteArrayInputStream(content[index]));
return input;
}
public int getLength() {
return uris.length;
}
};
XSModel xsm = schemaLoader.loadInputList(list);
return new SchemaModelImpl(xsm);
}