gpt4 book ai didi

org.eclipse.persistence.oxm.mappings.XMLTransformationMapping类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 13:10:40 26 4
gpt4 key购买 nike

本文整理了Java中org.eclipse.persistence.oxm.mappings.XMLTransformationMapping类的一些代码示例,展示了XMLTransformationMapping类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLTransformationMapping类的具体详情如下:
包路径:org.eclipse.persistence.oxm.mappings.XMLTransformationMapping
类名称:XMLTransformationMapping

XMLTransformationMapping介绍

[英]Transformation XML mappings are used to create a custom mapping where one or more XML nodes can be used to create the object to be stored in a Java class's attribute. To handle the custom requirements at marshal (write) and unmarshall (read) time, a transformation mapping takes instances of org.eclipse.persistence.mappings.transformers (such as AttributeTransformer and FieldTransformer), providing a non-intrusive solution that avoids the need for domain objects to implement any 'special' interfaces.

Setting the XPath: TopLink XML mappings make use of XPath statements 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 field transformer that is set on the mapping. The XPath is set as the first parameter of the addFieldTransformer method.

The following XPath statements may be used to specify the location of XML data relating to an object's name attribute:
XPathDescription@nameThe "@" character indicates that the node is an attribute.text()"text()" indicates that the node is a text node. In this case the name value in the text node belongs to the context node.full-name/text()The name information is stored in the text node of the full-name element.personal-info/name/text()The XPath statement may be used to specify any valid path.name[2]/text()The XPath statement may contain positional information. In this case the name information is stored in the text node of the second occurrence of the name element.

Mapping a transformation: A transformer can be configured to perform both the XML instance-to-Java attribute transformation at unmarshall time (via attribute transformer) and the Java attribute-to-XML instance transformation at marshal time (via field transformer).

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="name" type="xsd:string"/>       <xsd:element name="normal-hours" type="normal-hours-type"/>     </xsd:sequence>   </xsd:complexType>   <xsd:complexType name="normal-hours-type">     <xsd:sequence>       <xsd:element name="start-time" type="xsd:string"/>       <xsd:element name="end-time" type="xsd:string"/>     </xsd:sequence>   </xsd:complexType> </xsd:schema>

