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() 

Source Link

Document

Constructs a CloneNotSupportedException with no detail message.

Usage

From source file:Tutorial.java

public static void main(String args[]) {

    Main t = new Main() {
        protected final Object clone() throws CloneNotSupportedException {
            throw new CloneNotSupportedException();
        }//from w w  w  .  ja v a2  s  .  c om
    };

    for (Tutorial m : Tutorial.values()) {
        System.out.println(m + " costs " + m.showPrice() + " dollars");
    }
}

From source file:Main.java

public static Object clone(final Object obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }// www. j a  va 2 s  . co m
    if (obj instanceof Cloneable) {
        Class<?> clazz = obj.getClass();
        Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            return m.invoke(obj, (Object[]) null);
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:com.cseur.createRoutingService.Routing.java

@Override
public Routing clone() throws CloneNotSupportedException {
    try {/*from w  w  w .j ava  2  s.c  o m*/
        return (Routing) BeanUtils.cloneBean(this);
    } catch (Exception ex) {
        throw new CloneNotSupportedException();
    }
}

From source file:Main.java

/**
 * @since 4.3/*from w w  w.  ja v  a2  s .  c  o m*/
 */
public static <T> T cloneObject(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {
        final Class<?> clazz = obj.getClass();
        final Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (final NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            @SuppressWarnings("unchecked")
            // OK because clone() preserves the class
            final T result = (T) m.invoke(obj, (Object[]) null);
            return result;
        } catch (final InvocationTargetException ex) {
            final Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:Main.java

/**
 * @since 4.3//  w w  w.j a v  a  2 s.c om
 */
public static <T> T cloneObject(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {
        final Class<?> clazz = obj.getClass();
        final Method m;
        try {
            m = clazz.getMethod("clone", (Class<?>[]) null);
        } catch (final NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            @SuppressWarnings("unchecked")
            // OK because clone() preserves the class
            final T result = (T) m.invoke(obj, (Object[]) null);
            return result;
        } catch (final InvocationTargetException ex) {
            final Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:com.bibisco.dao.SqlSessionFactoryManager.java

public Object clone() throws CloneNotSupportedException {
    return new CloneNotSupportedException();
}

From source file:de.document.entity.Krankheit.java

@Override
public Krankheit clone() throws CloneNotSupportedException {
    try {/*from   w  ww .  java  2  s  .com*/
        return (Krankheit) BeanUtils.cloneBean(this);
    } catch (Exception ex) {
        throw new CloneNotSupportedException();
    }
}

From source file:com.nimbits.user.GoogleAuthentication.java

@Override
public Object clone() throws CloneNotSupportedException {
    super.clone();
    throw new CloneNotSupportedException();
    // that'll teach 'em
}

From source file:org.fhcrc.cpl.toolbox.datastructure.BoundMap.java

@SuppressWarnings({ "CloneDoesntCallSuperClone" })
@Override//from   w  w  w. jav  a 2s. c om
public Object clone() throws CloneNotSupportedException {
    throw new CloneNotSupportedException();
}

From source file:com.blackducksoftware.integration.hub.bamboo.HubBambooUtils.java

@Override
protected Object clone() throws CloneNotSupportedException {
    throw new CloneNotSupportedException();
}