Search in sources :

Example 1 with CoreAttributeGroup

use of org.eclipse.persistence.core.queries.CoreAttributeGroup in project eclipselink by eclipse-ee4j.

the class JAXBUnmarshaller method getProperty.

/**
 * Get a property from the JAXBMarshaller. Attempting to get any unsupported
 * property will result in a jakarta.xml.bind.PropertyException
 * See <a href="#supportedProps">Supported Properties</a>.
 * @see org.eclipse.persistence.jaxb.UnmarshallerProperties
 */
@Override
public Object getProperty(String key) throws PropertyException {
    if (key == null) {
        throw new IllegalArgumentException();
    }
    if (key.equals(UnmarshallerProperties.MEDIA_TYPE)) {
        return xmlUnmarshaller.getMediaType();
    } else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)) {
        return xmlUnmarshaller.isAutoDetectMediaType();
    } else if (key.equals(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE)) {
        return xmlUnmarshaller.isCaseInsensitive();
    } else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)) {
        return xmlUnmarshaller.getAttributePrefix();
    } else if (key.equals(UnmarshallerProperties.JSON_INCLUDE_ROOT)) {
        return xmlUnmarshaller.isIncludeRoot();
    } else if (key.equals(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR)) {
        return xmlUnmarshaller.getNamespaceSeparator();
    } else if (key.equals(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER)) {
        if (xmlUnmarshaller.getNamespaceResolver() == null) {
            return null;
        }
        if (xmlUnmarshaller.getNamespaceResolver() instanceof PrefixMapperNamespaceResolver) {
            PrefixMapperNamespaceResolver wrapper = (PrefixMapperNamespaceResolver) xmlUnmarshaller.getNamespaceResolver();
            return wrapper.getPrefixMapper();
        } else {
            Map<String, String> nsMap = new HashMap<String, String>();
            Map<String, String> prefixesToNS = xmlUnmarshaller.getNamespaceResolver().getPrefixesToNamespaces();
            // Reverse the prefixesToNS map
            Iterator<Entry<String, String>> namesapcesIter = prefixesToNS.entrySet().iterator();
            for (int i = 0; i < prefixesToNS.size(); i++) {
                Entry<String, String> nextEntry = namesapcesIter.next();
                nsMap.put(nextEntry.getValue(), nextEntry.getKey());
            }
            return nsMap;
        }
    } else if (key.equals(UnmarshallerProperties.JSON_VALUE_WRAPPER)) {
        return xmlUnmarshaller.getValueWrapper();
    } else if (UnmarshallerProperties.JSON_USE_XSD_TYPES_WITH_PREFIX.equals(key)) {
        return xmlUnmarshaller.getJsonTypeConfiguration().isUseXsdTypesWithPrefix();
    } else if (UnmarshallerProperties.JSON_TYPE_COMPATIBILITY.equals(key)) {
        return xmlUnmarshaller.getJsonTypeConfiguration().isJsonTypeCompatibility();
    } else if (MarshallerProperties.JSON_TYPE_ATTRIBUTE_NAME.equals(key)) {
        return xmlUnmarshaller.getJsonTypeConfiguration().getJsonTypeAttributeName();
    } else if (UnmarshallerProperties.ID_RESOLVER.equals(key)) {
        return xmlUnmarshaller.getIDResolver();
    } else if (SUN_ID_RESOLVER.equals(key) || SUN_JSE_ID_RESOLVER.equals(key)) {
        IDResolverWrapper wrapper = (IDResolverWrapper) xmlUnmarshaller.getIDResolver();
        if (wrapper == null) {
            return null;
        }
        return wrapper.getResolver();
    } else if (UnmarshallerProperties.OBJECT_GRAPH.equals(key)) {
        Object graph = xmlUnmarshaller.getUnmarshalAttributeGroup();
        if (graph instanceof CoreAttributeGroup) {
            return new ObjectGraphImpl((CoreAttributeGroup) graph);
        }
        return graph;
    } else if (UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME.equals(key)) {
        return xmlUnmarshaller.isWrapperAsCollectionName();
    } else if (UnmarshallerProperties.BEAN_VALIDATION_MODE.equals(key)) {
        return this.beanValidationMode;
    } else if (UnmarshallerProperties.BEAN_VALIDATION_FACTORY.equals(key)) {
        return this.prefValidatorFactory;
    } else if (UnmarshallerProperties.BEAN_VALIDATION_GROUPS.equals(key)) {
        return this.beanValidationGroups;
    } else if (UnmarshallerProperties.BEAN_VALIDATION_NO_OPTIMISATION.equals(key)) {
        return this.bvNoOptimisation;
    } else if (UnmarshallerProperties.DISABLE_SECURE_PROCESSING.equals(key)) {
        return xmlUnmarshaller.isSecureProcessingDisabled();
    } else if (UnmarshallerProperties.MOXY_LOG_PAYLOAD.equals(key)) {
        return xmlUnmarshaller.isLogPayload();
    }
    throw new PropertyException(key);
}
Also used : CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) HashMap(java.util.HashMap) PropertyException(jakarta.xml.bind.PropertyException) ObjectGraphImpl(org.eclipse.persistence.internal.jaxb.ObjectGraphImpl) PrefixMapperNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver) Entry(java.util.Map.Entry) IDResolverWrapper(org.eclipse.persistence.internal.jaxb.IDResolverWrapper)

