Search in sources :

Example 46 with Text$JAXB.readText

use of org.apache.openejb.jee.Text$JAXB.readText in project tomee by apache.

the class Method$JAXB method _write.

public static final void _write(final XoXMLStreamWriter writer, final Method method, RuntimeContext context) throws Exception {
    if (method == null) {
        writer.writeXsiNil();
        return;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
    if (Method.class != method.getClass()) {
        context.unexpectedSubclass(writer, method, Method.class);
        return;
    }
    context.beforeMarshal(method, LifecycleCallback.NONE);
    // ATTRIBUTE: id
    final String idRaw = method.id;
    if (idRaw != null) {
        String id = null;
        try {
            id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(method, "id", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "id", id);
    }
    // ELEMENT: descriptions
    Text[] descriptions = null;
    try {
        descriptions = method.getDescriptions();
    } catch (final Exception e) {
        context.getterError(method, "descriptions", Method.class, "getDescriptions", e);
    }
    if (descriptions != null) {
        for (final Text descriptionsItem : descriptions) {
            if (descriptionsItem != null) {
                writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
                writeText(writer, descriptionsItem, context);
                writer.writeEndElement();
            } else {
                context.unexpectedNullValue(method, "descriptions");
            }
        }
    }
    // ELEMENT: ejbName
    final String ejbNameRaw = method.ejbName;
    String ejbName = null;
    try {
        ejbName = Adapters.collapsedStringAdapterAdapter.marshal(ejbNameRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(method, "ejbName", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (ejbName != null) {
        writer.writeStartElement(prefix, "ejb-name", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(ejbName);
        writer.writeEndElement();
    } else {
        context.unexpectedNullValue(method, "ejbName");
    }
    // ELEMENT: methodIntf
    final MethodIntf methodIntf = method.methodIntf;
    if (methodIntf != null) {
        writer.writeStartElement(prefix, "method-intf", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(toStringMethodIntf(method, null, context, methodIntf));
        writer.writeEndElement();
    }
    // ELEMENT: methodName
    final String methodNameRaw = method.methodName;
    String methodName = null;
    try {
        methodName = Adapters.collapsedStringAdapterAdapter.marshal(methodNameRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(method, "methodName", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (methodName != null) {
        writer.writeStartElement(prefix, "method-name", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(methodName);
        writer.writeEndElement();
    } else {
        context.unexpectedNullValue(method, "methodName");
    }
    // ELEMENT: methodParams
    final MethodParams methodParams = method.methodParams;
    if (methodParams != null) {
        writer.writeStartElement(prefix, "method-params", "http://java.sun.com/xml/ns/javaee");
        writeMethodParams(writer, methodParams, context);
        writer.writeEndElement();
    }
    context.afterMarshal(method, LifecycleCallback.NONE);
}
Also used : CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) MethodParams$JAXB.writeMethodParams(org.apache.openejb.jee.MethodParams$JAXB.writeMethodParams) MethodParams$JAXB.readMethodParams(org.apache.openejb.jee.MethodParams$JAXB.readMethodParams) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) MethodIntf$JAXB.parseMethodIntf(org.apache.openejb.jee.MethodIntf$JAXB.parseMethodIntf) MethodIntf$JAXB.toStringMethodIntf(org.apache.openejb.jee.MethodIntf$JAXB.toStringMethodIntf)

Example 47 with Text$JAXB.readText

use of org.apache.openejb.jee.Text$JAXB.readText in project tomee by apache.

the class Method$JAXB method _read.

public static final Method _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final Method method = new Method();
    context.beforeUnmarshal(method, LifecycleCallback.NONE);
    ArrayList<Text> descriptions = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("methodType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, Method.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, method);
            method.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 (("description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: descriptions
            final Text descriptionsItem = readText(elementReader, context);
            if (descriptions == null) {
                descriptions = new ArrayList<Text>();
            }
            descriptions.add(descriptionsItem);
        } else if (("ejb-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: ejbName
            final String ejbNameRaw = elementReader.getElementAsString();
            final String ejbName;
            try {
                ejbName = Adapters.collapsedStringAdapterAdapter.unmarshal(ejbNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            method.ejbName = ejbName;
        } else if (("method-intf" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: methodIntf
            final MethodIntf methodIntf = parseMethodIntf(elementReader, context, elementReader.getElementAsString());
            if (methodIntf != null) {
                method.methodIntf = methodIntf;
            }
        } else if (("method-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: methodName
            final String methodNameRaw = elementReader.getElementAsString();
            final String methodName;
            try {
                methodName = Adapters.collapsedStringAdapterAdapter.unmarshal(methodNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            method.methodName = methodName;
        } else if (("method-params" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: methodParams
            final MethodParams methodParams = readMethodParams(elementReader, context);
            method.methodParams = methodParams;
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "ejb-name"), new QName("http://java.sun.com/xml/ns/javaee", "method-intf"), new QName("http://java.sun.com/xml/ns/javaee", "method-name"), new QName("http://java.sun.com/xml/ns/javaee", "method-params"));
        }
    }
    if (descriptions != null) {
        try {
            method.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
        } catch (final Exception e) {
            context.setterError(reader, Method.class, "setDescriptions", Text[].class, e);
        }
    }
    context.afterUnmarshal(method, LifecycleCallback.NONE);
    return method;
}
Also used : Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) MethodParams$JAXB.writeMethodParams(org.apache.openejb.jee.MethodParams$JAXB.writeMethodParams) MethodParams$JAXB.readMethodParams(org.apache.openejb.jee.MethodParams$JAXB.readMethodParams) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) MethodIntf$JAXB.parseMethodIntf(org.apache.openejb.jee.MethodIntf$JAXB.parseMethodIntf) MethodIntf$JAXB.toStringMethodIntf(org.apache.openejb.jee.MethodIntf$JAXB.toStringMethodIntf) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 48 with Text$JAXB.readText

use of org.apache.openejb.jee.Text$JAXB.readText in project tomee by apache.

the class MethodPermission$JAXB method _read.

public static final MethodPermission _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final MethodPermission methodPermission = new MethodPermission();
    context.beforeUnmarshal(methodPermission, LifecycleCallback.NONE);
    ArrayList<Text> descriptions = null;
    List<String> roleName = null;
    List<Method> method = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("method-permissionType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, MethodPermission.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, methodPermission);
            methodPermission.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 (("description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: descriptions
            final Text descriptionsItem = readText(elementReader, context);
            if (descriptions == null) {
                descriptions = new ArrayList<Text>();
            }
            descriptions.add(descriptionsItem);
        } else if (("role-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: roleName
            final String roleNameItemRaw = elementReader.getElementAsString();
            final String roleNameItem;
            try {
                roleNameItem = Adapters.collapsedStringAdapterAdapter.unmarshal(roleNameItemRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            if (roleName == null) {
                roleName = methodPermission.roleName;
                if (roleName != null) {
                    roleName.clear();
                } else {
                    roleName = new ArrayList<String>();
                }
            }
            roleName.add(roleNameItem);
        } else if (("unchecked" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: unchecked
            final Empty unchecked = readEmpty(elementReader, context);
            methodPermission.unchecked = unchecked;
        } else if (("method" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: method
            final Method methodItem = readMethod(elementReader, context);
            if (method == null) {
                method = methodPermission.method;
                if (method != null) {
                    method.clear();
                } else {
                    method = new ArrayList<Method>();
                }
            }
            method.add(methodItem);
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "role-name"), new QName("http://java.sun.com/xml/ns/javaee", "unchecked"), new QName("http://java.sun.com/xml/ns/javaee", "method"));
        }
    }
    if (descriptions != null) {
        try {
            methodPermission.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
        } catch (final Exception e) {
            context.setterError(reader, MethodPermission.class, "setDescriptions", Text[].class, e);
        }
    }
    if (roleName != null) {
        methodPermission.roleName = roleName;
    }
    if (method != null) {
        methodPermission.method = method;
    }
    context.afterUnmarshal(methodPermission, LifecycleCallback.NONE);
    return methodPermission;
}
Also used : Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) Method$JAXB.readMethod(org.apache.openejb.jee.Method$JAXB.readMethod) Method$JAXB.writeMethod(org.apache.openejb.jee.Method$JAXB.writeMethod) Empty$JAXB.writeEmpty(org.apache.openejb.jee.Empty$JAXB.writeEmpty) Empty$JAXB.readEmpty(org.apache.openejb.jee.Empty$JAXB.readEmpty) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 49 with Text$JAXB.readText

use of org.apache.openejb.jee.Text$JAXB.readText in project tomee by apache.

the class PersistenceContextRef$JAXB method _read.

public static final PersistenceContextRef _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final PersistenceContextRef persistenceContextRef = new PersistenceContextRef();
    context.beforeUnmarshal(persistenceContextRef, LifecycleCallback.NONE);
    ArrayList<Text> descriptions = null;
    List<Property> persistenceProperty = null;
    Set<InjectionTarget> injectionTarget = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("persistence-context-refType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, PersistenceContextRef.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, persistenceContextRef);
            persistenceContextRef.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 (("description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: descriptions
            final Text descriptionsItem = readText(elementReader, context);
            if (descriptions == null) {
                descriptions = new ArrayList<Text>();
            }
            descriptions.add(descriptionsItem);
        } else if (("persistence-context-ref-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: persistenceContextRefName
            final String persistenceContextRefNameRaw = elementReader.getElementAsString();
            final String persistenceContextRefName;
            try {
                persistenceContextRefName = Adapters.collapsedStringAdapterAdapter.unmarshal(persistenceContextRefNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            persistenceContextRef.persistenceContextRefName = persistenceContextRefName;
        } else if (("persistence-unit-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: persistenceUnitName
            final String persistenceUnitNameRaw = elementReader.getElementAsString();
            final String persistenceUnitName;
            try {
                persistenceUnitName = Adapters.collapsedStringAdapterAdapter.unmarshal(persistenceUnitNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            persistenceContextRef.persistenceUnitName = persistenceUnitName;
        } else if (("persistence-context-type" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: persistenceContextType
            final PersistenceContextType persistenceContextType = parsePersistenceContextType(elementReader, context, elementReader.getElementAsString());
            if (persistenceContextType != null) {
                persistenceContextRef.persistenceContextType = persistenceContextType;
            }
        } else if (("persistence-context-synchronization" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: persistenceContextType
            final PersistenceContextSynchronization synchronization = parsePersistenceContextSynchronization(elementReader, context, elementReader.getElementAsString());
            if (synchronization != null) {
                persistenceContextRef.persistenceContextSynchronization = synchronization;
            }
        } else if (("persistence-property" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: persistenceProperty
            final Property persistencePropertyItem = readProperty(elementReader, context);
            if (persistenceProperty == null) {
                persistenceProperty = persistenceContextRef.persistenceProperty;
                if (persistenceProperty != null) {
                    persistenceProperty.clear();
                } else {
                    persistenceProperty = new ArrayList<Property>();
                }
            }
            persistenceProperty.add(persistencePropertyItem);
        } else if (("mapped-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: mappedName
            final String mappedNameRaw = elementReader.getElementAsString();
            final String mappedName;
            try {
                mappedName = Adapters.collapsedStringAdapterAdapter.unmarshal(mappedNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            persistenceContextRef.mappedName = mappedName;
        } else if (("injection-target" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: injectionTarget
            final InjectionTarget injectionTargetItem = readInjectionTarget(elementReader, context);
            if (injectionTarget == null) {
                injectionTarget = persistenceContextRef.injectionTarget;
                if (injectionTarget != null) {
                    injectionTarget.clear();
                } else {
                    injectionTarget = new LinkedHashSet<InjectionTarget>();
                }
            }
            injectionTarget.add(injectionTargetItem);
        } else if (("lookup-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: lookupName
            final String lookupNameRaw = elementReader.getElementAsString();
            final String lookupName;
            try {
                lookupName = Adapters.collapsedStringAdapterAdapter.unmarshal(lookupNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            persistenceContextRef.lookupName = lookupName;
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "persistence-context-ref-name"), new QName("http://java.sun.com/xml/ns/javaee", "persistence-unit-name"), new QName("http://java.sun.com/xml/ns/javaee", "persistence-context-type"), new QName("http://java.sun.com/xml/ns/javaee", "persistence-property"), new QName("http://java.sun.com/xml/ns/javaee", "mapped-name"), new QName("http://java.sun.com/xml/ns/javaee", "injection-target"), new QName("http://java.sun.com/xml/ns/javaee", "lookup-name"));
        }
    }
    if (descriptions != null) {
        try {
            persistenceContextRef.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
        } catch (final Exception e) {
            context.setterError(reader, PersistenceContextRef.class, "setDescriptions", Text[].class, e);
        }
    }
    if (persistenceProperty != null) {
        persistenceContextRef.persistenceProperty = persistenceProperty;
    }
    if (injectionTarget != null) {
        persistenceContextRef.injectionTarget = injectionTarget;
    }
    context.afterUnmarshal(persistenceContextRef, LifecycleCallback.NONE);
    return persistenceContextRef;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PersistenceContextType$JAXB.parsePersistenceContextType(org.apache.openejb.jee.PersistenceContextType$JAXB.parsePersistenceContextType) PersistenceContextType$JAXB.toStringPersistenceContextType(org.apache.openejb.jee.PersistenceContextType$JAXB.toStringPersistenceContextType) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) InjectionTarget$JAXB.writeInjectionTarget(org.apache.openejb.jee.InjectionTarget$JAXB.writeInjectionTarget) InjectionTarget$JAXB.readInjectionTarget(org.apache.openejb.jee.InjectionTarget$JAXB.readInjectionTarget) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) Property$JAXB.writeProperty(org.apache.openejb.jee.Property$JAXB.writeProperty) Property$JAXB.readProperty(org.apache.openejb.jee.Property$JAXB.readProperty) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 50 with Text$JAXB.readText

use of org.apache.openejb.jee.Text$JAXB.readText in project tomee by apache.

the class PersistenceUnitRef$JAXB method _read.

public static final PersistenceUnitRef _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final PersistenceUnitRef persistenceUnitRef = new PersistenceUnitRef();
    context.beforeUnmarshal(persistenceUnitRef, LifecycleCallback.NONE);
    ArrayList<Text> descriptions = null;
    Set<InjectionTarget> injectionTarget = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("persistence-unit-refType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, PersistenceUnitRef.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, persistenceUnitRef);
            persistenceUnitRef.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 (("description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: descriptions
            final Text descriptionsItem = readText(elementReader, context);
            if (descriptions == null) {
                descriptions = new ArrayList<Text>();
            }
            descriptions.add(descriptionsItem);
        } else if (("persistence-unit-ref-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: persistenceUnitRefName
            final String persistenceUnitRefNameRaw = elementReader.getElementAsString();
            final String persistenceUnitRefName;
            try {
                persistenceUnitRefName = Adapters.collapsedStringAdapterAdapter.unmarshal(persistenceUnitRefNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            persistenceUnitRef.persistenceUnitRefName = persistenceUnitRefName;
        } else if (("persistence-unit-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: persistenceUnitName
            final String persistenceUnitNameRaw = elementReader.getElementAsString();
            final String persistenceUnitName;
            try {
                persistenceUnitName = Adapters.collapsedStringAdapterAdapter.unmarshal(persistenceUnitNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            persistenceUnitRef.persistenceUnitName = persistenceUnitName;
        } else if (("mapped-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: mappedName
            final String mappedNameRaw = elementReader.getElementAsString();
            final String mappedName;
            try {
                mappedName = Adapters.collapsedStringAdapterAdapter.unmarshal(mappedNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            persistenceUnitRef.mappedName = mappedName;
        } else if (("injection-target" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: injectionTarget
            final InjectionTarget injectionTargetItem = readInjectionTarget(elementReader, context);
            if (injectionTarget == null) {
                injectionTarget = persistenceUnitRef.injectionTarget;
                if (injectionTarget != null) {
                    injectionTarget.clear();
                } else {
                    injectionTarget = new LinkedHashSet<InjectionTarget>();
                }
            }
            injectionTarget.add(injectionTargetItem);
        } else if (("lookup-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: lookupName
            final String lookupNameRaw = elementReader.getElementAsString();
            final String lookupName;
            try {
                lookupName = Adapters.collapsedStringAdapterAdapter.unmarshal(lookupNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            persistenceUnitRef.lookupName = lookupName;
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "persistence-unit-ref-name"), new QName("http://java.sun.com/xml/ns/javaee", "persistence-unit-name"), new QName("http://java.sun.com/xml/ns/javaee", "mapped-name"), new QName("http://java.sun.com/xml/ns/javaee", "injection-target"), new QName("http://java.sun.com/xml/ns/javaee", "lookup-name"));
        }
    }
    if (descriptions != null) {
        try {
            persistenceUnitRef.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
        } catch (final Exception e) {
            context.setterError(reader, PersistenceUnitRef.class, "setDescriptions", Text[].class, e);
        }
    }
    if (injectionTarget != null) {
        persistenceUnitRef.injectionTarget = injectionTarget;
    }
    context.afterUnmarshal(persistenceUnitRef, LifecycleCallback.NONE);
    return persistenceUnitRef;
}
Also used : CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) InjectionTarget$JAXB.writeInjectionTarget(org.apache.openejb.jee.InjectionTarget$JAXB.writeInjectionTarget) InjectionTarget$JAXB.readInjectionTarget(org.apache.openejb.jee.InjectionTarget$JAXB.readInjectionTarget) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Aggregations

Text$JAXB.readText (org.apache.openejb.jee.Text$JAXB.readText)155 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)155 Text$JAXB.writeText (org.apache.openejb.jee.Text$JAXB.writeText)154 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)126 QName (javax.xml.namespace.QName)80 Attribute (org.metatype.sxc.util.Attribute)78 XoXMLStreamReader (org.metatype.sxc.util.XoXMLStreamReader)78 Icon$JAXB.readIcon (org.apache.openejb.jee.Icon$JAXB.readIcon)70 Icon$JAXB.writeIcon (org.apache.openejb.jee.Icon$JAXB.writeIcon)70 ArrayList (java.util.ArrayList)56 InjectionTarget$JAXB.readInjectionTarget (org.apache.openejb.jee.InjectionTarget$JAXB.readInjectionTarget)18 InjectionTarget$JAXB.writeInjectionTarget (org.apache.openejb.jee.InjectionTarget$JAXB.writeInjectionTarget)18 DataSource$JAXB.readDataSource (org.apache.openejb.jee.DataSource$JAXB.readDataSource)14 DataSource$JAXB.writeDataSource (org.apache.openejb.jee.DataSource$JAXB.writeDataSource)14 EjbLocalRef$JAXB.readEjbLocalRef (org.apache.openejb.jee.EjbLocalRef$JAXB.readEjbLocalRef)14 EjbLocalRef$JAXB.writeEjbLocalRef (org.apache.openejb.jee.EjbLocalRef$JAXB.writeEjbLocalRef)14 EjbRef$JAXB.readEjbRef (org.apache.openejb.jee.EjbRef$JAXB.readEjbRef)14 EjbRef$JAXB.writeEjbRef (org.apache.openejb.jee.EjbRef$JAXB.writeEjbRef)14 EnvEntry$JAXB.readEnvEntry (org.apache.openejb.jee.EnvEntry$JAXB.readEnvEntry)14 EnvEntry$JAXB.writeEnvEntry (org.apache.openejb.jee.EnvEntry$JAXB.writeEnvEntry)14