use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class WSDLSchemaManager method createXmlSchemaForDefinition.
public XmlSchema createXmlSchemaForDefinition(Definition defn, String schemans, XmlSchemaCollection schemaCol) {
XmlSchema xmlSchema = createXmlSchema(schemans, schemaCol);
defnSchemas.put(schemans, xmlSchema);
return xmlSchema;
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class WSDLParameter method findSchemaType.
// This willl search the current schemas and any included
// schemas for the schema type.
private static XmlSchemaType findSchemaType(XmlSchema xmlSchema, QName typeName) {
XmlSchemaType schemaType = xmlSchema.getTypeByName(typeName);
if (schemaType == null) {
for (XmlSchemaExternal ext : xmlSchema.getExternals()) {
if (ext instanceof XmlSchemaImport) {
XmlSchemaImport xmlImport = (XmlSchemaImport) ext;
if (xmlImport.getNamespace().equals(typeName.getNamespaceURI())) {
XmlSchema importSchema = xmlImport.getSchema();
schemaType = importSchema.getTypeByName(typeName);
} else {
schemaType = findSchemaType(ext.getSchema(), typeName);
if (schemaType != null) {
return schemaType;
}
}
}
}
if (schemaType != null) {
return schemaType;
}
}
return schemaType;
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class JAXBDataBinding method addedEnumClassToCollector.
// JAXB bug. JAXB ClassNameCollector may not be invoked when generated
// class is an enum. We need to use this method to add the missed file
// to classCollector.
private void addedEnumClassToCollector(SchemaCollection schemaCollection, ClassNameAllocatorImpl allocator) {
// for (Element schemaElement : schemaList.values()) {
for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
String targetNamespace = schema.getTargetNamespace();
if (StringUtils.isEmpty(targetNamespace)) {
continue;
}
String packageName = context.mapPackageName(targetNamespace);
if (!addedToClassCollector(packageName)) {
allocator.assignClassName(packageName, "*");
}
}
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class ProcessorUtil method isSchemaFormQualified.
public static boolean isSchemaFormQualified(ToolContext context, QName partElement) {
ServiceInfo serviceInfo = context.get(ServiceInfo.class);
SchemaCollection schemaCol = serviceInfo.getXmlSchemaCollection();
XmlSchema schema = schemaCol.getSchemaForElement(partElement);
if (schema != null) {
return schema.getElementFormDefault() == XmlSchemaForm.QUALIFIED;
}
return false;
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class WSDLToJavaContainer method generateLocalWSDL.
@SuppressWarnings("unchecked")
private void generateLocalWSDL(ToolContext context) {
String outputdir = (String) context.get(ToolConstants.CFG_CLASSDIR);
File wsdlFile = new File(outputdir, (String) context.get(ToolConstants.CFG_WSDLLOCATION));
Definition def = context.get(Definition.class);
try {
// get imported schemas
int xsdCount = 0;
SchemaCollection schemas = (SchemaCollection) context.get(ToolConstants.XML_SCHEMA_COLLECTION);
Map<String, String> sourceMap = new HashMap<>();
for (XmlSchema imp : schemas.getXmlSchemas()) {
if (imp.getSourceURI() != null && !imp.getSourceURI().contains(".wsdl#")) {
String schemaFileName = "schema" + (++xsdCount) + ".xsd";
sourceMap.put(imp.getTargetNamespace(), schemaFileName);
}
}
// get imported wsdls
int wsdlImportCount = 0;
List<Definition> defs = (List<Definition>) context.get(ToolConstants.IMPORTED_DEFINITION);
Map<String, String> importWSDLMap = new HashMap<>();
for (Definition importDef : defs) {
File importedWsdlFile = null;
if (!StringUtils.isEmpty(importDef.getDocumentBaseURI())) {
importedWsdlFile = new File(importDef.getDocumentBaseURI());
} else {
importedWsdlFile = new File(importDef.getQName().getLocalPart() + ".wsdl");
}
if (!FileUtils.isValidFileName(importedWsdlFile.getName())) {
importedWsdlFile = new File("import" + (++wsdlImportCount) + ".wsdl");
}
importWSDLMap.put(importDef.getTargetNamespace(), importedWsdlFile.getName());
}
OutputStreamCreator outputStreamCreator = null;
if (context.get(OutputStreamCreator.class) != null) {
outputStreamCreator = context.get(OutputStreamCreator.class);
} else {
outputStreamCreator = new OutputStreamCreator();
context.put(OutputStreamCreator.class, outputStreamCreator);
}
Writer os = null;
for (XmlSchema imp : schemas.getXmlSchemas()) {
if (imp.getSourceURI() != null && !imp.getSourceURI().contains(".wsdl#")) {
String schemaFileName = sourceMap.get(imp.getTargetNamespace());
File impfile = new File(wsdlFile.getParentFile(), schemaFileName);
Element el = imp.getSchemaDocument().getDocumentElement();
updateImports(el, sourceMap);
os = new FileWriterUtil(impfile.getParent(), context.get(OutputStreamCreator.class)).getWriter(impfile, StandardCharsets.UTF_8.name());
StaxUtils.writeTo(el, os, 2);
os.close();
}
}
// change the import location in wsdl file
OutputStream wsdloutput = new BufferedOutputStream(Files.newOutputStream(wsdlFile.toPath()));
WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
wsdlWriter.writeWSDL(def, bout);
Element defEle = StaxUtils.read(bout.createInputStream()).getDocumentElement();
List<Element> xsdElements = DOMUtils.findAllElementsByTagNameNS(defEle, WSDLConstants.NS_SCHEMA_XSD, "schema");
for (Element xsdEle : xsdElements) {
updateImports(xsdEle, sourceMap);
}
updateWSDLImports(defEle, importWSDLMap);
StaxUtils.writeTo(defEle, wsdloutput);
wsdloutput.close();
for (Definition importDef : defs) {
File importWsdlFile = new File(outputdir, importWSDLMap.get(importDef.getTargetNamespace()));
OutputStream wsdlOs = new BufferedOutputStream(Files.newOutputStream(importWsdlFile.toPath()));
bout = new LoadingByteArrayOutputStream();
wsdlWriter.writeWSDL(importDef, bout);
Element importEle = StaxUtils.read(bout.createInputStream()).getDocumentElement();
xsdElements = DOMUtils.findAllElementsByTagNameNS(importEle, WSDLConstants.NS_SCHEMA_XSD, "schema");
for (Element xsdEle : xsdElements) {
updateImports(xsdEle, sourceMap);
}
updateWSDLImports(importEle, importWSDLMap);
StaxUtils.writeTo(importEle, wsdlOs);
wsdlOs.close();
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, "FAILED_TO_GEN_LOCAL_WSDL", ex);
Message msg = new Message("FAILED_TO_GEN_LOCAL_WSDL", LOG);
throw new ToolException(msg, ex);
}
}
Aggregations