Search in sources :

Example 6 with OutboundResourceAdapter

use of org.apache.openejb.jee.OutboundResourceAdapter in project tomee by apache.

the class ResourceAdapter$JAXB method _read.

public static final ResourceAdapter _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final ResourceAdapter resourceAdapter = new ResourceAdapter();
    context.beforeUnmarshal(resourceAdapter, LifecycleCallback.NONE);
    List<ConfigProperty> configProperty = null;
    List<AdminObject> adminObject = null;
    List<SecurityPermission> securityPermission = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("resourceadapterType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, ResourceAdapter.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, resourceAdapter);
            resourceAdapter.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 (("resourceadapter-class" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: resourceAdapterClass
            final String resourceAdapterClassRaw = elementReader.getElementAsString();
            final String resourceAdapterClass;
            try {
                resourceAdapterClass = Adapters.collapsedStringAdapterAdapter.unmarshal(resourceAdapterClassRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            resourceAdapter.resourceAdapterClass = resourceAdapterClass;
        } else if (("config-property" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: configProperty
            final ConfigProperty configPropertyItem = readConfigProperty(elementReader, context);
            if (configProperty == null) {
                configProperty = resourceAdapter.configProperty;
                if (configProperty != null) {
                    configProperty.clear();
                } else {
                    configProperty = new ArrayList<ConfigProperty>();
                }
            }
            configProperty.add(configPropertyItem);
        } else if (("outbound-resourceadapter" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: outboundResourceAdapter
            final OutboundResourceAdapter outboundResourceAdapter = readOutboundResourceAdapter(elementReader, context);
            resourceAdapter.outboundResourceAdapter = outboundResourceAdapter;
        } else if (("inbound-resourceadapter" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: inboundResourceAdapter
            final InboundResourceadapter inboundResourceAdapter = readInboundResourceadapter(elementReader, context);
            resourceAdapter.inboundResourceAdapter = inboundResourceAdapter;
        } else if (("adminobject" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: adminObject
            final AdminObject adminObjectItem = readAdminObject(elementReader, context);
            if (adminObject == null) {
                adminObject = resourceAdapter.adminObject;
                if (adminObject != null) {
                    adminObject.clear();
                } else {
                    adminObject = new ArrayList<AdminObject>();
                }
            }
            adminObject.add(adminObjectItem);
        } else if (("security-permission" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: securityPermission
            final SecurityPermission securityPermissionItem = readSecurityPermission(elementReader, context);
            if (securityPermission == null) {
                securityPermission = resourceAdapter.securityPermission;
                if (securityPermission != null) {
                    securityPermission.clear();
                } else {
                    securityPermission = new ArrayList<SecurityPermission>();
                }
            }
            securityPermission.add(securityPermissionItem);
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "resourceadapter-class"), new QName("http://java.sun.com/xml/ns/javaee", "config-property"), new QName("http://java.sun.com/xml/ns/javaee", "outbound-resourceadapter"), new QName("http://java.sun.com/xml/ns/javaee", "inbound-resourceadapter"), new QName("http://java.sun.com/xml/ns/javaee", "adminobject"), new QName("http://java.sun.com/xml/ns/javaee", "security-permission"));
        }
    }
    if (configProperty != null) {
        resourceAdapter.configProperty = configProperty;
    }
    if (adminObject != null) {
        resourceAdapter.adminObject = adminObject;
    }
    if (securityPermission != null) {
        resourceAdapter.securityPermission = securityPermission;
    }
    context.afterUnmarshal(resourceAdapter, LifecycleCallback.NONE);
    return resourceAdapter;
}
Also used : CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ConfigProperty$JAXB.readConfigProperty(org.apache.openejb.jee.ConfigProperty$JAXB.readConfigProperty) ConfigProperty$JAXB.writeConfigProperty(org.apache.openejb.jee.ConfigProperty$JAXB.writeConfigProperty) OutboundResourceAdapter$JAXB.readOutboundResourceAdapter(org.apache.openejb.jee.OutboundResourceAdapter$JAXB.readOutboundResourceAdapter) OutboundResourceAdapter$JAXB.writeOutboundResourceAdapter(org.apache.openejb.jee.OutboundResourceAdapter$JAXB.writeOutboundResourceAdapter) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) InboundResourceadapter$JAXB.readInboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter$JAXB.readInboundResourceadapter) InboundResourceadapter$JAXB.writeInboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter$JAXB.writeInboundResourceadapter) AdminObject$JAXB.readAdminObject(org.apache.openejb.jee.AdminObject$JAXB.readAdminObject) AdminObject$JAXB.writeAdminObject(org.apache.openejb.jee.AdminObject$JAXB.writeAdminObject) OutboundResourceAdapter$JAXB.readOutboundResourceAdapter(org.apache.openejb.jee.OutboundResourceAdapter$JAXB.readOutboundResourceAdapter) OutboundResourceAdapter$JAXB.writeOutboundResourceAdapter(org.apache.openejb.jee.OutboundResourceAdapter$JAXB.writeOutboundResourceAdapter) SecurityPermission$JAXB.writeSecurityPermission(org.apache.openejb.jee.SecurityPermission$JAXB.writeSecurityPermission) SecurityPermission$JAXB.readSecurityPermission(org.apache.openejb.jee.SecurityPermission$JAXB.readSecurityPermission) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Aggregations

ConnectionDefinition (org.apache.openejb.jee.ConnectionDefinition)4 Connector (org.apache.openejb.jee.Connector)4 OutboundResourceAdapter (org.apache.openejb.jee.OutboundResourceAdapter)4 ResourceAdapter (org.apache.openejb.jee.ResourceAdapter)4 ConnectionFactory (javax.resource.cci.ConnectionFactory)3 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)3 Module (org.apache.openejb.testing.Module)3 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)2 AdminObject$JAXB.readAdminObject (org.apache.openejb.jee.AdminObject$JAXB.readAdminObject)2 AdminObject$JAXB.writeAdminObject (org.apache.openejb.jee.AdminObject$JAXB.writeAdminObject)2 ConfigProperty (org.apache.openejb.jee.ConfigProperty)2 ConfigProperty$JAXB.readConfigProperty (org.apache.openejb.jee.ConfigProperty$JAXB.readConfigProperty)2 ConfigProperty$JAXB.writeConfigProperty (org.apache.openejb.jee.ConfigProperty$JAXB.writeConfigProperty)2 InboundResourceadapter$JAXB.readInboundResourceadapter (org.apache.openejb.jee.InboundResourceadapter$JAXB.readInboundResourceadapter)2 InboundResourceadapter$JAXB.writeInboundResourceadapter (org.apache.openejb.jee.InboundResourceadapter$JAXB.writeInboundResourceadapter)2 OutboundResourceAdapter$JAXB.readOutboundResourceAdapter (org.apache.openejb.jee.OutboundResourceAdapter$JAXB.readOutboundResourceAdapter)2 OutboundResourceAdapter$JAXB.writeOutboundResourceAdapter (org.apache.openejb.jee.OutboundResourceAdapter$JAXB.writeOutboundResourceAdapter)2 SecurityPermission$JAXB.readSecurityPermission (org.apache.openejb.jee.SecurityPermission$JAXB.readSecurityPermission)2 SecurityPermission$JAXB.writeSecurityPermission (org.apache.openejb.jee.SecurityPermission$JAXB.writeSecurityPermission)2 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)2