Example usage for java.lang ClassNotFoundException toString

List of usage examples for java.lang ClassNotFoundException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.jamwiki.db.DatabaseConnection.java

/**
 * Static method that will configure a DataSource based on the Environment setup.
 *///w  ww  . j  a  v  a  2  s.c  o  m
private synchronized static void configDataSource() throws SQLException {
    if (dataSource != null) {
        closeConnectionPool(); // DataSource has already been created so remove it
    }
    String url = Environment.getValue(Environment.PROP_DB_URL);
    DataSource targetDataSource = null;
    if (url.startsWith("jdbc:")) {
        try {
            // Use an internal "LocalDataSource" configured from the Environment
            targetDataSource = new LocalDataSource();
        } catch (ClassNotFoundException e) {
            logger.error("Failure while configuring local data source", e);
            throw new SQLException("Failure while configuring local data source: " + e.toString());
        }
    } else {
        try {
            // Use a container DataSource obtained via JNDI lookup
            // TODO: Should try prefix java:comp/env/ if not already part of the JNDI name?
            Context ctx = new InitialContext();
            targetDataSource = (DataSource) ctx.lookup(url);
        } catch (NamingException e) {
            logger.error("Failure while configuring JNDI data source with URL: " + url, e);
            throw new SQLException(
                    "Unable to configure JNDI data source with URL " + url + ": " + e.toString());
        }
    }
    dataSource = new LazyConnectionDataSourceProxy(targetDataSource);
    transactionManager = new DataSourceTransactionManager(targetDataSource);
}

From source file:org.xenei.classpathutils.ClassPathUtils.java

/**
 * Find all classes accessible from the class loader which belong to the
 * given package and sub packages.//from   w w  w. j  av  a2s  . c o  m
 *
 * Adapted from http://snippets.dzone.com/posts/show/4831 and extended to
 * support use of JAR files
 *
 * @param classLoader
 *            The class loader to load the classes from.
 * @param packageName
 *            The package name to locate the classes in.
 * @param filter
 *            The filter for the classes.
 * @return A collection of Class objects
 */
public static Collection<Class<?>> getClasses(final ClassLoader classLoader, final String packageName,
        final ClassPathFilter filter) {
    if (classLoader == null) {
        LOG.error("Class loader may not be null.");
        return Collections.emptyList();
    }
    if (packageName == null) {
        LOG.error("Package name may not be null.");
        return Collections.emptyList();
    }

    String dirName = packageName.replace('.', '/');
    Enumeration<URL> resources;
    try {
        resources = classLoader.getResources(dirName);
    } catch (final IOException e1) {
        LOG.error(e1.toString());
        return Collections.emptyList();
    }

    final Set<Class<?>> classes = new HashSet<Class<?>>();
    final Set<String> directories = new HashSet<String>();
    if (resources.hasMoreElements()) {
        while (resources.hasMoreElements()) {
            final URL resource = resources.nextElement();
            String dir = resource.getPath();
            if (!directories.contains(dir)) {
                directories.add(dir);

                try {
                    for (final String clazz : findClasses(dir, packageName, filter)) {
                        try {
                            LOG.debug("Adding class {}", clazz);
                            classes.add(Class.forName(clazz, false, classLoader));
                        } catch (final ClassNotFoundException e) {
                            LOG.warn(e.toString());
                        }
                    }
                } catch (final IOException e) {
                    LOG.warn(e.toString());
                }
            }
        }
    } else {
        if (packageName.length() > 0) {
            // there are no resources at that path so see if it is a class
            try {
                classes.add(Class.forName(packageName, false, classLoader));
            } catch (final ClassNotFoundException e) {
                LOG.warn(String.format("'%s' was neither a package name nor a class name", packageName));
            }
        }
    }
    return classes;
}

From source file:com.cisco.oss.foundation.logging.structured.AbstractFoundationLoggingMarker.java

private static FoundationLoggingMarkerFormatter getFormatter(
        Class<? extends FoundationLoggingMarker> markerClass) {
    try {/*  ww  w .  jav a 2s.c o  m*/

        //         generateAndUpdateFormatterInMap(markerClass);

        Class<? extends FoundationLoggingMarkerFormatter> formatterClass = null;
        try {
            formatterClass = (Class<? extends FoundationLoggingMarkerFormatter>) Class
                    .forName(markerClass.getName() + "Formatter");
        } catch (ClassNotFoundException e) {
            LOGGER.error("annotation processign ahs failed. " + e.toString());
        }
        FoundationLoggingMarkerFormatter newFormatter = null;
        if (formatterClass == null) {
            newFormatter = new DefaultMarkerFormatter();
        } else {
            newFormatter = formatterClass.newInstance();
        }

        return newFormatter;
    } catch (Exception e) {
        LOGGER.error("Can't find a proxied class for: " + markerClass, e);
        throw new IllegalArgumentException(e);
    }
}

