Jaxbを使用してJavaクラスを生成しています。私のスキーマには次の要素が定義されています。
<xs:complexType name="AutomobileType" abstract="true">
<xs:sequence>
<xs:element name="Color" type="core:ColorName"/>
<xs:element name="Weight" type="core:PoundsWeightType"/>
<xs:element name="Fuel" type="Fuel"/>
<xs:element name="NumDoors" type="xs:nonNegativeInteger"/>
<xs:element name="NumCylinders">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="12"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="Automobile" type="AutomobileType"/>
ご覧のとおり、Automobileという要素が1つあります。
Jaxbは、Automobileのインスタンスを作成するために使用するクラスとObjectFactoryを作成します。私を困惑させるのは、自動車のインスタンスを作成する方法は次のとおりです。
public JAXBElement<AutomobileType> createAutomobile(AutomobileType value)
createAutomobileメソッドに引数があるのはなぜですか?この方法を使用するにはどうすればよいですか?
私は次のことを試しました:
ObjectFactory objectFactory = new ObjectFactory();
objectFactory.createAutomobile(new Automobile());
ただし、 Automobileクラスは抽象であり、インスタンスを作成できないため、これはコンパイルされません。