Example usage for java.lang CloneNotSupportedException CloneNotSupportedException

List of usage examples for java.lang CloneNotSupportedException CloneNotSupportedException

Introduction

In this page you can find the example usage for java.lang CloneNotSupportedException CloneNotSupportedException.

Prototype

public CloneNotSupportedException(String s) 

Source Link

Document

Constructs a CloneNotSupportedException with the specified detail message.

Usage

From source file:Main.java

/**
 * Returns a clone of the specified object, if it can be cloned, otherwise
 * throws a CloneNotSupportedException./* www  .j  a  v  a 2 s .c o m*/
 * 
 * @param object
 *          the object to clone (<code>null</code> not permitted).
 * @return A clone of the specified object.
 * @throws CloneNotSupportedException
 *           if the object cannot be cloned.
 */
public static Object clone(final Object object) throws CloneNotSupportedException {
    if (object == null) {
        throw new IllegalArgumentException("Null 'object' argument.");
    }

    try {
        final Method method = object.getClass().getMethod("clone", (Class[]) null);
        if (Modifier.isPublic(method.getModifiers())) {
            return method.invoke(object, (Object[]) null);
        }
    } catch (NoSuchMethodException e) {
        System.out.println("Object without clone() method is impossible.");
    } catch (IllegalAccessException e) {
        System.out.println("Object.clone(): unable to call method.");
    } catch (InvocationTargetException e) {
        System.out.println("Object without clone() method is impossible.");
    }

    throw new CloneNotSupportedException("Failed to clone.");
}

From source file:com.networking.nemo.network.NetworkRequestManager.java

@Override
protected Object clone() throws CloneNotSupportedException {
    throw new CloneNotSupportedException("Cloning NetworkRequestManager is not allowed.");
}

From source file:org.sparkcommerce.core.offer.domain.CandidateItemOfferImpl.java

public void checkCloneable(CandidateItemOffer itemOffer)
        throws CloneNotSupportedException, SecurityException, NoSuchMethodException {
    Method cloneMethod = itemOffer.getClass().getMethod("clone", new Class[] {});
    if (cloneMethod.getDeclaringClass().getName().startsWith("org.sparkcommerce")
            && !itemOffer.getClass().getName().startsWith("org.sparkcommerce")) {
        //subclass is not implementing the clone method
        throw new CloneNotSupportedException(
                "Custom extensions and implementations should implement clone in order to guarantee split and merge operations are performed accurately");
    }/*w w  w  . java2s . c  o  m*/
}

From source file:org.pentaho.reporting.libraries.base.util.ObjectUtilities.java

/**
 * Returns a clone of the specified object, if it can be cloned, otherwise throws a CloneNotSupportedException.
 *
 * @param object the object to clone (<code>null</code> not permitted).
 * @return A clone of the specified object.
 * @throws CloneNotSupportedException if the object cannot be cloned.
 *//*  w w  w .  j a  v a2 s . c o  m*/
public static Object clone(final Object object) throws CloneNotSupportedException {
    if (object == null) {
        throw new IllegalArgumentException("Null 'object' argument.");
    }
    final Class aClass = object.getClass();
    if (aClass.isArray()) {
        final int length = Array.getLength(object);
        final Object clone = Array.newInstance(aClass.getComponentType(), length);
        //noinspection SuspiciousSystemArraycopy
        System.arraycopy(object, 0, clone, 0, length);
        return object;
    }

    try {
        final Method method = aClass.getMethod("clone", (Class[]) null);
        if (Modifier.isPublic(method.getModifiers())) {
            return method.invoke(object, (Object[]) null);
        }
        throw new CloneNotSupportedException(
                "Failed to clone: Method 'clone()' is not public on class " + aClass);
    } catch (NoSuchMethodException e) {
        LOGGER.warn("Object without clone() method is impossible on class " + aClass, e);
    } catch (IllegalAccessException e) {
        LOGGER.warn("Object.clone(): unable to call method 'clone()'  on class " + aClass, e);
    } catch (InvocationTargetException e) {
        LOGGER.warn("Object without clone() method is impossible on class " + aClass, e);
    }
    throw new CloneNotSupportedException(
            "Failed to clone: Clone caused an Exception while cloning type " + aClass);

}

