use of org.apache.openejb.jee.PackageMapping$JAXB.readPackageMapping in project tomee by apache.
the class JavaWsdlMapping$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final JavaWsdlMapping javaWsdlMapping, RuntimeContext context) throws Exception {
if (javaWsdlMapping == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (JavaWsdlMapping.class != javaWsdlMapping.getClass()) {
context.unexpectedSubclass(writer, javaWsdlMapping, JavaWsdlMapping.class);
return;
}
context.beforeMarshal(javaWsdlMapping, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = javaWsdlMapping.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(javaWsdlMapping, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ATTRIBUTE: version
final String versionRaw = javaWsdlMapping.version;
if (versionRaw != null) {
String version = null;
try {
version = Adapters.collapsedStringAdapterAdapter.marshal(versionRaw);
} catch (final Exception e) {
context.xmlAdapterError(javaWsdlMapping, "version", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "version", version);
}
// ELEMENT: packageMapping
final KeyedCollection<String, PackageMapping> packageMapping = javaWsdlMapping.packageMapping;
if (packageMapping != null) {
for (final PackageMapping packageMappingItem : packageMapping) {
if (packageMappingItem != null) {
writer.writeStartElement(prefix, "package-mapping", "http://java.sun.com/xml/ns/javaee");
writePackageMapping(writer, packageMappingItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(javaWsdlMapping, "packageMapping");
}
}
}
// ELEMENT: javaXmlTypeMapping
final List<JavaXmlTypeMapping> javaXmlTypeMapping = javaWsdlMapping.javaXmlTypeMapping;
if (javaXmlTypeMapping != null) {
for (final JavaXmlTypeMapping javaXmlTypeMappingItem : javaXmlTypeMapping) {
if (javaXmlTypeMappingItem != null) {
writer.writeStartElement(prefix, "java-xml-type-mapping", "http://java.sun.com/xml/ns/javaee");
writeJavaXmlTypeMapping(writer, javaXmlTypeMappingItem, context);
writer.writeEndElement();
}
}
}
// ELEMENT: exceptionMapping
final KeyedCollection<QName, ExceptionMapping> exceptionMapping = javaWsdlMapping.exceptionMapping;
if (exceptionMapping != null) {
for (final ExceptionMapping exceptionMappingItem : exceptionMapping) {
if (exceptionMappingItem != null) {
writer.writeStartElement(prefix, "exception-mapping", "http://java.sun.com/xml/ns/javaee");
writeExceptionMapping(writer, exceptionMappingItem, context);
writer.writeEndElement();
}
}
}
// ELEMENT: serviceInterfaceMapping
final List<ServiceInterfaceMapping> serviceInterfaceMapping = javaWsdlMapping.serviceInterfaceMapping;
if (serviceInterfaceMapping != null) {
for (final ServiceInterfaceMapping serviceInterfaceMappingItem : serviceInterfaceMapping) {
if (serviceInterfaceMappingItem != null) {
writer.writeStartElement(prefix, "service-interface-mapping", "http://java.sun.com/xml/ns/javaee");
writeServiceInterfaceMapping(writer, serviceInterfaceMappingItem, context);
writer.writeEndElement();
}
}
}
// ELEMENT: serviceEndpointInterfaceMapping
final KeyedCollection<String, ServiceEndpointInterfaceMapping> serviceEndpointInterfaceMapping = javaWsdlMapping.serviceEndpointInterfaceMapping;
if (serviceEndpointInterfaceMapping != null) {
for (final ServiceEndpointInterfaceMapping serviceEndpointInterfaceMappingItem : serviceEndpointInterfaceMapping) {
if (serviceEndpointInterfaceMappingItem != null) {
writer.writeStartElement(prefix, "service-endpoint-interface-mapping", "http://java.sun.com/xml/ns/javaee");
writeServiceEndpointInterfaceMapping(writer, serviceEndpointInterfaceMappingItem, context);
writer.writeEndElement();
}
}
}
context.afterMarshal(javaWsdlMapping, LifecycleCallback.NONE);
}
use of org.apache.openejb.jee.PackageMapping$JAXB.readPackageMapping in project tomee by apache.
the class JavaWsdlMapping$JAXB method _read.
public static final JavaWsdlMapping _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
// Check for xsi:nil
if (reader.isXsiNil()) {
return null;
}
if (context == null) {
context = new RuntimeContext();
}
final JavaWsdlMapping javaWsdlMapping = new JavaWsdlMapping();
context.beforeUnmarshal(javaWsdlMapping, LifecycleCallback.NONE);
KeyedCollection<String, PackageMapping> packageMapping = null;
List<JavaXmlTypeMapping> javaXmlTypeMapping = null;
KeyedCollection<QName, ExceptionMapping> exceptionMapping = null;
List<ServiceInterfaceMapping> serviceInterfaceMapping = null;
KeyedCollection<String, ServiceEndpointInterfaceMapping> serviceEndpointInterfaceMapping = null;
// Check xsi:type
final QName xsiType = reader.getXsiType();
if (xsiType != null) {
if (("java-wsdl-mappingType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
return context.unexpectedXsiType(reader, JavaWsdlMapping.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, javaWsdlMapping);
javaWsdlMapping.id = id;
} else if (("version" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
// ATTRIBUTE: version
javaWsdlMapping.version = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
} else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
context.unexpectedAttribute(attribute, new QName("", "id"), new QName("", "version"));
}
}
// Read elements
for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
if (("package-mapping" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: packageMapping
final PackageMapping packageMappingItem = readPackageMapping(elementReader, context);
if (packageMapping == null) {
packageMapping = javaWsdlMapping.packageMapping;
if (packageMapping != null) {
packageMapping.clear();
} else {
packageMapping = new KeyedCollection<String, PackageMapping>();
}
}
packageMapping.add(packageMappingItem);
} else if (("java-xml-type-mapping" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: javaXmlTypeMapping
final JavaXmlTypeMapping javaXmlTypeMappingItem = readJavaXmlTypeMapping(elementReader, context);
if (javaXmlTypeMapping == null) {
javaXmlTypeMapping = javaWsdlMapping.javaXmlTypeMapping;
if (javaXmlTypeMapping != null) {
javaXmlTypeMapping.clear();
} else {
javaXmlTypeMapping = new ArrayList<JavaXmlTypeMapping>();
}
}
javaXmlTypeMapping.add(javaXmlTypeMappingItem);
} else if (("exception-mapping" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: exceptionMapping
final ExceptionMapping exceptionMappingItem = readExceptionMapping(elementReader, context);
if (exceptionMapping == null) {
exceptionMapping = javaWsdlMapping.exceptionMapping;
if (exceptionMapping != null) {
exceptionMapping.clear();
} else {
exceptionMapping = new KeyedCollection<QName, ExceptionMapping>();
}
}
exceptionMapping.add(exceptionMappingItem);
} else if (("service-interface-mapping" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: serviceInterfaceMapping
final ServiceInterfaceMapping serviceInterfaceMappingItem = readServiceInterfaceMapping(elementReader, context);
if (serviceInterfaceMapping == null) {
serviceInterfaceMapping = javaWsdlMapping.serviceInterfaceMapping;
if (serviceInterfaceMapping != null) {
serviceInterfaceMapping.clear();
} else {
serviceInterfaceMapping = new ArrayList<ServiceInterfaceMapping>();
}
}
serviceInterfaceMapping.add(serviceInterfaceMappingItem);
} else if (("service-endpoint-interface-mapping" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: serviceEndpointInterfaceMapping
final ServiceEndpointInterfaceMapping serviceEndpointInterfaceMappingItem = readServiceEndpointInterfaceMapping(elementReader, context);
if (serviceEndpointInterfaceMapping == null) {
serviceEndpointInterfaceMapping = javaWsdlMapping.serviceEndpointInterfaceMapping;
if (serviceEndpointInterfaceMapping != null) {
serviceEndpointInterfaceMapping.clear();
} else {
serviceEndpointInterfaceMapping = new KeyedCollection<String, ServiceEndpointInterfaceMapping>();
}
}
serviceEndpointInterfaceMapping.add(serviceEndpointInterfaceMappingItem);
} else {
context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "package-mapping"), new QName("http://java.sun.com/xml/ns/javaee", "java-xml-type-mapping"), new QName("http://java.sun.com/xml/ns/javaee", "exception-mapping"), new QName("http://java.sun.com/xml/ns/javaee", "service-interface-mapping"), new QName("http://java.sun.com/xml/ns/javaee", "service-endpoint-interface-mapping"));
}
}
if (packageMapping != null) {
javaWsdlMapping.packageMapping = packageMapping;
}
if (javaXmlTypeMapping != null) {
javaWsdlMapping.javaXmlTypeMapping = javaXmlTypeMapping;
}
if (exceptionMapping != null) {
javaWsdlMapping.exceptionMapping = exceptionMapping;
}
if (serviceInterfaceMapping != null) {
javaWsdlMapping.serviceInterfaceMapping = serviceInterfaceMapping;
}
if (serviceEndpointInterfaceMapping != null) {
javaWsdlMapping.serviceEndpointInterfaceMapping = serviceEndpointInterfaceMapping;
}
context.afterUnmarshal(javaWsdlMapping, LifecycleCallback.NONE);
return javaWsdlMapping;
}
use of org.apache.openejb.jee.PackageMapping$JAXB.readPackageMapping 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 (RPC_HOLDER_CLASSES.containsKey(paramMapping.getParamType())) {
// This is a standard type with a built in holder class
paramJavaType = RPC_HOLDER_CLASSES.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;
}
use of org.apache.openejb.jee.PackageMapping$JAXB.readPackageMapping in project tomee by apache.
the class LightweightTypeInfoBuilder method loadClass.
private Class loadClass(QName typeQName, JavaWsdlMapping mapping) throws OpenEJBException {
String namespace = typeQName.getNamespaceURI();
// package name comes from the package mapping
PackageMapping packageMapping = mapping.getPackageMappingMap().get(namespace);
if (packageMapping == null) {
throw new OpenEJBException("Namespace " + namespace + " was not mapped in jaxrpc mapping file");
}
String packageName = packageMapping.getPackageType();
// class name is package + type local part
String className = packageName + "." + typeQName.getLocalPart();
try {
Class clazz = Class.forName(className, false, classLoader);
return clazz;
} catch (ClassNotFoundException e) {
throw new OpenEJBException("Could not load java type " + className, e);
}
}
Aggregations