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:org.broadleafcommerce.common.copy.MultiTenantCopyContext.java

/**
 * Detects whether or not the current cloned entity is an extension of an entity in Broadleaf, and if so, if the
 * extension itself does not implement clone.
 *
 * @param cloned the cloned entity instance
 * @throws CloneNotSupportedException thrown if the entity is an extension and is does not implement clone
 *///from  www  .j a v  a  2s  .  com
public void checkCloneable(Object cloned) throws CloneNotSupportedException {
    Method cloneMethod;
    try {
        cloneMethod = cloned.getClass().getMethod("createOrRetrieveCopyInstance",
                new Class[] { MultiTenantCopyContext.class });
    } catch (NoSuchMethodException e) {
        throw ExceptionHelper.refineException(e);
    }
    boolean cloneMethodLocal = false;
    for (String prefix : BROADLEAF_PACKAGE_PREFIXES) {
        if (cloneMethod.getDeclaringClass().getName().startsWith(prefix)) {
            cloneMethodLocal = true;
            break;
        }
    }
    boolean cloneClassLocal = false;
    for (String prefix : BROADLEAF_PACKAGE_PREFIXES) {
        if (cloned.getClass().getName().startsWith(prefix)) {
            cloneClassLocal = true;
            break;
        }
    }
    if (cloneMethodLocal && !cloneClassLocal) {
        //subclass is not implementing the clone method
        throw new CloneNotSupportedException("The system is attempting to clone " + cloned.getClass().getName()
                + " and has determined the custom extension does not implement clone. This class should implement "
                + "clone, and inside first call super.clone() to get back an instance of your class ("
                + cloned.getClass().getName()
                + "), and then finish populating this instance with your custom fields before passing back the finished object.");
    }
}

From source file:org.kuali.rice.krad.uif.util.CopyUtils.java

/**
 * Get a shallow copy (clone) of an object.
 * //from ww  w  . j a  v  a2s .co  m
 * <p>
 * This method simplifies access to the clone() method.
 * </p>
 * 
 * @param <T> copyable type
 * @param obj The object to clone.
 * @return A shallow copy of obj, or null if obj is null.
 * @throws CloneNotSupportedException If copying is not available on the object, or if thrown by
 *         clone() itself. When isShallowCopyAvailable() returns true, then this exception is
 *         not expected and may be considered an internal error.
 */
@SuppressWarnings("unchecked")
public static <T> T getShallowCopy(T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }

    if (ViewLifecycle.isTrace()) {
        ProcessLogger.ntrace("clone:", ":" + obj.getClass().getSimpleName(), 1000);
    }

    synchronized (obj) {
        if (obj instanceof Copyable) {
            return (T) ((Copyable) obj).clone();
        }

        if (obj instanceof Object[]) {
            return (T) ((Object[]) obj).clone();
        }

        // synchronized on collections/maps below here is to avoid
        // concurrent modification
        if (obj instanceof ArrayList) {
            return (T) ((ArrayList<?>) obj).clone();
        }

        if (obj instanceof LinkedList) {
            return (T) ((LinkedList<?>) obj).clone();
        }

        if (obj instanceof HashSet) {
            return (T) ((HashSet<?>) obj).clone();
        }

        if (obj instanceof HashMap) {
            return (T) ((HashMap<?, ?>) obj).clone();
        }

        throw new CloneNotSupportedException(
                "Not a supported copyable type.  This condition should not be reached. " + obj.getClass() + " "
                        + obj);
    }
}

From source file:org.sparkcommerce.openadmin.server.security.domain.AdminRoleImpl.java

public void checkCloneable(AdminRole adminRole)
        throws CloneNotSupportedException, SecurityException, NoSuchMethodException {
    Method cloneMethod = adminRole.getClass().getMethod("clone", new Class[] {});
    if (cloneMethod.getDeclaringClass().getName().startsWith("org.sparkcommerce")
            && !adminRole.getClass().getName().startsWith("org.sparkcommerce")) {
        //subclass is not implementing the clone method
        throw new CloneNotSupportedException("Custom extensions and implementations should implement clone.");
    }// ww w  . jav  a2 s .  com
}

From source file:org.broadleafcommerce.openadmin.server.security.domain.AdminRoleImpl.java

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

From source file:org.dresdenocl.pivotmodel.impl.NamedElementImpl.java

/**
 * The default implementation in this class throws a
 * {@link CloneNotSupportedException}. Subclasses may override to implement
 * cloning behaviour. Because <code>NamedElement</code> is at the root of the
 * inheritance tree, we do not make this method abstract. This avoids having
 * to change all subclasses.//  ww w.j a va 2s.  c  o m
 * 
 * @throws CloneNotSupportedException
 *           if this element does not support cloning
 * 
 * @generated NOT
 */
