Example usage for java.lang ClassCastException toString

List of usage examples for java.lang ClassCastException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.eclipse.ecr.testlib.runner.web.WebDriverFeature.java

@Override
public void initialize(FeaturesRunner runner) throws Exception {
    Class<?> classToTest = runner.getTargetTestClass();
    Browser browser = FeaturesRunner.getScanner().getFirstAnnotation(classToTest, Browser.class);
    DriverFactory factory;/*  w ww.  j a  v  a2s  .  c  o  m*/
    // test here if the driver factory is specified by environment
    String fcName = System.getProperty(DriverFactory.class.getName());
    if (fcName != null) {
        factory = (DriverFactory) Class.forName(fcName).newInstance();
    } else {
        if (browser == null) {
            factory = BrowserFamily.HTML_UNIT.getDriverFactory();
        } else {
            Class<? extends DriverFactory> fc = browser.factory();
            if (fc == DriverFactory.class) {
                factory = browser.type().getDriverFactory();
            } else {
                factory = fc.newInstance();
            }
        }
    }
    config = new Configuration(factory);

    // get the home page and the url - first check for an url from the
    // environment
    String url = System.getProperty(HomePage.class.getName() + ".url");
    HomePage home = FeaturesRunner.getScanner().getFirstAnnotation(classToTest, HomePage.class);
    if (home != null) {
        config.setHomePageClass(home.type());
        if (url == null) {
            url = home.url();
        }
    }
    config.setHome(url);
    try {
        runner.filter(new Filter() {
            @Override
            public boolean shouldRun(Description description) {
                SkipBrowser skip = description.getAnnotation(SkipBrowser.class);
                if (skip == null) {
                    return true;
                }
                for (BrowserFamily family : skip.value()) {
                    if (config.getBrowserFamily().equals(family)) {
                        return false;
                    }
                }
                return true;
            }

            @Override
            public String describe() {
                return "Filtering tests according to current browser settings";
            }
        });
    } catch (ClassCastException e) {
        // OK - just skip
    } catch (NoTestsRemainException e) {
        log.error(e.toString(), e);
    }
}

From source file:at.rocworks.oa4j.logger.logger.DataSink.java

private void createGroups() {
    // Logging Groups
    JDebug.out.info("logging groups...");
    int gcount;//from   ww  w  .  j a va2 s .  c o  m
    String gprimary = settings.getStringProperty("logger", "primary", "");
    String sgroups = settings.getStringProperty("logger", "groups", "");
    try {
        JSONArray jgroups = (JSONArray) JSONValue.parse(sgroups);
        gcount = jgroups.size();
        for (int j = 0; j < gcount; j++) {
            if (createGroup(settings, jgroups.get(j).toString())) {
                if (gprimary.isEmpty()) {
                    gprimary = jgroups.get(j).toString();
                }
            }
        }
        JDebug.out.log(Level.CONFIG, "primary={0}", gprimary);
        logger.setReadGroup(gprimary);
    } catch (java.lang.ClassCastException ex) {
        JDebug.out.log(Level.SEVERE, "not a valid json group string '{0} [{1}]'!",
                new Object[] { sgroups, ex.toString() });
    }
}

From source file:com.app4am.app4am.LatestNewsListFragment.java

/**
 * When the AsyncTask finishes, it calls onRefreshComplete(), which updates the data in the
 * ListAdapter and turns off the progress bar.
 *///from  w  w  w .  j a v a 2s.  c o m
private void onRefreshComplete(List<String> result) {
    Log.i(LOG_TAG, "onRefreshComplete");

    // Remove all items from the ListAdapter, and then replace them with the new items
    try {
        ArrayAdapter<String> adapter = (ArrayAdapter<String>) getListAdapter();
        adapter.clear();
        for (String cheese : result) {
            adapter.add(cheese);
        }
    } catch (ClassCastException e) {
        Log.e(LOG_TAG, e.toString());
    }

    // Stop the refreshing indicator
    setRefreshing(false);
}

From source file:me.lehrner.newsgroupsndy.view.MainActivity.java

@Override
public void onAttachFragment(Fragment fragment) {
    if (fragment.getClass().getSimpleName().equals("AddServerDialogFragment")) {
        try {/* w  ww. j a  va 2  s .com*/
            mServerClickHandlerWeakReference = new WeakReference<>((AddServerClickHandler) fragment);
        } catch (ClassCastException e) {
            Log.e(LOG_TAG, "Fragment doesn't implement AddServerClickHandler: " + e.toString());
        }
    }
}

