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));
}
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++;
}
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());
}
Aggregations