use of org.apache.openejb.jee.JavaXmlTypeMapping$JAXB.readJavaXmlTypeMapping 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.JavaXmlTypeMapping$JAXB.readJavaXmlTypeMapping 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.JavaXmlTypeMapping$JAXB.readJavaXmlTypeMapping in project tomee by apache.
the class HeavyweightTypeInfoBuilder method buildTypeInfo.
public List<JaxRpcTypeInfo> buildTypeInfo() throws OpenEJBException {
List<JaxRpcTypeInfo> typeInfos = new ArrayList<JaxRpcTypeInfo>();
Set<QName> mappedTypeQNames = new HashSet<QName>();
//
for (JavaXmlTypeMapping javaXmlTypeMapping : mapping.getJavaXmlTypeMapping()) {
// get the QName for this mapping
QName qname;
if (javaXmlTypeMapping.getRootTypeQname() != null) {
qname = javaXmlTypeMapping.getRootTypeQname();
// Skip the wrapper elements.
if (wrapperElementQNames.contains(qname)) {
continue;
}
} else if (javaXmlTypeMapping.getAnonymousTypeQname() != null) {
String anonTypeQNameString = javaXmlTypeMapping.getAnonymousTypeQname();
// this appears to be ignored...
int pos = anonTypeQNameString.lastIndexOf(":");
if (pos == -1) {
throw new OpenEJBException("anon QName is invalid, no final ':' " + anonTypeQNameString);
}
String namespace = anonTypeQNameString.substring(0, pos);
String localPart = anonTypeQNameString.substring(pos + 1);
qname = new QName(namespace, localPart);
// todo why is this +2
if (wrapperElementQNames.contains(new QName(namespace, anonTypeQNameString.substring(pos + 2)))) {
continue;
}
} else {
throw new OpenEJBException("either root type qname or anonymous type qname must be set");
}
// get the xml type qname of this mapping
QName xmlTypeQName;
if ("element".equals(javaXmlTypeMapping.getQNameScope())) {
XmlElementInfo elementInfo = schemaInfo.elements.get(qname);
if (elementInfo == null) {
log.warn("Element [" + qname + "] not been found in schema, known elements: " + schemaInfo.elements.keySet());
}
xmlTypeQName = elementInfo.xmlType;
} else {
xmlTypeQName = qname;
}
// finally, get the xml type info for the mapping
XmlTypeInfo xmlTypeInfo = schemaInfo.types.get(xmlTypeQName);
if (xmlTypeInfo == null) {
// if this is a built in type then assume this is a redundant mapping
if (WebserviceNameSpaces.contains(xmlTypeInfo.qname.getNamespaceURI())) {
continue;
}
log.warn("Schema type QName [" + qname + "] not been found in schema: " + schemaInfo.types.keySet());
continue;
}
// mark this type as mapped
mappedTypeQNames.add(xmlTypeInfo.qname);
// load the java class
Class clazz;
try {
clazz = Class.forName(javaXmlTypeMapping.getJavaType(), false, classLoader);
} catch (ClassNotFoundException e) {
throw new OpenEJBException("Could not load java type " + javaXmlTypeMapping.getJavaType(), e);
}
// create the jax-rpc type mapping
JaxRpcTypeInfo typeInfo = createTypeInfo(qname, xmlTypeInfo, clazz);
mapFields(clazz, xmlTypeInfo, javaXmlTypeMapping, typeInfo);
typeInfos.add(typeInfo);
}
//
for (JaxRpcOperationInfo operationInfo : operations) {
List<JaxRpcParameterInfo> parameters = new ArrayList<JaxRpcParameterInfo>(operationInfo.parameters);
// add the return type to the parameters so it is processed below
if (operationInfo.returnXmlType != null) {
JaxRpcParameterInfo returnParameter = new JaxRpcParameterInfo();
returnParameter.xmlType = operationInfo.returnXmlType;
returnParameter.javaType = operationInfo.returnJavaType;
parameters.add(returnParameter);
}
// add type mappings for each parameter (including the return type)
for (JaxRpcParameterInfo parameterInfo : parameters) {
QName xmlType = parameterInfo.xmlType;
// skip types that have already been mapped or are built in types
if (xmlType == null || mappedTypeQNames.contains(xmlType) || xmlType.getNamespaceURI().equals(XML_SCHEMA_NS) || xmlType.getNamespaceURI().equals(SOAP_ENCODING_NS)) {
continue;
}
// get the xml type info
XmlTypeInfo xmlTypeInfo = schemaInfo.types.get(xmlType);
if (xmlTypeInfo == null) {
log.warn("Type QName [" + xmlType + "] defined by operation [" + operationInfo + "] has not been found in schema: " + schemaInfo.types.keySet());
continue;
}
mappedTypeQNames.add(xmlTypeInfo.qname);
// load the java class
Class<?> clazz;
try {
clazz = classLoader.loadClass(parameterInfo.javaType);
} catch (ClassNotFoundException e) {
throw new OpenEJBException("Could not load paramter");
}
// we only process simpleTypes and arrays (not normal complex types)
if (xmlTypeInfo.simpleBaseType == null && !clazz.isArray()) {
if (!mappedTypeQNames.contains(xmlTypeInfo.qname)) {
// TODO: this lookup is not enough: the jaxrpc mapping file may define an anonymous mapping
log.warn("Operation " + operationInfo.name + "] uses XML type [" + xmlTypeInfo + "], whose mapping is not declared by the jaxrpc mapping file.\n Continuing deployment; " + "yet, the deployment is not-portable.");
}
continue;
}
// create the jax-rpc type mapping
JaxRpcTypeInfo typeInfo = createTypeInfo(parameterInfo.qname, xmlTypeInfo, clazz);
typeInfos.add(typeInfo);
}
}
return typeInfos;
}
Aggregations