From source file:org.opendatakit.common.android.data.RawRow.java

/**
 * Return the data stored in the cursor at the given cellIndex column position
 * as null OR whatever data type it is./*from  w ww. j av a 2 s. c o m*/
 * <p>
 * This does not actually convert data types from one type to the other.
 * Instead, it safely preserves null values and returns boxed data values.
 * If you specify ArrayList or HashMap, it JSON deserializes the value into
 * one of those.
 *
 * @param cellIndex
 *          cellIndex of data or metadata column (0..nCol-1)
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public final <T> T getRawDataType(int cellIndex, Class<T> clazz) {
    // If you add additional return types here be sure to modify the javadoc.
    try {
        String value = getRawDataOrMetadataByIndex(cellIndex);
        if (value == null) {
            return null;
        }
        if (clazz == Long.class) {
            Long l = Long.parseLong(value);
            return (T) (Long) l;
        } else if (clazz == Integer.class) {
            Integer l = Integer.parseInt(value);
            return (T) (Integer) l;
        } else if (clazz == Double.class) {
            Double d = Double.parseDouble(value);
            return (T) (Double) d;
        } else if (clazz == String.class) {
            return (T) (String) value;
        } else if (clazz == Boolean.class) {
            // booleans are stored as integer 1 or 0 in user tables.
            return (T) (Boolean) Boolean.valueOf(!value.equals("0"));
        } else if (clazz == ArrayList.class) {
            // json deserialization of an array
            return (T) ODKFileUtils.mapper.readValue(value, ArrayList.class);
        } else if (clazz == HashMap.class) {
            // json deserialization of an object
            return (T) ODKFileUtils.mapper.readValue(value, HashMap.class);
        } else if (clazz == TreeMap.class) {
            // json deserialization of an object
            return (T) ODKFileUtils.mapper.readValue(value, TreeMap.class);
        } else {
            throw new IllegalStateException("Unexpected data type in SQLite table");
        }
    } catch (ClassCastException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " in SQLite table ");
    } catch (JsonParseException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    } catch (JsonMappingException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    }
}

From source file:org.opendatakit.common.android.data.Row.java

/**
 * Return the data stored in the cursor at the given index and given
 * position (ie the given row which the cursor is currently on) as null OR
 * whatever data type it is./*from w ww.java  2  s  . c  o  m*/
 * <p>
 * This does not actually convert data types from one type to the other.
 * Instead, it safely preserves null values and returns boxed data values.
 * If you specify ArrayList or HashMap, it JSON deserializes the value into
 * one of those.
 *
 * @param elementKey
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public final <T> T getRawDataType(String elementKey, Class<T> clazz) {
    // If you add additional return types here be sure to modify the javadoc.
    try {
        String value = getRawDataOrMetadataByElementKey(elementKey);
        if (value == null) {
            return null;
        }
        if (clazz == Long.class) {
            Long l = Long.parseLong(value);
            return (T) (Long) l;
        } else if (clazz == Integer.class) {
            Integer l = Integer.parseInt(value);
            return (T) (Integer) l;
        } else if (clazz == Double.class) {
            Double d = Double.parseDouble(value);
            return (T) (Double) d;
        } else if (clazz == String.class) {
            return (T) (String) value;
        } else if (clazz == Boolean.class) {
            // booleans are stored as integer 1 or 0 in user tables.
            return (T) (Boolean) Boolean.valueOf(!value.equals("0"));
        } else if (clazz == ArrayList.class) {
            // json deserialization of an array
            return (T) ODKFileUtils.mapper.readValue(value, ArrayList.class);
        } else if (clazz == HashMap.class) {
            // json deserialization of an object
            return (T) ODKFileUtils.mapper.readValue(value, HashMap.class);
        } else if (clazz == TreeMap.class) {
            // json deserialization of an object
            return (T) ODKFileUtils.mapper.readValue(value, TreeMap.class);
        } else {
            throw new IllegalStateException("Unexpected data type in SQLite table");
        }
    } catch (ClassCastException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " in SQLite table ");
    } catch (JsonParseException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    } catch (JsonMappingException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unexpected data type conversion failure " + e.toString() + " on SQLite table");
    }
}

From source file:org.lsc.jndi.FullDNJndiDstService.java

/**
 * Returns a list of all the objects' identifiers.
 * /*from   w w  w.j  a  v a 2 s.c  o m*/
 * @return   Map of all entries DNs (this is not for display only!)
 *          that are returned by the directory with an associated map of attribute names and values (never null)
 * @throws LscServiceException 
 * @throws NamingException 
 */
