* @throws JiBXException on unrecoverable error in schemas
* @throws IOException on error reading schemas
*/
public static SchemaElement[] load(Collection resolves, String uri, ValidationContext vctx)
throws JiBXException, IOException {
IBindingFactory factory = BindingDirectory.getFactory(SchemaUtils.XS_PREFIX_BINDING, SchemaElement.class);
IUnmarshallingContext ictx = factory.createUnmarshallingContext();
int count = resolves.size();
int offset = 0;
SchemaElement[] schemas = new SchemaElement[count];
for (Iterator iter = resolves.iterator(); iter.hasNext();) {
// unmarshal document to construct schema structure
ISchemaResolver resolver = (ISchemaResolver)iter.next();
ictx.setDocument(resolver.getContent(), resolver.getName(), null);
ictx.setUserContext(vctx);
SchemaElement schema = new SchemaElement();
((IUnmarshallable)schema).unmarshal(ictx);
// set resolver for use during schema processing
schemas[offset++] = schema;
schema.setResolver(resolver);
String id = resolver.getId();
vctx.setSchema(id, schema);
// verify schema roundtripping if debug enabled
if (s_logger.isDebugEnabled()) {
try {
// determine encoding of input document
String enc = ((UnmarshallingContext)ictx).getInputEncoding();
if (enc == null) {
enc = "UTF-8";
}
// marshal root object back out to document in memory
IMarshallingContext mctx = factory.createMarshallingContext();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
mctx.setIndent(2);
mctx.marshalDocument(schema, "UTF-8", null, bos);
// compare with original input document