org.jboss.marshalling.cloner.CloneableCloner Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.marshalling.cloner;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.InvalidObjectException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.IdentityHashMap;
/**
* An object cloner which clones objects that implement {@link Cloneable}.
*/
class CloneableCloner implements ObjectCloner {
private final CloneTable cloneTable;
/**
* Create a new instance.
*
* @param configuration the configuration
*/
CloneableCloner(final ClonerConfiguration configuration) {
final CloneTable cloneTable = configuration.getCloneTable();
this.cloneTable = cloneTable == null ? CloneTable.NULL : cloneTable;
}
private static final Method CLONE = AccessController.doPrivileged(new PrivilegedAction() {
public Method run() {
final Method method;
try {
method = Object.class.getDeclaredMethod("clone");
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
}
method.setAccessible(true);
return method;
}
});
/** {@inheritDoc} */
public void reset() {
synchronized (this) {
clones.clear();
}
}
private final IdentityHashMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy