Example usage for java.lang ClassNotFoundException getLocalizedMessage

List of usage examples for java.lang ClassNotFoundException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:cross.io.PropertyFileGenerator.java

/**
 * Creates a property file for the given class, containing those fields,
 * which are annotated by {@link cross.annotations.Configurable}.
 *
 * @param className/*  ww w  .  ja  va 2  s.co  m*/
 * @param basedir
 */
public static void createProperties(String className, File basedir) {
    Class<?> c;
    try {
        c = PropertyFileGenerator.class.getClassLoader().loadClass(className);
        LoggerFactory.getLogger(PropertyFileGenerator.class).info("Class: {}", c.getName());
        PropertiesConfiguration pc = createProperties(c);
        if (!basedir.exists()) {
            basedir.mkdirs();
        }
        try {
            pc.save(new File(basedir, c.getSimpleName() + ".properties"));
        } catch (ConfigurationException ex) {
            LoggerFactory.getLogger(PropertyFileGenerator.class).warn("{}", ex.getLocalizedMessage());
        }
    } catch (ClassNotFoundException e) {
        LoggerFactory.getLogger(PropertyFileGenerator.class).warn("{}", e.getLocalizedMessage());
    }
}

From source file:org.rifidi.emulator.reader.commandhandler.CommandHandlerInvoker.java

/**
 * This method takes in a CommandObject as the parameter and then calls the
 * handler method stored in it via reflection. <br />
 * <br />/*from  w ww.  j a va  2s.  c  o m*/
 * The handler method has several assumptions: - It takes a CommandObject as
 * a parameter <br /> - It returns a CommandObject <br />
 * 
 * 
 * If any of the preceding are not met, an exception will be thrown and the
 * parameter will be returned unmodified.
 * 
 * @param newObject
 *            CommandObject that specifies the method and arguments
 * @return Returns CommandObject with the operation's result
 */
@SuppressWarnings("unchecked")
public static CommandObject invokeHandler(CommandObject newObject, AbstractReaderSharedResources asr,
        GenericExceptionHandler geh) {
    String className = newObject.getHandlerClass();
    String methodName = newObject.getHandlerMethod();
    Class c = null;
    try {
        c = Class.forName(className);
    } catch (ClassNotFoundException e) {
        logger.error(e.getLocalizedMessage());
    }

    // Force the single parameter to be a CommandObject. If you
    // want different arguments, this class must be rewritten.
    Class[] parameter = new Class[] { CommandObject.class, AbstractReaderSharedResources.class };
    Method commandMethod;
    Object[] arguments = new Object[] { newObject, asr };

    try {
        commandMethod = c.getMethod(methodName, parameter);
        // You must invoke reflection on an instance of this object
        Object instance = null;
        instance = c.newInstance();
        // Force the return type to be a CommandObject. ;
        newObject = (CommandObject) commandMethod.invoke(instance, arguments);
    } catch (NoSuchMethodException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("error caused by: " + methodName);
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    } catch (IllegalAccessException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("error caused by: " + methodName);
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        logger.error(e.getCause());
        logger.debug("error caused by: " + methodName);
        logger.error(e.getTargetException());
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    } catch (InstantiationException e) {
        logger.debug("error caused by: " + methodName);
        logger.error(e.getLocalizedMessage());
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    } catch (Exception e) {
        e.printStackTrace();
        logger.debug("error caused by: " + methodName);
        logger.error("Something is defined in the XML that is not" + " defined by a handler method: "
                + newObject.getHandlerMethod());
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    }

    return newObject;
}

From source file:org.owasp.webgoat.session.DatabaseUtilities.java

private static Connection makeConnection(String user, WebgoatContext context) throws SQLException {
    try {/*  w ww. ja v  a2 s  . c o  m*/
        Class.forName(context.getDatabaseDriver());

        if (context.getDatabaseConnectionString().contains("hsqldb"))
            return getHsqldbConnection(user, context);

        String userPrefix = context.getDatabaseUser();
        String password = context.getDatabasePassword();
        String url = context.getDatabaseConnectionString();
        return DriverManager.getConnection(url, userPrefix + "_" + user, password);
    } catch (ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
        throw new SQLException("Couldn't load the database driver: " + cnfe.getLocalizedMessage());
    }
}