Example 2 with CoreAttributeGroup

use of org.eclipse.persistence.core.queries.CoreAttributeGroup in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method processSubgraphs.

private Map<String, List<CoreAttributeGroup>> processSubgraphs(List<XmlNamedSubgraph> subgraphs) {
    Map<String, List<CoreAttributeGroup>> subgroups = new HashMap<>();
    // Iterate through once and create all the AttributeGroups
    for (XmlNamedSubgraph next : subgraphs) {
        String type = next.getType();
        if (type == null) {
            type = "java.lang.Object";
        }
        AttributeGroup group = new AttributeGroup(next.getName(), type, false);
        if (subgroups.containsKey(group.getName())) {
            List<CoreAttributeGroup> groups = subgroups.get(group.getName());
            groups.add(group);
        } else {
            List<CoreAttributeGroup> groups = new ArrayList<>(1);
            groups.add(group);
            subgroups.put(group.getName(), groups);
        }
    }
    // Iterate through a second time to populate the groups and set up links.
    for (XmlNamedSubgraph next : subgraphs) {
        List<XmlNamedAttributeNode> attributeNodes = next.getXmlNamedAttributeNode();
        List<CoreAttributeGroup> attributeGroups = subgroups.get(next.getName());
        if (attributeGroups != null) {
            for (CoreAttributeGroup group : attributeGroups) {
                String typeName = next.getType();
                if (typeName == null) {
                    typeName = "java.lang.Object";
                }
                if (group.getTypeName().equals(typeName)) {
                    for (XmlNamedAttributeNode attributeNode : attributeNodes) {
                        if (attributeNode.getSubgraph() == null || attributeNode.getSubgraph().length() == 0) {
                            group.addAttribute(attributeNode.getName());
                        } else {
                            List<CoreAttributeGroup> nestedGroups = subgroups.get(attributeNode.getSubgraph());
                            if (nestedGroups == null || nestedGroups.size() == 0) {
                            // TODO: Exception or check for root level ones on target class
                            } else {
                                group.addAttribute(attributeNode.getName(), nestedGroups.get(0));
                            }
                        }
                    }
                }
            }
        }
    }
    return subgroups;
}
Also used : CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) HashMap(java.util.HashMap) XmlNamedAttributeNode(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode) XmlNamedSubgraph(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph) AttributeGroup(org.eclipse.persistence.queries.AttributeGroup) CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 3 with CoreAttributeGroup

use of org.eclipse.persistence.core.queries.CoreAttributeGroup in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method setupAttributeGroups.

