use of org.apache.ws.commons.schema.XmlSchemaComplexType 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 + "'] = " + nameManager.getJavascriptName(name) + "_serialize;");
utils.appendLine("this.globalElementDeserializers['" + name + "'] = " + 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 + "'] = " + nameManager.getJavascriptName(name) + "_serialize;");
utils.appendLine("this.globalElementDeserializers['" + name + "'] = " + nameManager.getJavascriptName(name) + "_deserialize;");
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType 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 ").append(currentOperation.getName()).append('\n');
if (!isWrapped) {
code.append("// - bare operation. Parameters:\n");
for (ParticleInfo ei : unwrappedElementsAndNames) {
code.append("// - ").append(getElementObjectName(ei)).append('\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 ").append(inputParameterNames.get(i)).append('\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 ").append(nameManager.getJavascriptName(baseName)).append('\n');
} else if (type != null) {
code.append("// - simple type ").append(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).append(".prototype.").append(opFunctionPropertyName).append(" = ").append(opFunctionGlobalName).append(";\n\n");
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.
the class JavascriptUtils method generateCodeToSerializeElement.
/**
* Given an element, generate the serialization code.
*
* @param elementInfo description of the element we are serializing
* @param referencePrefix prefix to the Javascript variable. Nothing for
* args, this._ for members.
* @param schemaCollection caller's schema collection.
*/
public void generateCodeToSerializeElement(ParticleInfo elementInfo, String referencePrefix, SchemaCollection schemaCollection) {
if (elementInfo.isGroup()) {
for (ParticleInfo childElement : elementInfo.getChildren()) {
generateCodeToSerializeElement(childElement, referencePrefix, schemaCollection);
}
return;
}
XmlSchemaType type = elementInfo.getType();
boolean nillable = elementInfo.isNillable();
boolean optional = elementInfo.isOptional();
boolean array = elementInfo.isArray();
boolean mtom = treatAsMtom(elementInfo.getParticle());
String jsVar = referencePrefix + elementInfo.getJavascriptName();
appendLine("// block for local variables");
// allow local variables.
startBlock();
// first question: optional?
if (optional) {
startIf(jsVar + " != null");
}
// and nillable in the array case applies to the elements.
if (nillable && !array) {
startIf(jsVar + " == null");
appendString("<" + elementInfo.getXmlName() + " " + XmlSchemaUtils.XSI_NIL + "/>");
appendElse();
}
if (array) {
// protected against null in arrays.
startIf(jsVar + " != null");
startFor("var ax = 0", "ax < " + jsVar + ".length", "ax ++");
jsVar = jsVar + "[ax]";
// we need an extra level of 'nil' testing here. Or do we, depending
// on the type structure?
// Recode and fiddle appropriately.
startIf(jsVar + " == null");
if (nillable) {
appendString("<" + elementInfo.getXmlName() + " " + XmlSchemaUtils.XSI_NIL + "/>");
} else {
appendString("<" + elementInfo.getXmlName() + "/>");
}
appendElse();
}
if (elementInfo.isAnyType()) {
serializeAnyTypeElement(elementInfo, jsVar);
// mtom can be turned on for the special complex type that is really a basic type with
// a content-type attribute.
} else if (!mtom && type instanceof XmlSchemaComplexType) {
// it has a value
// pass the extra null in the slot for the 'extra namespaces' needed
// by 'any'.
appendExpression(jsVar + ".serialize(cxfjsutils, '" + elementInfo.getXmlName() + "', null)");
} else {
// simple type
appendString("<" + elementInfo.getXmlName() + ">");
if (mtom) {
appendExpression("cxfjsutils.packageMtom(" + jsVar + ")");
} else {
appendExpression("cxfjsutils.escapeXmlEntities(" + jsVar + ")");
}
appendString("</" + elementInfo.getXmlName() + ">");
}
if (array) {
// for the extra level of nil checking, which might be
endBlock();
// wrong.
// for the for loop.
endBlock();
// the null protection.
endBlock();
}
if (nillable && !array) {
endBlock();
}
if (optional) {
endBlock();
}
// local variables
endBlock();
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.
the class CorbaHandlerUtils method getXmlSchemaSequenceElement.
public static XmlSchemaElement getXmlSchemaSequenceElement(XmlSchemaObject schemaType, ServiceInfo serviceInfo) {
XmlSchemaObject stype = schemaType;
final XmlSchemaElement el;
if (schemaType instanceof XmlSchemaElement) {
stype = ((XmlSchemaElement) schemaType).getSchemaType();
if (stype == null) {
stype = CorbaUtils.getXmlSchemaType(serviceInfo, ((XmlSchemaElement) schemaType).getRef().getTargetQName());
}
}
if (stype instanceof XmlSchemaComplexType) {
// only one element inside the XmlSchemaComplexType
XmlSchemaComplexType ctype = (XmlSchemaComplexType) stype;
XmlSchemaParticle group = ctype.getParticle();
/* This code seems to think that we're guaranteed a sequence here */
XmlSchemaSequence seq = (XmlSchemaSequence) group;
/* and an element in it, too */
el = (XmlSchemaElement) seq.getItems().get(0);
} else {
el = (XmlSchemaElement) schemaType;
}
return el;
}
use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.
the class BeanTest method testCharMappings.
@Test
public void testCharMappings() throws Exception {
defaultContext();
BeanType type = (BeanType) mapping.getTypeCreator().createType(SimpleBean.class);
type.setTypeClass(SimpleBean.class);
type.setTypeMapping(mapping);
XmlSchema schema = newXmlSchema("urn:Bean");
type.writeSchema(schema);
XmlSchemaComplexType btype = (XmlSchemaComplexType) schema.getTypeByName("SimpleBean");
XmlSchemaSequence seq = (XmlSchemaSequence) btype.getParticle();
boolean charok = false;
for (int x = 0; x < seq.getItems().size(); x++) {
XmlSchemaSequenceMember o = seq.getItems().get(x);
if (o instanceof XmlSchemaElement) {
XmlSchemaElement oe = (XmlSchemaElement) o;
if ("character".equals(oe.getName())) {
charok = true;
assertNotNull(oe.getSchemaTypeName());
assertTrue(oe.isNillable());
assertEquals(CharacterAsStringType.CHARACTER_AS_STRING_TYPE_QNAME, oe.getSchemaTypeName());
}
}
}
assertTrue(charok);
}
Aggregations