use of org.apache.xerces.xni.grammars.XSGrammar in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathWTPTest method getGrammar.
protected XSModel getGrammar(URL schemaURL) throws IOException, SAXException {
InputStream schemaIs = testResolve(schemaURL);
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new StreamSource(schemaIs));
XSGrammarPoolContainer poolContainer = (XSGrammarPoolContainer) schema;
XMLGrammarPool pool = poolContainer.getGrammarPool();
Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
XSGrammar[] xsGrammars = new XSGrammar[grammars.length];
System.arraycopy(grammars, 0, xsGrammars, 0, grammars.length);
return xsGrammars[0].toXSModel(xsGrammars);
}
use of org.apache.xerces.xni.grammars.XSGrammar in project iaf by ibissource.
the class JavaxValidationContext method createValidationContext.
@Override
public JavaxValidationContext createValidationContext(IPipeLineSession session, Set<List<String>> rootValidations, Map<List<String>, List<String>> invalidRootNamespaces) throws ConfigurationException, PipeRunException {
// clear session variables
super.createValidationContext(session, rootValidations, invalidRootNamespaces);
String schemasId;
Schema schema;
Set<String> namespaceSet = new HashSet<String>();
List<XSModel> xsModels = null;
init();
schemasId = schemasProvider.getSchemasId();
if (schemasId == null) {
schemasId = schemasProvider.getSchemasId(session);
getSchemaObject(schemasId, schemasProvider.getSchemas(session));
}
schema = javaxSchemas.get(schemasId);
String mainFailureMessage = "Validation using " + schemasProvider.getClass().getSimpleName() + " with '" + schemasId + "' failed";
if (schema != null) {
org.apache.xerces.jaxp.validation.XSGrammarPoolContainer xercesSchema = (org.apache.xerces.jaxp.validation.XSGrammarPoolContainer) schema;
xercesSchema.getGrammarPool();
xsModels = new LinkedList<XSModel>();
Grammar[] grammars = xercesSchema.getGrammarPool().retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
for (int i = 0; i < grammars.length; i++) {
XSModel model = ((XSGrammar) grammars[i]).toXSModel();
xsModels.add(model);
StringList namespaces = model.getNamespaces();
for (int j = 0; j < namespaces.getLength(); j++) {
String namespace = namespaces.item(j);
namespaceSet.add(namespace);
}
}
}
JavaxValidationContext result = new JavaxValidationContext(schemasId, schema, namespaceSet, xsModels);
result.init(schemasProvider, schemasId, namespaceSet, rootValidations, invalidRootNamespaces, ignoreUnknownNamespaces);
return result;
}
Aggregations