几乎是 jaxb 的新手,试图用 xjc (jdk 8) 将 PLMXMLSchema.xsd 绑定到 java 类。
这是架构的摘录
<xsd:complexType name="ProductType">
<xsd:annotation>
<xsd:documentation>
This is the revision-independent Product, derived from Structure.
It corresponds to the STEP 'product'.
Attributes:
productId: The identifier of the Product, unique in some context, e.g. an
Organisation.
alternateForRef: An 'alternate' Product is one which is substitutable, in all
contexts, for a particular Product. If this is an 'alternate'
Product, then this attribute references the Product for which
this is an alternate.
unitRef: The default Unit for the 'quantity' attribute of any referencing
ProductInstance elements.
designRequired: true if all the revisions of this Product must have
at least one associated DesignRevision
source: whether the Product is manufactured or bought-in
vendorRef: References the Vendor when the Product represents a
vendor part.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="plm:StructureBase">
<xsd:attribute name="productId" type="xsd:string" use="optional"/>
<xsd:attribute name="alternateForRef" type="plm:anyURIType" use="optional" plm:refType="plm:Product"/>
<xsd:attribute name="unitRef" type="plm:anyURIType" use="optional" plm:refType="plm:Unit"/>
<xsd:attribute name="designRequired" type="xsd:boolean" default="true"/>
<xsd:attribute name="source" type="plm:ProductSourceEnum" use="optional"/>
<xsd:attribute name="vendorRef" type="plm:anyURIType" use="optional" plm:refType="plm:Vendor"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="Product" type="plm:ProductType" substitutionGroup="plm:Structure"/>
第一点
xjc 编译器构建类ProductType.java
,但我更喜欢Product.java
。这只是一个示例,因为架构始终使用命名约定“FooType”和我更喜欢摆脱的“Type”后缀。使用此处建议的“简单”绑定https://stackoverflow.com/a/4818344/2668213似乎没有效果..
第二点
架构中的属性
<xsd:attribute name="alternateForRef" type="plm:anyURIType" use="optional" plm:refType="plm:Product"/>
被翻译成
@XmlAttribute(name = "alternateForRef")
protected String alternateForRef;
但我非常喜欢
@XmlAttribute(name = "alternateForRef")
@XmlIDREF
protected Product alternateForRef;
这种模式在模式中始终适用,其中一些属性是plm:refType
类的 idref。所以我希望应该有一个(外部绑定?)解决方案来一次解决所有这些情况。