use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class ImportRepairTest method newSchema.
private XmlSchema newSchema(String uri) {
XmlSchema schema = collection.newXmlSchemaInCollection(uri);
NamespaceMap map = new NamespaceMap();
map.add("", XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema.setNamespaceContext(map);
return schema;
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class AttributeInfo method factoryCommon.
private static void factoryCommon(XmlSchemaAnnotated annotated, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, AttributeInfo attributeInfo) {
if (annotated instanceof XmlSchemaAttribute) {
XmlSchemaAttribute attribute = (XmlSchemaAttribute) annotated;
String attributeNamespaceURI = attribute.getQName().getNamespaceURI();
boolean attributeNoNamespace = "".equals(attributeNamespaceURI);
XmlSchema attributeSchema = null;
if (!attributeNoNamespace) {
attributeSchema = schemaCollection.getSchemaByTargetNamespace(attributeNamespaceURI);
if (attributeSchema == null) {
throw new RuntimeException("Missing schema " + attributeNamespaceURI);
}
}
boolean qualified = !attributeNoNamespace && XmlSchemaUtils.isAttributeQualified(attribute, true, currentSchema, attributeSchema);
attributeInfo.xmlName = prefixAccumulator.xmlAttributeString(attribute, qualified);
// we are assuming here that we are not dealing, in close proximity,
// with elements with identical local names and different
// namespaces.
attributeInfo.javascriptName = attribute.getQName().getLocalPart();
attributeInfo.defaultValue = attribute.getDefaultValue();
attributeInfo.fixedValue = attribute.getFixedValue();
attributeInfo.use = attribute.getUse();
factorySetupType(attribute, schemaCollection, attributeInfo);
} else {
// any
attributeInfo.any = true;
// unknown until runtime.
attributeInfo.xmlName = null;
attributeInfo.javascriptName = "any";
// runtime for any.
attributeInfo.type = null;
attributeInfo.use = XmlSchemaUse.OPTIONAL;
}
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class ServiceJavascriptBuilder method generateGlobalElementDictionary.
private void generateGlobalElementDictionary() {
// to handle 'any', we need a dictionary of all the global elements of all the schemas.
utils.appendLine("this.globalElementSerializers = [];");
utils.appendLine("this.globalElementDeserializers = [];");
for (XmlSchema schemaInfo : xmlSchemaCollection.getXmlSchemas()) {
for (Map.Entry<QName, XmlSchemaElement> e : schemaInfo.getElements().entrySet()) {
QName name = e.getKey();
XmlSchemaElement element = e.getValue();
// That comes later to improve deserialization.
if (JavascriptUtils.notVeryComplexType(element.getSchemaType())) {
continue;
}
// If the element uses a named type, we use the functions for the type.
XmlSchemaComplexType elementType = (XmlSchemaComplexType) element.getSchemaType();
if (elementType != null && elementType.getQName() != null) {
name = elementType.getQName();
}
utils.appendLine("this.globalElementSerializers['" + name.toString() + "'] = " + nameManager.getJavascriptName(name) + "_serialize;");
utils.appendLine("this.globalElementDeserializers['" + name.toString() + "'] = " + nameManager.getJavascriptName(name) + "_deserialize;");
}
for (Map.Entry<QName, XmlSchemaType> e : schemaInfo.getSchemaTypes().entrySet()) {
QName name = e.getKey();
XmlSchemaType type = e.getValue();
// For now, at least, don't handle simple types.
if (JavascriptUtils.notVeryComplexType(type)) {
continue;
}
// the names are misleading, but that's OK.
utils.appendLine("this.globalElementSerializers['" + name.toString() + "'] = " + nameManager.getJavascriptName(name) + "_serialize;");
utils.appendLine("this.globalElementDeserializers['" + name.toString() + "'] = " + nameManager.getJavascriptName(name) + "_deserialize;");
}
}
}
use of org.apache.ws.commons.schema.XmlSchema in project cxf by apache.
the class ServiceJavascriptBuilder method buildOperationFunction.
private void buildOperationFunction(StringBuilder parameterList) {
String responseCallbackParams = "";
if (!currentOperation.isOneWay()) {
responseCallbackParams = "successCallback, errorCallback";
}
MessageInfo inputMessage = currentOperation.getInput();
code.append("//\n");
code.append("// Operation " + currentOperation.getName() + "\n");
if (!isWrapped) {
code.append("// - bare operation. Parameters:\n");
for (ParticleInfo ei : unwrappedElementsAndNames) {
code.append("// - " + getElementObjectName(ei) + "\n");
}
} else {
code.append("// Wrapped operation.\n");
QName contextQName = inputWrapperComplexType.getQName();
if (contextQName == null) {
contextQName = inputWrapperElement.getQName();
}
XmlSchemaSequence sequence = JavascriptUtils.getSequence(inputWrapperComplexType);
XmlSchema wrapperSchema = xmlSchemaCollection.getSchemaByTargetNamespace(contextQName.getNamespaceURI());
for (int i = 0; i < sequence.getItems().size(); i++) {
code.append("// parameter " + inputParameterNames.get(i) + "\n");
XmlSchemaSequenceMember sequenceItem = sequence.getItems().get(i);
ParticleInfo itemInfo = ParticleInfo.forLocalItem((XmlSchemaObject) sequenceItem, wrapperSchema, xmlSchemaCollection, prefixAccumulator, contextQName);
if (itemInfo.isArray()) {
code.append("// - array\n");
}
// null for an any.
XmlSchemaType type = itemInfo.getType();
if (type instanceof XmlSchemaComplexType) {
QName baseName;
if (type.getQName() != null) {
baseName = type.getQName();
} else {
baseName = ((XmlSchemaElement) sequenceItem).getQName();
}
code.append("// - Object constructor is " + nameManager.getJavascriptName(baseName) + "\n");
} else if (type != null) {
code.append("// - simple type " + type.getQName());
}
}
}
code.append("//\n");
code.append("function " + opFunctionGlobalName + "(" + responseCallbackParams + ((parameterList.length() > 0 && !currentOperation.isOneWay()) ? ", " : "") + parameterList + ") {\n");
utils.appendLine("this.client = new CxfApacheOrgClient(this.jsutils);");
utils.appendLine("var xml = null;");
if (inputMessage != null) {
utils.appendLine("var args = new Array(" + inputParameterNames.size() + ");");
int px = 0;
for (String param : inputParameterNames) {
utils.appendLine("args[" + px + "] = " + param + ";");
px++;
}
utils.appendLine("xml = this." + getFunctionPropertyName(inputMessagesWithNameConflicts, inputMessage, inputMessage.getName()) + "_serializeInput" + "(this.jsutils, args);");
}
// functions.
if (!currentOperation.isOneWay()) {
utils.appendLine("this.client.user_onsuccess = successCallback;");
utils.appendLine("this.client.user_onerror = errorCallback;");
utils.appendLine("var closureThis = this;");
// client will pass itself and the response XML.
utils.appendLine("this.client.onsuccess = function(client, responseXml) { closureThis." + opFunctionPropertyName + "_onsuccess(client, responseXml); };");
// client will pass itself.
utils.appendLine("this.client.onerror = function(client) { closureThis." + opFunctionPropertyName + "_onerror(client); };");
}
utils.appendLine("var requestHeaders = [];");
if (soapBindingInfo != null) {
String action = soapBindingInfo.getSoapAction(currentOperation);
utils.appendLine("requestHeaders['SOAPAction'] = '" + action + "';");
}
// default 'method' by passing null. Is there some place this lives in the
// service model?
String syncAsyncFlag;
if (currentOperation.isOneWay()) {
utils.appendLine("this.jsutils.trace('oneway operation');");
syncAsyncFlag = "false";
} else {
utils.appendLine("this.jsutils.trace('synchronous = ' + this.synchronous);");
syncAsyncFlag = "this.synchronous";
}
utils.appendLine("this.client.request(this.url, xml, null, " + syncAsyncFlag + ", requestHeaders);");
code.append("}\n\n");
code.append(currentInterfaceClassName + ".prototype." + opFunctionPropertyName + " = " + opFunctionGlobalName + ";\n\n");
}
use of org.apache.ws.commons.schema.XmlSchema 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