Code Sample
XMLTransformationMapping mapping = new XMLTransformationMapping(); mapping.setAttributeName("normalHours"); mapping.setAttributeTransformerClassName("org.eclipse.persistence.testing.oxm.mappings.transformation.NormalHoursAttributeTransformer"); mapping.addFieldTransformer("normal-hours/start-time/text()", new StartTimeTransformer()); mapping.addFieldTransformer("normal-hours/end-time/text()", new EndTimeTransformer()");

More Information: For more information about using the XML Transformation Mapping, see the "Understanding XML Mappings" chapter of the Oracle TopLink Developer's Guide.
[中]转换XML映射用于创建自定义映射,其中一个或多个XML节点可用于创建要存储在Java类属性中的对象。为了在封送(写)和解封送(读)时处理定制需求,转换映射需要org的实例。日食坚持不懈映射。transformers(如AttributeTransformer和FieldTransformer),提供非侵入性解决方案,避免了域对象实现任何“特殊”接口的需要。
设置XPath:TopLink XML映射使用XPath语句在XML文档中查找相关数据。XPath语句与描述符中指定的上下文节点相关。XPath可能包含节点类型、路径和位置信息。XPath是在映射上设置的字段转换器上指定的。XPath被设置为addFieldTransformer方法的第一个参数。
以下XPath语句可用于指定与对象名称属性相关的XML数据的位置:
XPathDescription@nameThe“@”字符表示节点是一个属性。text()“text()”表示该节点是文本节点。在这种情况下,文本节点中的名称值属于上下文节点。全名/text()全名信息存储在全名元素的文本节点中。personal info/name/text()XPath语句可用于指定任何有效路径。name[2]/text()XPath语句可能包含位置信息。在这种情况下,名称信息存储在名称元素第二次出现的文本节点中。
映射转换:可以将转换器配置为在解组时(通过属性转换器)执行XML实例到Java属性的转换,并在封送时(通过字段转换器)执行Java属性到XML实例的转换。
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="name" type="xsd:string"/>       <xsd:element name="normal-hours" type="normal-hours-type"/>     </xsd:sequence>   </xsd:complexType>   <xsd:complexType name="normal-hours-type">     <xsd:sequence>       <xsd:element name="start-time" type="xsd:string"/>       <xsd:element name="end-time" type="xsd:string"/>     </xsd:sequence>   </xsd:complexType> </xsd:schema>
代码示例
XMLTransformationMapping mapping = new XMLTransformationMapping(); mapping.setAttributeName("normalHours"); mapping.setAttributeTransformerClassName("org.eclipse.persistence.testing.oxm.mappings.transformation.NormalHoursAttributeTransformer"); mapping.addFieldTransformer("normal-hours/start-time/text()", new StartTimeTransformer()); mapping.addFieldTransformer("normal-hours/end-time/text()", new EndTimeTransformer()");
更多信息:有关使用XML转换映射的更多信息,请参阅《Oracle TopLink开发人员指南》的“理解XML映射”一章。

代码示例

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.dbws

protected XMLDescriptor buildProcedureOutputArgumentDescriptor() {
  XMLDescriptor descriptor = buildProcedureArgumentDescriptor();
  descriptor.setJavaClass(ProcedureOutputArgument.class);
  XMLTransformationMapping resultType = new XMLTransformationMapping();
  resultType.setAttributeName("resultType");
  QNameTransformer qNameTransformer = new QNameTransformer("type/text()");
  resultType.addFieldTransformer("type/text()", qNameTransformer);
  resultType.setAttributeTransformer(qNameTransformer);
  descriptor.addMapping(resultType);
  return descriptor;
}

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public void addFieldTransformation(String fieldName, String methodName) {
  this.addFieldTransformation(new XMLField(fieldName), methodName);
}
public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

public void addFieldTransformerClassName(String fieldName, String className) {
  this.addFieldTransformerClassName(new XMLField(fieldName), className);
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

public void preInitialize(AbstractSession session) throws DescriptorException {
  getAttributeAccessor().setIsWriteOnly(this.isWriteOnly());
  getAttributeAccessor().setIsReadOnly(this.isReadOnly());
  super.preInitialize(session);
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

XMLTransformationMapping versionMapping = new XMLTransformationMapping();
versionMapping.addFieldTransformer("@version", getConstantTransformerForProjectVersionMapping());
descriptor.addMapping(versionMapping);

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public void addFieldTransformer(String fieldName, FieldTransformer transformer) {
  this.addFieldTransformer(new XMLField(fieldName), transformer);
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

TransformationMapping mapping = new XMLTransformationMapping();
if (property.isMethodProperty()) {
  if (property.getGetMethodName() == null) {

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {
  this.writeFromObjectIntoRow(parent, row, session, WriteType.UNDEFINED);
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

XMLTransformationMapping versionMapping = new XMLTransformationMapping();
versionMapping.addFieldTransformer("@version", getConstantTransformerForProjectVersionMapping());
descriptor.addMapping(versionMapping);

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

public void preInitialize(AbstractSession session) throws DescriptorException {
  getAttributeAccessor().setIsWriteOnly(this.isWriteOnly());
  getAttributeAccessor().setIsReadOnly(this.isReadOnly());
  super.preInitialize(session);
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

public void addFieldTransformer(String fieldName, FieldTransformer transformer) {
  this.addFieldTransformer(new XMLField(fieldName), transformer);
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.moxy

TransformationMapping mapping = new XMLTransformationMapping();
if (property.isMethodProperty()) {
  if (property.getGetMethodName() == null) {

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {
  this.writeFromObjectIntoRow(parent, row, session, WriteType.UNDEFINED);
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

protected XMLDescriptor buildProcedureOutputArgumentDescriptor() {
  XMLDescriptor descriptor = buildProcedureArgumentDescriptor();
  descriptor.setJavaClass(ProcedureOutputArgument.class);
  XMLTransformationMapping resultType = new XMLTransformationMapping();
  resultType.setAttributeName("resultType");
  QNameTransformer qNameTransformer = new QNameTransformer("type/text()");
  resultType.addFieldTransformer("type/text()", qNameTransformer);
  resultType.setAttributeTransformer(qNameTransformer);
  descriptor.addMapping(resultType);
  return descriptor;
}

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

XMLTransformationMapping versionMapping = new XMLTransformationMapping();
versionMapping.addFieldTransformer("@version", getConstantTransformerForProjectVersionMapping());
descriptor.addMapping(versionMapping);

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public void preInitialize(AbstractSession session) throws DescriptorException {
    getAttributeAccessor().setIsWriteOnly(this.isWriteOnly());
    getAttributeAccessor().setIsReadOnly(this.isReadOnly());
    super.preInitialize(session);
  }
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

public void addFieldTransformer(String fieldName, FieldTransformer transformer) {
  this.addFieldTransformer(new XMLField(fieldName), transformer);
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

public void addFieldTransformation(String fieldName, String methodName) {
  this.addFieldTransformation(new XMLField(fieldName), methodName);
}
public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) {
  this.writeFromObjectIntoRow(parent, row, session);
}

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public void addFieldTransformerClassName(String fieldName, String className) {
  this.addFieldTransformerClassName(new XMLField(fieldName), className);
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com