Search in sources :

Example 1 with ResultTypeMapping$JAXB.toStringResultTypeMapping

use of org.apache.openejb.jee.ResultTypeMapping$JAXB.toStringResultTypeMapping in project tomee by apache.

the class Query$JAXB method _write.

public static final void _write(final XoXMLStreamWriter writer, final Query query, RuntimeContext context) throws Exception {
    if (query == null) {
        writer.writeXsiNil();
        return;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
    if (Query.class != query.getClass()) {
        context.unexpectedSubclass(writer, query, Query.class);
        return;
    }
    context.beforeMarshal(query, LifecycleCallback.NONE);
    // ATTRIBUTE: id
    final String idRaw = query.id;
    if (idRaw != null) {
        String id = null;
        try {
            id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(query, "id", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "id", id);
    }
    // ELEMENT: description
    final Text description = query.description;
    if (description != null) {
        writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
        writeText(writer, description, context);
        writer.writeEndElement();
    }
    // ELEMENT: queryMethod
    final QueryMethod queryMethod = query.queryMethod;
    if (queryMethod != null) {
        writer.writeStartElement(prefix, "query-method", "http://java.sun.com/xml/ns/javaee");
        writeQueryMethod(writer, queryMethod, context);
        writer.writeEndElement();
    } else {
        context.unexpectedNullValue(query, "queryMethod");
    }
    // ELEMENT: resultTypeMapping
    final ResultTypeMapping resultTypeMapping = query.resultTypeMapping;
    if (resultTypeMapping != null) {
        writer.writeStartElement(prefix, "result-type-mapping", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(toStringResultTypeMapping(query, null, context, resultTypeMapping));
        writer.writeEndElement();
    }
    // ELEMENT: ejbQl
    final String ejbQlRaw = query.ejbQl;
    String ejbQl = null;
    try {
        ejbQl = Adapters.collapsedStringAdapterAdapter.marshal(ejbQlRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(query, "ejbQl", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (ejbQl != null) {
        writer.writeStartElement(prefix, "ejb-ql", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(ejbQl);
        writer.writeEndElement();
    } else {
        context.unexpectedNullValue(query, "ejbQl");
    }
    context.afterMarshal(query, LifecycleCallback.NONE);
}
Also used : ResultTypeMapping$JAXB.toStringResultTypeMapping(org.apache.openejb.jee.ResultTypeMapping$JAXB.toStringResultTypeMapping) ResultTypeMapping$JAXB.parseResultTypeMapping(org.apache.openejb.jee.ResultTypeMapping$JAXB.parseResultTypeMapping) CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) QueryMethod$JAXB.writeQueryMethod(org.apache.openejb.jee.QueryMethod$JAXB.writeQueryMethod) QueryMethod$JAXB.readQueryMethod(org.apache.openejb.jee.QueryMethod$JAXB.readQueryMethod) 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)

Example 2 with ResultTypeMapping$JAXB.toStringResultTypeMapping

use of org.apache.openejb.jee.ResultTypeMapping$JAXB.toStringResultTypeMapping in project tomee by apache.

the class Query$JAXB method _read.

public static final Query _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final Query query = new Query();
    context.beforeUnmarshal(query, LifecycleCallback.NONE);
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("queryType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, Query.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, query);
            query.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: description
            final Text description = readText(elementReader, context);
            query.description = description;
        } else if (("query-method" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: queryMethod
            final QueryMethod queryMethod = readQueryMethod(elementReader, context);
            query.queryMethod = queryMethod;
        } else if (("result-type-mapping" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: resultTypeMapping
            final ResultTypeMapping resultTypeMapping = parseResultTypeMapping(elementReader, context, elementReader.getElementAsString());
            if (resultTypeMapping != null) {
                query.resultTypeMapping = resultTypeMapping;
            }
        } else if (("ejb-ql" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: ejbQl
            final String ejbQlRaw = elementReader.getElementAsString();
            final String ejbQl;
            try {
                ejbQl = Adapters.collapsedStringAdapterAdapter.unmarshal(ejbQlRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            query.ejbQl = ejbQl;
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "query-method"), new QName("http://java.sun.com/xml/ns/javaee", "result-type-mapping"), new QName("http://java.sun.com/xml/ns/javaee", "ejb-ql"));
        }
    }
    context.afterUnmarshal(query, LifecycleCallback.NONE);
    return query;
}
Also used : ResultTypeMapping$JAXB.toStringResultTypeMapping(org.apache.openejb.jee.ResultTypeMapping$JAXB.toStringResultTypeMapping) ResultTypeMapping$JAXB.parseResultTypeMapping(org.apache.openejb.jee.ResultTypeMapping$JAXB.parseResultTypeMapping) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) QueryMethod$JAXB.writeQueryMethod(org.apache.openejb.jee.QueryMethod$JAXB.writeQueryMethod) QueryMethod$JAXB.readQueryMethod(org.apache.openejb.jee.QueryMethod$JAXB.readQueryMethod) 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) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 3 with ResultTypeMapping$JAXB.toStringResultTypeMapping

use of org.apache.openejb.jee.ResultTypeMapping$JAXB.toStringResultTypeMapping in project tomee by apache.

the class EjbJarInfoBuilder method initEntityBean.

private EnterpriseBeanInfo initEntityBean(final EntityBean e, final Map m) throws OpenEJBException {
    final EntityBeanInfo bean = new EntityBeanInfo();
    final EjbDeployment d = (EjbDeployment) m.get(e.getEjbName());
    if (d == null) {
        throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + e.getEjbName() + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();
    final Icon icon = e.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = e.getDescription();
    bean.displayName = e.getDisplayName();
    bean.ejbClass = e.getEjbClass();
    bean.abstractSchemaName = e.getAbstractSchemaName();
    bean.ejbName = e.getEjbName();
    bean.home = e.getHome();
    bean.remote = e.getRemote();
    bean.localHome = e.getLocalHome();
    bean.local = e.getLocal();
    bean.transactionType = "Container";
    bean.primKeyClass = e.getPrimKeyClass();
    bean.primKeyField = e.getPrimkeyField();
    bean.persistenceType = e.getPersistenceType().toString();
    bean.reentrant = String.valueOf(e.getReentrant());
    bean.properties.putAll(d.getProperties());
    final CmpVersion cmpVersion = e.getCmpVersion();
    if (e.getPersistenceType() == PersistenceType.CONTAINER) {
        if (cmpVersion != null && cmpVersion == CmpVersion.CMP1) {
            bean.cmpVersion = 1;
        } else {
            bean.cmpVersion = 2;
        }
    }
    final List<CmpField> cmpFields = e.getCmpField();
    for (final CmpField cmpField : cmpFields) {
        bean.cmpFieldNames.add(cmpField.getFieldName());
    }
    if (bean.persistenceType.equalsIgnoreCase("Container")) {
        for (final Query q : e.getQuery()) {
            final QueryInfo query = new QueryInfo();
            query.queryStatement = q.getEjbQl().trim();
            final MethodInfo method = new MethodInfo();
            method.ejbName = bean.ejbName;
            method.className = "*";
            final QueryMethod qm = q.getQueryMethod();
            method.methodName = qm.getMethodName();
            if (qm.getMethodParams() != null) {
                method.methodParams = qm.getMethodParams().getMethodParam();
            }
            query.method = method;
            final ResultTypeMapping resultType = q.getResultTypeMapping();
            if (ResultTypeMapping.REMOTE.equals(resultType)) {
                query.remoteResultType = true;
            }
            bean.queries.add(query);
        }
        for (final org.apache.openejb.jee.oejb3.Query q : d.getQuery()) {
            final QueryInfo query = new QueryInfo();
            query.description = q.getDescription();
            query.queryStatement = q.getObjectQl().trim();
            final MethodInfo method = new MethodInfo();
            method.ejbName = bean.ejbName;
            method.className = "*";
            final org.apache.openejb.jee.oejb3.QueryMethod qm = q.getQueryMethod();
            method.methodName = qm.getMethodName();
            if (qm.getMethodParams() != null) {
                method.methodParams = qm.getMethodParams().getMethodParam();
            }
            query.method = method;
            bean.queries.add(query);
        }
    }
    return bean;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ResultTypeMapping(org.apache.openejb.jee.ResultTypeMapping) Query(org.apache.openejb.jee.Query) QueryMethod(org.apache.openejb.jee.QueryMethod) QueryInfo(org.apache.openejb.assembler.classic.QueryInfo) CmpField(org.apache.openejb.jee.CmpField) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) MethodInfo(org.apache.openejb.assembler.classic.MethodInfo) InitMethodInfo(org.apache.openejb.assembler.classic.InitMethodInfo) NamedMethodInfo(org.apache.openejb.assembler.classic.NamedMethodInfo) RemoveMethodInfo(org.apache.openejb.assembler.classic.RemoveMethodInfo) EntityBeanInfo(org.apache.openejb.assembler.classic.EntityBeanInfo) Icon(org.apache.openejb.jee.Icon) CmpVersion(org.apache.openejb.jee.CmpVersion)

Aggregations

QueryMethod$JAXB.readQueryMethod (org.apache.openejb.jee.QueryMethod$JAXB.readQueryMethod)2 QueryMethod$JAXB.writeQueryMethod (org.apache.openejb.jee.QueryMethod$JAXB.writeQueryMethod)2 ResultTypeMapping$JAXB.parseResultTypeMapping (org.apache.openejb.jee.ResultTypeMapping$JAXB.parseResultTypeMapping)2 ResultTypeMapping$JAXB.toStringResultTypeMapping (org.apache.openejb.jee.ResultTypeMapping$JAXB.toStringResultTypeMapping)2 Text$JAXB.readText (org.apache.openejb.jee.Text$JAXB.readText)2 Text$JAXB.writeText (org.apache.openejb.jee.Text$JAXB.writeText)2 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)2 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)1 QName (javax.xml.namespace.QName)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 EntityBeanInfo (org.apache.openejb.assembler.classic.EntityBeanInfo)1 InitMethodInfo (org.apache.openejb.assembler.classic.InitMethodInfo)1 MethodInfo (org.apache.openejb.assembler.classic.MethodInfo)1 NamedMethodInfo (org.apache.openejb.assembler.classic.NamedMethodInfo)1 QueryInfo (org.apache.openejb.assembler.classic.QueryInfo)1 RemoveMethodInfo (org.apache.openejb.assembler.classic.RemoveMethodInfo)1 CmpField (org.apache.openejb.jee.CmpField)1 CmpVersion (org.apache.openejb.jee.CmpVersion)1 Icon (org.apache.openejb.jee.Icon)1 Query (org.apache.openejb.jee.Query)1