Search in sources :

Example 1 with TreeObjectBuilder

use of org.eclipse.persistence.internal.oxm.TreeObjectBuilder in project eclipselink by eclipse-ee4j.

the class LazyInitTestCases method testTreeObjectBuilder.

public void testTreeObjectBuilder() throws Exception {
    JAXBContext jc = JAXBContextFactory.createContext(new Class<?>[] { Root.class }, null);
    XMLDescriptor xmlDescriptor = JAXBHelper.getJAXBContext(jc).getXMLContext().getDescriptor(new QName("root"));
    TreeObjectBuilder treeObjectBuilder = (TreeObjectBuilder) xmlDescriptor.getObjectBuilder();
    assertNull(getFieldValue(TreeObjectBuilder.class, "readOnlyMappingsByField", treeObjectBuilder));
    assertNull(getFieldValue(TreeObjectBuilder.class, "mappingsByAttribute", treeObjectBuilder));
    assertNull(getFieldValue(TreeObjectBuilder.class, "primaryKeyMappings", treeObjectBuilder));
    assertNull(getFieldValue(TreeObjectBuilder.class, "nonPrimaryKeyMappings", treeObjectBuilder));
    assertNull(getFieldValue(TreeObjectBuilder.class, "eagerMappings", treeObjectBuilder));
    assertNull(getFieldValue(TreeObjectBuilder.class, "relationshipMappings", treeObjectBuilder));
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) TreeObjectBuilder(org.eclipse.persistence.internal.oxm.TreeObjectBuilder) QName(javax.xml.namespace.QName) JAXBContext(jakarta.xml.bind.JAXBContext)

Example 2 with TreeObjectBuilder

use of org.eclipse.persistence.internal.oxm.TreeObjectBuilder in project eclipselink by eclipse-ee4j.

the class SDOUnmappedContentHandler method giveToOXToProcess.

private void giveToOXToProcess(String namespaceURI, String localName, String qName, Attributes atts, XMLDescriptor xmlDescriptor) throws SAXException {
    AbstractSession session = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().getReadSession(xmlDescriptor);
    // taken from SAXUnmarshallerHandler start Element
    UnmarshalRecord unmarshalRecord;
    if (xmlDescriptor.hasInheritance()) {
        unmarshalRecord = new UnmarshalRecord((TreeObjectBuilder) xmlDescriptor.getObjectBuilder());
        unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
        unmarshalRecord.setAttributes(atts);
        if (parentRecord != null) {
            unmarshalRecord.setXMLReader(parentRecord.getXMLReader());
        }
        Class<?> classValue = xmlDescriptor.getInheritancePolicy().classFromRow(unmarshalRecord, 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 = (XMLDescriptor) session.getDescriptor(classValue);
        } else {
            // sure it is non-abstract
            if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
                // need to throw an exception here
                throw DescriptorException.missingClassIndicatorField((XMLRecord) unmarshalRecord, xmlDescriptor.getInheritancePolicy().getDescriptor());
            }
        }
    }
    unmarshalRecord = (UnmarshalRecord) xmlDescriptor.getObjectBuilder().createRecord(session);
    unmarshalRecord.setParentRecord(parentRecord);
    unmarshalRecord.setUnmarshaller(parentRecord.getUnmarshaller());
    unmarshalRecord.setXMLReader(parentRecord.getXMLReader());
    unmarshalRecord.startDocument();
    unmarshalRecord.setUnmarshalNamespaceResolver(unmarshalNamespaceResolver);
    unmarshalRecord.startElement(namespaceURI, localName, qName, atts);
    parentRecord.getXMLReader().setContentHandler(unmarshalRecord);
    try {
        unmarshalRecord.getXMLReader().setProperty("http://xml.org/sax/properties/lexical-handler", unmarshalRecord);
    } catch (SAXNotRecognizedException ex) {
    } catch (SAXNotSupportedException ex) {
    // if lexical handling is not supported by this parser, just ignore.
    }
    currentDataObjects.push(unmarshalRecord.getCurrentObject());
    depth++;
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) TreeObjectBuilder(org.eclipse.persistence.internal.oxm.TreeObjectBuilder) QName(javax.xml.namespace.QName) UnmarshalRecord(org.eclipse.persistence.oxm.record.UnmarshalRecord) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 3 with TreeObjectBuilder