From source file:org.lockss.util.Logger.java

/**
 * Get the default output target for all loggers.
 *//*from  w w  w.j a  v a  2  s .  c  o m*/
static LogTarget getDefaultTarget() {
    Class tgtClass = StdErrTarget.class;
    String tgtName = System.getProperty(SYSPROP_DEFAULT_LOG_TARGET);
    if (!StringUtil.isNullString(tgtName)) {
        try {
            tgtClass = Class.forName(tgtName);
        } catch (ClassNotFoundException e) {
            System.err.println("Couldn't load log target " + tgtName + ": " + e.toString());
        }
    }
    LogTarget tgt;
    try {
        tgt = (LogTarget) tgtClass.newInstance();
    } catch (Exception e) {
        System.err.println("Couldn't instantiate log target " + tgtName + ": " + e.toString());
        tgt = new StdErrTarget();
    }
    return tgt;
}

From source file:info.guardianproject.netcipher.web.WebkitProxy.java

@TargetApi(21) // for android.util.ArrayMap methods
@SuppressWarnings("rawtypes")
private static boolean setWebkitProxyLollipop(Context appContext, String host, int port) {
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", port + "");
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", port + "");
    try {/*from   w  w  w  .  j a  va  2s  . c  o  m*/
        Class applictionClass = Class.forName("android.app.Application");
        Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk");
        mLoadedApkField.setAccessible(true);
        Object mloadedApk = mLoadedApkField.get(appContext);
        Class loadedApkClass = Class.forName("android.app.LoadedApk");
        Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers");
        mReceiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object receiver : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = receiver.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(receiver, appContext, intent);
                }
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (NoSuchFieldException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (IllegalAccessException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (NoSuchMethodException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (InvocationTargetException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    }
    return false;
}

From source file:info.guardianproject.netcipher.webkit.WebkitProxy.java

@TargetApi(21) // for android.util.ArrayMap methods
@SuppressWarnings("rawtypes")
private static boolean setWebkitProxyLollipop(Context appContext, String host, int port) {
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", Integer.toString(port));
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", Integer.toString(port));
    try {/*from w w w .  j  a  va2  s  . co  m*/
        Class applictionClass = Class.forName("android.app.Application");
        Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk");
        mLoadedApkField.setAccessible(true);
        Object mloadedApk = mLoadedApkField.get(appContext);
        Class loadedApkClass = Class.forName("android.app.LoadedApk");
        Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers");
        mReceiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object receiver : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = receiver.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(receiver, appContext, intent);
                }
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (NoSuchFieldException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (IllegalAccessException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (NoSuchMethodException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    } catch (InvocationTargetException e) {
        Log.d("ProxySettings",
                "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString());
    }
    return false;
}

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

/** Create MBean for Object.
 * Attempts to create an MBean for the object by searching the
 * package and class name space.  For example an object of the
 * type <PRE>/*from   ww w .  ja  v a 2  s .c o m*/
 *   class com.acme.MyClass extends com.acme.util.BaseClass
 * </PRE>
 * Then this method would look for the following
 * classes:<UL>
 * <LI>com.acme.MyClassMBean
 * <LI>com.acme.jmx.MyClassMBean
 * <LI>com.acme.util.BaseClassMBean
 * <LI>com.acme.util.jmx.BaseClassMBean
 * </UL>
 * @param o The object
 * @return A new instance of an MBean for the object or null.
 */
public static ModelMBean mbeanFor(Object o) {
    try {
        Class oClass = o.getClass();
        ClassLoader loader = oClass.getClassLoader();

        ModelMBean mbean = null;
        boolean jmx = false;
        Class[] interfaces = null;
        int i = 0;

        while (mbean == null && oClass != null) {
            Class focus = interfaces == null ? oClass : interfaces[i];
            String pName = focus.getPackage().getName();
            String cName = focus.getName().substring(pName.length() + 1);
            String mName = pName + (jmx ? ".jmx." : ".") + cName + "MBean";

            try {
                Class mClass = loader.loadClass(mName);
                if (log.isTraceEnabled())
                    log.trace("mbeanFor " + o + " mClass=" + mClass);
                mbean = (ModelMBean) mClass.newInstance();
                mbean.setManagedResource(o, "objectReference");
                if (log.isDebugEnabled())
                    log.debug("mbeanFor " + o + " is " + mbean);
                return mbean;
            } catch (ClassNotFoundException e) {
                if (e.toString().endsWith("MBean")) {
                    if (log.isTraceEnabled())
                        log.trace(e.toString());
                } else
                    log.warn(LogSupport.EXCEPTION, e);
            } catch (Error e) {
                log.warn(LogSupport.EXCEPTION, e);
                mbean = null;
            } catch (Exception e) {
                log.warn(LogSupport.EXCEPTION, e);
                mbean = null;
            }

            if (jmx) {
                if (interfaces != null) {
                    i++;
                    if (i >= interfaces.length) {
                        interfaces = null;
                        oClass = oClass.getSuperclass();
                    }
                } else {
                    interfaces = oClass.getInterfaces();
                    i = 0;
                    if (interfaces == null || interfaces.length == 0) {
                        interfaces = null;
                        oClass = oClass.getSuperclass();
                    }
                }
            }
            jmx = !jmx;
        }
    } catch (Exception e) {
        LogSupport.ignore(log, e);
    }
    return null;
}

From source file:com.cloudera.sqoop.manager.TestHsqldbManager.java

@Before
public void setUp() {
    testServer = new HsqldbTestServer();
    try {//from   www.j ava2s  .  c o m
        testServer.resetServer();
    } catch (SQLException sqlE) {
        LOG.error("Got SQLException: " + sqlE.toString());
        fail("Got SQLException: " + sqlE.toString());
    } catch (ClassNotFoundException cnfe) {
        LOG.error("Could not find class for db driver: " + cnfe.toString());
        fail("Could not find class for db driver: " + cnfe.toString());
    }

    manager = testServer.getManager();
}

From source file:nc.noumea.mairie.annuairev2.saisie.viewmodel.AbstractViewModel.java

/**
 * Mthode utilitaire, pour lister les valeurs d'une numration (dans
 * l'ordre de leur dclaration), avec la possibilit d'insrer en tte la
 * valeur null./*from w ww  .  j av  a  2  s. co  m*/
 * 
 * @param enumClassName
 *            nom complet de la classe (avec le package, ex :
 *            "nc.noumea.mairie.pdc.enums.Civilite")
 * @param insertNull
 *            indique s'il faut insrer en tte de la liste rsultat la
 *            valeur null
 * @return la liste des valeurs numres, dans l'ordre de leur dclaration
 *         (avec null en tte optionnellement)
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public ListModelList<?> getListeEnum(String enumClassName, boolean insertNull) {
    try {
        Class<?> classe = Class.forName(enumClassName);
        ListModelList result = new ListModelList(classe.getEnumConstants());
        if (insertNull) {
            result.add(0, null);
        }
        return result;
    } catch (ClassNotFoundException e) {
        Messagebox.show(e.toString());
    }
    return null;
}

From source file:org.jamwiki.db.DatabaseConnection.java

/**
 * Return a connection to the database with the specified parameters.
 * The caller <b>must</b> close this connection when finished!
 *
 * @param driver A String indicating the full path for the database driver class.
 * @param url The JDBC driver URL./* w  ww  . ja v a 2  s  .  c o m*/
 * @param user The database user.
 * @param password The database user password.
 * @throws SQLException Thrown if any failure occurs while getting the test connection.
 */
protected static Connection getTestConnection(String driver, String url, String user, String password)
        throws SQLException {
    if (url.startsWith("jdbc:")) {
        if (!StringUtils.isBlank(driver)) {
            try {
                // ensure that the Driver class has been loaded
                ResourceUtil.forName(driver);
            } catch (ClassNotFoundException e) {
                throw new SQLException("Unable to instantiate class with name: " + driver);
            }
        }
        return DriverManager.getConnection(url, user, password);
    } else {
        DataSource testDataSource = null;
        try {
            Context ctx = new InitialContext();
            // TODO: Try appending "java:comp/env/" to the JNDI Name if it is missing?
            testDataSource = (DataSource) ctx.lookup(url);
        } catch (NamingException e) {
            logger.error("Failure while configuring JNDI data source with URL: " + url, e);
            throw new SQLException(
                    "Unable to configure JNDI data source with URL " + url + ": " + e.toString());
        }
        return testDataSource.getConnection();
    }
}