когда вы генерируете свои объекты JAXB / JAXWS из своего XSD / WSDL, вы можете использовать средство настройки JAXB, чтобы сказать компилятору JAXB, что нужно создать метод isSet для ваших объектов Java.
Обычно я включаюфайл с этой настройкой JAXB во всех моих задачах генерации JAXB / JAXWS:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jxb:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
targetNamespace="http://java.sun.com/xml/ns/jaxb"
version="1.0">
<jxb:globalBindings
generateIsSetMethod="true"
/>
</jxb:bindings>
при условии, что у вас есть этот XML в файле с именем "jaxb_global_customization.jxb", вы можете включить его в свои шаги генерации:
<wsimport
sourcedestdir="${dao.dir}/build/generated"
destdir="${dao.dir}/build/bin/generated"
wsdl="${dao.dir}/src/resources/schema/dao/SomeService.wsdl"
wsdlLocation="./wsdl/SomeService.wsdl"
>
<binding dir="${dao.dir}/src/resources/schema/" includes="*.xml"/>
<binding dir="${dao.dir}/src/resources/schema/" includes="*.xsd"/>
<binding dir="${dao.dir}/src/resources/schema/" includes="*.jxb"/>
</wsimport>
или с задачей XJC:
<xjc destdir="${dao.dir}/build/generated" package="com.example.dao">
<schema dir="${dao.dir}/src/resources/schema" includes="*.xsd" />
<binding dir="${dao.dir}/src/resources/schema" includes="*.jxb" />
</xjc>
в вашем сгенерированном коде для вашего образца, сгенерированный код JAXWS / JAXB будет включать в себя такие методы:
if (document.isSetDestination()) {
// here you know that if Destination is a complex type, that the object which represents Destination is not null
// if destination is a simple type, you know that it is not null and that it is not empty (meaning Destination != null && Destination.length() >0
// if Destination is a repeating type, you know that it is not null and if it has any elements in it (ie, it's present and not an empty list)
... check validity
}
Это значительно упрощает ваш код.