List of usage examples for org.apache.commons.lang SerializationUtils clone
public static Object clone(Serializable object)
Deep clone an Object
using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:org.pentaho.osgi.platform.webjars.utils.RequireJsGenerator.java
private Map<String, Object> modifyConfigPaths(HashMap<String, String> artifactModules) { Map<String, Object> requirejs = new HashMap<>(); HashMap<String, String> keyMap = new HashMap<>(); HashMap<String, Object> moduleDetails = new HashMap<>(); moduleDetails.put("name", moduleInfo.getName()); moduleDetails.put("versionedName", moduleInfo.getVersionedName()); moduleDetails.put("path", moduleInfo.getPath()); moduleDetails.put("versionedPath", moduleInfo.getVersionedPath()); if (dependencies != null && !dependencies.isEmpty()) { moduleDetails.put("dependencies", dependencies); }/*from w ww.jav a 2 s. co m*/ final boolean isAmdPackage = moduleInfo.isAmdPackage(); moduleDetails.put("isAmdPackage", isAmdPackage); if (!isAmdPackage && moduleInfo.getExports() != null) { moduleDetails.put("exports", moduleInfo.getExports()); } final HashMap<String, String> paths = (HashMap<String, String>) requireConfig.get("paths"); if (paths != null) { HashMap<String, String> convertedPaths = new HashMap<>(); for (String key : paths.keySet()) { String versionedKey; if (key.startsWith("./")) { versionedKey = moduleInfo.getVersionedName() + key.substring(1); } else { versionedKey = key + "_" + moduleInfo.getVersion(); Map<String, Object> module = new HashMap<>(); module.put(moduleInfo.getVersion(), moduleDetails); moduleInfo.addModuleId(key, module); artifactModules.put(key, moduleInfo.getVersion()); } keyMap.put(key, versionedKey); String path = paths.get(key); if (path.length() > 0) { if (path.startsWith("/")) { convertedPaths.put(versionedKey, path); } else { convertedPaths.put(versionedKey, moduleInfo.getVersionedPath() + "/" + path); } } else { convertedPaths.put(versionedKey, moduleInfo.getVersionedPath()); } } requirejs.put("paths", convertedPaths); } final List packages = (List) requireConfig.get("packages"); if (packages != null && !packages.isEmpty()) { moduleDetails.put("packages", SerializationUtils.clone((Serializable) packages)); List<Object> convertedPackages = new ArrayList<>(); for (Object pack : packages) { if (pack instanceof String) { String packageName = (String) pack; String convertedName; if (!packageName.isEmpty()) { convertedName = moduleInfo.getVersionedName() + "/" + packageName; } else { packageName = moduleInfo.getName(); convertedName = moduleInfo.getVersionedName(); } keyMap.put(packageName, convertedName); keyMap.put(packageName + "/main", convertedName + "/main"); convertedPackages.add(convertedName); } else if (pack instanceof HashMap) { final HashMap<String, String> packageObj = (HashMap<String, String>) pack; if (((HashMap) pack).containsKey("name")) { String packageName = packageObj.get("name"); final String mainScript = ((HashMap) pack).containsKey("main") ? packageObj.get("main") : "main"; String convertedName; if (!packageName.isEmpty()) { convertedName = moduleInfo.getVersionedName() + "/" + packageName; } else { packageName = moduleInfo.getName(); convertedName = moduleInfo.getVersionedName(); } keyMap.put(packageName, convertedName); keyMap.put(packageName + "/" + mainScript, convertedName + "/" + mainScript); packageObj.put("name", convertedName); } convertedPackages.add(pack); } } requirejs.put("packages", convertedPackages); } final HashMap<String, ?> shim = (HashMap<String, ?>) requireConfig.get("shim"); if (shim != null) { requirejs.put("shim", convertSubConfig(keyMap, shim)); } final HashMap<String, ?> map = (HashMap<String, ?>) requireConfig.get("map"); if (map != null) { requirejs.put("map", convertSubConfig(keyMap, map)); } final HashMap<String, ?> config = (HashMap<String, ?>) requireConfig.get("config"); if (config != null) { requirejs.put("config", convertSubConfig(keyMap, config)); } return requirejs; }
From source file:org.seasar.caching.interceptor.CallCacheInterceptor.java
public Object invoke(MethodInvocation invocation) throws Throwable { // ???Serializable??????????????? if (!isAllArgumentsSerializable(invocation) || !isReturnTypeSerializable(invocation)) { return invocation.proceed(); }/*from w w w . java 2 s .c o m*/ // ??Serializable??? CallDescription???????? CallDescription description = new CallDescription(invocation); Element element = cache.get(description); if (element != null) { Serializable originalResult = element.getValue(); return SerializationUtils.clone(originalResult); } else { Object result = invocation.proceed(); // ???????????? Element insertElement = new Element(description, (Serializable) result); cache.put(insertElement); return SerializationUtils.clone((Serializable) result); } }
From source file:org.springframework.sync.util.DeepCloneUtils.java
/** * Deep clones an object.//w ww. j a va2 s. c om * @param original a single, non-list object to be cloned * @param <T> the object's type * @return the cloned object */ @SuppressWarnings("unchecked") public static <T> T deepClone(T original) { return (T) SerializationUtils.clone((Serializable) original); }
From source file:org.springframework.sync.util.DeepCloneUtils.java
/** * Deep clones a list./* w w w. j ava2s. c o m*/ * @param original a list to be cloned * @param <T> the list's generic type * @return the cloned list */ @SuppressWarnings("unchecked") public static <T> List<T> deepClone(List<T> original) { List<T> copy = new ArrayList<T>(original.size()); for (T t : original) { copy.add((T) SerializationUtils.clone((Serializable) t)); } return copy; }
From source file:org.syncope.client.util.AttributableOperations.java
public static <T extends AbstractAttributableTO> T clone(final T original) { return (T) SerializationUtils.clone(original); }
From source file:org.syncope.core.init.ConnInstanceLoader.java
/** * Create connector bean starting from connector instance and configuration * properties. This method has to be used to create a connector instance * without any linked external resource. * @param connInstance connector instance. * @param configuration configuration properties. * @return connector facade proxy./*from w ww. j ava 2 s . com*/ * @throws NotFoundException when not able to fetch all the required data. */ public ConnectorFacadeProxy createConnectorBean(final ConnInstance connInstance, final Set<ConnConfProperty> configuration) throws NotFoundException { final ConnInstance connInstanceClone = (ConnInstance) SerializationUtils.clone(connInstance); connInstanceClone.setConfiguration(configuration); return new ConnectorFacadeProxy(connInstanceClone, connBundleManager); }
From source file:org.wicketopia.metadata.TestWicketopiaBeanFacet.java
@Test public void testSerialization() { final BeanMetaDataFactory factory = new BeanMetaDataFactory(); final BeanMetaData metaData = factory.getBeanMetaData(Person.class); WicketopiaBeanFacet facet = WicketopiaBeanFacet.get(metaData); assertSame(SerializationUtils.clone(facet), facet); }
From source file:org.wicketopia.metadata.TestWicketopiaPropertyFacet.java
@Test public void testSerialization() { final BeanMetaDataFactory factory = new BeanMetaDataFactory(); final BeanMetaData metaData = factory.getBeanMetaData(Person.class); WicketopiaPropertyFacet first = WicketopiaPropertyFacet.get(metaData.getPropertyMetaData("first")); assertSame(SerializationUtils.clone(first), first); }
From source file:org.yes.cart.payment.impl.AuthInvoicePaymentGatewayImpl.java
/** * {@inheritDoc}/*from www. ja va2s .c o m*/ */ public Payment authorize(Payment paymentIn) { final Payment payment = (Payment) SerializationUtils.clone(paymentIn); payment.setTransactionOperation(AUTH); payment.setTransactionReferenceId(UUID.randomUUID().toString()); payment.setTransactionAuthorizationCode(UUID.randomUUID().toString()); payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_OK); payment.setPaymentProcessorBatchSettlement(false); return payment; }
From source file:org.yes.cart.payment.impl.AuthInvoicePaymentGatewayImpl.java
/** * {@inheritDoc}/*ww w.ja va2 s . co m*/ */ public Payment reverseAuthorization(Payment paymentIn) { final Payment payment = (Payment) SerializationUtils.clone(paymentIn); payment.setTransactionOperation(REVERSE_AUTH); payment.setTransactionReferenceId(UUID.randomUUID().toString()); payment.setTransactionAuthorizationCode(UUID.randomUUID().toString()); payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_OK); payment.setPaymentProcessorBatchSettlement(false); return payment; }