/** * Creates a copy of a conceptName * * @param conceptName the conceptName to be cloned * @return the cloned conceptName */ private ConceptName cloneConceptName(ConceptName conceptName) { ConceptName copy = new ConceptName(); try { copy = (ConceptName) BeanUtils.cloneBean(conceptName); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException e) { log.warn(errorMessage, e); } return copy; }
private Object clone(Object itemId) { final Object clone; try { clone = BeanUtils.cloneBean(itemId); } catch (Exception e) { throw new RuntimeException(e); } return clone; }
/** * clone自己 * * @return self type object */ @SuppressWarnings("unchecked") default <T> T cloneSelf() { try { return (T) BeanUtils.cloneBean(this); } catch (Exception e) { throw new RuntimeException(e); } }
public static Object cloneBean(Class<?> classe, Object bean) { try { Object cloneBean = classe.cast(BeanUtils.cloneBean(bean)); return classe.cast(cloneBean(cloneBean, cloneBean, bean)); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { throw new RuntimeException(ex); } }
public static Object cloneBean(Class<?> classe, Object bean) { try { Object cloneBean = classe.cast(BeanUtils.cloneBean(bean)); return classe.cast(cloneBean(cloneBean, cloneBean, bean)); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { throw new RuntimeException(ex); } }
@Override public ICrawlData clone() { try { return (ICrawlData) BeanUtils.cloneBean(this); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { throw new CollectorException( "Cannot clone HttpDocReference: " + this, e); } }
public static Object cloneBean(Object bean){ try { return org.apache.commons.beanutils.BeanUtils.cloneBean(bean); } catch (Exception e) { handleReflectionException(e); return null; } }
public ControllerConfiguration getRecommendedDefaultConfiguration( InputDevice inputDevice) { ControllerConfiguration result = recommendedDefaultConfigurations.get(inputDevice.getName()); if(result==null) result = recommendedDefaultConfigurations.get("fallback "+inputDevice.getClass().getName()); if(result!=null){ try{result = (ControllerConfiguration)BeanUtils.cloneBean(result);} catch(Exception e){e.printStackTrace();} }//end if(!null) return result; }//end getRecommendedDefaultConfiguration()
@SuppressWarnings("unchecked") public static <S, D> D map(final S source, final Class<D> destType) { D retVal = null; if (source != null) { try { retVal = (D)BeanUtils.cloneBean(source); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } } return retVal; }
/** * @see Obs#isDirty() */ @Test public void isDirty_shouldReturnFalseWhenNoChangeHasBeenMade() throws Exception { assertFalse(new Obs().isDirty()); //Should also work if setters are called with same values as the original Obs obs = createObs(2); obs.setGroupMembers(new LinkedHashSet<>()); obs.getConcept().setDatatype(new ConceptDatatype()); assertFalse(obs.isDirty()); BeanUtils.copyProperties(obs, BeanUtils.cloneBean(obs)); assertFalse(obs.isDirty()); obs = createObs(null); obs.setGroupMembers(new LinkedHashSet<>()); obs.getConcept().setDatatype(new ConceptDatatype()); assertFalse(obs.isDirty()); BeanUtils.copyProperties(obs, BeanUtils.cloneBean(obs)); assertFalse(obs.isDirty()); }
private static Object cloneBean(Object object) { try { return BeanUtils.cloneBean(object); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } }
private <T extends IntactObject> T clone(T intactObject) { T clone = null; try { clone = (T) BeanUtils.cloneBean(intactObject); clone.setAc(null); } catch (Exception e) { throw new IntactException("Problem creating intact object clone: "+intactObject, e); } return clone; }
public static void main(String[] args)throws Exception { Book book = new Book(); book.setIsbn("123"); Object cloneBean = BeanUtils.cloneBean(book); book.setName("xml.czy"); System.out.println(book); System.out.println(cloneBean); } }
private <T extends IntactObject> T clone(T intactObject) { T clone = null; try { clone = (T) BeanUtils.cloneBean(intactObject); clone.setAc(null); } catch (Exception e) { throw new IntactException("Problem creating intact object clone: "+intactObject, e); } return clone; }
/** * Should be overridden if log data structure is changed. */ private static LogEntry translate(LogEntry logEntry, DocumentRef newRef) { LogEntry newLogEntry; try { newLogEntry = (LogEntry) BeanUtils.cloneBean(logEntry); } catch (ReflectiveOperationException e) { throw new NuxeoException("cannot clone bean " + logEntry, e); } newLogEntry.setDocUUID(newRef); return newLogEntry; }
protected MailTemplate getTemplate(String templateName) throws Exception { final List<MailTemplate> configuration = mailModule.getTemplatesConfiguration(); for (MailTemplate mailTemplate : configuration) { if (StringUtils.equals(mailTemplate.getName(), templateName)) { MailTemplate cloned = (MailTemplate) BeanUtils.cloneBean(mailTemplate); cloned.setParameters(new HashMap<>(mailTemplate.getParameters())); cloned.setAttachments(new ArrayList<>(mailTemplate.getAttachments())); return cloned; } } return null; }
public static Object get(IdRef<?> id) { try { Object bean = store.get(createNamespacedId(id)); if (bean == null) { return null; } return BeanUtils.cloneBean(bean); } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { throw new RuntimeException(e); } }
@Override public Object clone () { try { return BeanUtils.cloneBean(this); } catch (IllegalAccessException illegalAccessException) { throw new CloneFailedException("Illegal access exception thrown", illegalAccessException); } catch (InstantiationException instantiationException) { throw new CloneFailedException("Failed to instantiate the class.", instantiationException); } catch (InvocationTargetException invocationTargetException) { throw new CloneFailedException("Invocation target exception thrown.", invocationTargetException); } catch (NoSuchMethodException noSuchMethodException) { throw new CloneFailedException("No such method exception thrown.", noSuchMethodException); } }
@Override @SneakyThrows public Account mapAccount(InputStream jsonStream) { GraphQlResponse<Account> graphQlResponse = mapObject(jsonStream, "me/postaddict/instagram/scraper/model/account-binding.json", GraphQlResponse.class); Account account = graphQlResponse.getPayload(); Account accountCopy = (Account) BeanUtils.cloneBean(account); accountCopy.setMedia(null); if(account.getMedia()!=null && account.getMedia().getNodes()!=null) { account.getMedia().getNodes().forEach(media -> media.setOwner(accountCopy)); account.getMedia().getNodes().forEach(this::updateMediaTime); } return account; }
@Override @SneakyThrows public Account mapAccount(InputStream jsonStream) { GraphQlResponse<Account> graphQlResponse = mapObject(jsonStream, "me/postaddict/instagram/scraper/model/account-binding.json", GraphQlResponse.class); Account account = graphQlResponse.getPayload(); Account accountCopy = (Account) BeanUtils.cloneBean(account); accountCopy.setMedia(null); if(account.getMedia()!=null && account.getMedia().getNodes()!=null) { account.getMedia().getNodes().forEach(media -> media.setOwner(accountCopy)); account.getMedia().getNodes().forEach(this::updateMediaTime); } return account; }