Example usage for java.lang ClassNotFoundException ClassNotFoundException

List of usage examples for java.lang ClassNotFoundException ClassNotFoundException

Introduction

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

Prototype

public ClassNotFoundException() 

Source Link

Document

Constructs a ClassNotFoundException with no detail message.

Usage

From source file:egovframework.rte.fdl.string.EgovObjectUtil.java

/**
 * ? ? ./*from w  ww . j a  v  a 2 s.  c  o  m*/
 * @param className
 * @return
 * @throws ClassNotFoundException
 * @throws Exception
 */
public static Class<?> loadClass(String className) throws ClassNotFoundException, Exception {

    Class<?> clazz = null;
    try {
        clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ClassNotFoundException();
    } catch (Exception e) {
        throw new Exception(e);
    }

    if (clazz == null) {
        clazz = Class.forName(className);
    }

    return clazz;

}

From source file:egovframework.rte.fdl.string.EgovObjectUtil.java

/**
 * ? ?   ? ./*  ww  w  .  j  a  v  a2 s.co m*/
 * @param className
 * @return
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws Exception
 */
public static Object instantiate(String className)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception {
    Class<?> clazz;

    try {
        clazz = loadClass(className);
        return clazz.newInstance();
    } catch (ClassNotFoundException e) {
        if (log.isErrorEnabled())
            log.error(className + " : Class is can not instantialized.");
        throw new ClassNotFoundException();
    } catch (InstantiationException e) {
        if (log.isErrorEnabled())
            log.error(className + " : Class is can not instantialized.");
        throw new InstantiationException();
    } catch (IllegalAccessException e) {
        if (log.isErrorEnabled())
            log.error(className + " : Class is not accessed.");
        throw new IllegalAccessException();
    } catch (Exception e) {
        if (log.isErrorEnabled())
            log.error(className + " : Class is not accessed.");
        throw new Exception(e);
    }
}

From source file:com.bluecloud.ioc.classloader.ClassHandler.java

/**
 * <h3>Class</h3>/*from   w w w  .  j  ava2  s.c o  m*/
 * 
 * @param clazz
 * @return
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws SecurityException
 * @throws IllegalArgumentException
 */
private static Object getClassNewInstrance(Class<?> clazz)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException,
        SecurityException, InvocationTargetException, NoSuchMethodException {
    if (clazz == null) {
        throw new ClassNotFoundException();
    }
    return clazz.getConstructor((Class[]) null).newInstance((Object[]) null);
}

From source file:org.dcm4che3.conf.core.util.ConfigIterators.java

public static Class<?> getExtensionClassBySimpleName(String extensionSimpleName,
        List<Class<?>> allExtensionClasses) throws ClassNotFoundException {

    List<Class<?>> extensionClasses = allExtensionClasses;

    for (Class<?> aClass : extensionClasses) {
        if (aClass.getSimpleName().equals(extensionSimpleName))
            return aClass;
    }/*  w  ww . j a  va  2  s .c  om*/

    throw new ClassNotFoundException();
}

From source file:org.pentaho.test.platform.engine.core.TestManager.java

public static TestManager getInstance(TestSuite all) throws Exception {
    if (manager == null) {
        String testManagerClassName = PentahoSystem.getSystemSetting("test-suite/test-settings.xml", //$NON-NLS-1$
                "test-manager", "org.pentaho.test.TestManager"); //$NON-NLS-1$ //$NON-NLS-2$
        if (testManagerClassName == null) {
            testManagerClassName = "org.pentaho.test.TestManager"; //$NON-NLS-1$
        }//from w w  w .  j a va 2s .c om
        Class componentClass = Class.forName(testManagerClassName.trim());
        manager = (TestManager) componentClass.newInstance();
        if (manager != null) {
            manager.init(all);
        } else {
            throw new ClassNotFoundException();
        }
    }
    return manager;
}

From source file:me.rgcjonas.portableMinecraftLauncher.ModdingClassLoader.java