private void setupAttributeGroups(JavaClass javaClass) {
    TypeInfo info = this.typeInfo.get(javaClass.getQualifiedName());
    XMLDescriptor descriptor = (XMLDescriptor) info.getDescriptor();
    if (!info.getObjectGraphs().isEmpty()) {
        for (XmlNamedObjectGraph next : info.getObjectGraphs()) {
            AttributeGroup group = descriptor.getAttributeGroup(next.getName());
            Map<String, List<CoreAttributeGroup>> subgraphs = processSubgraphs(next.getXmlNamedSubgraph());
            for (XmlNamedAttributeNode nextAttributeNode : next.getXmlNamedAttributeNode()) {
                if (nextAttributeNode.getSubgraph() == null || nextAttributeNode.getSubgraph().length() == 0) {
                    group.addAttribute(nextAttributeNode.getName());
                } else {
                    List<CoreAttributeGroup> nestedGroups = subgraphs.get(nextAttributeNode.getSubgraph());
                    if (nestedGroups == null || nestedGroups.isEmpty()) {
                        Property property = info.getProperties().get(nextAttributeNode.getName());
                        if (property == null) {
                            // if there's no property associated with the attributeNode, just ignore it
                            continue;
                        }
                        JavaClass cls = property.getActualType();
                        TypeInfo referenceType = typeInfo.get(cls.getQualifiedName());
                        if (referenceType != null) {
                            AttributeGroup targetGroup = (AttributeGroup) referenceType.getDescriptor().getAttributeGroup(nextAttributeNode.getSubgraph());
                            group.addAttribute(nextAttributeNode.getName(), targetGroup);
                        } else {
                        // TODO: Exception
                        }
                    } else {
                        if (nestedGroups.size() == 1) {
                            group.addAttribute(nextAttributeNode.getName(), nestedGroups.get(0));
                        } else {
                            group.addAttribute(nextAttributeNode.getName(), nestedGroups);
                        }
                    }
                }
            }
            for (XmlNamedSubgraph nextSubclass : next.getXmlNamedSubclassGraph()) {
                AttributeGroup subclassGroup = new AttributeGroup(next.getName(), nextSubclass.getType(), true);
                group.getSubClassGroups().put(nextSubclass.getType(), subclassGroup);
                for (XmlNamedAttributeNode nextAttributeNode : nextSubclass.getXmlNamedAttributeNode()) {
                    if (nextAttributeNode.getSubgraph() == null || nextAttributeNode.getSubgraph().length() == 0) {
                        subclassGroup.addAttribute(nextAttributeNode.getName());
                    } else {
                        List<CoreAttributeGroup> nestedGroups = subgraphs.get(nextAttributeNode.getSubgraph());
                        if (nestedGroups == null || nestedGroups.isEmpty()) {
                            Property property = info.getProperties().get(nextAttributeNode.getName());
                            JavaClass cls = property.getActualType();
                            TypeInfo referenceType = typeInfo.get(cls.getQualifiedName());
                            if (referenceType != null) {
                                AttributeGroup targetGroup = (AttributeGroup) referenceType.getDescriptor().getAttributeGroup(nextAttributeNode.getSubgraph());
                                subclassGroup.addAttribute(nextAttributeNode.getName(), targetGroup);
                            } else {
                            // TODO: Exception
                            }
                        } else {
                            if (nestedGroups.size() == 1) {
                                subclassGroup.addAttribute(nextAttributeNode.getName(), nestedGroups.get(0));
                            } else {
                                subclassGroup.addAttribute(nextAttributeNode.getName(), nestedGroups);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) XmlNamedObjectGraph(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedObjectGraph) XmlNamedAttributeNode(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode) AttributeGroup(org.eclipse.persistence.queries.AttributeGroup) CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) XmlNamedSubgraph(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 4 with CoreAttributeGroup

use of org.eclipse.persistence.core.queries.CoreAttributeGroup in project eclipselink by eclipse-ee4j.

the class SAXUnmarshallerHandler method startElement.

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    try {
        String name;
        if (localName == null || localName.length() == 0) {
            name = qName;
        } else {
            name = localName;
        }
        XPathQName rootQName;
        if (namespaceURI == null || namespaceURI.length() == 0) {
            rootQName = new XPathQName(name, xmlReader.isNamespaceAware());
        } else {
            rootQName = new XPathQName(namespaceURI, name, xmlReader.isNamespaceAware());
        }
        Class<?> primitiveWrapperClass = null;
        Descriptor xmlDescriptor = xmlContext.getDescriptor(rootQName);
        // if no match on root element look for xsi:type
        if (xmlDescriptor == null || (unmarshaller.getMediaType() == MediaType.APPLICATION_JSON && unmarshaller.getJsonTypeConfiguration().getJsonTypeAttributeName() != null && !Constants.SCHEMA_TYPE_ATTRIBUTE.equals(unmarshaller.getJsonTypeConfiguration().getJsonTypeAttributeName()))) {
            boolean isPrimitiveType = false;
            String type = null;
            if (xmlReader.isNamespaceAware()) {
                type = atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.SCHEMA_TYPE_ATTRIBUTE);
            } else if (unmarshaller.getMediaType() != MediaType.APPLICATION_JSON || unmarshaller.getJsonTypeConfiguration().useJsonTypeCompatibility()) {
                type = atts.getValue(Constants.EMPTY_STRING, Constants.SCHEMA_TYPE_ATTRIBUTE);
            } else if (unmarshaller.getMediaType() == MediaType.APPLICATION_JSON && unmarshaller.getJsonTypeConfiguration().getJsonTypeAttributeName() != null) {
                type = atts.getValue(Constants.EMPTY_STRING, unmarshaller.getJsonTypeConfiguration().getJsonTypeAttributeName());
            }
            if (null != type) {
                XPathFragment typeFragment = new XPathFragment(type, xmlReader.getNamespaceSeparator(), xmlReader.isNamespaceAware());
                // set the prefix using a reverse key lookup by uri value on namespaceMap
                if (xmlReader.isNamespaceAware() && null != unmarshalNamespaceResolver) {
                    typeFragment.setNamespaceURI(unmarshalNamespaceResolver.getNamespaceURI(typeFragment.getPrefix()));
                }
                Descriptor lookupDescriptor = xmlContext.getDescriptorByGlobalType(typeFragment);
                if (lookupDescriptor == null) {
                    QName lookupQName = null;
                    if (typeFragment.getNamespaceURI() == null) {
                        lookupQName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, typeFragment.getLocalName());
                    } else {
                        lookupQName = new QName(typeFragment.getNamespaceURI(), typeFragment.getLocalName());
                    }
                    // check to see if type attribute represents simple type
                    if (null == session) {
                        session = (CoreAbstractSession) xmlContext.getSession();
                    }
                    ConversionManager conversionManager = (ConversionManager) session.getDatasourcePlatform().getConversionManager();
                    primitiveWrapperClass = conversionManager.javaType(lookupQName);
                } else {
                    // found descriptor based on type attribute
                    xmlDescriptor = lookupDescriptor;
                    session = xmlContext.getSession(xmlDescriptor);
                }
            }
        } else {
            if (null != xmlDescriptor.getDefaultRootElementField() && !unmarshaller.isResultAlwaysXMLRoot()) {
                String descLocalName = xmlDescriptor.getDefaultRootElementField().getXPathFragment().getLocalName();
                if (descLocalName != null && descLocalName.equals(localName)) {
                    String descUri = xmlDescriptor.getDefaultRootElementField().getXPathFragment().getNamespaceURI();
                    if (!xmlReader.isNamespaceAware() || (xmlReader.isNamespaceAware() && ((namespaceURI == null && descUri == null) || (namespaceURI != null && namespaceURI.length() == 0 && descUri == null) || (namespaceURI != null && namespaceURI.equals(descUri))))) {
                        // found a descriptor based on root element then know we won't need to wrap in an XMLRoot
                        shouldWrap = false;
                    }
                }
            }
            if (xmlDescriptor.hasInheritance()) {
                // if descriptor has inheritance check class indicator
                session = xmlContext.getSession(xmlDescriptor);
                UnmarshalRecord tmpUnmarshalRecord = new UnmarshalRecordImpl(null);
                tmpUnmarshalRecord.setUnmarshaller(unmarshaller);
                tmpUnmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
                tmpUnmarshalRecord.setXMLReader(this.getXMLReader());
                tmpUnmarshalRecord.setAttributes(atts);
                Class<?> classValue = xmlDescriptor.getInheritancePolicy().classFromRow(new org.eclipse.persistence.oxm.record.UnmarshalRecord(tmpUnmarshalRecord), session);
                if (classValue == null) {
                    // no xsi:type attribute - look for type indicator on the default root element
                    QName leafElementType = xmlDescriptor.getDefaultRootElementType();
                    // if we have a user-set type, try to get the class from the inheritance policy
                    if (leafElementType != null) {
                        Object indicator = xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementType);
                        if (indicator != null) {
                            classValue = (Class) indicator;
                        }
                    }
                }
                if (classValue != null) {
                    xmlDescriptor = (Descriptor) session.getDescriptor(classValue);
                } else {
                    // sure it is non-abstract
                    if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
                        // need to throw an exception here
                        throw DescriptorException.missingClassIndicatorField(tmpUnmarshalRecord, (org.eclipse.persistence.oxm.XMLDescriptor) xmlDescriptor.getInheritancePolicy().getDescriptor());
                    }
                }
            }
        }
        if (null == xmlDescriptor) {
            // check for a cached object and look for descriptor by class
            Object obj = this.xmlReader.getCurrentObject(session, null);
            if (obj != null) {
                xmlDescriptor = (Descriptor) xmlContext.getSession(obj.getClass()).getDescriptor(obj.getClass());
            }
        }
        if (null == xmlDescriptor && primitiveWrapperClass == null) {
            if (!this.keepAsElementPolicy.isKeepNoneAsElement()) {
                this.documentBuilder = new SAXDocumentBuilder();
                documentBuilder.startDocument();
                // start any prefixes that have already been started
                for (String prefix : this.unmarshalNamespaceResolver.getPrefixes()) {
                    documentBuilder.startPrefixMapping(prefix, this.unmarshalNamespaceResolver.getNamespaceURI(prefix));
                }
                documentBuilder.startElement(namespaceURI, localName, qName, atts);
                this.xmlReader.setContentHandler(documentBuilder);
                return;
            }
            Class<?> unmappedContentHandlerClass = unmarshaller.getUnmappedContentHandlerClass();
            if (null == unmappedContentHandlerClass) {
                throw XMLMarshalException.noDescriptorWithMatchingRootElement(rootQName.toString());
            } else {
                UnmappedContentHandler unmappedContentHandler;
                try {
                    PrivilegedNewInstanceFromClass privilegedNewInstanceFromClass = new PrivilegedNewInstanceFromClass(unmappedContentHandlerClass);
                    unmappedContentHandler = (UnmappedContentHandler) privilegedNewInstanceFromClass.run();
                } catch (ClassCastException e) {
                    throw XMLMarshalException.unmappedContentHandlerDoesntImplement(e, unmappedContentHandlerClass.getName());
                } catch (IllegalAccessException e) {
                    throw XMLMarshalException.errorInstantiatingUnmappedContentHandler(e, unmappedContentHandlerClass.getName());
                } catch (InstantiationException e) {
                    throw XMLMarshalException.errorInstantiatingUnmappedContentHandler(e, unmappedContentHandlerClass.getName());
                }
                UnmappedContentHandlerWrapper unmappedContentHandlerWrapper = new UnmappedContentHandlerWrapper(unmappedContentHandler, this);
                unmappedContentHandler.startElement(namespaceURI, localName, qName, atts);
                xmlReader.setContentHandler(unmappedContentHandler);
                setObject(unmappedContentHandlerWrapper.getCurrentObject());
                return;
            }
        }
        if (xmlDescriptor == null && primitiveWrapperClass != null) {
            session = xmlContext.getSession((Descriptor) null);
            rootRecord = unmarshaller.createRootUnmarshalRecord(primitiveWrapperClass);
            rootRecord.setSession((CoreAbstractSession) unmarshaller.getContext().getSession());
        } else {
            if (session == null) {
                session = xmlContext.getSession(xmlDescriptor);
            }
            rootRecord = unmarshaller.createUnmarshalRecord(xmlDescriptor, session);
        }
        this.descriptor = xmlDescriptor;
        rootRecord.setUnmarshaller(this.unmarshaller);
        rootRecord.setXMLReader(this.getXMLReader());
        if (locator != null) {
            rootRecord.setDocumentLocator(xmlReader.getLocator());
        }
        rootRecord.setAttributes(atts);
        boolean hasNilAttribute = (atts != null && null != atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.SCHEMA_NIL_ATTRIBUTE));
        rootRecord.setNil(isNil || hasNilAttribute);
        rootRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
        rootRecord.startDocument();
        rootRecord.initializeRecord(null);
        xmlReader.setContentHandler(rootRecord);
        xmlReader.setLexicalHandler(rootRecord);
        Object attributeGroup = this.unmarshaller.getUnmarshalAttributeGroup();
        if (attributeGroup != null) {
            if (attributeGroup.getClass() == CoreClassConstants.STRING) {
                CoreAttributeGroup group = descriptor.getAttributeGroup((String) attributeGroup);
                if (group != null) {
                    rootRecord.setUnmarshalAttributeGroup(group);
                } else {
                // Error
                }
            } else if (attributeGroup instanceof CoreAttributeGroup) {
                rootRecord.setUnmarshalAttributeGroup((CoreAttributeGroup) attributeGroup);
            } else {
            // Error case
            }
        }
        rootRecord.startElement(namespaceURI, localName, qName, atts);
    // if we located the descriptor via xsi:type attribute, create and
    // return an XMLRoot object
    } catch (EclipseLinkException e) {
        if (null == xmlReader.getErrorHandler()) {
            throw e;
        } else {
            SAXParseException saxParseException = new SAXParseException(null, null, null, 0, 0, e);
            xmlReader.getErrorHandler().error(saxParseException);
        }
    }
}
Also used : CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) SAXParseException(org.xml.sax.SAXParseException) ConversionManager(org.eclipse.persistence.internal.oxm.ConversionManager) UnmappedContentHandler(org.eclipse.persistence.internal.oxm.unmapped.UnmappedContentHandler) XPathQName(org.eclipse.persistence.internal.oxm.XPathQName) QName(javax.xml.namespace.QName) XPathQName(org.eclipse.persistence.internal.oxm.XPathQName) SAXDocumentBuilder(org.eclipse.persistence.platform.xml.SAXDocumentBuilder) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor)