use of org.eclipse.persistence.internal.oxm.TreeObjectBuilder in project eclipselink by eclipse-ee4j.

the class JAXBValueStore method getJAXBMappingForProperty.

/**
 * Return the JAXB mapping for the SDO property.  They are matched
 * on their XML schema representation.
 */
Mapping getJAXBMappingForProperty(SDOProperty sdoProperty) {
    DatabaseMapping sdoMapping = sdoProperty.getXmlMapping();
    XMLField field;
    if (sdoMapping instanceof XMLObjectReferenceMapping) {
        XMLObjectReferenceMapping referenceMapping = (XMLObjectReferenceMapping) sdoMapping;
        field = (XMLField) referenceMapping.getFields().get(0);
    } else {
        field = (XMLField) sdoMapping.getField();
    }
    TreeObjectBuilder treeObjectBuilder = (TreeObjectBuilder) descriptor.getObjectBuilder();
    XPathNode xPathNode = treeObjectBuilder.getRootXPathNode();
    XPathFragment xPathFragment = field.getXPathFragment();
    while (xPathNode != null && xPathFragment != null) {
        if (xPathFragment.isAttribute()) {
            if (sdoProperty.isMany() && !sdoProperty.isContainment() && !sdoProperty.getType().isDataType()) {
                xPathFragment = null;
                break;
            }
            Map<XPathFragment, XPathNode> attributeChildrenMap = xPathNode.getAttributeChildrenMap();
            if (null == attributeChildrenMap) {
                xPathNode = null;
            } else {
                xPathNode = attributeChildrenMap.get(xPathFragment);
            }
        } else if (xPathFragment.nameIsText()) {
            xPathNode = xPathNode.getTextNode();
        } else {
            Map<XPathFragment, XPathNode> nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap();
            if (null == nonAttributeChildrenMap) {
                xPathNode = null;
            } else {
                xPathNode = nonAttributeChildrenMap.get(xPathFragment);
            }
        }
        xPathFragment = xPathFragment.getNextFragment();
        if (xPathFragment != null && xPathFragment.nameIsText()) {
            if (sdoProperty.isMany() && !sdoProperty.isContainment()) {
                xPathFragment = null;
                break;
            }
        }
    }
    if (null == xPathFragment && xPathNode != null) {
        if (xPathNode.getNodeValue().isMappingNodeValue()) {
            MappingNodeValue mappingNodeValue = (MappingNodeValue) xPathNode.getNodeValue();
            return mappingNodeValue.getMapping();
        }
    }
    throw SDOException.sdoJaxbNoMappingForProperty(sdoProperty.getName(), field.getXPath());
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) TreeObjectBuilder(org.eclipse.persistence.internal.oxm.TreeObjectBuilder) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) MappingNodeValue(org.eclipse.persistence.internal.oxm.MappingNodeValue) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) XPathNode(org.eclipse.persistence.internal.oxm.XPathNode)

Aggregations

TreeObjectBuilder (org.eclipse.persistence.internal.oxm.TreeObjectBuilder)3 QName (javax.xml.namespace.QName)2 DataObject (commonj.sdo.DataObject)1 JAXBContext (jakarta.xml.bind.JAXBContext)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 MappingNodeValue (org.eclipse.persistence.internal.oxm.MappingNodeValue)1 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)1 XPathNode (org.eclipse.persistence.internal.oxm.XPathNode)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)1 UnmarshalRecord (org.eclipse.persistence.oxm.record.UnmarshalRecord)1 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)1 SAXNotRecognizedException (org.xml.sax.SAXNotRecognizedException)1 SAXNotSupportedException (org.xml.sax.SAXNotSupportedException)1