@Override
public NamedElement clone() throws CloneNotSupportedException {

    throw new CloneNotSupportedException("Element " + this + " does not support cloning."); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:com.gzj.tulip.jade.context.JadeInvocationHandler.java

private Object invokeObjectMethod(Object proxy, Method method, Object[] args)
        throws CloneNotSupportedException {
    String methodName = method.getName();
    if (methodName.equals("toString")) {
        return JadeInvocationHandler.this.toString();
    }/*  w  w w . j av a 2 s.c  o m*/
    if (methodName.equals("hashCode")) {
        return daoMetaData.getDAOClass().hashCode() * 13 + this.hashCode();
    }
    if (methodName.equals("equals")) {
        return args[0] == proxy;
    }
    if (methodName.equals("clone")) {
        throw new CloneNotSupportedException("clone is not supported for jade dao.");
    }
    throw new UnsupportedOperationException(daoMetaData.getDAOClass().getName() + "#" + method.getName());
}

From source file:com.krminc.phr.security.PHRRealm.java

protected Object clone() throws CloneNotSupportedException {
    throw new CloneNotSupportedException("Not supported");
}

From source file:org.broadleafcommerce.common.copy.MultiTenantCopyContext.java

/**
 * Create a new instance of the polymorphic entity type - could be an extended type outside of Broadleaf.
 *
 * @param instance the object instance for the actual entity type (could be extended)
 * @param <G>/*from ww w  . j a  v  a  2s . c o m*/
 * @return the new, empty instance of the entity
 * @throws java.lang.CloneNotSupportedException
 */
public <G> CreateResponse<G> createOrRetrieveCopyInstance(Object instance) throws CloneNotSupportedException {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    context.setCurrentCatalog(getToCatalog());
    context.setCurrentProfile(getToSite());
    context.setSite(getToSite());
    if (instance instanceof Status && 'Y' == ((Status) instance).getArchived()) {
        throw new CloneNotSupportedException("Attempting to clone an archived instance");
    }
    Class<?> instanceClass = instance.getClass();
    if (instanceClass.getAnnotation(Embeddable.class) != null) {
        G response;
        try {
            response = (G) instanceClass.newInstance();
        } catch (InstantiationException e) {
            throw ExceptionHelper.refineException(e);
        } catch (IllegalAccessException e) {
            throw ExceptionHelper.refineException(e);
        }
        return new CreateResponse<G>(response, false);
    }
    Long originalId = getIdentifier(instance);
    Object previousClone;
    if (currentEquivalentMap.inverse().containsKey(instanceClass.getName() + "_" + originalId)) {
        previousClone = currentCloneMap
                .get(currentEquivalentMap.inverse().get(instanceClass.getName() + "_" + originalId));
    } else {
        previousClone = getClonedVersion(instanceClass, originalId);
    }
    G response;
    boolean alreadyPopulate;
    if (previousClone != null) {
        response = (G) previousClone;
        alreadyPopulate = true;
    } else {
        try {
            response = (G) instanceClass.newInstance();
        } catch (InstantiationException e) {
            throw ExceptionHelper.refineException(e);
        } catch (IllegalAccessException e) {
            throw ExceptionHelper.refineException(e);
        }
        checkCloneable(response);
        alreadyPopulate = false;
        currentEquivalentMap.put(System.identityHashCode(response), instanceClass.getName() + "_" + originalId);
        currentCloneMap.put(System.identityHashCode(response), response);
        try {
            for (Field field : getAllFields(instanceClass)) {
                if (field.getType().getAnnotation(Embeddable.class) != null
                        && MultiTenantCloneable.class.isAssignableFrom(field.getType())) {
                    Object embeddable = field.get(instance);
                    if (embeddable != null) {
                        field.set(response, ((MultiTenantCloneable) embeddable)
                                .createOrRetrieveCopyInstance(this).getClone());
                    }
                }
            }
        } catch (IllegalAccessException e) {
            throw ExceptionHelper.refineException(e);
        }
    }
    context.setCurrentCatalog(getFromCatalog());
    context.setCurrentProfile(getFromSite());
    context.setSite(getFromSite());
    return new CreateResponse<G>(response, alreadyPopulate);
}

From source file:org.kalypsodeegree_impl.model.geometry.GM_PolyhedralSurface_Impl.java

@Override
public Object clone() throws CloneNotSupportedException {
    try {/*w  w  w.j  a  v a  2  s.  c o  m*/
        final GM_PolyhedralSurface<T> clone = createCloneInstance();
        for (final T polygon : this)
            clone.add((T) polygon.clone());
        return clone;
    } catch (final GM_Exception e) {
        e.printStackTrace();

        throw new CloneNotSupportedException(e.getLocalizedMessage());
    }
}

From source file:com.sinosoft.one.data.jade.context.JadeInvocationHandler.java

private Object invokeObjectMethod(Object proxy, Method method, Object[] args)
        throws CloneNotSupportedException {
    String methodName = method.getName();
    if (methodName.equals("toString")) {
        return JadeInvocationHandler.this.toString();
    }//from  w w  w .  j ava  2s .com
    if (methodName.equals("hashCode")) {
        return daoMetaData.getDAOClass().hashCode() * 13 + this.hashCode();
    }
    if (methodName.equals("equals")) {
        return args[0] == proxy;
    }
    if (methodName.equals("clone")) {
        throw new CloneNotSupportedException("clone is not supported for jade model.");
    }
    throw new UnsupportedOperationException(daoMetaData.getDAOClass().getName() + "#" + method.getName());
}