From source file:main.RankerOCR.java

/**
 * Evaluate the ranker parameter.//from w  w  w. java 2  s  .c  om
 * <p>
 * @param s ranker parameter as a string
 * @return Ranker class if possible. Otherwise, stop the program and return
 * an error code
 */
private static Class evalRanker(String s) {
    try {
        return Class.forName("ranking." + s);
    } catch (ClassNotFoundException ex) {
        printFormated(ex.getLocalizedMessage());
        System.exit(-11);
        return null;
    }
}

From source file:ru.objective.jni.utils.Utils.java

public static boolean isExportClass(JavaClass javaClass, String[] excludes, String[] excludedPackages)
        throws ClassNotFoundException {
    if (javaClass.isAnonymous() || javaClass.isAnnotation() || javaClass.isSynthetic())
        return false;

    if (isClassNameExcluded(javaClass.getClassName(), excludes, excludedPackages))
        return false;

    try {//  w  w w.j a  v a  2s.  c o m
        JavaClass[] interfaces = javaClass.getAllInterfaces();
        JavaClass[] supers = javaClass.getSuperClasses();

        for (JavaClass superClass : supers) {
            if (isClassNameExcluded(superClass.getClassName(), excludes, excludedPackages))
                return false;
        }

        for (JavaClass superInterface : interfaces) {
            if (isClassNameExcluded(superInterface.getClassName(), excludes, excludedPackages))
                return false;
        }
    } catch (ClassNotFoundException cnf) {
        System.out.println();
        System.out.println("WARNING! One of superclass or interface of class " + javaClass.getClassName()
                + " does not included in classpath and will skip. Reason: " + cnf.getLocalizedMessage());

        return false; // ignore classes that does not included in classpath
    }

    return true;
}

From source file:org.apache.airavata.gfac.core.GFacUtils.java

public static CredentialReader getCredentialReader()
        throws ApplicationSettingsException, IllegalAccessException, InstantiationException {
    try {//from   w w w  . j a  va  2  s  . com
        String jdbcUrl = ServerSettings.getCredentialStoreDBURL();
        String jdbcUsr = ServerSettings.getCredentialStoreDBUser();
        String jdbcPass = ServerSettings.getCredentialStoreDBPassword();
        String driver = ServerSettings.getCredentialStoreDBDriver();
        return new CredentialReaderImpl(new DBUtil(jdbcUrl, jdbcUsr, jdbcPass, driver));
    } catch (ClassNotFoundException e) {
        log.error("Not able to find driver: " + e.getLocalizedMessage());
        return null;
    }
}

From source file:net.sourceforge.mavenhippo.ClassPathBeanFinder.java

@SuppressWarnings("unchecked")
private Class<? extends Annotation> getNodeAnnotationClass() {
    try {//from  ww w  . ja v a2 s .  c  o  m
        if (nodeAnnotationClass == null) {
            synchronized (this) {
                if (nodeAnnotationClass == null) {
                    nodeAnnotationClass = (Class<? extends Annotation>) Class
                            .forName("org.hippoecm.hst.content.beans.Node", true, projectClassloader);

                }
            }
        }

        return nodeAnnotationClass;
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e.getLocalizedMessage(), e);
    }
}

From source file:com.ibm.research.rdf.store.cmd.AbstractRdfCommand.java

