本文整理了Java中org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping
类的一些代码示例,展示了XMLCompositeDirectCollectionMapping
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLCompositeDirectCollectionMapping
类的具体详情如下:
包路径:org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping
类名称:XMLCompositeDirectCollectionMapping
[英]Composite direct collection XML mappings map a collection of simple types (String, Number, Date, etc.) to and from a sequence of composite XML nodes.
Composite direct collection XML mappings can be used in the following scenarios:
Setting the XPath: TopLink XML mappings make use of an XPath statement to find the relevant data in an XML document. The XPath statement is relative to the context node specified in the descriptor. The XPath may contain node type, path, and positional information. The XPath is specified on the mapping using the setXPath
method.
The following XPath statements may be used to specify the location of XML data relating to an object's name attribute:
XPathDescription@tasksThe "@" character indicates that the node is an attribute. This XPath applies only to the single attribute node case; each member of the collection is mapped to a single node.tasks/@taskThe "@" character indicates that the node is an attribute. The information is stored in the attribute node of the tasks element.text()"text()" indicates that the node is a text node. In this case the task value in the text node belongs to the context node.tasks/text()The task information is stored in the text node of the tasks element.tasks/task/text()The XPath statement may be used to specify any valid path.task[2]/text()The XPath statement may contain positional information. In this case the task information is stored in the text node of the second occurrence of the task element.
Mapping to a Single Text Node: By default, TopLink maps each member of a collection to it's own node. It is possible, however, to mapping a collection to a single node; here the contents of the node is treated as a space-separated list. This behavior is set on the mapping using the setUsesSingleNode
method, with 'true' as the parameter.
XML Schema<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="employee" type="employee-type"/> <xsd:complexType name="employee-type"> <xsd:sequence> <xsd:element name="tasks" type="tasks-type"/> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="tasks-type"> <xsd:list itemType="xsd:string"/> </xsd:simpleType> </xsd:schema>
Code SampleXMLCompositeDirectCollectionMapping tasksMapping = new XMLCompositeDirectCollectionMapping(); tasksMapping.setAttributeName("tasks"); tasksMapping.setXPath("tasks/text()"); tasksMapping.setUsesSingleNode(true);
Specifying the Content Type of a Collection: By default, TopLink will treat the node values read in by a composite direct collection XML mapping as objects of type String. You can override this behavior by specifying the type of the collection's contents.
XML Schema<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="employee" type="employee-type"/> <xsd:complexType name="employee-type"> <xsd:sequence> <xsd:element name="vacation" type="xsd:string" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
Code SampleXMLCompositeDirectCollectionMapping tasksMapping = new XMLCompositeDirectCollectionMapping(); tasksMapping.setAttributeName("vacationDays"); tasksMapping.setXPath("vacation/text()"); tasksMapping.setAttributeElementClass(Calendar.class);
Mapping to a List of Unions:
XML Schema<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="vacation" type="listOfUnions"/> <xsd:simpleType name="listOfUnions"> <xsd:list> <xsd:simpleType> <xsd:union memberTypes="xsd:date xsd:integer"/> </xsd:simpleType> </xsd:list> </xsd:simpleType> </xsd:schema>
Code SampleXMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping(); mapping.setAttributeName("myattribute"); XMLUnionField field = new XMLUnionField("listOfUnions/text()"); mapping.addSchemaType(new QName(url,XMLConstants.INT)); mapping.addSchemaType(new QName(url,XMLConstants.DATE)); mapping.setField(field); mapping.useSingleElement(false);
More Information: For more information about using the XML Composite Direct Collection Mapping, see the "Understanding XML Mappings" chapter of the Oracle TopLink Developer's Guide.
[中]复合直接集合XML映射将简单类型(字符串、数字、日期等)的集合映射到复合XML节点序列,并从中映射。
复合直接收集XML映射可用于以下场景:
*映射到多个文本节点
*映射到多个属性
*映射到单个文本节点
*映射到单个属性
*映射到联合列表
*映射列表的并集
*指定集合的内容类型
设置XPath:TopLink XML映射使用XPath语句在XML文档中查找相关数据。XPath语句与描述符中指定的上下文节点相关。XPath可能包含节点类型、路径和位置信息。XPath是使用setXPath
方法在映射上指定的。
以下XPath语句可用于指定与对象名称属性相关的XML数据的位置:
XPathDescription@tasksThe“@”字符表示节点是一个属性。此XPath仅适用于单属性节点情况;集合的每个成员都映射到单个节点。tasks/@task“@”字符表示节点是一个属性。信息存储在tasks元素的属性节点中。text()“text()”表示该节点是文本节点。在这种情况下,文本节点中的任务值属于上下文节点。tasks/text()任务信息存储在tasks元素的text节点中。tasks/task/text()XPath语句可用于指定任何有效路径。任务[2]/text()XPath语句可能包含位置信息。在这种情况下,任务信息存储在任务元素第二次出现的文本节点中。
映射到单个文本节点:默认情况下,TopLink将集合的每个成员映射到它自己的节点。但是,可以将集合映射到单个节点;在这里,节点的内容被视为一个以空格分隔的列表。此行为是使用setUsesSingleNode
方法在映射上设置的,参数为“true”。
XML模式<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="employee" type="employee-type"/> <xsd:complexType name="employee-type"> <xsd:sequence> <xsd:element name="tasks" type="tasks-type"/> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="tasks-type"> <xsd:list itemType="xsd:string"/> </xsd:simpleType> </xsd:schema>
代码示例XMLCompositeDirectCollectionMapping tasksMapping = new XMLCompositeDirectCollectionMapping(); tasksMapping.setAttributeName("tasks"); tasksMapping.setXPath("tasks/text()"); tasksMapping.setUsesSingleNode(true);
指定集合的内容类型:默认情况下,TopLink将把复合直接集合XML映射读入的节点值视为String类型的对象。可以通过指定集合内容的类型来覆盖此行为。
XML模式<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="employee" type="employee-type"/> <xsd:complexType name="employee-type"> <xsd:sequence> <xsd:element name="vacation" type="xsd:string" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
代码示例XMLCompositeDirectCollectionMapping tasksMapping = new XMLCompositeDirectCollectionMapping(); tasksMapping.setAttributeName("vacationDays"); tasksMapping.setXPath("vacation/text()"); tasksMapping.setAttributeElementClass(Calendar.class);
映射到工会列表:
XML模式<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="vacation" type="listOfUnions"/> <xsd:simpleType name="listOfUnions"> <xsd:list> <xsd:simpleType> <xsd:union memberTypes="xsd:date xsd:integer"/> </xsd:simpleType> </xsd:list> </xsd:simpleType> </xsd:schema>
代码示例XMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping(); mapping.setAttributeName("myattribute"); XMLUnionField field = new XMLUnionField("listOfUnions/text()"); mapping.addSchemaType(new QName(url,XMLConstants.INT)); mapping.addSchemaType(new QName(url,XMLConstants.DATE)); mapping.setField(field); mapping.useSingleElement(false);
更多信息:有关使用XML复合直接集合映射的更多信息,请参阅《Oracle TopLink开发人员指南》的“理解XML映射”一章。
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
/**
* INTERNAL:
*/
protected XMLCompositeDirectCollectionMapping getResultClasses() {
XMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping();
mapping.setAttributeName("m_resultClassNames");
mapping.setGetMethodName("getResultClassNames");
mapping.setSetMethodName("setResultClassNames");
mapping.setXPath("orm:result-class");
return mapping;
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
public void writeSingleValue(Object value, Object parent, XMLRecord record, AbstractSession session) {
Object element = value;
if (hasValueConverter()) {
if (getValueConverter() instanceof XMLConverter) {
element = ((XMLConverter) getValueConverter()).convertObjectValueToDataValue(element, session, record.getMarshaller());
} else {
element = getValueConverter().convertObjectValueToDataValue(element, session);
}
}
record.add(this.getField(), element);
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
/**
* PUBLIC:
* Allows the user to indicate that this mapping should also allow for mixed content in addition to
* any of the elements in the choice. The grouping element parameter is used in the case that there is
* a common grouping element to all the other elements in this choice. If so, that grouping element can
* be specified here to allow the mixed content to be written/detected inside the wrapper element.
* @since EclipseLink 2.3.1
*/
public void setMixedContent(String groupingElement) {
isMixedContent = true;
String xpath = groupingElement;
if(groupingElement.length() == 0) {
xpath = "text()";
} else {
xpath += "/" + "text()";
}
XMLField field = new XMLField(xpath);
XMLCompositeDirectCollectionMapping xmlMapping = new XMLCompositeDirectCollectionMapping();
Class theClass = ClassConstants.STRING;
xmlMapping.setAttributeElementClass(theClass);
xmlMapping.setField(field);
xmlMapping.setAttributeAccessor(temporaryAccessor);
this.mixedContentMapping = xmlMapping;
this.choiceElementMappings.put(field, xmlMapping);
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
public void preInitialize(AbstractSession session) throws DescriptorException {
getAttributeAccessor().setIsWriteOnly(this.isWriteOnly());
getAttributeAccessor().setIsReadOnly(this.isReadOnly());
super.preInitialize(session);
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
private XMLDescriptor buildAnnotationDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Annotation.class);
descriptor.setNamespaceResolver(namespaceResolver);
XMLCompositeDirectCollectionMapping documentationMapping = new XMLCompositeDirectCollectionMapping();
documentationMapping.setAttributeName("documentation");
documentationMapping.useCollectionClass(ArrayList.class);
documentationMapping.setXPath(Constants.SCHEMA_PREFIX + ":" + "documentation");
((XMLField)documentationMapping.getField()).setUsesSingleNode(false);
descriptor.addMapping(documentationMapping);
XMLFragmentCollectionMapping appInfoMapping = new XMLFragmentCollectionMapping();
appInfoMapping.setAttributeName("appInfo");
appInfoMapping.setXPath(Constants.SCHEMA_PREFIX + ":" + "appinfo");
appInfoMapping.useCollectionClass(java.util.ArrayList.class);
descriptor.addMapping(appInfoMapping);
return descriptor;
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
descriptor.getInheritancePolicy().addClassIndicator(DescriptorEventManager.class, getPrimaryNamespaceXPath() + "event-policy");
XMLCompositeDirectCollectionMapping eventListenersMapping = new XMLCompositeDirectCollectionMapping();
eventListenersMapping.setAttributeName("eventListeners");
eventListenersMapping.setGetMethodName("getEventListeners");
eventListenersMapping.setSetMethodName("setEventListeners");
eventListenersMapping.useCollectionClass(org.eclipse.persistence.internal.helper.NonSynchronizedVector.class);
eventListenersMapping.setValueConverter(new ClassInstanceConverter());
eventListenersMapping.setXPath(getSecondaryNamespaceXPath() + "event-listeners/" + getSecondaryNamespaceXPath() + "event-listener/text()");
descriptor.addMapping(eventListenersMapping);
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
private DatabaseMapping buildXMLCompositeDirectCollectionMapping(String mappingUri) {
XMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping();
mapping.setAttributeName(getName());
String xpath = getQualifiedXPath(mappingUri, true);
mapping.setXPath(xpath);
mapping.setAttributeElementClass(getType().getInstanceClass());
if (getXsdType() != null) {
((XMLField)mapping.getField()).setSchemaType(getXsdType());
}
if (getType().equals(SDOConstants.SDO_STRINGS)) {
mapping.setUsesSingleNode(true);
}
if (getType().getInstanceClass() != null) {
if (shouldAddInstanceClassConverter()) {
InstanceClassConverter converter = new InstanceClassConverter();
converter.setCustomClass(getType().getInstanceClass());
mapping.setValueConverter(converter);
}
}
return mapping;
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
protected ClassDescriptor buildIsSetNullPolicyDescriptor() {
// The IsSetPerformedForAbsentNode flag is always false on this IsSet mapping
XMLDescriptor aDescriptor = new XMLDescriptor();
aDescriptor.setJavaClass(IsSetNullPolicy.class);
aDescriptor.getInheritancePolicy().setParentClass(AbstractNullPolicy.class);
XMLDirectMapping isSetMethodNameMapping = new XMLDirectMapping();
isSetMethodNameMapping.setAttributeName("isSetMethodName");
isSetMethodNameMapping.setXPath(getPrimaryNamespaceXPath() + "is-set-method-name/text()");
aDescriptor.addMapping(isSetMethodNameMapping);
// 20070922: Bug#6039730 - add IsSet capability for 1+ parameters for SDO
XMLCompositeDirectCollectionMapping isSetParameterTypesMapping = new XMLCompositeDirectCollectionMapping();
isSetParameterTypesMapping.setAttributeName("isSetParameterTypes");
isSetParameterTypesMapping.setXPath(getPrimaryNamespaceXPath() + "is-set-parameter-type");
((DatabaseMapping)isSetParameterTypesMapping).setAttributeAccessor(new IsSetNullPolicyIsSetParameterTypesAttributeAccessor());
aDescriptor.addMapping(isSetParameterTypesMapping);
XMLCompositeDirectCollectionMapping isSetParametersMapping = new XMLCompositeDirectCollectionMapping();
isSetParametersMapping.setAttributeName("isSetParameters");
isSetParametersMapping.setXPath(getPrimaryNamespaceXPath() + "is-set-parameter");
((DatabaseMapping)isSetParametersMapping).setAttributeAccessor(new IsSetNullPolicyIsSetParametersAttributeAccessor());
aDescriptor.addMapping(isSetParametersMapping);
return aDescriptor;
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
private XMLDescriptor buildUnionDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Union.class);
descriptor.setNamespaceResolver(namespaceResolver);
XMLCompositeDirectCollectionMapping memberTypeMapping = new XMLCompositeDirectCollectionMapping();
memberTypeMapping.setAttributeName("memberTypes");
memberTypeMapping.setXPath("@memberTypes");
memberTypeMapping.setUsesSingleNode(true);
descriptor.addMapping(memberTypeMapping);
XMLCompositeCollectionMapping simpleTypesMapping = new XMLCompositeCollectionMapping();
simpleTypesMapping.setReferenceClass(SimpleType.class);
simpleTypesMapping.setAttributeName("simpleTypes");
simpleTypesMapping.setXPath(Constants.SCHEMA_PREFIX + ":" + "simpleType");
descriptor.addMapping(simpleTypesMapping);
return descriptor;
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
if (this.isReadOnly()) {
return;
Object attributeValue = this.getAttributeValueFromObject(object);
if (attributeValue == null) {
row.put(this.getField(), null);
return;
ContainerPolicy cp = this.getContainerPolicy();
while (cp.hasNext(iter)) {
Object element = cp.next(iter, session);
element = convertObjectValueToDataValue(element, session, ((XMLRecord) row).getMarshaller());
} else if(!usesSingleNode()){
AbstractNullPolicy nullPolicy = getNullPolicy();
if (nullPolicy == null) {
elements.addElement(null);
fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session);
row.put(this.getField(), fieldValue);
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
if (this.isReadOnly()) {
return;
Object attributeValue = this.getAttributeValueFromObject(object);
if (attributeValue == null) {
row.put(this.getField(), null);
return;
ContainerPolicy cp = this.getContainerPolicy();
if (hasValueConverter()) {
if (getValueConverter() instanceof XMLConverter) {
element = ((XMLConverter) getValueConverter()).convertObjectValueToDataValue(element, session, ((XMLRecord) row).getMarshaller());
} else {
element = getValueConverter().convertObjectValueToDataValue(element, session);
elements.addElement(element);
} else {
if (getNullPolicy() == null) {
elements.addElement(null);
} else {
if (getNullPolicy().getMarshalNullRepresentation() == XMLNullRepresentationType.XSI_NIL) {
elements.addElement(XMLRecord.NIL);
} else if (getNullPolicy().getMarshalNullRepresentation() == XMLNullRepresentationType.ABSENT_NODE) {
fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session);
row.put(this.getField(), fieldValue);
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
protected ClassDescriptor buildFetchGroupDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(FetchGroup.class);
descriptor.setDefaultRootElement("fetch-group");
XMLDirectMapping fetchGroupNameMapping = new XMLDirectMapping();
fetchGroupNameMapping.setAttributeName("name");
fetchGroupNameMapping.setXPath(getPrimaryNamespaceXPath() + "name");
descriptor.addMapping(fetchGroupNameMapping);
XMLCompositeDirectCollectionMapping fetchGroupAttributeMapping = new XMLCompositeDirectCollectionMapping();
CollectionContainerPolicy containerPolicy = new CollectionContainerPolicy(TreeSet.class);
fetchGroupAttributeMapping.setContainerPolicy(containerPolicy);
fetchGroupAttributeMapping.setAttributeName("attributes");
fetchGroupAttributeMapping.setXPath(getPrimaryNamespaceXPath() + "fetch-group-attributes/" + getPrimaryNamespaceXPath() + "fetch-group-attribute/text()");
descriptor.addMapping(fetchGroupAttributeMapping);
return descriptor;
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.dbws
/**
* Build an XMLDescriptor for BatchQueryOperation.
*/
protected XMLDescriptor buildBatchQueryDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(BatchQueryOperation.class);
descriptor.setDefaultRootElement("batch-sql-query");
XMLDirectMapping name = new XMLDirectMapping();
name.setAttributeName("name");
name.setXPath("name/text()");
descriptor.addMapping(name);
XMLCompositeDirectCollectionMapping statementsMapping = new XMLCompositeDirectCollectionMapping();
statementsMapping.setAttributeName("batchSql");
XMLField f1 = new XMLField("batch-statement/text()");
f1.setIsCDATA(true);
statementsMapping.setField(f1);
descriptor.addMapping(statementsMapping);
return descriptor;
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
ContainerPolicy cp = this.getContainerPolicy();
Object fieldValue = domRecord.getValues(this.getField(), this.getNullPolicy());
if (fieldValue == null) {
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
return container != null ? container : cp.containerInstance();
} else {
Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue);
if (fieldValues == null) {
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
return container != null ? container : cp.containerInstance();
} else {
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
result = container != null ? container : cp.containerInstance();
} else {
if (hasValueConverter()) {
if (getValueConverter() instanceof XMLConverter) {
element = ((XMLConverter) getValueConverter()).convertDataValueToObjectValue(element, executionSession, ((XMLRecord) row).getUnmarshaller());
} else {
element = getValueConverter().convertDataValueToObjectValue(element, executionSession);
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
ContainerPolicy cp = this.getContainerPolicy();
Object fieldValue = domRecord.getValues(this.getField(), this.getNullPolicy());
if (fieldValue == null) {
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
return container != null ? container : cp.containerInstance();
} else {
Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue);
if (fieldValues == null) {
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
return container != null ? container : cp.containerInstance();
} else {
if (reuseContainer) {
Object currentObject = ((XMLRecord) row).getCurrentObject();
Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
result = container != null ? container : cp.containerInstance();
} else {
element = convertDataValueToObjectValue(element, executionSession, ((XMLRecord) row).getUnmarshaller());
if (element != null && element.getClass() == ClassConstants.STRING) {
if (isCollapsingStringValues) {
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
if (xmlCompositeDirectCollectionMapping.isReadOnly()) {
return false;
Object collection = xmlCompositeDirectCollectionMapping.getAttributeAccessor().getAttributeValueFromObject(object);
if (null == collection) {
return false;
String newValue;
QName schemaType;
if (xmlCompositeDirectCollectionMapping.usesSingleNode()) {
while (cp.hasNext(iterator)) {
objectValue = cp.next(iterator, session);
if (xmlCompositeDirectCollectionMapping.hasValueConverter()) {
if (xmlCompositeDirectCollectionMapping.getValueConverter() instanceof XMLConverter) {
objectValue = ((XMLConverter) xmlCompositeDirectCollectionMapping.getValueConverter()).convertObjectValueToDataValue(objectValue, session, marshalRecord.getMarshaller());
} else {
objectValue = xmlCompositeDirectCollectionMapping.getValueConverter().convertObjectValueToDataValue(objectValue, session);
schemaType = getSchemaType((XMLField) xmlCompositeDirectCollectionMapping.getField(), objectValue, session);
newValue = getValueToWrite(schemaType, objectValue, (XMLConversionManager) session.getDatasourcePlatform().getConversionManager(), namespaceResolver);
if (null != newValue) {
} else {
marshalRecord.closeStartGroupingElements(groupingFragment);
if (xmlCompositeDirectCollectionMapping.isCDATA()) {
marshalRecord.cdata(stringValue);
} else {
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
private void addChoiceElementMapping(XMLField xmlField, String className){
if (xmlField.getLastXPathFragment().nameIsText() || xmlField.getLastXPathFragment().isAttribute()) {
XMLCompositeDirectCollectionMapping xmlMapping = new XMLCompositeDirectCollectionMapping();
xmlMapping.setAttributeElementClassName(className);
xmlMapping.setField(xmlField);
xmlMapping.setAttributeAccessor(temporaryAccessor);
this.choiceElementMappings.put(xmlField, xmlMapping);
this.choiceElementMappingsByClassName.put(className, xmlMapping);
} else {
if(isBinaryType(className)) {
XMLBinaryDataCollectionMapping xmlMapping = new XMLBinaryDataCollectionMapping();
xmlMapping.setField(xmlField);
xmlMapping.setAttributeAccessor(temporaryAccessor);
Class theClass = XMLConversionManager.getDefaultXMLManager().convertClassNameToClass(className);
xmlMapping.setAttributeElementClass(theClass);
this.choiceElementMappings.put(xmlField, xmlMapping);
this.choiceElementMappingsByClassName.put(className, xmlMapping);
} else {
XMLCompositeCollectionMapping xmlMapping = new XMLCompositeCollectionMapping();
if(!className.equals("java.lang.Object")){
xmlMapping.setReferenceClassName(className);
}
xmlMapping.setField(xmlField);
xmlMapping.setAttributeAccessor(temporaryAccessor);
this.choiceElementMappings.put(xmlField, xmlMapping);
this.choiceElementMappingsByClassName.put(className, xmlMapping);
}
}
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
private void addUnmarshalValue(UnmarshalRecord unmarshalRecord, Object value, Object collection) {
if (null == value) {
return;
}
if (xmlCompositeDirectCollectionMapping.getNullPolicy().isNullRepresentedByXsiNil() && xmlCompositeDirectCollectionMapping.getNullPolicy().valueIsNull(unmarshalRecord.getAttributes())) {
return;
}
if ((!isWhitespaceAware() && XMLConstants.EMPTY_STRING.equals(value))) {
return;
}
XMLField xmlField = (XMLField) xmlCompositeDirectCollectionMapping.getField();
XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager();
if (unmarshalRecord.getTypeQName() != null) {
Class typeClass = xmlField.getJavaClass(unmarshalRecord.getTypeQName());
value = xmlConversionManager.convertObject(value, typeClass, unmarshalRecord.getTypeQName());
} else {
value = xmlField.convertValueBasedOnSchemaType(value, xmlConversionManager, unmarshalRecord);
}
if (xmlCompositeDirectCollectionMapping.hasValueConverter()) {
if (xmlCompositeDirectCollectionMapping.getValueConverter() instanceof XMLConverter) {
value = ((XMLConverter) xmlCompositeDirectCollectionMapping.getValueConverter()).convertDataValueToObjectValue(value, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller());
} else {
value = xmlCompositeDirectCollectionMapping.getValueConverter().convertDataValueToObjectValue(value, unmarshalRecord.getSession());
}
}
unmarshalRecord.addAttributeValue(this, value, collection);
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
/**
* Return a new direct collection/element collection mapping for this type of descriptor.
*/
@Override
public DatabaseMapping newDirectCollectionMapping() {
return new XMLCompositeDirectCollectionMapping();
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
/**
* INTERNAL:
* Initialize the mapping.
*/
public void initialize(AbstractSession session) throws DescriptorException {
super.initialize(session);
if (this.getField() instanceof XMLField) {
if (valueConverter instanceof TypeConversionConverter) {
TypeConversionConverter converter = (TypeConversionConverter) valueConverter;
this.getField().setType(converter.getObjectClass());
}
String xpathString = ((XMLField) getField()).getXPath();
if (this.isAbstractCompositeDirectCollectionMapping() && (xpathString.indexOf(XMLConstants.ATTRIBUTE) == -1) && (!xpathString.endsWith(XMLConstants.TEXT))) {
throw DescriptorException.invalidXpathForXMLDirectMapping(this);
}
}
ContainerPolicy cp = getContainerPolicy();
if (cp != null) {
if (cp.getContainerClass() == null) {
Class cls = session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(cp.getContainerClassName());
cp.setContainerClass(cls);
}
}
((XMLField) this.getField()).setIsCDATA(this.isCDATA());
}
内容来源于网络,如有侵权,请联系作者删除!