Java Code Examples for org.apache.commons.beanutils.BeanUtils#cloneBean()
The following examples show how to use
org.apache.commons.beanutils.BeanUtils#cloneBean() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonConfigurationAction.java From oxTrust with MIT License | 6 votes |
private String getProtectedOxTrustappConfiguration(AppConfiguration oxTrustappConfiguration) { if (oxTrustappConfiguration != null) { try { AppConfiguration resultOxTrustappConfiguration = (AppConfiguration) BeanUtils .cloneBean(oxTrustappConfiguration); resultOxTrustappConfiguration.setKeystorePassword(HIDDEN_PASSWORD_TEXT); resultOxTrustappConfiguration.setIdpSecurityKeyPassword(HIDDEN_PASSWORD_TEXT); resultOxTrustappConfiguration.setIdpBindPassword(HIDDEN_PASSWORD_TEXT); resultOxTrustappConfiguration.setCaCertsPassphrase(HIDDEN_PASSWORD_TEXT); resultOxTrustappConfiguration.setOxAuthClientPassword(HIDDEN_PASSWORD_TEXT); return jsonService.objectToJson(resultOxTrustappConfiguration); } catch (Exception ex) { log.error("Failed to prepare JSON from appConfiguration: '{}'", oxTrustappConfiguration, ex); } return null; } return null; }
Example 2
Source File: Fido2DeviceTest.java From SCIM-Client with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "retrieve") public void updateWithJson() throws Exception{ //shallow clone device Fido2DeviceResource clone=(Fido2DeviceResource) BeanUtils.cloneBean(device); String name = "The quick brown fox jumps over the lazy dog"; clone.setDisplayName(name); String json=mapper.writeValueAsString(clone); logger.debug("Updating device with json"); Response response=client.updateF2Device(json, device.getId(), null, null); assertEquals(response.getStatus(), OK.getStatusCode()); Fido2DeviceResource updated=response.readEntity(fido2Class); assertNotEquals(updated.getDisplayName(), device.getDisplayName()); assertEquals(updated.getDisplayName(), name); }
Example 3
Source File: LuceneEngine.java From jstarcraft-core with Apache License 2.0 | 6 votes |
public LuceneEngine(IndexWriterConfig config, Path path) { try { this.config = config; Directory transienceDirectory = new ByteBuffersDirectory(); this.transienceManager = new TransienceManager((IndexWriterConfig) BeanUtils.cloneBean(config), transienceDirectory); Directory persistenceDirectory = FSDirectory.open(path); this.persistenceManager = new PersistenceManager((IndexWriterConfig) BeanUtils.cloneBean(config), persistenceDirectory); this.searcher = new LuceneSearcher(this.transienceManager, this.persistenceManager); this.semaphore = new AtomicInteger(); ReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); } catch (Exception exception) { throw new StorageException(exception); } }
Example 4
Source File: FidoU2fDeviceTest.java From SCIM-Client with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "retrieve") public void updateWithJson() throws Exception{ //shallow clone device FidoDeviceResource clone=(FidoDeviceResource) BeanUtils.cloneBean(device); clone.setDisplayName(Double.toString(Math.random())); clone.setNickname("compromised"); String json=mapper.writeValueAsString(clone); logger.debug("Updating device with json"); Response response=client.updateDevice(json, device.getId(), null, null); assertEquals(response.getStatus(), OK.getStatusCode()); FidoDeviceResource updated=response.readEntity(fidoClass); assertNotEquals(updated.getDisplayName(), device.getDisplayName()); assertEquals(updated.getNickname(), "compromised"); }
Example 5
Source File: AbstractCardsProvider.java From MtgDesktopCompanion with GNU General Public License v3.0 | 6 votes |
@Override public MagicEdition getSetById(String id) { try { MagicEdition ed = cacheEditions.get(id, new Callable<MagicEdition>() { @Override public MagicEdition call() throws Exception { return listEditions().stream().filter(ed->ed.getId().equalsIgnoreCase(id)).findAny().orElse(new MagicEdition(id,id)); } }); return (MagicEdition) BeanUtils.cloneBean(ed); } catch (Exception e) { return new MagicEdition(id,id); } }
Example 6
Source File: MockStore.java From yawp with MIT License | 5 votes |
private static Object cloneBean(Object object) { try { return BeanUtils.cloneBean(object); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } }
Example 7
Source File: LogObjectHolder.java From web-flash with MIT License | 5 votes |
public void set(Object obj) { try { //为表面后面的逻辑对obj进行变更,这里克隆一份存储,用于后续变化对比 Object cloneObj = BeanUtils.cloneBean(obj); this.object = cloneObj; } catch (Exception e) { e.printStackTrace(); } }
Example 8
Source File: MockStore.java From yawp with MIT License | 5 votes |
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); } }
Example 9
Source File: ArticleController.java From website with GNU Affero General Public License v3.0 | 5 votes |
private Article createNewArticleRevision(Article article) { Article newArticle = null; try { newArticle = (Article) BeanUtils.cloneBean(article); newArticle.setId(null); newArticle.setCreatedDate(null); newArticle.setRevision(article.getRevision() + 1); } catch (Exception e) { e.printStackTrace(); newArticle = article; } return newArticle; }
Example 10
Source File: OrderUtil.java From AlgoTrader with GNU General Public License v2.0 | 5 votes |
public static Order modifyOrderQuantity(Order order, long quantity) { try { Order newOrder = (Order) BeanUtils.cloneBean(order); newOrder.setQuantity(quantity); return newOrder; } catch (Exception e) { throw new RuntimeException(e); } }
Example 11
Source File: OrderUtil.java From AlgoTrader with GNU General Public License v2.0 | 5 votes |
public static LimitOrder modifyOrderLimit(LimitOrder order, BigDecimal limit) { try { LimitOrder newOrder = (LimitOrder) BeanUtils.cloneBean(order); newOrder.setLimit(limit); return newOrder; } catch (Exception e) { throw new RuntimeException(e); } }
Example 12
Source File: FIXClient.java From sailfish-core with Apache License 2.0 | 5 votes |
@Override public IServiceSettings getSettings() { try { //return copy of the settings to prevent it's change return fixSettings != null ? (IServiceSettings)BeanUtils.cloneBean(fixSettings) : null; } catch (Exception e) { logger.error("Could not copy settings object", e); throw new EPSCommonException("Could not copy settings object", e); } }
Example 13
Source File: LuceneEngine.java From jstarcraft-core with Apache License 2.0 | 5 votes |
/** * 合并管理器 * * @throws Exception */ void mergeManager() throws Exception { writeLock.lock(); TransienceManager newTransienceManager = new TransienceManager((IndexWriterConfig) BeanUtils.cloneBean(config), new ByteBuffersDirectory()); TransienceManager oldTransienceManager = this.transienceManager; try { lockWrite(); this.transienceManager = newTransienceManager; // 触发变更 this.persistenceManager.setManager(oldTransienceManager); } finally { unlockWrite(); } // 此处需要防止有线程在使用时关闭. try { lockRead(); // 只关闭writer,不关闭reader. oldTransienceManager.close(); } finally { unlockRead(); } this.persistenceManager.mergeManager(); try { lockWrite(); // 触发变更 this.persistenceManager.setManager(null); } finally { unlockWrite(); } writeLock.unlock(); }
Example 14
Source File: CustomerLoadServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Clone the address object * * @param address * @return */ private CustomerAddress cloneCustomerAddress(CustomerAddress address) { CustomerAddress clonedAddress = null; try { clonedAddress = (CustomerAddress) BeanUtils.cloneBean(address); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { LOG.error("Unable to clone address [" + address + "]", ex); throw new RuntimeException("Unable to clone address [" + address + "]", ex); } return clonedAddress; }
Example 15
Source File: ServerConfigManagementService.java From identity-api-server with Apache License 2.0 | 5 votes |
/** * Create a shallow copy of the input Service Provider. * * @param serviceProvider Service Provider. * @return Clone of Application. */ private ServiceProvider createApplicationClone(ServiceProvider serviceProvider) { try { return (ServiceProvider) BeanUtils.cloneBean(serviceProvider); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { throw handleException(Response.Status.INTERNAL_SERVER_ERROR, Constants.ErrorMessage .ERROR_CODE_ERROR_UPDATING_CONFIGS, null); } }
Example 16
Source File: ServerConfigManagementService.java From identity-api-server with Apache License 2.0 | 5 votes |
/** * Create a shallow copy of the input Identity Provider. * * @param idP Identity Provider. * @return Clone of IDP. */ private IdentityProvider createIdPClone(IdentityProvider idP) { try { return (IdentityProvider) BeanUtils.cloneBean(idP); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { throw handleException(Response.Status.INTERNAL_SERVER_ERROR, Constants.ErrorMessage .ERROR_CODE_ERROR_UPDATING_CONFIGS, null); } }
Example 17
Source File: ServerIdpManagementService.java From identity-api-server with Apache License 2.0 | 5 votes |
/** * Create a duplicate of the input Identity Provider. * * @param idP Identity Provider. * @return Clone of IDP. */ private IdentityProvider createIdPClone(IdentityProvider idP) { try { return (IdentityProvider) BeanUtils.cloneBean(idP); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) { throw handleException(Response.Status.INTERNAL_SERVER_ERROR, Constants.ErrorMessage .ERROR_CODE_ERROR_UPDATING_IDP, idP.getResourceId()); } }
Example 18
Source File: LogObjectHolder.java From flash-waimai with MIT License | 5 votes |
public void set(Object obj) { try { //为表面后面的逻辑对obj进行变更,这里克隆一份存储,用于后续变化对比 Object cloneObj = BeanUtils.cloneBean(obj); this.object = cloneObj; } catch (Exception e) { e.printStackTrace(); } }
Example 19
Source File: ActionEdit.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception { ActionResult<Wo> result = new ActionResult<>(); WrapProcess wrap = this.convertToWrapIn(jsonElement, WrapProcess.class); try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { Business business = new Business(emc); Process process = emc.find(id, Process.class); if (null == process) { throw new ExceptionProcessNotExisted(id); } Application application = emc.find(process.getApplication(), Application.class); if (null == application) { throw new ExceptionApplicationNotExist(process.getApplication()); } if (!business.editable(effectivePerson, application)) { throw new ExceptionApplicationAccessDenied(effectivePerson.getDistinguishedName(), application.getName(), application.getId()); } Process oldProcess = (Process) BeanUtils.cloneBean(process); emc.beginTransaction(Process.class); emc.beginTransaction(Agent.class); emc.beginTransaction(Begin.class); emc.beginTransaction(Cancel.class); emc.beginTransaction(Choice.class); emc.beginTransaction(Delay.class); emc.beginTransaction(Embed.class); emc.beginTransaction(End.class); emc.beginTransaction(Invoke.class); emc.beginTransaction(Manual.class); emc.beginTransaction(Merge.class); emc.beginTransaction(Message.class); emc.beginTransaction(Parallel.class); emc.beginTransaction(Route.class); emc.beginTransaction(Service.class); emc.beginTransaction(Split.class); WrapProcess.inCopier.copy(wrap, process); this.updateCreatePersonLastUpdatePerson(effectivePerson, business, process); this.updateEdition(oldProcess, process); process.setLastUpdateTime(new Date()); emc.check(process, CheckPersistType.all); update_agent(business, wrap.getAgentList(), process); update_begin(business, wrap.getBegin(), process); update_cancel(business, wrap.getCancelList(), process); update_choice(business, wrap.getChoiceList(), process); update_delay(business, wrap.getDelayList(), process); update_embed(business, wrap.getEmbedList(), process); update_end(business, wrap.getEndList(), process); update_invoke(business, wrap.getInvokeList(), process); update_manual(business, wrap.getManualList(), process); update_merge(business, wrap.getMergeList(), process); update_message(business, wrap.getMessageList(), process); update_parallel(business, wrap.getParallelList(), process); update_route(business, wrap.getRouteList(), process); update_service(business, wrap.getServiceList(), process); update_split(business, wrap.getSplitList(), process); emc.commit(); cacheNotify(); /* 保存历史版本 */ ThisApplication.processVersionQueue.send(new ProcessVersion(process.getId(), jsonElement)); Wo wo = new Wo(); wo.setId(process.getId()); result.setData(wo); MessageFactory.process_update(process); return result; } }
Example 20
Source File: BeanUtil.java From feilong-core with Apache License 2.0 | 3 votes |
/** * 调用{@link BeanUtils#cloneBean(Object)}. * * <h3>注意:</h3> * <blockquote> * * <ol> * <li>这个方法通过<b>默认构造函数</b>建立一个bean的新实例,然后拷贝每一个属性到这个新的bean中,即使这个bean没有实现 {@link Cloneable}接口 .</li> * <li>是为那些本身没有实现clone方法的类准备的</li> * <li>在源码上看是调用了 <b>getPropertyUtils().copyProperties(newBean, bean)</b>;最后实际上还是<b>复制的引用,无法实现深clone</b><br> * 但还是可以帮助我们减少工作量的,假如类的属性不是基础类型的话(即自定义类),可以先clone出那个自定义类,在把他付给新的类,覆盖原来类的引用 * </li> * <li> * 如果需要深度clone,可以使用 {@link org.apache.commons.lang3.SerializationUtils#clone(java.io.Serializable) SerializationUtils.clone} * ,但是它的性能要慢很多倍</li> * <li>由于内部实现是通过 {@link java.lang.Class#newInstance() Class.newInstance()}来构造新的对象,所以需要被clone的对象<b>必须存在默认无参构造函数</b>,否则会出现异常 * {@link java.lang.InstantiationException InstantiationException}</li> * <li>目前无法clone list,总是返回empty list,参见 * <a href="https://issues.apache.org/jira/browse/BEANUTILS-471">BeanUtils.cloneBean with List is broken</a> * </li> * </ol> * </blockquote> * * @param <T> * the generic type * @param bean * Bean to be cloned * @return the cloned bean (复制的引用 ,无法实现深clone)<br> * @throws NullPointerException * 如果 <code>bean</code> 是null * @throws BeanOperationException * 在调用api有任何异常,转成{@link BeanOperationException}返回 * @see org.apache.commons.beanutils.BeanUtils#cloneBean(Object) * @see org.apache.commons.beanutils.PropertyUtilsBean#copyProperties(Object, Object) * @see org.apache.commons.lang3.SerializationUtils#clone(java.io.Serializable) * @see org.apache.commons.lang3.ObjectUtils#clone(Object) * @see org.apache.commons.lang3.ObjectUtils#cloneIfPossible(Object) * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-471">BeanUtils.cloneBean with List is broken</a> */ @SuppressWarnings("unchecked") public static <T> T cloneBean(T bean){ Validate.notNull(bean, "bean can't be null!"); //--------------------------------------------------------------- try{ return (T) BeanUtils.cloneBean(bean); }catch (Exception e){ String message = Slf4jUtil.format("cloneBean exception,bean:[{}]]", bean); throw new BeanOperationException(message, e); } }