Joaquín Reñé
2026-03-27 4ee50e257b32f6ec0f72907305d1f2b1212808a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
/*
 * Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
 */
package net.curisit.securis.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.curisit.integrity.exception.CurisRuntimeException;
/**
 * Utils
 * <p>
 * General-purpose static utilities: hashing, dates/times, collections, I/O helpers,
 * simple email validation, reflection helpers, file tailing, etc.
 *
 * Author: JRA
 * Last reviewed by JRA on Oct 6, 2025.
 */
public class Utils {
   private static final Logger LOG = LogManager.getLogger(Utils.class);
   /* --------------------- Hash functions --------------------- */
   /**
    * md5<p>
    * Returns MD5 digest (hex, 32 chars) for the input text.
    *
    * @param str source text
    * @return lowercase hex MD5 or null on error
    */
   public static String md5(String str) {
       try {
           MessageDigest mDigest = MessageDigest.getInstance("MD5");
           mDigest.update(str.getBytes(), 0, str.length());
           BigInteger i = new BigInteger(1, mDigest.digest());
           return String.format("%1$032x", i);
       } catch (NoSuchAlgorithmException e) {
           LOG.error("Error generating MD5 for string: " + str, e);
       }
       return null;
   }
   /**
    * sha1<p>
    * Returns SHA-1 digest (hex, 40 chars) for the input text.
    *
    * @param str source text
    * @return lowercase hex SHA-1 or null on error
    */
   public static String sha1(String str) {
       try {
           MessageDigest mDigest = MessageDigest.getInstance("SHA1");
           mDigest.update(str.getBytes(), 0, str.length());
           BigInteger i = new BigInteger(1, mDigest.digest());
           return String.format("%1$040x", i);
       } catch (NoSuchAlgorithmException e) {
           LOG.error("Error generating SHA1 for string: " + str, e);
       }
       return null;
   }
   /**
    * sha256<p>
    * Returns SHA-256 digest (hex, 64 chars) for the input text.
    *
    * @param str source text
    * @return lowercase hex SHA-256 or null on error
    */
   public static String sha256(String str) {
       return sha256(str.getBytes());
   }
   /**
    * sha256<p>
    * Returns SHA-256 digest (hex) for a byte array.
    *
    * @param bytes data
    * @return hex SHA-256 or null on error
    */
   public static String sha256(byte[] bytes) {
       try {
           MessageDigest mDigest = MessageDigest.getInstance("SHA-256");
           mDigest.update(bytes, 0, bytes.length);
           BigInteger i = new BigInteger(1, mDigest.digest());
           return String.format("%1$064x", i);
       } catch (NoSuchAlgorithmException e) {
           LOG.error("Error generating SHA-256 for bytes: " + bytes, e);
       }
       return null;
   }
   /**
    * sha256<p>
    * Incrementally updates SHA-256 with multiple byte arrays and returns hex digest.
    *
    * @param bytes multiple byte chunks
    * @return hex SHA-256 or null on error
    */
   public static String sha256(byte[]... bytes) {
       try {
           MessageDigest mDigest = MessageDigest.getInstance("SHA-256");
           for (byte[] bs : bytes) {
               mDigest.update(bs, 0, bs.length);
           }
           BigInteger i = new BigInteger(1, mDigest.digest());
           return String.format("%1$064x", i);
       } catch (NoSuchAlgorithmException e) {
           LOG.error("Error generating SHA-256 for bytes: " + bytes, e);
       }
       return null;
   }
   