private Connection getConnection() {

    String backend = params.get("-backend");
    String db = params.get("-db");
    String port = params.get("-port");
    String host = params.get("-host");
    String user = params.get("-user");
    String password = params.get("-password");
    if (backend == null)
        backend = Store.Backend.db2.name();
    if (host == null)
        host = "localhost";
    if (port == null)
        port = "50000";

    String JDBC_URL;//from  www .ja  va2 s  .  c om
    String classNameString;
    if (backend.equalsIgnoreCase(Store.Backend.postgresql.name())) {
        JDBC_URL = new String("jdbc:postgresql://" + host + ":" + port + "/" + db);
        classNameString = new String("org.postgresql.Driver");
    } else if (backend.equalsIgnoreCase(Store.Backend.shark.name())) {
        JDBC_URL = new String("jdbc:hive2://" + host + ":" + port + "/" + db);
        classNameString = new String("org.apache.hive.jdbc.HiveDriver");
    } else {
        JDBC_URL = new String("jdbc:db2://" + host + ":" + port + "/" + db);
        classNameString = new String("com.ibm.db2.jcc.DB2Driver");
    }

    try {
        Class.forName(classNameString);
        Connection conn = DriverManager.getConnection(JDBC_URL, user, password);
        if (conn != null) {
            if (!backend.equalsIgnoreCase(Store.Backend.shark.name())) {
                // this will cause StoreManager to start a txn
                // and commit on success, which is good for us
                conn.setAutoCommit(true);
            }
        } else {
            System.err.println("Failed to establish connection to the database");
        }
        return conn;
    } catch (ClassNotFoundException e) {
        System.err.println(e.getLocalizedMessage());
        return null;
    } catch (SQLException e) {
        System.err.println(e.getLocalizedMessage());
        return null;
    }

    // + ":traceFile=c:/jcc.log;traceLevel=-1;traceFileAppend=false;" ;

}

From source file:cross.ObjectFactory.java

/**
 * Load a class by its name. Tries to locate the given class name on the
 * user class path and on the default java class path. Currently only
 * supports loading of classes from local storage.
 *
 * @param name the fully qualified name of the class
 * @return the loaded class or null if any exception is encountered
 *//* w ww  .j  a  v  a2 s.c o m*/
protected Class<?> loadClass(final String name) {
    EvalTools.notNull(name, ObjectFactory.class);
    Class<?> cls = null;
    try {
        log.debug("Loading class {}", name);
        try {
            cls = this.getClass().getClassLoader().loadClass(name);
            EvalTools.notNull(cls, ObjectFactory.class);
            return cls;
        } catch (final NullPointerException npe) {
            log.error("Could not load class with name " + name + "! Check for typos!");
        }
    } catch (final ClassNotFoundException e) {
        log.error(e.getLocalizedMessage());
    }
    return cls;
}

From source file:org.xcmis.search.SearchService.java

/**
 * Add interceptors that handle {@link ModifyIndexCommand} and
 * {@link ExecuteSelectorCommand}//from   w  ww .j a  v  a  2 s.c  o  m
 * 
 * @param interceptorChain
 *           InterceptorChain
 * @throws SearchServiceException
 *            if error occurs
 */
protected void addQueryableIndexStorageInterceptor(InterceptorChain interceptorChain)
        throws SearchServiceException {
    String className = configuration.getIndexConfuguration().getQueryableIndexStorage();
    try {
        Class<?> queryableIndexStorageClass = Class.forName(className);
        if (QueryableIndexStorage.class.isAssignableFrom(queryableIndexStorageClass)) {

            Constructor<QueryableIndexStorage> constructor = (Constructor<QueryableIndexStorage>) queryableIndexStorageClass
                    .getConstructor(configuration.getClass());
            QueryableIndexStorage queryableIndexStorage = constructor.newInstance(configuration);
            interceptorChain.addBeforeInterceptor(queryableIndexStorage, ContentReaderInterceptor.class);
        } else {
            throw new SearchServiceException(
                    className + "is no assignable from " + QueryableIndexStorage.class);
        }
    } catch (ClassNotFoundException e) {
        throw new SearchServiceException(e.getLocalizedMessage(), e);
    } catch (SecurityException e) {
        throw new SearchServiceException(e.getLocalizedMessage(), e);
    } catch (NoSuchMethodException e) {
        throw new SearchServiceException(e.getLocalizedMessage(), e);
    } catch (IllegalArgumentException e) {
        throw new SearchServiceException(e.getLocalizedMessage(), e);
    } catch (InstantiationException e) {
        throw new SearchServiceException(e.getLocalizedMessage(), e);
    } catch (IllegalAccessException e) {
        throw new SearchServiceException(e.getLocalizedMessage(), e);
    } catch (InvocationTargetException e) {
        throw new SearchServiceException(e.getTargetException());
    }

}