use of org.apache.openejb.jee.WsdlMessageMapping$JAXB.writeWsdlMessageMapping in project tomee by apache.
the class MethodParamPartsMapping$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final MethodParamPartsMapping methodParamPartsMapping, RuntimeContext context) throws Exception {
if (methodParamPartsMapping == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (MethodParamPartsMapping.class != methodParamPartsMapping.getClass()) {
context.unexpectedSubclass(writer, methodParamPartsMapping, MethodParamPartsMapping.class);
return;
}
context.beforeMarshal(methodParamPartsMapping, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = methodParamPartsMapping.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(methodParamPartsMapping, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ELEMENT: paramPosition
final BigInteger paramPosition = methodParamPartsMapping.paramPosition;
if (paramPosition != null) {
writer.writeStartElement(prefix, "param-position", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(paramPosition.toString());
writer.writeEndElement();
} else {
context.unexpectedNullValue(methodParamPartsMapping, "paramPosition");
}
// ELEMENT: paramType
final String paramTypeRaw = methodParamPartsMapping.paramType;
String paramType = null;
try {
paramType = Adapters.collapsedStringAdapterAdapter.marshal(paramTypeRaw);
} catch (final Exception e) {
context.xmlAdapterError(methodParamPartsMapping, "paramType", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (paramType != null) {
writer.writeStartElement(prefix, "param-type", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(paramType);
writer.writeEndElement();
} else {
context.unexpectedNullValue(methodParamPartsMapping, "paramType");
}
// ELEMENT: wsdlMessageMapping
final WsdlMessageMapping wsdlMessageMapping = methodParamPartsMapping.wsdlMessageMapping;
if (wsdlMessageMapping != null) {
writer.writeStartElement(prefix, "wsdl-message-mapping", "http://java.sun.com/xml/ns/javaee");
writeWsdlMessageMapping(writer, wsdlMessageMapping, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(methodParamPartsMapping, "wsdlMessageMapping");
}
context.afterMarshal(methodParamPartsMapping, LifecycleCallback.NONE);
}
use of org.apache.openejb.jee.WsdlMessageMapping$JAXB.writeWsdlMessageMapping in project tomee by apache.
the class MethodParamPartsMapping$JAXB method _read.
public static final MethodParamPartsMapping _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
// Check for xsi:nil
if (reader.isXsiNil()) {
return null;
}
if (context == null) {
context = new RuntimeContext();
}
final MethodParamPartsMapping methodParamPartsMapping = new MethodParamPartsMapping();
context.beforeUnmarshal(methodParamPartsMapping, LifecycleCallback.NONE);
// Check xsi:type
final QName xsiType = reader.getXsiType();
if (xsiType != null) {
if (("method-param-parts-mappingType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
return context.unexpectedXsiType(reader, MethodParamPartsMapping.class);
}
}
// Read attributes
for (final Attribute attribute : reader.getAttributes()) {
if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
// ATTRIBUTE: id
final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
context.addXmlId(reader, id, methodParamPartsMapping);
methodParamPartsMapping.id = id;
} else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
context.unexpectedAttribute(attribute, new QName("", "id"));
}
}
// Read elements
for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
if (("param-position" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: paramPosition
final BigInteger paramPosition = new BigInteger(elementReader.getElementAsString());
methodParamPartsMapping.paramPosition = paramPosition;
} else if (("param-type" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: paramType
final String paramTypeRaw = elementReader.getElementAsString();
final String paramType;
try {
paramType = Adapters.collapsedStringAdapterAdapter.unmarshal(paramTypeRaw);
} catch (final Exception e) {
context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
continue;
}
methodParamPartsMapping.paramType = paramType;
} else if (("wsdl-message-mapping" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: wsdlMessageMapping
final WsdlMessageMapping wsdlMessageMapping = readWsdlMessageMapping(elementReader, context);
methodParamPartsMapping.wsdlMessageMapping = wsdlMessageMapping;
} else {
context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "param-position"), new QName("http://java.sun.com/xml/ns/javaee", "param-type"), new QName("http://java.sun.com/xml/ns/javaee", "wsdl-message-mapping"));
}
}
context.afterUnmarshal(methodParamPartsMapping, LifecycleCallback.NONE);
return methodParamPartsMapping;
}
use of org.apache.openejb.jee.WsdlMessageMapping$JAXB.writeWsdlMessageMapping in project tomee by apache.
the class HeavyweightOperationInfoBuilder method mapParameter.
private JaxRpcParameterInfo mapParameter(MethodParamPartsMapping paramMapping) throws OpenEJBException {
WsdlMessageMapping wsdlMessageMappingType = paramMapping.getWsdlMessageMapping();
QName wsdlMessageQName = wsdlMessageMappingType.getWsdlMessage();
String wsdlMessagePartName = wsdlMessageMappingType.getWsdlMessagePartName();
Mode mode = Mode.valueOf(wsdlMessageMappingType.getParameterMode());
if ((mode == Mode.OUT || mode == Mode.INOUT) && outputMessage == null) {
throw new OpenEJBException("Mapping for output parameter " + wsdlMessagePartName + " found, but no output message for operation " + operationName);
}
//
// Determine the param qname and xml schema type
//
QName paramQName;
QName paramXmlType;
if (mode == Mode.IN || mode == Mode.INOUT) {
//
if (!wsdlMessageQName.equals(inputMessage.getQName())) {
throw new OpenEJBException("QName of input message: " + inputMessage.getQName() + " does not match mapping message QName: " + wsdlMessageQName + " for operation " + operationName);
}
Part part = null;
XmlElementInfo inParameter = null;
if (bindingStyle.isWrapped()) {
Part inPart = getWrappedPart(inputMessage);
// operation name == wraper element name
QName name = inPart.getElementName();
if (!name.getLocalPart().equals(operationName)) {
throw new OpenEJBException("message " + inputMessage.getQName() + " refers to a global element named " + name.getLocalPart() + ", which is not equal to the operation name " + operationName);
}
inParameter = getWrapperChild(inPart, wsdlMessagePartName);
paramQName = new QName("", inParameter.qname.getLocalPart());
paramXmlType = inParameter.xmlType;
} else if (bindingStyle.isRpc()) {
part = inputMessage.getPart(wsdlMessagePartName);
if (part == null) {
throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in input message for operation " + operationName);
}
paramQName = new QName("", part.getName());
// RPC can only use type
paramXmlType = part.getTypeName();
} else {
part = inputMessage.getPart(wsdlMessagePartName);
if (part == null) {
throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in input message for operation " + operationName);
}
// Document should use element, but type is allowed
paramQName = getPartName(part);
paramXmlType = paramQName;
}
inParamNames.add(wsdlMessagePartName);
//
if (mode == Mode.INOUT) {
if (bindingStyle.isWrapped()) {
// Verify output message supports this inout parameter
Part outPart = getWrappedPart(outputMessage);
XmlElementInfo outParameter = getWrapperChild(outPart, wsdlMessagePartName);
if (inParameter.xmlType != outParameter.xmlType) {
throw new OpenEJBException("The wrapper children " + wsdlMessagePartName + " do not have the same type for operation " + operationName);
}
} else if (bindingStyle.isRpc()) {
// Verify output message supports this inout parameter
Part outPart = outputMessage.getPart(wsdlMessagePartName);
if (outPart == null) {
throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in output message for INOUT parameter of operation " + operationName);
}
// TODO this cannot happen.
if (!part.getName().equals(outPart.getName())) {
throw new OpenEJBException("Mismatched input part name: " + part.getName() + " and output part name: " + outPart.getName() + " for INOUT parameter for wsdlMessagePartName " + wsdlMessagePartName + " for operation " + operationName);
}
if (!(part.getElementName() == null ? outPart.getElementName() == null : part.getElementName().equals(outPart.getElementName()))) {
throw new OpenEJBException("Mismatched input part element name: " + part.getElementName() + " and output part element name: " + outPart.getElementName() + " for INOUT parameter for wsdlMessagePartName " + wsdlMessagePartName + " for operation " + operationName);
}
if (!(part.getTypeName() == null ? outPart.getTypeName() == null : part.getTypeName().equals(outPart.getTypeName()))) {
throw new OpenEJBException("Mismatched input part type name: " + part.getTypeName() + " and output part type name: " + outPart.getTypeName() + " for INOUT parameter for wsdlMessagePartName " + wsdlMessagePartName + " for operation " + operationName);
}
} else {
part = outputMessage.getPart(wsdlMessagePartName);
if (part == null) {
throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in output message for operation " + operationName);
}
// todo this seem strange... shouldn't the name and type be the same as the in binding above
paramQName = getPartName(part);
paramXmlType = paramQName;
}
outParamNames.add(wsdlMessagePartName);
}
} else {
//
if (!wsdlMessageQName.equals(outputMessage.getQName())) {
throw new OpenEJBException("QName of output message: " + outputMessage.getQName() + " does not match mapping message QName: " + wsdlMessageQName + " for operation " + operationName);
}
if (bindingStyle.isWrapped()) {
Part outPart = getWrappedPart(outputMessage);
XmlElementInfo outParameter = getWrapperChild(outPart, wsdlMessagePartName);
paramQName = new QName("", outParameter.qname.getLocalPart());
paramXmlType = outParameter.xmlType;
} else if (bindingStyle.isRpc()) {
Part part = outputMessage.getPart(wsdlMessagePartName);
if (part == null) {
throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in output message for operation " + operationName);
}
paramQName = new QName("", part.getName());
// RPC can only use type
paramXmlType = part.getTypeName();
} else {
Part part = outputMessage.getPart(wsdlMessagePartName);
if (part == null) {
throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in output message for operation " + operationName);
}
paramQName = getPartName(part);
paramXmlType = paramQName;
}
outParamNames.add(wsdlMessagePartName);
}
//
// Determine the param java type
//
String paramJavaType;
if (mode == Mode.IN) {
// IN only prarmeters don't have holders
paramJavaType = paramMapping.getParamType();
} else if (rpcHolderClasses.containsKey(paramMapping.getParamType())) {
// This is a standard type with a built in holder class
paramJavaType = rpcHolderClasses.get(paramMapping.getParamType());
} else {
// holderClass == ${packageName}.holders.${typeName}Holder
String packageName;
String typeName;
PackageMapping packageMapping = mapping.getPackageMappingMap().get(paramXmlType.getNamespaceURI());
if (packageMapping != null) {
packageName = packageMapping.getPackageType();
// Type name is typeQName local part, but make sure it is capitalized correctly
typeName = paramXmlType.getLocalPart();
typeName = Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1);
} else {
// a.b.foo.Bar >>> a.b.foo.holders.BarHolder
String paramJavaTypeName = paramMapping.getParamType();
int lastDot = paramJavaTypeName.lastIndexOf(".");
packageName = paramJavaTypeName.substring(0, lastDot);
typeName = paramJavaTypeName.substring(lastDot + 1);
}
paramJavaType = packageName + ".holders." + typeName + "Holder";
}
//
// Build JaxRpcParameterInfo
//
JaxRpcParameterInfo parameterInfo = new JaxRpcParameterInfo();
parameterInfo.qname = paramQName;
parameterInfo.xmlType = paramXmlType;
parameterInfo.javaType = paramJavaType;
parameterInfo.mode = Mode.valueOf(wsdlMessageMappingType.getParameterMode());
parameterInfo.soapHeader = wsdlMessageMappingType.getSoapHeader() != null;
return parameterInfo;
}
Aggregations