This is the method I was referring to: /** * Renames and/or renumbers a document. * - If object is RevisionControlled, this affects the MASTER (which means ALL version are affected). * - The Mastered or the Identified object must have a setName() and setNumber() in order to actually * update the name and number. If the method does not exist, a warning will be displayed with a * stack trace, and the method will continue anyway. * @param pers - the object to rename/renumber. Should support any RevisionControlled or Identified * implementation/subclass. * @param newName - The desired target name. If null, defaults to match current name. * @param newNumber - The desired target number. If null, defaults to match the current Number. * * @throws WTException * @throws ObjectNoLongerExistsException */ public static void changeIdentity(Persistable pers, String newName, String newNumber) throws WTException, ObjectNoLongerExistsException {
// Look for the setName method (using reflection because we don't know which subclass it may be // and it's not part of the interface) try { Method setName = idObj.getClass().getMethod("setName", new Class[]{String.class}); setName.invoke(idObj, new Object[]{newName}); } catch (SecurityException e) { log.error(e.getMessage(), e); } catch (IllegalArgumentException e) { log.error(e.getMessage(), e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); } catch (InvocationTargetException e) { log.error(e.getMessage(), e); }
// Look for the setNumber method (using reflection because we don't know which subclass it may be // and it's not part of the interface) try { Method setNumber = idObj.getClass().getMethod("setNumber", new Class[]{String.class}); setNumber.invoke(idObj, new Object[]{newNumber}); } catch (SecurityException e) { log.error(e.getMessage(), e); } catch (IllegalArgumentException e) { log.error(e.getMessage(), e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); } catch (InvocationTargetException e) { log.error(e.getMessage(), e); }
id = IdentityHelper.service.changeIdentity(id, idObj); pers = PersistenceHelper.manager.refresh(pers, true, true); }