public Class<?> findClass(String name) throws ClassNotFoundException {
    byte[] data = null;
    String resourceName = name.replace('.', '/').concat(".class"); //getResource expects this form
    if (moddedClasses.containsKey(name)) {
        data = moddedClasses.get(name);//from   w w w.  j a  va  2 s . com
    } else {
        try {
            InputStream is = this.getResourceAsStream(resourceName);
            if (is == null) {
                System.out.println("class not found: " + resourceName + "\n");
                throw new ClassNotFoundException();
            }
            data = IOUtils.toByteArray(is);
        } catch (IOException e) {
            throw new ClassNotFoundException(e.toString());
        }
    }
    CodeSource source = new CodeSource(this.getResource(resourceName), new Certificate[] {});
    return defineClass(name, data, 0, data.length, source);
}

From source file:egovframework.rte.fdl.string.EgovObjectUtil.java

/**
 * ? ?  ?? ?? ? . ) Class <?>/*from  w w  w. j av  a2s  . c  o m*/
 * clazz = EgovObjectUtil.loadClass(this.mapClass);
 * Constructor <?> constructor =
 * clazz.getConstructor(new Class
 * []{DataSource.class, String.class}); Object []
 * params = new Object []{getDataSource(),
 * getUsersByUsernameQuery()};
 * this.usersByUsernameMapping =
 * (EgovUsersByUsernameMapping)
 * constructor.newInstance(params);
 * @param className
 * @return
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws Exception
 */
public static Object instantiate(String className, String[] types, Object[] values)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception {
    Class<?> clazz;
    Class<?>[] classParams = new Class[values.length];
    Object[] objectParams = new Object[values.length];

    try {
        clazz = loadClass(className);

        for (int i = 0; i < values.length; i++) {
            classParams[i] = loadClass(types[i]);
            objectParams[i] = values[i];
        }

        Constructor<?> constructor = clazz.getConstructor(classParams);
        return constructor.newInstance(values);

    } catch (ClassNotFoundException e) {
        if (log.isErrorEnabled())
            log.error(className + " : Class is can not instantialized.");
        throw new ClassNotFoundException();
    } catch (InstantiationException e) {
        if (log.isErrorEnabled())
            log.error(className + " : Class is can not instantialized.");
        throw new InstantiationException();
    } catch (IllegalAccessException e) {
        if (log.isErrorEnabled())
            log.error(className + " : Class is not accessed.");
        throw new IllegalAccessException();
    } catch (Exception e) {
        if (log.isErrorEnabled())
            log.error(className + " : Class is not accessed.");
        throw new Exception(e);
    }
}

From source file:pt.webdetails.cdv.notifications.NotificationEngine.java

private void listAlerts(Document doc) {
    alerts = new HashMap<NotificationKey, List<NotificationOutlet>>();
    List<Node> alertNodes = doc.selectNodes("//alerts/alert");
    for (Node alertNode : alertNodes) {
        String outletName = "";
        try {/* w  w w.  jav  a  2  s.c om*/
            outletName = alertNode.selectSingleNode("./@outlet").getStringValue();
            Class outletClass = outlets.get(outletName);
            if (outletClass == null) {
                throw new ClassNotFoundException();
            }
            List<Node> groups = alertNode.selectNodes("./groups/group");
            for (Node group : groups) {
                Constructor cons = outletClass.getConstructor(Node.class);
                NotificationOutlet outlet = (NotificationOutlet) cons.newInstance(alertNode);
                String minLevel = group.selectSingleNode("./@threshold").getStringValue();
                if (minLevel.equals("*")) {
                    minLevel = "ALL";
                }
                String groupName = group.selectSingleNode("./@name").getStringValue();
                Level level;
                try {
                    level = Level.valueOf(minLevel.toUpperCase());
                } catch (Exception ex) {
                    level = Level.WARN;
                }
                NotificationKey key = new NotificationKey(level, groupName);
                if (!alerts.containsKey(key)) {
                    alerts.put(key, new ArrayList<NotificationOutlet>());
                }
                alerts.get(key).add(outlet);
            }
        } catch (InstantiationException e) {
            logger.error("Failed to instantiate " + outletName, e);
        } catch (ClassNotFoundException ex) {
            logger.error("Failed to get class for outlet " + outletName, ex);
        } catch (NoSuchMethodException ex) {
            logger.error("Class " + outletName + " doesn't provide the necessary interface");
            logger.error(ex);
        } catch (InvocationTargetException ex) {
            logger.error("Failed to set defaults on " + outletName);
            logger.error(ex);
        } catch (IllegalAccessException ex) {
            logger.error("Failed to set defaults on " + outletName);
            logger.error(ex);
        }
    }
}

