Пример #1
0
 protected IData extractIData(IData data, String key, boolean mandatory, IData defaultValue)
     throws ServiceOutputException {
   IDataCursor cur = data.getCursor();
   try {
     IData result = IDataUtil.getIData(cur, key);
     if (result == null) {
       result = defaultValue;
     }
     if (mandatory && result == null) {
       throw new ServiceOutputException(this, String.format("missing required IData in %s", key));
     }
     return result;
   } finally {
     cur.destroy();
   }
 }
Пример #2
0
 protected <T> T extractSingleValue(
     IData data, ValueConverter<?, T> converter, String key, boolean mandatory, T defaultValue)
     throws ServiceOutputException {
   T result = defaultValue;
   IDataCursor cur = data.getCursor();
   try {
     Object value = IDataUtil.get(cur, key);
     if (value != null) {
       if (converter.canConvert(value)) {
         result = converter.convert(value);
       } else {
         throw new ServiceOutputException(
             this, "can not convert " + key + " to " + converter.getResultType());
       }
     }
     if (result == null && mandatory) {
       throw new ServiceOutputException(this, String.format("missing required %s", key));
     }
   } finally {
     cur.destroy();
   }
   return result;
 }