use of org.apache.ws.commons.schema.XmlSchemaSerializer in project cxf by apache.
the class EnumTypeTest method testWSDL.
@Test
public void testWSDL() throws Exception {
EnumType type = new EnumType();
type.setTypeClass(SmallEnum.class);
type.setSchemaType(new QName("urn:test", "test"));
XmlSchema schema = newXmlSchema("urn:test");
type.writeSchema(schema);
XmlSchemaSerializer ser = new XmlSchemaSerializer();
Document doc = ser.serializeSchema(schema, false)[0];
addNamespace("xsd", Constants.URI_2001_SCHEMA_XSD);
assertValid("//xsd:simpleType[@name='test']/xsd:restriction[@base='xsd:string']", doc);
assertValid("//xsd:restriction[@base='xsd:string']/xsd:enumeration[@value='VALUE1']", doc);
assertValid("//xsd:restriction[@base='xsd:string']/xsd:enumeration[@value='VALUE2']", doc);
}
use of org.apache.ws.commons.schema.XmlSchemaSerializer in project cxf by apache.
the class JAXBDataBinding method getSchemaNode.
private Object getSchemaNode(XmlSchema schema, SchemaCollection schemaCollection) {
XmlSchemaSerializer xser = new XmlSchemaSerializer();
xser.setExtReg(schemaCollection.getExtReg());
Document[] docs;
try {
docs = xser.serializeSchema(schema, false);
} catch (XmlSchemaSerializerException e) {
throw new RuntimeException(e);
}
return docs[0].getDocumentElement();
}
use of org.apache.ws.commons.schema.XmlSchemaSerializer in project cxf by apache.
the class DynamicClientFactory method addSchemas.
private void addSchemas(Options opts, SchemaCompiler schemaCompiler, List<ServiceInfo> serviceList, SchemaCollection schemaCollection) {
Map<String, Element> done = new HashMap<>();
Map<String, Element> notDone = new HashMap<>();
OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
}
String key = schema.getSourceURI();
if (done.containsKey(key)) {
continue;
}
if (!key.startsWith("file:") && !key.startsWith("jar:")) {
XmlSchemaSerializer xser = new XmlSchemaSerializer();
xser.setExtReg(schemaCollection.getExtReg());
Document[] docs;
try {
docs = xser.serializeSchema(schema, false);
} catch (XmlSchemaSerializerException e) {
throw new RuntimeException(e);
}
Element ele = docs[0].getDocumentElement();
ele = removeImportElement(ele, key, catalog, done, notDone);
try {
docs[0].setDocumentURI(key);
} catch (Throwable t) {
// ignore - DOM level 3
}
if (ele != null) {
InputSource is = new InputSource((InputStream) null);
// key = key.replaceFirst("#types[0-9]+$", "");
is.setSystemId(key);
is.setPublicId(key);
opts.addGrammar(is);
schemaCompiler.parseSchema(key, ele);
}
}
}
for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
}
String key = schema.getSourceURI();
if (done.containsKey(key)) {
continue;
}
if (key.startsWith("file:") || key.startsWith("jar:")) {
InputStream in = null;
try {
if (key.contains("#")) {
for (ServiceInfo si : serviceList) {
for (SchemaInfo sci : si.getSchemas()) {
if (key != null && key.equals(sci.getSystemId())) {
key = null;
}
}
}
}
if (key == null) {
continue;
}
if (key.startsWith("file:")) {
in = Files.newInputStream(new File(new URI(key)).toPath());
} else {
in = new URL(key).openStream();
}
XMLStreamReader reader = StaxUtils.createXMLStreamReader(key, in);
reader = new LocationFilterReader(reader, catalog);
InputSource is = new InputSource(key);
opts.addGrammar(is);
schemaCompiler.parseSchema(key, reader);
reader.close();
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
}
}
for (ServiceInfo si : serviceList) {
for (SchemaInfo sci : si.getSchemas()) {
String key = sci.getSystemId();
if (done.containsKey(key)) {
continue;
}
Element ele = sci.getElement();
ele = removeImportElement(ele, key, catalog, done, notDone);
if (ele != null) {
InputSource is = new InputSource((InputStream) null);
// key = key.replaceFirst("#types[0-9]+$", "");
is.setSystemId(key);
is.setPublicId(key);
opts.addGrammar(is);
schemaCompiler.parseSchema(key, StaxUtils.createXMLStreamReader(ele, key));
}
}
}
for (Map.Entry<String, Element> el : notDone.entrySet()) {
InputSource is = new InputSource((InputStream) null);
// key = key.replaceFirst("#types[0-9]+$", "");
is.setSystemId(el.getKey());
is.setPublicId(el.getKey());
opts.addGrammar(is);
schemaCompiler.parseSchema(el.getKey(), StaxUtils.createXMLStreamReader(el.getValue(), el.getKey()));
}
}
Aggregations