From source file:it.eng.spagobi.commons.utilities.ExecutionProxy.java

/**
 * Executes a document in background with the given profile.
 * //from w ww  . j  a  va2  s  .c o  m
 * @param profile The user profile
 * @param modality The execution modality (for auditing)
 * @param defaultOutputFormat The default output format (optional)
 * , considered if the document has no output format parameter set
 * 
 * @return the byte[]
 */
public byte[] exec(IEngUserProfile profile, String modality, String defaultOutputFormat) {
    logger.debug("IN");
    byte[] response = new byte[0];
    try {
        if (biObject == null)
            return response;
        // get the engine of the biobject
        Engine eng = biObject.getEngine();
        // if engine is not an external it's not possible to call it using
        // url
        if (!EngineUtilities.isExternal(eng))
            if (eng.getClassName().equals("it.eng.spagobi.engines.kpi.SpagoBIKpiInternalEngine")) {
                SourceBean request = null;
                SourceBean resp = null;
                EMFErrorHandler errorHandler = null;

                try {
                    request = new SourceBean("");
                    resp = new SourceBean("");
                } catch (SourceBeanException e1) {
                    e1.printStackTrace();
                }
                RequestContainer reqContainer = new RequestContainer();
                ResponseContainer resContainer = new ResponseContainer();
                reqContainer.setServiceRequest(request);
                resContainer.setServiceResponse(resp);
                DefaultRequestContext defaultRequestContext = new DefaultRequestContext(reqContainer,
                        resContainer);
                resContainer.setErrorHandler(new EMFErrorHandler());
                RequestContainer.setRequestContainer(reqContainer);
                ResponseContainer.setResponseContainer(resContainer);
                Locale locale = new Locale("it", "IT", "");
                SessionContainer session = new SessionContainer(true);
                reqContainer.setSessionContainer(session);
                SessionContainer permSession = session.getPermanentContainer();
                //IEngUserProfile profile = new AnonymousCMSUserProfile();
                permSession.setAttribute(IEngUserProfile.ENG_USER_PROFILE, profile);
                errorHandler = defaultRequestContext.getErrorHandler();

                String className = eng.getClassName();
                logger.debug("Try instantiating class " + className + " for internal engine " + eng.getName()
                        + "...");
                InternalEngineIFace internalEngine = null;
                // tries to instantiate the class for the internal engine
                try {
                    if (className == null && className.trim().equals(""))
                        throw new ClassNotFoundException();
                    internalEngine = (InternalEngineIFace) Class.forName(className).newInstance();
                } catch (ClassNotFoundException cnfe) {
                    logger.error("The class ['" + className + "'] for internal engine " + eng.getName()
                            + " was not found.", cnfe);
                    Vector params = new Vector();
                    params.add(className);
                    params.add(eng.getName());
                    errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, 2001, params));
                    return response;
                } catch (Exception e) {
                    logger.error("Error while instantiating class " + className, e);
                    errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, 100));
                    return response;
                }
                try {
                    reqContainer.setAttribute("scheduledExecution", "true");
                    internalEngine.execute(reqContainer, biObject, resp);
                } catch (EMFUserError e) {
                    logger.error("Error during engine execution", e);
                    errorHandler.addError(e);
                } catch (Exception e) {
                    logger.error("Error while engine execution", e);
                    errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, 100));
                }
                return response;
            } else if (eng.getClassName().equals("it.eng.spagobi.engines.chart.SpagoBIChartInternalEngine")) {
                SourceBean request = null;
                EMFErrorHandler errorHandler = null;
                try {
                    request = new SourceBean("");
                } catch (SourceBeanException e1) {
                    e1.printStackTrace();
                }
                RequestContainer reqContainer = new RequestContainer();
                SpagoBIChartInternalEngine sbcie = new SpagoBIChartInternalEngine();

                // Call chart engine
                File file = sbcie.executeChartCode(reqContainer, biObject, null, profile);

                // read input from file
                InputStream is = new FileInputStream(file);

                // Get the size of the file
                long length = file.length();

                if (length > Integer.MAX_VALUE) {
                    logger.error("file too large");
                    return null;
                }

                // Create the byte array to hold the data
                byte[] bytes = new byte[(int) length];

                // Read in the bytes
                int offset = 0;
                int numRead = 0;
                while (offset < bytes.length
                        && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
                    offset += numRead;
                }

                // Ensure all the bytes have been read in
                if (offset < bytes.length) {
                    logger.warn("Could not read all the file");
                }
                // Close the input stream and return bytes
                is.close();
                return bytes;
            } // end chart case
            else {
                return response;
            }
        // get driver class
        String driverClassName = eng.getDriverName();

        // build an instance of the driver
        IEngineDriver aEngineDriver = (IEngineDriver) Class.forName(driverClassName).newInstance();

        // get the map of parameter to send to the engine
        Map mapPars = aEngineDriver.getParameterMap(biObject, profile, "");
        if (defaultOutputFormat != null && !defaultOutputFormat.trim().equals("")) {
            List params = biObject.getBiObjectParameters();
            Iterator iterParams = params.iterator();
            boolean findOutPar = false;
            while (iterParams.hasNext()) {
                BIObjectParameter par = (BIObjectParameter) iterParams.next();
                String parUrlName = par.getParameterUrlName();
                List values = par.getParameterValues();
                logger.debug("processing biparameter with url name " + parUrlName);
                if (parUrlName.equalsIgnoreCase("outputType") && values != null && values.size() > 0) {
                    findOutPar = true;
                    break;
                }
            }
            if (!findOutPar) {
                mapPars.put("outputType", defaultOutputFormat);
            }
        }

        adjustParametersForExecutionProxy(aEngineDriver, mapPars, modality);

        // pass ticket ...
        String pass = SingletonConfig.getInstance().getConfigValue("SPAGOBI_SSO.PASS");
        if (pass == null)
            logger.warn("Pass Ticket is null");
        mapPars.put(SpagoBIConstants.PASS_TICKET, pass);

        // TODO merge with ExecutionInstance.addSystemParametersForExternalEngines for SBI_CONTEXT, locale parameters, etc...

        // set spagobi context
        if (!mapPars.containsKey(SpagoBIConstants.SBI_CONTEXT)) {
            String sbicontext = GeneralUtilities.getSpagoBiContext();
            if (sbicontext != null) {
                mapPars.put(SpagoBIConstants.SBI_CONTEXT, sbicontext);
            }
        }

        // set country and language (locale)
        Locale locale = GeneralUtilities.getDefaultLocale();
        if (!mapPars.containsKey(SpagoBIConstants.SBI_COUNTRY)) {
            String country = locale.getCountry();
            mapPars.put(SpagoBIConstants.SBI_COUNTRY, country);
        }
        if (!mapPars.containsKey(SpagoBIConstants.SBI_LANGUAGE)) {
            String language = locale.getLanguage();
            mapPars.put(SpagoBIConstants.SBI_LANGUAGE, language);
        }

        //set userId if it's a send mail operation (backend operation)
        if (sendMailOperation.equals(modality) || exportOperation.equals(modality)) {
            mapPars.put(SsoServiceInterface.USER_ID, ((UserProfile) profile).getUserUniqueIdentifier());
        }

        // adding SBI_EXECUTION_ID parameter
        if (!mapPars.containsKey("SBI_EXECUTION_ID")) {
            UUIDGenerator uuidGen = UUIDGenerator.getInstance();
            UUID uuidObj = uuidGen.generateTimeBasedUUID();
            String executionId = uuidObj.toString();
            executionId = executionId.replaceAll("-", "");
            mapPars.put("SBI_EXECUTION_ID", executionId);
        }

        // AUDIT
        AuditManager auditManager = AuditManager.getInstance();
        Integer auditId = auditManager.insertAudit(biObject, null, profile, "",
                modality != null ? modality : "");
        // adding parameters for AUDIT updating
        if (auditId != null) {
            mapPars.put(AuditManager.AUDIT_ID, auditId.toString());
        }

        // built the request to sent to the engine
        Iterator iterMapPar = mapPars.keySet().iterator();
        HttpClient client = new HttpClient();
        // get the url of the engine
        String urlEngine = getExternalEngineUrl(eng);
        PostMethod httppost = new PostMethod(urlEngine);
        while (iterMapPar.hasNext()) {
            String parurlname = (String) iterMapPar.next();
            String parvalue = "";
            if (mapPars.get(parurlname) != null)
                parvalue = mapPars.get(parurlname).toString();
            httppost.addParameter(parurlname, parvalue);
        }
        // sent request to the engine
        int statusCode = client.executeMethod(httppost);
        logger.debug("statusCode=" + statusCode);
        response = httppost.getResponseBody();
        logger.debug("response=" + response.toString());
        Header headContetType = httppost.getResponseHeader("Content-Type");
        if (headContetType != null) {
            returnedContentType = headContetType.getValue();
        } else {
            returnedContentType = "application/octet-stream";
        }

        auditManager.updateAudit(auditId, null, new Long(GregorianCalendar.getInstance().getTimeInMillis()),
                "EXECUTION_PERFORMED", null, null);
        httppost.releaseConnection();
    } catch (Exception e) {
        logger.error("Error while executing object ", e);
    }
    logger.debug("OUT");
    return response;
}

