Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java XML模式继承与OOP继承的工作原理相同吗?_Java_Xsd_Jaxb - Fatal编程技术网

Java XML模式继承与OOP继承的工作原理相同吗?

Java XML模式继承与OOP继承的工作原理相同吗?,java,xsd,jaxb,Java,Xsd,Jaxb,我正在编写一个模式文件,打算在我的一个项目中与JAXB一起使用。在Java中,我有以下代码结构 public interface Condition { ... } public class AndCondition implements Condition { public AndCondition(List<Condition> conditions){ ... } } public class StateCondition implements

我正在编写一个模式文件,打算在我的一个项目中与JAXB一起使用。在Java中,我有以下代码结构

public interface Condition {
   ...
}

public class AndCondition implements Condition {
   public AndCondition(List<Condition> conditions){
      ...
   }
}

public class StateCondition implements Condition {
   public StateCondition(Item item, String attributeName, String attributeValue){
      ...
   }
}
公共接口条件{
...
}
公共类和条件实现条件{
公共和条件(列出条件){
...
}
}
公共类StateCondition实现条件{
公共状态条件(项项、字符串属性名称、字符串属性值){
...
}
}
当然,我的代码中还有其他依赖于条件对象的对象

public class Action{
   List<Item> targets;
   List<Item> tools;
   Condition condition;
   ...
}
公共集体诉讼{
列出目标;
列出工具;
条件;
...
}
我的问题是,如果我在XML模式中定义complexType并扩展它们:

<xs:element name="Condition">
</xs:element>

<xs:element name="StateCondition">
   <xs:complexContent>
      <xs:extension base="Condition">
         <xs:sequence>
            <xs:element ref="Item" />
            <xs:element name="ATTRIB" type="AttributeType" />
         </xs:sequence>
      </xs:extension>
   </xs:complexContent>
</xs:element>

<xs:element name="AndCondition">
   <xs:complexContent>
      <xs:extension base="Condition">
         <xs:sequence>
            <xs:element ref="Condition" minOccurs="1" maxOccurs="unbounded" />
         </xs:sequence>
      </xs:extension>
   </xs:complexContent>
</xs:element>

<xs:element name="Item">
   <xs:sequence>
      <xs:element name="TARGETS">
         <xs:element ref="Item" minOccurs="0" maxOccurs="unbounded />
      </xs:element>
      <xs:element name="TOOLS">
         <xs:element ref="Item" minOccurs="0" maxOccurs="unbounded />
      </xs:element>
      <xs:element ref="Condition" />
   </xs:sequence>
</xs:element>


我会实现同样的想法吗?我的意思是,如果我创建一个包含一个AND条件的XML文件,它会满足验证器吗?

我自己在读了一点之后找到了答案。希望这个问题能为其他人所用。要读取的资源是,它定义了JAXB如何处理XML模式定义中的扩展基类型

是的,JAXB快速而简短地将模式中的扩展视为Java中的继承。这是一种内置类型、使用名称定义的简单类型或使用名称定义的复杂类型。因此,您可以定义与示例中的元素对应的类型(ConditionType、StateConditionType等),并将它们应用于命名属性。然后在基本模式中,可以定义一个元素,以确保至少选择一个定义的元素