Java 为什么静态类在JAXB解组中是特殊的
我有几个例子,JAXB从xsd文件生成的类有一系列的类列表,其中也包含类列表。生成的类在处理这些情况时使用静态内部类,但这会导致一个类多次存在多个实例 例如,我有一个存在于多个xsd文件中的参数类。在每个实例中,该参数类都是相同的,并且包含一个键值对。为每个xsd文件生成代码时,每个生成的类都包含一个带有name参数的内部类 为了减少冗余,我从所有生成的类中删除了参数类,重新实现了它,并更新了所有引用这与预期相符 当我有另一个类,如LogicalDevice,它也在几个类中实现时,就会出现问题。LogicalDevice包含一个参数列表。当LogicalDevice被提取到它自己的类中,并且引用被更新时,只有Parameter类中的第一个属性被维护,其余属性为null 这让我相信静态内部类有一些特殊之处 这里是我的xml和代码供参考Java 为什么静态类在JAXB解组中是特殊的,java,xml,jaxb,Java,Xml,Jaxb,我有几个例子,JAXB从xsd文件生成的类有一系列的类列表,其中也包含类列表。生成的类在处理这些情况时使用静态内部类,但这会导致一个类多次存在多个实例 例如,我有一个存在于多个xsd文件中的参数类。在每个实例中,该参数类都是相同的,并且包含一个键值对。为每个xsd文件生成代码时,每个生成的类都包含一个带有name参数的内部类 为了减少冗余,我从所有生成的类中删除了参数类,重新实现了它,并更新了所有引用这与预期相符 当我有另一个类,如LogicalDevice,它也在几个类中实现时,就会出现问题。
<Jetstream xmlns="http://Jetstream.TersoSolutions.com/v1.1/GetPoliciesResponse">
<Header/>
<GetPoliciesResponse>
<PolicyList>
<Policy Id="53bb663f-7ed0-41f8-9757-90ad4e015995" Name="MyPolicy"
DeviceDefinitionId="f3536a6d-4610-4d56-82d9-54fd6602a883" >
<ParameterList>
<Parameter Name="aggregateeventscancount" Value="2"/>
<Parameter Name="aggregateeventscantime" Value="10"/>
<Parameter Name="antenna1rxsensitivity" Value="50"/>
<Parameter Name="antenna1txpower" Value="30"/>
<Parameter Name="antenna2rxsensitivity" Value="50"/>
<Parameter Name="antenna2txpower" Value="30"/>
<Parameter Name="antenna3rxsensitivity" Value="50"/>
<Parameter Name="antenna3txpower" Value="30"/>
<Parameter Name="antenna4rxsensitivity" Value="50"/>
<Parameter Name="antenna4txpower" Value="30"/>
<Parameter Name="commandpollinterval" Value="60"/>
<Parameter Name="dns" Value="0.0.0.0"/>
<Parameter Name="dooropentimelimit" Value="300"/>
<Parameter Name="gateway" Value="0.0.0.0"/>
<Parameter Name="ip" Value="0.0.0.0"/>
<Parameter Name="jetstreamdeviceurl" Value="https://us-device.tersosolutions.com/v1.0/device/"/>
<Parameter Name="lockdownhightemp" Value="127"/>
<Parameter Name="lockdownonacpowerfailure" Value="0"/>
<Parameter Name="lockdownonreaderfailure" Value="0"/>
<Parameter Name="lockdownonhightemp" Value="0"/>
<Parameter Name="logentryeventhightemp" Value="127"/>
<Parameter Name="logentryeventlowtemp" Value="-128"/>
<Parameter Name="numberofantennas" Value="4"/>
<Parameter Name="logentrylevel" Value="Warning"/>
<Parameter Name="objecteventscancount" Value="2"/>
<Parameter Name="objecteventscantime" Value="10"/>
<Parameter Name="Subnet" Value="0.0.0.0"/>
</ParameterList>
<LogicalDeviceList>
<LogicalDevice LogicalDeviceId="MyDevice">
<ParameterList>
<Parameter Name="ip" value="192.168.91.100" />
<Parameter Name="subnet" value="255.255.255.0" />
<Parameter Name="gateway" value="192.168.91.1" />
<Parameter Name="dns" value="192.168.91.2" />
</ParameterList>
</LogicalDevice>
</LogicalDeviceList>
</Policy>
</PolicyList>
</GetPoliciesResponse>
</Jetstream>
*
*
*
*列表中允许以下类型的对象
*{@link Jetstream.GetPoliciesResponse.PolicyList.Policy}
*
*
*/
公共列表getPolicy(){
如果(策略==null){
policy=newarraylist();
}
退回本保单;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=“Policy”,比例={
“参数列表”,
“逻辑设备论者”,
“任何”
})
公共静态类策略{
@xmlement(name=“ParameterList”,必需=true)
受保护的com.TersoSolutions.Jetstream.SDK.XML.ParameterList参数列表;
@XmlElement(name=“LogicalDeviceList”,必需=true)
受保护的LogicalDeviceList LogicalDeviceList;
@xmlanyement(lax=true)
任何受保护的清单;
@xmltattribute(name=“Id”,required=true)
受保护的字符串id;
@XmlAttribute(name=“name”,required=true)
受保护的字符串名称;
@XmlAttribute(name=“DeviceDefinitionId”,必需=true)
受保护的字符串deviceDefinitionId;
@XmlAnyAttribute
私有映射otherAttributes=newhashmap();
/**
*获取parameterList属性的值。
*
*@返回
*可能的对象是
*{@link Jetstream.GetPoliciesResponse.PolicyList.Policy.ParameterList}
*
*/
public com.TersoSolutions.Jetstream.SDK.XML.ParameterList getParameterList(){
返回参数列表;
}
/**
*获取logicalDeviceList属性的值。
*
*@返回
*可能的对象是
*{@link Jetstream.GetPoliciesResponse.PolicyList.Policy.LogicalDeviceList}
*
*/
公共LogicalDeviceList getLogicalDeviceList(){
返回逻辑设备列表;
}
/**
*获取id属性的值。
*
*@返回
*可能的对象是
*{@link String}
*
*/
公共字符串getId(){
返回id;
}
/**
*获取name属性的值。
*
*@返回
*可能的对象是
*{@link String}
*
*/
公共字符串getName(){
返回名称;
}
/**
*获取deviceDefinitionId属性的值。
*
*@返回
*可能的对象是
*{@link String}
*
*/
公共字符串getDeviceDefinitionId(){
返回设备定义ID;
}
}
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=“Header”)
公共静态类头{
@XmlAnyAttribute
私有映射otherAttributes=newhashmap();
}
}
这是更新的逻辑设备
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "ParameterList")
public class ParameterList {
@XmlElement(name = "Parameter", required = true)
protected List<com.TersoSolutions.Jetstream.SDK.XML.Parameter> parameter;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
/**
* Gets the value of the parameter property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the parameter property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getParameter().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Jetstream.LogEntryEvent.LogEntryList.LogEntry.ParameterList.Parameter }
*
*
*/
public List<com.TersoSolutions.Jetstream.SDK.XML.Parameter> getParameter() {
if (parameter == null) {
parameter = new ArrayList<com.TersoSolutions.Jetstream.SDK.XML.Parameter>();
}
return this.parameter;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Parameter")
public static class Parameter {
@XmlAttribute(name = "Name", required = true)
protected String name;
@XmlAttribute(name = "Value", required = true)
protected String value;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}
}
}
*
*
*
*列表中允许以下类型的对象
*{@link Jetstream.GetConfigurationResponse.LogicalDeviceList.LogicalDevice}
*
*
*/
公共列表getLogicalDevice(){
if(logicalDevice==null){
logicalDevice=new ArrayList();
}
返回此.logicalDevice;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name=“LogicalDevice”)
公共静态类逻辑设备{
@XmlElement(name=“ParameterList”)
受保护的com.TersoSolutions.Jetstream.SDK.XML.ParameterList参数列表;
@XmlAttribute(name=“DeviceDefinitionId”)
受保护的字符串deviceDefinitionId;
@XmlAttribute(name=“DeviceSerialNumber”)
受保护的字符串设备序列号;
@xmltattribute(name=“Health”)
保护字符串健康;
@XmlAttribute(name=“LogicalDeviceId”,必需=true)
受保护的字符串logicalDeviceId;
@xmltattribute(name=“Region”)
保护串区域;
@xmldattribute(name=“PolicyId”)
受保护的字符串policyId;
@XmlAnyAttribute
私有映射otherAttributes=newhashmap();
/**
*获取deviceDefinitionId属性的值。
*
*@返回
*可能的对象是
*{@link String}
*
*/
公共字符串getDeviceDefinitionId(){
返回设备定义ID;
}
/**
*获取deviceSerialNumbe的值
package com.TersoSolutions.Jetstream.SDK.XML;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;
import com.TersoSolutions.Jetstream.SDK.XML.Model.GetConfigurationResponse.Jetstream;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "LogicalDeviceList")
public class LogicalDeviceList {
@XmlElement(name = "LogicalDevice")
protected List<LogicalDevice> logicalDevice;
/**
* Gets the value of the logicalDevice property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the logicalDevice property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getLogicalDevice().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Jetstream.GetConfigurationResponse.LogicalDeviceList.LogicalDevice }
*
*
*/
public List<LogicalDevice> getLogicalDevice() {
if (logicalDevice == null) {
logicalDevice = new ArrayList<LogicalDevice>();
}
return this.logicalDevice;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "LogicalDevice")
public static class LogicalDevice {
@XmlElement(name = "ParameterList")
protected com.TersoSolutions.Jetstream.SDK.XML.ParameterList parameterList;
@XmlAttribute(name = "DeviceDefinitionId")
protected String deviceDefinitionId;
@XmlAttribute(name = "DeviceSerialNumber")
protected String deviceSerialNumber;
@XmlAttribute(name = "Health")
protected String health;
@XmlAttribute(name = "LogicalDeviceId", required = true)
protected String logicalDeviceId;
@XmlAttribute(name = "Region")
protected String region;
@XmlAttribute(name = "PolicyId")
protected String policyId;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
/**
* Gets the value of the deviceDefinitionId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getDeviceDefinitionId() {
return deviceDefinitionId;
}
/**
* Gets the value of the deviceSerialNumber property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getDeviceSerialNumber() {
return deviceSerialNumber;
}
/**
* Gets the value of the health property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getHealth() {
return health;
}
/**
* Gets the value of the logicalDeviceId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getLogicalDeviceId() {
return logicalDeviceId;
}
/**
* Gets the value of the region property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getRegion() {
return region;
}
/**
* Gets the value of the policyId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPolicyId() {
return policyId;
}
/**
* Gets the value of the parameterList property.
*
* @return
* possible object is
* {@link Jetstream.GetPoliciesResponse.PolicyList.Policy.LogicalDeviceList.LogicalDevice.ParameterList }
*
*/
public com.TersoSolutions.Jetstream.SDK.XML.ParameterList getParameterList() {
return parameterList;
}
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "ParameterList")
public class ParameterList {
@XmlElement(name = "Parameter", required = true)
protected List<com.TersoSolutions.Jetstream.SDK.XML.Parameter> parameter;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
/**
* Gets the value of the parameter property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the parameter property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getParameter().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Jetstream.LogEntryEvent.LogEntryList.LogEntry.ParameterList.Parameter }
*
*
*/
public List<com.TersoSolutions.Jetstream.SDK.XML.Parameter> getParameter() {
if (parameter == null) {
parameter = new ArrayList<com.TersoSolutions.Jetstream.SDK.XML.Parameter>();
}
return this.parameter;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Parameter")
public static class Parameter {
@XmlAttribute(name = "Name", required = true)
protected String name;
@XmlAttribute(name = "Value", required = true)
protected String value;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}
}
}