From source file:rubah.runtime.classloader.RubahClassloader.java

@Override
protected synchronized Class<?> loadClass(String className, boolean resolve) throws ClassNotFoundException {
    byte[] classBytes = null;
    VersionManager updateManager = VersionManager.getInstance();

    Class<?> ret = findLoadedClass(className);

    if (ret != null) {
        // Do nothing
    } else if (className.startsWith("rubah.") || className.startsWith("java") ||
    //            className.startsWith("com.sun.jna") ||
            className.startsWith("org.xml.sax") || className.startsWith("sun")) {
        ret = super.loadClass(className, resolve);
        resolve = false;//from  w  ww .j  a  va  2  s.c  om
    } else if (className.startsWith(PureConversionClassLoader.PURE_CONVERSION_PREFFIX)) {
        try {
            Version version = updateManager.getRunningVersion();
            UpdateClass updateClass = updateManager.getUpdateClass(version);
            classBytes = new PureConversionClassLoader(version, updateClass).getClass(className);
            writeClassFile(className, classBytes);
            ret = this.defineClass(className, classBytes, 0, classBytes.length);
            //            return ret;
        } catch (IOException e) {
            throw new Error(e);
        }
    } else if (ProxyGenerator.isProxyName(className)) {
        Version latest = updateManager.getLatestVersion();
        String proxiedName = ProxyGenerator.getOriginalName(className);
        String originalName = latest.getOriginalName(proxiedName);
        originalName = (originalName == null ? proxiedName : originalName);
        Clazz c = latest.getNamespace().getClass(Type.getObjectType(originalName.replace('.', '/')));
        classBytes = new ProxyGenerator(c, updateManager.getRunningVersion()).generateProxy(className);
        writeClassFile(className, classBytes);
        ret = this.defineClass(className, classBytes, 0, classBytes.length);
    } else {

        try {
            classBytes = Rubah.getClassBytes(className);
            writeClassFile(className, classBytes);
            ret = this.defineClass(className, classBytes, 0, classBytes.length);
            redefinableClasses.add(ret);
        } catch (IOException e) {
            throw new ClassNotFoundException();
        }

        Version latest = VersionManager.getInstance().getLatestVersion();
        Version prev = latest.getPrevious();

        if (prev != null) {
            String prevName = prev.getUpdatableName(latest.getOriginalName(className));
            Class<?> prevClass = this.findLoadedClass(prevName);

            if (prevClass != null) {
                setHashCode(ret, prevClass.hashCode());
            }
        }
    }

    if (AddTraverseMethod.isAllowed(className)) {
        loadedClasses.add(ret);
        loadedClassNames.add(ret.getName());
    }

    if (resolve)
        this.resolveClass(ret);

    if (ret.hashCode() == 0)
        setHashCode(ret);

    Boolean isResolved = this.resolved.get(ret.getName());
    if (isResolved == null)
        this.resolved.put(ret.getName(), false);

    return ret;
}