2
實體「消息」的XML描述。如何在xStream中指定接口的實現?
<Message id="11600005" name="some_name">
<sourcePartitionId>11600</sourcePartitionId>
<destPartitionId>11700</destPartitionId>
<payloadId>1300005</payloadId>
<sourceUdp>1045</sourceUdp>
<destUdp>1046</destUdp>
<sourceIp>10.4.48.0</sourceIp>
<destIp>10.4.49.0</destIp>
<sourcePort id="1045" name="sp_q_1045_11600_11700_005">
<type>Queuing</type>
<maxMessageSize>8192</maxMessageSize>
<characteristic>1</characteristic>
</sourcePort>
<destPort id="1046" name="dp_q_1045_1046_11600_11700_005">
<type>Queuing</type>
<maxMessageSize>8192</maxMessageSize>
<characteristic>1</characteristic>
</destPort>
</Message>
在字段sourcePort
和destPort
描述對象實現了接口ComPort
:
public interface ComPort {
enum PortType {Sampling, Queuing}
enum PortDirection {Rx,Tx}
public PortType getPortType();
public PortDirection getPortDirection();
public int getMaxMessageSize();
public int getPortCharacteristic();
在界面有兩個實現:SamplingPort
和QueuingPort
。主要差異 - 特徵領域。告訴我如何使基於<type>
標記的xstream創建相應實現的實例?
重要的一點:這也是需要考慮的是,當sourcePort
標籤 - 方向字段爲Tx
,當destPort
標籤 - 方向場Rx