@SuppressWarnings("unchecked")
public Map<String, LscDatasets> getListPivots() throws LscServiceException {
    List<String> idList = null;
    try {
        // get list of DNs
        idList = jndiServices.getDnList(getBaseDn(), getFilterAll(), SearchControls.SUBTREE_SCOPE);

        // sort the list by shortest first - this makes sure clean operations delete leaf elements first
        Collections.sort(idList, new StringLengthComparator());
    } catch (ClassCastException e) {
        // ignore errors, just leave list unsorted
    } catch (UnsupportedOperationException e) {
        // ignore errors, just leave list unsorted
    } catch (NamingException e) {
        throw new LscServiceException(e.toString(), e);
    }

    // convert to correct return format

    /* TODO: This is a bit of a hack - we use ListOrderedMap to keep order of the list returned,
     * since it may be important when cleaning by full DN (for different levels).
     * This is really an API bug, getListPivots() should return a List, not a Map.
     */
    Map<String, LscDatasets> ids = new ListOrderedMap();

    for (String dn : idList) {
        String completedDn = jndiServices.completeDn(dn);
        LscDatasets attrs = new LscDatasets();
        attrs.put("dn", completedDn);
        ids.put(completedDn, attrs);
    }

    return ids;
}

From source file:com.yahoo.validatar.execution.rest.JSON.java

/**
 * Converts the String columnar JSON data into a Map of column names to List of column values. Internal use only.
 *
 * @param columnarData The String columnar JSON data.
 * @param query The Query object being run.
 * @return The Map version of the JSON data, null if exception (query is failed).
 *//*from   w  w  w. j  av a  2  s. c  o  m*/
Map<String, List<TypedObject>> convertToMap(String columnarData, Query query) {
    try {
        log.info("Converting processed JSON into a map...");
        // Type erasure will make this not enough if the JSON parses into a map but with the wrong keys, values.
        Map<String, List<Object>> result = (Map<String, List<Object>>) evaluator
                .eval(String.format(JSON_TO_MAP_FORMAT, columnarData));
        // But this will catch it.
        Map<String, List<TypedObject>> typed = type(result);
        log.info("Conversion complete!");
        return typed;
    } catch (ScriptException se) {
        log.error("Could not convert the processed JSON to the required format", se);
        query.setFailure("Invalid JSON (try a linter): " + columnarData);
        query.addMessage(se.toString());
    } catch (ClassCastException cce) {
        log.error("The returned JSON is not in the map of columns format", cce);
        query.setFailure("Your extracted JSON is not in a map of columns format: " + columnarData);
        query.addMessage(cce.toString());
    }
    return null;
}

From source file:us.mn.state.health.lims.common.action.BaseAction.java

protected void setFormAttributes(ActionForm form, HttpServletRequest request) throws Exception {
    try {//from w  ww . j  a v a 2 s  .co m
        if (null != form) {
            DynaActionForm theForm = (DynaActionForm) form;
            theForm.getDynaClass().getName();
            String name = theForm.getDynaClass().getName().toString();
            // use IActionConstants!
            request.setAttribute(FORM_NAME, name);
            request.setAttribute("formType", theForm.getClass().toString());
            String actionName = name.substring(1, name.length() - 4);
            actionName = name.substring(0, 1).toUpperCase() + actionName;
            request.setAttribute(ACTION_KEY, actionName);
            // bugzilla 2154
            LogEvent.logInfo("BaseAction", "setFormAttributes()", actionName);
        }
    } catch (ClassCastException e) {
        // bugzilla 2154
        LogEvent.logError("BaseAction", "setFormAttributes()", e.toString());
        throw new ClassCastException("Error Casting form into DynaForm");
    }
}

From source file:org.callimachusproject.auth.DetachedRealm.java

private DetachedAuthenticationManager detach(Resource resource, String protects, RealmManager manager,
        ObjectConnection con) throws OpenRDFException, IOException {
    List<String> domains = getDistinctRealm(protects);
    String path = getCommonPath(domains);
    Object am = con.getObject(resource);
    try {/*from w  w w.j  a v a 2s  . c o m*/
        return ((AuthenticationManager) am).detachAuthenticationManager(path, domains, manager);
    } catch (ClassCastException e) {
        logger.error(e.toString() + " on " + resource);
        return null;
    } catch (AbstractMethodError e) {
        logger.error(e.toString() + " on " + resource);
        return null;
    }
}