   /* --------------------- ISO date helpers --------------------- */
   private static final String ISO_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
   private static final SimpleDateFormat sdf = new SimpleDateFormat(ISO_PATTERN);
   static {
       sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
   }
   /**
    * toIsoFormat<p>
    * Formats a Date to ISO-8601-like string with milliseconds in GMT.
    *
    * @param date input date
    * @return formatted string
    */
   public static synchronized String toIsoFormat(Date date) {
       return sdf.format(date);
   }    
   private static final String ISO_PATTERN_REDUCED_PRECISION = "yyyy-MM-dd'T'HH:mm:ssZ";
   private static final SimpleDateFormat sdfReduced = new SimpleDateFormat(ISO_PATTERN_REDUCED_PRECISION);
   static {
       sdfReduced.setTimeZone(TimeZone.getTimeZone("GMT"));
   }
   /**
    * toIsoFormatReduced<p>
    * Formats a Date to ISO string without milliseconds in GMT.
    *
    * @param date input date
    * @return formatted string
    */
   public static synchronized String toIsoFormatReduced(Date date) {
       return sdfReduced.format(date);
   }
   /**
    * toDateFromIso<p>
    * Parses a string in {@link #ISO_PATTERN} into a Date (GMT).
    *
    * @param dateStr string to parse
    * @return Date or null if parsing fails
    */
   public static synchronized Date toDateFromIso(String dateStr) {
       try {
           return sdf.parse(dateStr);
       } catch (ParseException e) {
           LOG.error("Error parsing string '{}' to Date object with pattern: {}", dateStr, ISO_PATTERN);
           return null;
       }
   }
   /* --------------------- Null-safe helpers --------------------- */
   /**
    * nonull<p>
    * Returns {@code value} cast to T, or {@code defaultValue} if null.
    *
    * @param value input
    * @param defaultValue fallback
    * @return value or default
    */
   @SuppressWarnings("unchecked")
   public static <T> T nonull(Object value, T defaultValue) {
       return value == null ? defaultValue : (T) value;
   }
   /**
    * nonull<p>
    * Returns String value or empty string if null.
    *
    * @param value input
    * @return non-null string
    */
   public static String nonull(Object value) {
       return nonull(value, "");
   }
   /**
    * value<p>
    * Unchecked cast helper (avoid using unless necessary).
    *
    * @param value object
    * @param type  target type
    * @return casted value
    */
   @SuppressWarnings("unchecked")
   public static <T> T value(Object value, Class<T> type) {
       return (T) value;
   }
   /**
    * createMap<p>
    * Convenience to create a Map from varargs key/value pairs.
    *
    * @param keyValue alternating key, value
    * @return map with pairs
    */
   @SuppressWarnings("unchecked")
   public static <K extends Object, V extends Object> Map<K, V> createMap(Object... keyValue) {
       Map<K, V> map = (Map<K, V>) new HashMap<Object, Object>();
       for (int i = 0; i < keyValue.length; i += 2) {
           ((Map<Object, Object>) map).put(keyValue[i], keyValue[i + 1]);
       }
       return map;
   }
   /* --------------------- Date arithmetic --------------------- */
   /**
    * addDays<p>
    * Adds a number of days to a Date.
    *
    * @param date base date
    * @param days positive/negative days
    * @return new Date
    */
   public static Date addDays(Date date, int days) {
       Calendar cal = Calendar.getInstance();
       cal.setTime(date);
       cal.add(Calendar.DATE, days);
       return cal.getTime();
   }
   /**
    * addHours<p>
    * Adds hours to a Date.
    *
    * @param date base date
    * @param hours number of hours
    * @return new Date
    */
   public static Date addHours(Date date, int hours) {
       Calendar cal = Calendar.getInstance();
       cal.setTime(date);
       cal.add(Calendar.HOUR, hours);
       return cal.getTime();
   }
   /**
    * addMinutes<p>
    * Adds minutes to a Date.
    *
    * @param date base date
    * @param minutes number of minutes
    * @return new Date
    */
   public static Date addMinutes(Date date, int minutes) {
       Calendar cal = Calendar.getInstance();
       cal.setTime(date);
       cal.add(Calendar.MINUTE, minutes);
       return cal.getTime();
   }
   /**
    * getStrTime<p>
    * Formats seconds as H:MM:SS (H omitted if 0). Negative yields "??".
    *
    * @param seconds total seconds
    * @return formatted time
    */
   public static String getStrTime(int seconds) {
       if (seconds < 0)
           return "??";
       String secs = String.format("%02d", seconds % 60);
       String hours = "";
       String mins = "0:";
       if (seconds > 3600) {
           hours = String.format("%d:", seconds / 3600);
       }
       if (seconds > 60) {
           mins = String.format("%02d:", (seconds / 60) % 60);
       }
       return hours + mins + secs;
   }
   /* --------------------- Collections & conversions --------------------- */
   /**
    * areAllEmpty<p>
    * Checks if all provided collections are empty.
    *
    * @param lists vararg of collections
    * @return true if all empty
    */
   public static boolean areAllEmpty(Collection<?>... lists) {
       for (Collection<?> list : lists) {
           if (!list.isEmpty())
               return false;
       }
       return true;
   }
   /**
    * toDateFromLocalDate<p>
    * Converts a {@link LocalDate} to {@link Date} at system default zone start of day.
    *
    * @param ld local date
    * @return Date or null
    */
   public static Date toDateFromLocalDate(LocalDate ld) {
       if (ld == null)
           return null;
       Instant instant = ld.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
       return Date.from(instant);
   }
   /**
    * toLocalDateFromDate<p>
    * Converts a {@link Date} to {@link LocalDate} at system default zone.
    *
    * @param date Date
    * @return LocalDate or null
    */
   public static LocalDate toLocalDateFromDate(Date date) {
       if (date == null)
           return null;
       Instant instant = Instant.ofEpochMilli(date.getTime());
       return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate();
   }
   /**
    * compare<p>
    * Null-safe equals: both null → true; otherwise {@code equals()}.
    *
    * @param obj1 first object
    * @param obj2 second object
    * @return equality result
    */
   public static boolean compare(Object obj1, Object obj2) {
       if (obj1 == null) {
           return obj2 == null;
       } else {
           return obj1.equals(obj2);
       }
   }
   /* --------------------- Email validation --------------------- */
   private static final String EMAIL_PATTERN_STR = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
   private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_PATTERN_STR);
   /**
    * isValidEmail<p>
    * Validates an email address format with a basic regex.
    *
    * @param email candidate value
    * @return valid or not
    */
   public static boolean isValidEmail(final String email) {
       if (email == null) {
           return false;
       }
       return EMAIL_PATTERN.matcher(email).matches();
   }
   /* --------------------- Iterable helpers --------------------- */
   /**
    * Reversed<p>
    * Iterable wrapper to iterate a List in reverse order without copying.
    *
    * @param <T> element type
    */
   public static class Reversed<T> implements Iterable<T> {
       private final List<T> original;
       public Reversed(List<T> original) {
           this.original = original;
       }
       public Iterator<T> iterator() {
           return new Iterator<T>() {
               int cursor = original.size();
               public boolean hasNext() { return cursor > 0; }
               public T next() { return original.get(--cursor); }
               public void remove() { throw new CurisRuntimeException("ERROR removing item in read-only iterator"); }
           };
       }
   }
   /**
    * reversedList<p>
    * Returns a reversed-iteration view of a list.
    *
    * @param original list to view
    * @param <T> element type
    * @return iterable reverse view
    */
   public static <T> Reversed<T> reversedList(List<T> original) {
       return new Reversed<T>(original);
   }
   /**
    * isSorted<p>
    * Checks if a list of Doubles is non-decreasing.
    *
    * @param original list
    * @return true if sorted ascending
    */
   public static boolean isSorted(List<Double> original) {
       for (int i = 0; i < (original.size() - 1); i++) {
           Double v0 = original.get(i);
           Double v1 = original.get(i + 1);
           if (v0.doubleValue() > v1.doubleValue()) {
               return false;
           }
       }
       return true;
   }
   /* --------------------- Simple file reading helpers --------------------- */
   /**
    * readFileLines<p>
    * Reads a file as UTF-8 and splits each line by a separator.
    *
    * @param file source file
    * @param separator regex separator
    * @return list of line fields
    * @throws IOException on I/O errors
    */
   public static List<List<String>> readFileLines(File file, final String separator) throws IOException {
       List<String> lines = Files.readAllLines(Paths.get(file.toURI()), Charset.forName("utf8"));
       return lines.stream().map(line -> Arrays.asList(line.split(separator))).collect(Collectors.toList());
   }
   /**
    * readStreamLines<p>
    * Reads an InputStream as UTF-8 and splits each line by a separator.
    *
    * @param stream input stream (caller closes it)
    * @param separator regex separator
    * @return list of line fields
    * @throws IOException on I/O errors
    */
   public static List<List<String>> readStreamLines(InputStream stream, final String separator) throws IOException {
       try (
               InputStreamReader isr = new InputStreamReader(stream, Charset.forName("UTF-8"));
               BufferedReader br = new BufferedReader(isr);
               ) {
           String line;
           List<List<String>> lines = new ArrayList<>(); 
           while ((line = br.readLine()) != null) {
               lines.add(Arrays.asList(line.split(separator))); 
           }
           return lines;
       }
   }
   /**
    * deleteDirectoryTree<p>
    * Recursively deletes a directory and its contents.
    *
    * @param baseDirectory directory path
    * @throws IOException on failure
    */
   public static void deleteDirectoryTree(Path baseDirectory) throws IOException {
       Files.walkFileTree(baseDirectory, new SimpleFileVisitor<Path>() {
           @Override
           public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
               Files.deleteIfExists(file);
               return FileVisitResult.CONTINUE;
           }
           @Override
           public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
               Files.deleteIfExists(dir);
               return FileVisitResult.CONTINUE;
           }
       });
   }
   /* --------------------- Directory size & tail --------------------- */
   private static class LongWrapper { long num = 0L; }
   /**
    * getDirectoryContentSize<p>
    * Computes total size (bytes) of files within a directory tree.
    *
    * @param baseDirectory root path
    * @return total bytes
    * @throws IOException on traversal errors
    */
   public static long getDirectoryContentSize(Path baseDirectory) throws IOException {
       final LongWrapper size = new LongWrapper();
       Files.walkFileTree(baseDirectory, new SimpleFileVisitor<Path>() {
           @Override
           public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
               size.num += file.toFile().length();
               return FileVisitResult.CONTINUE;
           }
           @Override
           public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
               if (!dir.equals(baseDirectory)) {
                   size.num += dir.toFile().length();
               }
               return FileVisitResult.CONTINUE;
           }
       });
       return size.num;
   }
   /**
    * waitFor<p>
    * Asynchronously waits until a condition is true or a timeout is reached.
    *
    * @param condition supplier that should eventually return true
    * @param timeout max wait (ms)
    * @return future completing with true if condition met
    * @throws TimeoutException surfaced through CompletionException if timed out
    */
   public static CompletableFuture<Boolean> waitFor(Supplier<Boolean> condition, long timeout) throws TimeoutException {
       return CompletableFuture.<Boolean>supplyAsync(() -> {
           long t0 = System.currentTimeMillis();
           while(!condition.get()) {
               long t1 = System.currentTimeMillis();
               if ((t1 - t0) > timeout) {
                   throw new CompletionException(new TimeoutException()); 
               }
               try {
                   Thread.sleep(100);
               } catch (InterruptedException e) {
                   throw new CompletionException(e); 
               }
           }
           return true;
       });
   }
   private static final int BLOCK_SIZE = 4096; // 4KB
   /**
    * getLastLines<p>
    * Efficiently reads the last N lines of a text file by scanning from the end in blocks.
    *
    * @param file file to read
    * @param numLines number of lines from the end
    * @return list of lines in natural order (oldest→newest among the last N)
    * @throws IOException on I/O errors
    */
   public static List<String> getLastLines(File file, int numLines) throws IOException {
       LinkedList<String> lines = new LinkedList<>();
       long fileSize = file.length();
       int chunk = (fileSize < BLOCK_SIZE) ? (int)fileSize : BLOCK_SIZE;
       long seekPos = fileSize - chunk;
       FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.READ);
       final byte newLine = (byte)'\n';
       String partialLine = null;
       while (lines.size() < numLines) {
           ByteBuffer dst = ByteBuffer.allocate(chunk);
           int bytesRead = fc.read(dst, seekPos);
           byte[] content = dst.array();
           int lastLineIdx = bytesRead;  
           for (int i = bytesRead - 1; i > 0 ; i--) {
               byte b = content[i];
               if (b == newLine) {
                   if (i < (bytesRead - 1) || partialLine != null) {
                       String line = new String(Arrays.copyOfRange(content, i, lastLineIdx)).trim();
                       if (partialLine != null) {
                           line += partialLine;
                           partialLine = null;
                       }
                       lines.addFirst(line);
                       if (lines.size() == numLines) {
                           return lines;
                       }
                   }
                   lastLineIdx = i;
               }
           }
           if (lastLineIdx > 0) {
               if (partialLine == null) {
                   partialLine = new String(Arrays.copyOfRange(content, 0, lastLineIdx)).trim();
               } else {
                   partialLine = new String(Arrays.copyOfRange(content, 0, lastLineIdx)) + partialLine;
               }
           }
           if (seekPos == 0) {
               lines.addFirst(partialLine);
               break;
           }
           if (seekPos < BLOCK_SIZE) {
               chunk = (int)seekPos;
               seekPos = 0;                
           } else {
               seekPos -= BLOCK_SIZE;
           }
       }
       return lines;
   }
   /**
    * removeDuplicates<p>
    * Returns a sorted list without duplicates using a set roundtrip.
    *
    * @param list input list
    * @param <T> type must be Comparable
    * @return sorted distinct list
    */
   public static <T> List<T> removeDuplicates(List<T> list) {
       return new HashSet<>(list).stream().sorted().collect(Collectors.toList());        
   }
   /* --------------------- Reflection helpers --------------------- */
   /**
    * setProperty<p>
    * Sets a bean property by name using Apache BeanUtils PropertyUtils.
    *
    * @param bean target bean
    * @param fieldName property name (nested supported)
    * @param value value to assign
    * @throws RuntimeException wrapping reflection errors
    */
   public static void setProperty(Object bean, String fieldName, Object value) {
       try {
           PropertyUtils.setProperty(bean, fieldName, value);
       } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
           LOG.error("Missing field:" + fieldName);
           throw new RuntimeException(e);
       }
   }
   /**
    * getProperty<p>
    * Reads a bean property by name using Apache PropertyUtils.
    *
    * @param bean target bean
    * @param fieldName property name
    * @return value
    * @throws RuntimeException wrapping reflection errors
    */
   public static Object getProperty(Object bean, String fieldName) {
       try {
           return PropertyUtils.getProperty(bean, fieldName);
       } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
           LOG.error("Missing field:" + fieldName);
           throw new RuntimeException(e);
       }
   }
   /**
    * cloneBean<p>
    * Clones a bean using Apache BeanUtils' copy mechanisms (shallow copy).
    *
    * @param bean source bean
    * @return new cloned bean
    * @throws CurisRuntimeException on cloning errors
    */
   public static Object cloneBean(Object bean) {
       try {
           return BeanUtils.cloneBean(bean);
       } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
           throw new CurisRuntimeException("Error cloning bean", e);
       }    
   }
}