Example usage for java.lang ClassCastException getMessage

List of usage examples for java.lang ClassCastException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.wso2.carbon.bpmn.extensions.jms.JMSUtils.java

/**
 *
 * @param context/*from   w  w  w  .j  av a 2s  .  co m*/
 * @param className
 * @param name
 * @param <T>
 * @return
 * @throws NamingException
 * @throws BPMNJMSException
 */
public <T> T lookup(Context context, Class<T> className, String name) throws NamingException {
    Object object;
    object = context.lookup(name);

    try {
        return className.cast(object);
    } catch (ClassCastException e) {
        log.error(e.getMessage());
        return null;
    }
}

From source file:org.castor.cpa.test.test1158.Test1158.java

public void testSave() {
    try {//from  w  w  w  .j a va  2 s .  co  m
        Database db = getJDOManager(DBNAME, MAPPING).getDatabase();
        db.begin();
        try {
            ExtendedObject obj1 = db.load(ExtendedObject.class, new Integer(1));
            obj1.setDescription2(obj1.getDescription2() + " - 1");
            db.commit();
            db.close();
            fail();
        } catch (ClassCastException ex) {
            db.rollback();
            db.close();
        }
    } catch (MappingException ex) {
        LOG.error(ex.getMessage(), ex);
        fail(ex.getMessage());
    } catch (PersistenceException ex) {
        LOG.error(ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}

From source file:edu.harvard.iq.dataverse.dataaccess.StorageIOTest.java

@Test
public void testGetDvObject() {
    assertEquals(null, instance.getDvObject());
    instance.setDvObject(new Dataset());
    assertEquals(new Dataset(), instance.getDataset());

    try {//from w  w  w  .  j  ava  2 s .  c o m
        instance.getDataFile();
        fail("This should have thrown");
    } catch (ClassCastException ex) {
        assertEquals(ex.getMessage(),
                "edu.harvard.iq.dataverse.Dataset cannot be cast to edu.harvard.iq.dataverse.DataFile");
    }
    try {
        instance.getDataverse();
        fail("This should have thrown");
    } catch (ClassCastException ex) {
        assertEquals(ex.getMessage(),
                "edu.harvard.iq.dataverse.Dataset cannot be cast to edu.harvard.iq.dataverse.Dataverse");
    }
    assertEquals(new DataFile(), new FileAccessIO<>(new DataFile()).getDataFile());
    assertEquals(new Dataverse(), new FileAccessIO<>(new Dataverse()).getDataverse());
}

From source file:org.thingsplode.synapse.core.AbstractMessage.java

public <E> E expectBody(Class<E> type) throws MarshallerException {
    //todo: review if it makes sense
    if (body == null) {
        throw new MarshallerException("This message has not extension.", HttpStatus.EXPECTATION_FAILED);
    }/*from w w  w .  jav a  2s . c o m*/
    try {
        return type.cast(body);
    } catch (ClassCastException ex) {
        throw new MarshallerException(
                "The expected message is not type of " + type.getSimpleName() + ": " + ex.getMessage(),
                HttpStatus.EXPECTATION_FAILED, ex);
    }
}

From source file:com.github.restdriver.matchers.HasJsonPath.java

private long intToLong(Object o) {

    int i;/*from  w  w w  .  j a  va2  s.c om*/

    try {
        i = (Integer) o;
    } catch (ClassCastException cce) {
        throw new RuntimeJsonTypeMismatchException(
                "JSONpath returned a type unsuitable for matching with the given matcher: " + cce.getMessage(),
                cce);
    }

    return i;

}

From source file:com.github.helenusdriver.driver.impl.TypeClassInfoImpl.java

/**
 * Creates a new context for this class info with the given POJO object.
 *
 * @author paouelle/*w  ww  . ja  va2 s .c om*/
 *
 * @param  object the POJO object
 * @return a non-<code>null</code> newly created context for this class info
 * @throws NullPointerException if <code>object</code> is <code>null</code>
 * @throws IllegalArgumentException if <code>object</code> is not of the
 *         appropriate class
 */
public POJOContext newContextFromRoot(Object object) {
    try {
        return newContext(clazz.cast(object));
    } catch (ClassCastException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:com.microsoft.rightsmanagement.sampleapp.TextEditorFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();//w  ww.j  av  a 2  s  .c  o  m
    if (args != null) {
        if (args.containsKey(KEY_EDITOR_MODE)) {
            mTextEditorMode = TextEditorMode.values()[args.getInt(KEY_EDITOR_MODE)];
        }
        if (args.containsKey(KEY_USER_POLICY)) {
            Serializable userPolicyCandidate = (Serializable) args.getSerializable(KEY_USER_POLICY);
            try {
                mUserPolicy = (UserPolicy) userPolicyCandidate;
            } catch (ClassCastException ex) {
                Logger.ie(TAG, ex.getMessage());
                throw ex;
            }
        }
    }
    setHasOptionsMenu(true);
}

From source file:com.chiorichan.http.ssl.CertificateWrapper.java

public List<String> getSubjectAltNamesWithException(int type) throws CertificateParsingException {
    /*/*ww w  .  ja va 2  s. co  m*/
     * otherName [0] OtherName,
     * rfc822Name [1] IA5String,
     * dNSName [2] IA5String,
     * x400Address [3] ORAddress,
     * directoryName [4] Name,
     * ediPartyName [5] EDIPartyName,
     * uniformResourceIdentifier [6] IA5String,
     * iPAddress [7] OCTET STRING,
     * registeredID [8] OBJECT IDENTIFIER}
     */

    if (type < 0 || type > 8)
        throw new IllegalArgumentException("Type range out of bounds!");

    return new ArrayList<String>() {
        {
            if (cert.getSubjectAlternativeNames() != null)
                for (List<?> l : cert.getSubjectAlternativeNames())
                    try {
                        int i = ObjectFunc.castToIntWithException(l.get(0));
                        String dns = ObjectFunc.castToStringWithException(l.get(1));

                        if (i == type)
                            add(dns);
                    } catch (ClassCastException e) {
                        NetworkManager.getLogger().severe(e.getMessage());
                    }
        }
    };
}

From source file:edu.vuum.mocca.ui.tags.TagsListFragment.java

@Override
public void onAttach(Activity activity) {
    Log.d(LOG_TAG, "onAttach start");
    super.onAttach(activity);
    try {//from   w  w  w  .j a v  a 2s  .  c  o  m
        mOpener = (OnOpenWindowInterface) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                activity.toString() + " must implement OnOpenWindowListener" + e.getMessage());
    }
    Log.d(LOG_TAG, "onAttach end");
}

From source file:org.castor.cpa.test.test3065.Test3065.java

public void testSave() {
    try {//  www  . ja v  a 2 s.c o  m
        Database db = getJDOManager(DBNAME, MAPPING).getDatabase();
        db.begin();
        try {
            ExtendedObject obj1 = db.load(ExtendedObject.class, new Integer(1));
            obj1.setDescription2(obj1.getDescription2() + " - 1");
            db.commit();
            db.close();
        } catch (ClassCastException ex) {
            db.rollback();
            db.close();
        }
    } catch (MappingException ex) {
        LOG.error(ex.getMessage(), ex);
        fail(ex.getMessage());
    } catch (PersistenceException ex) {
        LOG.error(ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}