From source file:org.broadleafcommerce.common.site.domain.CatalogImpl.java

public void checkCloneable(Catalog catalog)
        throws CloneNotSupportedException, SecurityException, NoSuchMethodException {
    Method cloneMethod = catalog.getClass().getMethod("clone", new Class[] {});
    if (cloneMethod.getDeclaringClass().getName().startsWith("org.broadleafcommerce")
            && !catalog.getClass().getName().startsWith("org.broadleafcommerce")) {
        //subclass is not implementing the clone method
        throw new CloneNotSupportedException("Custom extensions and implementations should implement clone.");
    }/*from   w ww  . j ava  2  s  .co m*/
}

From source file:org.sparkcommerce.core.order.domain.DiscreteOrderItemFeePriceImpl.java

public void checkCloneable(DiscreteOrderItemFeePrice discreteFeePrice)
        throws CloneNotSupportedException, SecurityException, NoSuchMethodException {
    Method cloneMethod = discreteFeePrice.getClass().getMethod("clone", new Class[] {});
    if (cloneMethod.getDeclaringClass().getName().startsWith("org.sparkcommerce")
            && !discreteFeePrice.getClass().getName().startsWith("org.sparkcommerce")) {
        //subclass is not implementing the clone method
        throw new CloneNotSupportedException(
                "Custom extensions and implementations should implement clone in order to guarantee split and merge operations are performed accurately");
    }/*from ww  w  . j  a  va  2 s.c om*/
}

From source file:org.broadleafcommerce.core.order.domain.DiscreteOrderItemFeePriceImpl.java

public void checkCloneable(DiscreteOrderItemFeePrice discreteFeePrice)
        throws CloneNotSupportedException, SecurityException, NoSuchMethodException {
    Method cloneMethod = discreteFeePrice.getClass().getMethod("clone", new Class[] {});
    if (cloneMethod.getDeclaringClass().getName().startsWith("org.broadleafcommerce")
            && !discreteFeePrice.getClass().getName().startsWith("org.broadleafcommerce")) {
        //subclass is not implementing the clone method
        throw new CloneNotSupportedException(
                "Custom extensions and implementations should implement clone in order to guarantee split and merge operations are performed accurately");
    }/*from w ww  .  j  a v a 2  s . c  o m*/
}

From source file:org.sparkcommerce.core.order.domain.BundleOrderItemFeePriceImpl.java

public void checkCloneable(BundleOrderItemFeePrice bundleFeePrice)
        throws CloneNotSupportedException, SecurityException, NoSuchMethodException {
    Method cloneMethod = bundleFeePrice.getClass().getMethod("clone", new Class[] {});
    if (cloneMethod.getDeclaringClass().getName().startsWith("org.sparkcommerce")
            && !bundleFeePrice.getClass().getName().startsWith("org.sparkcommerce")) {
        //subclass is not implementing the clone method
        throw new CloneNotSupportedException(
                "Custom extensions and implementations should implement clone in order to guarantee split and merge operations are performed accurately");
    }/*from  w  ww  .ja v a2s  .c o  m*/
}

From source file:org.broadleafcommerce.core.order.domain.BundleOrderItemFeePriceImpl.java

public void checkCloneable(BundleOrderItemFeePrice bundleFeePrice)
        throws CloneNotSupportedException, SecurityException, NoSuchMethodException {
    Method cloneMethod = bundleFeePrice.getClass().getMethod("clone", new Class[] {});
    if (cloneMethod.getDeclaringClass().getName().startsWith("org.broadleafcommerce")
            && !bundleFeePrice.getClass().getName().startsWith("org.broadleafcommerce")) {
        //subclass is not implementing the clone method
        throw new CloneNotSupportedException(
                "Custom extensions and implementations should implement clone in order to guarantee split and merge operations are performed accurately");
    }/*from   ww  w .  j  a v  a  2s .com*/
}

From source file:testful.runner.RemoteClassLoader.java

@Override
public RemoteClassLoader clone() throws CloneNotSupportedException {
    throw new CloneNotSupportedException("Clone not supported in RemoteClassLoader");
}