Example 5 with CoreAttributeGroup

use of org.eclipse.persistence.core.queries.CoreAttributeGroup in project eclipselink by eclipse-ee4j.

the class XPathNode method marshal.

public boolean marshal(MarshalRecord marshalRecord, Object object, CoreAbstractSession session, NamespaceResolver namespaceResolver, Marshaller marshaller, MarshalContext marshalContext, XPathFragment rootFragment) {
    if ((null == marshalNodeValue) || isMarshalOnlyNodeValue) {
        if (marshalRecord.isWrapperAsCollectionName() && null != nonAttributeChildren && nonAttributeChildren.size() == 1) {
            XPathNode childXPathNode = nonAttributeChildren.get(0);
            NodeValue childXPathNodeUnmarshalNodeValue = childXPathNode.getUnmarshalNodeValue();
            if (childXPathNodeUnmarshalNodeValue != null && childXPathNodeUnmarshalNodeValue.isContainerValue()) {
                ContainerValue containerValue = (ContainerValue) childXPathNodeUnmarshalNodeValue;
                if (containerValue.isWrapperAllowedAsCollectionName()) {
                    XPathNode wrapperXPathNode = new XPathNode();
                    wrapperXPathNode.setXPathFragment(this.getXPathFragment());
                    wrapperXPathNode.setMarshalNodeValue(childXPathNode.getMarshalNodeValue());
                    return wrapperXPathNode.marshal(marshalRecord, object, session, namespaceResolver, marshaller, marshalContext, rootFragment);
                }
            }
        }
        marshalRecord.addGroupingElement(this);
        boolean hasValue = false;
        if (null != attributeChildren) {
            for (int x = 0, size = attributeChildren.size(); x < size; x++) {
                XPathNode xPathNode = attributeChildren.get(x);
                hasValue = xPathNode.marshal(marshalRecord, object, session, namespaceResolver, marshaller, ObjectMarshalContext.getInstance(), this.xPathFragment) || hasValue;
            }
        }
        if (anyAttributeNode != null) {
            hasValue = anyAttributeNode.marshal(marshalRecord, object, session, namespaceResolver, marshaller, ObjectMarshalContext.getInstance(), null) || hasValue;
        }
        if (null == nonAttributeChildren) {
            if (textNode != null) {
                hasValue = textNode.marshal(marshalRecord, object, session, namespaceResolver, marshaller, ObjectMarshalContext.getInstance(), null) || hasValue;
            }
        } else {
            for (int x = 0, size = marshalContext.getNonAttributeChildrenSize(this); x < size; x++) {
                XPathNode xPathNode = (XPathNode) marshalContext.getNonAttributeChild(x, this);
                MarshalContext childMarshalContext = marshalContext.getMarshalContext(x);
                hasValue = xPathNode.marshal(marshalRecord, object, session, namespaceResolver, marshaller, childMarshalContext, this.xPathFragment) || hasValue;
            }
        }
        if (hasValue) {
            marshalRecord.endElement(xPathFragment, namespaceResolver);
        } else {
            marshalRecord.removeGroupingElement(this);
        }
        return hasValue;
    } else {
        if (marshalNodeValue.isMappingNodeValue()) {
            Mapping mapping = ((MappingNodeValue) marshalNodeValue).getMapping();
            CoreAttributeGroup currentGroup = marshalRecord.getCurrentAttributeGroup();
            if (!(currentGroup.containsAttributeInternal(mapping.getAttributeName()))) {
                return false;
            }
        }
        return marshalContext.marshal(marshalNodeValue, xPathFragment, marshalRecord, object, session, namespaceResolver, rootFragment);
    }
}
Also used : ObjectMarshalContext(org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext) MarshalContext(org.eclipse.persistence.internal.oxm.record.MarshalContext) CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping)

Aggregations

CoreAttributeGroup (org.eclipse.persistence.core.queries.CoreAttributeGroup)18 QName (javax.xml.namespace.QName)6 CoreAttributeItem (org.eclipse.persistence.core.queries.CoreAttributeItem)6 List (java.util.List)5 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)4 AttributeItem (org.eclipse.persistence.internal.queries.AttributeItem)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)2 Field (org.eclipse.persistence.internal.oxm.mappings.Field)2 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)2 UnmarshalKeepAsElementPolicy (org.eclipse.persistence.internal.oxm.mappings.UnmarshalKeepAsElementPolicy)2 PrefixMapperNamespaceResolver (org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver)2 XmlNamedAttributeNode (org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode)2 XmlNamedSubgraph (org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph)2 AttributeGroup (org.eclipse.persistence.queries.AttributeGroup)2 Node (org.w3c.dom.Node)2 PropertyException (jakarta.xml.bind.PropertyException)1 Entry (java.util.Map.Entry)1