code: private static QName getDurationType(Duration value) {
          boolean hasYearMonth = (
                  value.isSet(DatatypeConstants.YEARS)  ||
                  value.isSet(DatatypeConstants.MONTHS)
                  );
          boolean hasDayTime = (
                  value.isSet(DatatypeConstants.DAYS)    ||
                  value.isSet(DatatypeConstants.HOURS)   ||
                  value.isSet(DatatypeConstants.MINUTES) ||
                  value.isSet(DatatypeConstants.SECONDS)
                  );
  
          if (hasYearMonth && !hasDayTime) {
              return DatatypeConstants.DURATION_YEARMONTH;
          } else if ((!hasYearMonth) && hasDayTime) {
              return DatatypeConstants.DURATION_DAYTIME;
          }
  
          throw new IllegalArgumentException("value must be yearMonthDuration or dayTimeDuration: "+value);
      }
docs: javax.xml.datatype.Duration.getXMLSchemaType() requires all fields to be set