java参数注解pam_java – 使用xmlelement defaultvalue注释指定默认值的简单方法

我通过JAXB有一个简单的pojo注释类:

public class MyPojo

implements Serializable

{

private final static long serialVersionUID = 1234L;

@XmlElement(name = "Type",required = true,defaultValue = "none")

@NotNull

protected SeismicDataAcquisitionSystemType type;

@XmlElement(name = "IpAddress",required = true)

@NotNull

@Pattern(regexp = "((1?[0-9]?[0-9]|2[0-4]|[0-9]|25[0-5]).){3}(1?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])")

protected String ipAddress;

@XmlElement(name = "SealServerTcpPort",defaultValue = "1477")

@NotNull

protected int sealServerTcpPort;

@XmlElement(name = "PamServerTcpPort",defaultValue = "1485")

@NotNull

protected int pamServerTcpPort;

/**

* Obtient la valeur de la propriété type.

*

* @return

* possible object is

* {@link SeismicDataAcquisitionSystemType }

*

*/

public SeismicDataAcquisitionSystemType getType() {

return type;

}

/**

* Définit la valeur de la propriété type.

*

* @param value

* allowed object is

* {@link SeismicDataAcquisitionSystemType }

*

*/

public void setType(SeismicDataAcquisitionSystemType value) {

this.type = value;

}

public boolean isSetType() {

return (this.type!= null);

}

/**

* Obtient la valeur de la propriété ipAddress.

*

* @return

* possible object is

* {@link String }

*

*/

public String getIpAddress() {

return ipAddress;

}

/**

* Définit la valeur de la propriété ipAddress.

*

* @param value

* allowed object is

* {@link String }

*

*/

public void setIpAddress(String value) {

this.ipAddress = value;

}

public boolean isSetIpAddress() {

return (this.ipAddress!= null);

}

/**

* Obtient la valeur de la propriété sealServerTcpPort.

*

*/

public int getSealServerTcpPort() {

return sealServerTcpPort;

}

/**

* Définit la valeur de la propriété sealServerTcpPort.

*

*/

public void setSealServerTcpPort(int value) {

this.sealServerTcpPort = value;

}

public boolean isSetSealServerTcpPort() {

return true;

}

/**

* Obtient la valeur de la propriété pamServerTcpPort.

*

*/

public int getPamServerTcpPort() {

return pamServerTcpPort;

}

/**

* Définit la valeur de la propriété pamServerTcpPort.

*

*/

public void setPamServerTcpPort(int value) {

this.pamServerTcpPort = value;

}

}

我尝试用默认值初始化我的pojo

像那样

MyPojo myPojo = new MyPojo();

myPojo.getPamServerTcpPort(); // return 0

setDefaultValues(myPojo); // assign attributes with annotated default values

myPojo.getPamServerTcpPort(); // return 1485

我正在使用方法setDefaultValues(MyPojo loMyPojo)尝试programmaticaly,该方法使用java.lang.annotation API和java.lang.reflect API解析类,但我的代码很难看,并且不能使用我自己的枚举默认值

我不得不提到我无法修改原始类MyPojo,因为它本身是通过JAX解析XSD而生成的

任何的想法?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值