use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class WSDLToCorbaBinding method addCorbaElements.
private void addCorbaElements(XmlSchema xmlSchemaTypes) throws Exception {
Map<QName, XmlSchemaElement> elements = xmlSchemaTypes.getElements();
for (XmlSchemaElement el : elements.values()) {
QName elName = el.getQName();
XmlSchemaType schemaType = el.getSchemaType();
if (elName == null) {
elName = el.getRef().getTargetQName();
schemaType = helper.getSchemaType(elName);
}
boolean anonymous;
if (schemaType == null) {
anonymous = true;
} else {
anonymous = WSDLTypes.isAnonymous(schemaType.getName());
}
if (schemaType != null) {
XmlSchemaAnnotation annotation = null;
if (el.getAnnotation() != null) {
annotation = el.getAnnotation();
}
// this situation won't be handled. REVISIT.
if (annotation != null) {
XmlSchemaAppInfo appInfo = null;
for (XmlSchemaAnnotationItem ann : annotation.getItems()) {
if (ann instanceof XmlSchemaAppInfo) {
appInfo = (XmlSchemaAppInfo) ann;
break;
}
}
if (appInfo != null) {
NodeList nlist = appInfo.getMarkup();
Node node = nlist.item(0);
String info = node.getNodeValue();
info = info.trim();
String annotationBindingName = "";
if ("corba:binding=".equals(info.substring(0, 14))) {
annotationBindingName = info.substring(14);
}
if (bindingName.equals(annotationBindingName)) {
annotation = null;
}
}
}
CorbaType corbaTypeImpl = helper.convertSchemaToCorbaType(schemaType, elName, schemaType, annotation, anonymous);
if (el.isNillable()) {
QName uname = helper.createQNameCorbaNamespace(corbaTypeImpl.getQName().getLocalPart() + "_nil");
boolean isQualified = corbaTypeImpl.isSetQualified() && corbaTypeImpl.isQualified();
corbaTypeImpl = helper.createNillableUnion(uname, helper.checkPrefix(elName), helper.checkPrefix(corbaTypeImpl.getQName()), isQualified);
}
if (corbaTypeImpl != null && !helper.isDuplicate(corbaTypeImpl)) {
typeMappingType.getStructOrExceptionOrUnion().add(corbaTypeImpl);
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class SchemaJavascriptBuilder method deserializeElement.
private void deserializeElement(XmlSchemaComplexType type, ParticleInfo itemInfo) {
if (itemInfo.isGroup()) {
for (ParticleInfo childElement : itemInfo.getChildren()) {
deserializeElement(type, childElement);
}
return;
}
XmlSchemaType itemType = itemInfo.getType();
boolean simple = itemType instanceof XmlSchemaSimpleType || JavascriptUtils.notVeryComplexType(itemType);
boolean mtomCandidate = JavascriptUtils.mtomCandidateType(itemType);
String accessorName = "set" + StringUtils.capitalize(itemInfo.getJavascriptName());
utils.appendLine("cxfjsutils.trace('processing " + itemInfo.getJavascriptName() + "');");
XmlSchemaElement element = (XmlSchemaElement) itemInfo.getParticle();
QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, xmlSchema);
String elementNamespaceURI = elementQName.getNamespaceURI();
boolean elementNoNamespace = "".equals(elementNamespaceURI);
XmlSchema elementSchema = null;
if (!elementNoNamespace) {
elementSchema = xmlSchemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
}
boolean qualified = !elementNoNamespace && XmlSchemaUtils.isElementQualified(element, itemInfo.isGlobal(), xmlSchema, elementSchema);
if (!qualified) {
elementNamespaceURI = "";
}
String localName = elementQName.getLocalPart();
String valueTarget = "item";
if (itemInfo.isOptional() || itemInfo.isArray()) {
utils.startIf("curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" + elementNamespaceURI + "', '" + localName + "')");
if (itemInfo.isArray()) {
utils.appendLine("item = [];");
utils.startDo();
valueTarget = "arrayItem";
utils.appendLine("var arrayItem = null;");
}
}
utils.appendLine("var value = null;");
utils.startIf("!cxfjsutils.isElementNil(curElement)");
if (itemInfo.isAnyType()) {
// use our utility
utils.appendLine(valueTarget + " = org_apache_cxf_deserialize_anyType(cxfjsutils, curElement);");
} else if (simple) {
if (mtomCandidate) {
utils.appendLine(valueTarget + " = cxfjsutils.deserializeBase64orMom(curElement);");
} else {
utils.appendLine("value = cxfjsutils.getNodeText(curElement);");
utils.appendLine(valueTarget + " = " + utils.javascriptParseExpression(itemType, "value") + ";");
}
} else {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) itemType;
QName baseQName = complexType.getQName();
if (baseQName == null) {
baseQName = element.getQName();
}
String elTypeJsName = nameManager.getJavascriptName(baseQName);
utils.appendLine(valueTarget + " = " + elTypeJsName + "_deserialize(cxfjsutils, curElement);");
}
// the if for the nil.
utils.endBlock();
if (itemInfo.isArray()) {
utils.appendLine("item.push(arrayItem);");
utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
utils.endBlock();
utils.appendLine(" while(curElement != null && cxfjsutils.isNodeNamedNS(curElement, '" + elementNamespaceURI + "', '" + localName + "'));");
}
utils.appendLine("newobject." + accessorName + "(item);");
utils.appendLine("var item = null;");
if (!itemInfo.isArray()) {
utils.startIf("curElement != null");
utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
utils.endBlock();
}
if (itemInfo.isOptional() || itemInfo.isArray()) {
utils.endBlock();
}
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class SchemaJavascriptBuilder method generateCodeForSchema.
public String generateCodeForSchema(XmlSchema schema) {
xmlSchema = schema;
code = new StringBuilder();
code.append("//\n");
code.append("// Definitions for schema: ").append(schema.getTargetNamespace());
if (schema.getSourceURI() != null) {
code.append("\n// ").append(schema.getSourceURI());
}
code.append("\n//\n");
Map<QName, XmlSchemaType> schemaTypes = schema.getSchemaTypes();
for (Map.Entry<QName, XmlSchemaType> e : schemaTypes.entrySet()) {
XmlSchemaType type = e.getValue();
if (type instanceof XmlSchemaComplexType) {
try {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() != null) {
complexTypeConstructorAndAccessors(complexType.getQName(), complexType);
complexTypeSerializerFunction(complexType.getQName(), complexType);
domDeserializerFunction(complexType.getQName(), complexType);
}
} catch (UnsupportedConstruct usc) {
LOG.warning(usc.toString());
// it could be empty, but the style checker
continue;
// would complain.
}
} else if (type instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
if (XmlSchemaUtils.isEumeration(simpleType)) {
List<String> values = XmlSchemaUtils.enumeratorValues(simpleType);
code.append("//\n");
code.append("// Simple type (enumeration) ").append(simpleType.getQName()).append('\n');
code.append("//\n");
for (String value : values) {
code.append("// - ").append(value).append('\n');
}
}
}
}
for (Map.Entry<QName, XmlSchemaElement> e : schema.getElements().entrySet()) {
XmlSchemaElement element = e.getValue();
try {
if (element.getSchemaTypeName() == null && element.getSchemaType() == null) {
Message message = new Message("ELEMENT_MISSING_TYPE", LOG, element.getQName(), element.getSchemaTypeName(), schema.getTargetNamespace());
LOG.warning(message.toString());
continue;
}
XmlSchemaType type;
if (element.getSchemaType() != null) {
type = element.getSchemaType();
} else {
type = schema.getTypeByName(element.getSchemaTypeName());
}
if (!(type instanceof XmlSchemaComplexType)) {
// we never make classes for simple type.
continue;
}
XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
// element.
if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() == null) {
complexTypeConstructorAndAccessors(element.getQName(), complexType);
complexTypeSerializerFunction(element.getQName(), complexType);
domDeserializerFunction(element.getQName(), complexType);
}
} catch (UnsupportedConstruct usc) {
LOG.warning(usc.getMessage());
// it could be empty, but the style checker
continue;
// would complain.
}
}
String returnValue = code.toString();
LOG.finer(returnValue);
return returnValue;
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class WSDLASTVisitor method setSequenceOctetType.
public void setSequenceOctetType(String type) throws Exception {
final XmlSchemaType stype;
if (type.equals(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE_BASE64BINARY)) {
stype = schemas.getTypeByQName(Constants.XSD_BASE64);
} else if (type.equals(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE_HEXBINARY)) {
stype = schemas.getTypeByQName(Constants.XSD_HEXBIN);
} else {
throw new ToolException("WSDLASTVisitor: Invalid XmlSchemaType specified " + "for idl:sequence<octet> mapping.");
}
sequenceOctetType = stype;
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class WSDLParameter method processInputParams.
private void processInputParams(WSDLToCorbaBinding wsdlToCorbaBinding, Operation operation, SchemaCollection xmlSchemaList, List<ParamType> inputs) throws Exception {
Input input = operation.getInput();
if (input != null) {
Message msg = input.getMessage();
List<Part> parts = CastUtils.cast(msg.getOrderedParts(null));
for (Part part : parts) {
XmlSchemaType schemaType = null;
boolean isObjectRef = isObjectReference(xmlSchemaList, part.getElementName());
if (part.getElementName() != null && !isObjectRef) {
XmlSchemaElement el = getElement(part, xmlSchemaList);
if (el != null) {
if (el.getSchemaType() != null) {
schemaType = el.getSchemaType();
}
QName typeName = el.getSchemaTypeName();
if (typeName == null) {
typeName = el.getQName();
}
QName idltype = getIdlType(wsdlToCorbaBinding, schemaType, typeName, el.isNillable());
ParamType paramtype = createParam(wsdlToCorbaBinding, "in", part.getName(), idltype);
if (paramtype != null) {
inputs.add(paramtype);
}
}
} else if (part.getTypeName() != null) {
schemaType = getType(part, xmlSchemaList);
QName typeName = part.getTypeName();
if (isObjectRef) {
typeName = part.getElementName();
}
QName idltype = getIdlType(wsdlToCorbaBinding, schemaType, typeName, false);
ParamType paramtype = createParam(wsdlToCorbaBinding, "in", part.getName(), idltype);
if (paramtype != null) {
inputs.add(paramtype);
}
}
}
}
}
Aggregations