dtd文件的JAXB绑定模式 [英] JAXB binding schema of dtd file
问题描述
一个noobie问题。我正在从dtd文件(USPTO dtd)生成Java代码。 DTD指定根元素如下:
A noobie question. I am generating Java code from a dtd file (USPTO dtd). The DTD specifies the root element as follows:
<!ELEMENT us-patent-grant (doc-page+ | (us-bibliographic-data-grant , abstract* , drawings? , description , us-sequence-list-doc? , us-megatable-doc?,table-external-doc* , us-chemistry* , us-math* ,us-claim-statement , claims))>
当我使用以下绑定架构运行xjc时
When I run xjc with the following binding schema
<?xml version="1.0"?>
<xml-java-binding-schema version="1.0ea2">
<element name="us-patent-grant" type="class" root="true"></element>
</xml-java-binding-schema>
我看到生成了以下Java对象
I see the following Java object generated
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"docPageOrUsBibliographicDataGrantOrAbstractOrDrawingsOrDescriptionOrUsSequenceListDocOrUsMegatableDocOrTableExternalDocOrUsChemistryOrUsMathOrUsClaimStatementOrClaims"
})
@XmlRootElement(name = "us-patent-grant")
public class UsPatentGrant {
....
@XmlElements({
@XmlElement(name = "doc-page", required = true, type = DocPage.class),
@XmlElement(name = "us-bibliographic-data-grant", required = true, type = UsBibliographicDataGrant.class),
@XmlElement(name = "abstract", required = true, type = Abstract.class),
@XmlElement(name = "drawings", required = true, type = Drawings.class),
@XmlElement(name = "description", required = true, type = Description.class),
@XmlElement(name = "us-sequence-list-doc", required = true, type = UsSequenceListDoc.class),
@XmlElement(name = "us-megatable-doc", required = true, type = UsMegatableDoc.class),
@XmlElement(name = "table-external-doc", required = true, type = TableExternalDoc.class),
@XmlElement(name = "us-chemistry", required = true, type = UsChemistry.class),
@XmlElement(name = "us-math", required = true, type = UsMath.class),
@XmlElement(name = "us-claim-statement", required = true, type = UsClaimStatement.class),
@XmlElement(name = "claims", required = true, type = Claims.class)
})
protected List<Object> docPageOrUsBibliographicDataGrantOrAbstractOrDrawingsOrDescriptionOrUsSequenceListDocOrUsMegatableDocOrTableExternalDocOrUsChemistryOrUsMathOrUsClaimStatementOrClaims;
.........
public List<Object> getDocPageOrUsBibliographicDataGrantOrAbstractOrDrawingsOrDescriptionOrUsSequenceListDocOrUsMegatableDocOrTableExternalDocOrUsChemistryOrUsMathOrUsClaimStatementOrClaims() {
if (docPageOrUsBibliographicDataGrantOrAbstractOrDrawingsOrDescriptionOrUsSequenceListDocOrUsMegatableDocOrTableExternalDocOrUsChemistryOrUsMathOrUsClaimStatementOrClaims == null) {
docPageOrUsBibliographicDataGrantOrAbstractOrDrawingsOrDescriptionOrUsSequenceListDocOrUsMegatableDocOrTableExternalDocOrUsChemistryOrUsMathOrUsClaimStatementOrClaims = new ArrayList<Object>();
}
return this.docPageOrUsBibliographicDataGrantOrAbstractOrDrawingsOrDescriptionOrUsSequenceListDocOrUsMegatableDocOrTableExternalDocOrUsChemistryOrUsMathOrUsClaimStatementOrClaims;
}
所以我的问题是如何更改长吸气剂的名称
So my question is how can i change the name of the long getter
getDocPageOrUsBibliographicDataGrantOrAbstractOrDrawingsOrDescriptionOrUsSequenceListDocOrUsMegatableDocOrTableExternalDocOrUsChemistryOrUsMathOrUsClaimStatementOrClaims
在绑定模式中?
提前谢谢你。
推荐答案
这不是一个答案,而是你怀疑的证据。
This isn't so much an answer as evidence for what you are suspecting.
在 JAXB / XJC <$ h $ => https://github.com/javaee/jaxb-v2中 com.sun.tools.xjc.reader.dtd.Element
的来源/blob/f1ef0676987b83b134b8c97fe99083423f7f3311/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/dtd/Element.java#L290\"relue =nofollow noreferrer> bind()方法,你可以看到这个摘录,遍历元素
的子元素
:
In the JAXB/XJC source for com.sun.tools.xjc.reader.dtd.Element
, in the bind() method, you can see this excerpt, iterating through the child elements
of the Element
:
if(b.isRepeated || b.elements.size()>1) {
// collection
StringBuilder name = new StringBuilder();
for( Element e : b.elements ) {
if(name.length()>0)
name.append("Or");
name.append(owner.model.getNameConverter().toPropertyName(e.name));
}
...
} else {
// single property
String name = b.elements.iterator().next().name;
String propName = owner.model.getNameConverter().toPropertyName(name);
...
}
看起来它几乎没有机会改变或
分隔符的序列,其中有多个子元素。
That looks like it offers little opportunity to change the sequence of "Or"
separators where there are multiple child elements.
您可以看到 bindInfo
允许自定义名称在元素
中的其他位置,但不在此附近。除非别人能够发现它,否则重命名的可能性似乎就此结束。简而言之, CElementPropertyInfo
此输出将导致 BeanGenerator.fields
,这将导致 JDefinedClass。字段
然后由 JDefinedClass.declareBody()
直接输出。
You can see the bindInfo
allowing custom names elsewhere in Element
, but not near here. Unless someone else can spot it, the chances to rename things seem to end there. In short, the CElementPropertyInfo
this outputs leads to BeanGenerator.fields
, which lead to JDefinedClass.fields
which are then output directly by JDefinedClass.declareBody()
.
作为 XJC docs 说,DTD支持仍然是实验性的......
As the XJC docs say, DTD support is still experimental...
这篇关于dtd文件的JAXB绑定模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!