List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:org.apache.axis2.context.ServiceContext.java
/** * Restore the contents of the object that was previously saved. * <p/>/* w w w.j a v a2 s.c o m*/ * NOTE: The field data must read back in the same order and type * as it was written. Some data will need to be validated when * resurrected. * * @param in The stream to read the object contents from * @throws IOException * @throws ClassNotFoundException */ public void readExternal(ObjectInput inObject) throws IOException, ClassNotFoundException { SafeObjectInputStream in = SafeObjectInputStream.install(inObject); // set the flag to indicate that the message context is being // reconstituted and will need to have certain object references // to be reconciled with the current engine setup needsToBeReconciled = true; // trace point if (LoggingControl.debugLoggingAllowed && log.isTraceEnabled()) { log.trace( myClassName + ":readExternal(): BEGIN bytes available in stream [" + in.available() + "] "); } //--------------------------------------------------------- // object level identifiers //--------------------------------------------------------- // serialization version ID long suid = in.readLong(); // revision ID int revID = in.readInt(); // make sure the object data is in a version we can handle if (suid != serialVersionUID) { throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_SUID); } // make sure the object data is in a revision level we can handle if (revID != REVISION_2) { throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_REVID); } //--------------------------------------------------------- // various simple fields //--------------------------------------------------------- long time = in.readLong(); setLastTouchedTime(time); cachingOperationContext = in.readBoolean(); logCorrelationIDString = (String) in.readObject(); // trace point if (LoggingControl.debugLoggingAllowed && log.isTraceEnabled()) { log.trace(myClassName + ":readExternal(): reading input stream for [" + getLogCorrelationIDString() + "] "); } // EndpointReference targetEPR targetEPR = (EndpointReference) in.readObject(); // EndpointReference myEPR myEPR = (EndpointReference) in.readObject(); //--------------------------------------------------------- // properties //--------------------------------------------------------- properties = in.readMap(new HashMap()); //--------------------------------------------------------- // AxisService //--------------------------------------------------------- // axisService is not usable until the meta data has been reconciled metaAxisService = (MetaDataEntry) in.readObject(); //--------------------------------------------------------- // parent //--------------------------------------------------------- // ServiceGroupContext is not usable until it has been activated metaParent = (ServiceGroupContext) in.readObject(); //--------------------------------------------------------- // other //--------------------------------------------------------- // currently not saving this object lastOperationContext = null; //--------------------------------------------------------- // done //--------------------------------------------------------- }
From source file:com.swordlord.gozer.builder.Parser.java
/** * Retrieve a Class/*from w w w . j a v a 2 s .c o m*/ * * @param pckgname * @param skipDollarClasses * @return the class */ public static Class<?>[] getClasses(String pckgname, boolean skipDollarClasses) { ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); try { File directory = getClassesHelper(pckgname); if (directory.exists()) { // Get the list of the files contained in the package String[] files = directory.list(); for (int i = 0; i < files.length; i++) { // we are only interested in .class files if (files[i].endsWith(".class")) { // get rid of the ".class" at the end String withoutclass = pckgname + '.' + files[i].substring(0, files[i].length() - 6); // in case we don't want $1 $2 etc. endings (i.e. common // in GUI classes) if (skipDollarClasses) { int dollar_occurence = withoutclass.indexOf("$"); if (dollar_occurence != -1) { withoutclass = withoutclass.substring(0, dollar_occurence); } } // add this class to our list but avoid duplicates boolean already_contained = false; for (Class<?> c : classes) { if (c.getCanonicalName().equals(withoutclass)) { already_contained = true; } } if (!already_contained) { classes.add(Class.forName(withoutclass)); } // REMARK this kind of checking is quite slow using // reflection, it would be better // to do the class.forName(...) stuff outside of this // method and change the method // to only return an ArrayList with fqcn Strings. Also // in reality we have the $1 $2 // etc. classes in our packages, so we are skipping some // "real" classes here } } } else { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } } catch (ClassNotFoundException e) { e.printStackTrace(); } Class<?>[] classesA = new Class[classes.size()]; classes.toArray(classesA); return classesA; }
From source file:org.ajax4jsf.renderkit.compiler.MethodCallElement.java
InvokeData invokeMethod(TemplateContext context, MethodCacheState state) { if (cls == null) throw new FacesException(className, new ClassNotFoundException(className)); return invokeMethod(context, methods, cls, null, state); }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
@Override protected Class<?> findClass(String className) throws ClassNotFoundException { String classResourceName = className.replace('.', '/') + ".class"; InputStream input = getResourceAsStream(classResourceName); if (input == null) { throw new ClassNotFoundException(className); } else {//from w ww .ja v a2s . com try { // read class bytes byte[] bytes = IOUtils2.readBytes(input); // apply processors for (IByteCodeProcessor processor : m_processors) { bytes = processor.process(className, bytes); } // implement abstract methods (only for required classes) if (m_nonAbstractClasses.contains(className)) { ClassReader classReader = new ClassReader(bytes); AbstractMethodsImplementorVisitor rewriter = new AbstractMethodsImplementorVisitor(className); classReader.accept(rewriter, 0); bytes = rewriter.toByteArray(); } // define package { String pkgName = StringUtils.substringBeforeLast(className, "."); if (getPackage(pkgName) == null) { definePackage(pkgName, null, null, null, null, null, null, null); } } // return (possibly modified) class ensureCodeSource(); return defineClass(className, bytes, 0, bytes.length, m_fakeCodeSource); } catch (Throwable e) { throw new ClassNotFoundException("Error loading class " + className, e); } } }
From source file:eu.annocultor.common.Utils.java
private static Set<String> getClassNamesPackage(String pckgname) throws ClassNotFoundException, IOException { // This will hold a list of directories matching the pckgname. There may be // more than one if a package is split over multiple jars/paths Queue<File> directories = new LinkedList<File>(); try {/*from w w w . ja v a2s .co m*/ ClassLoader cld = Thread.currentThread().getContextClassLoader(); if (cld == null) { throw new ClassNotFoundException("Can't get class loader."); } String path = pckgname.replace('.', '/'); // Ask for all resources for the path Enumeration<URL> resources = cld.getResources(path); while (resources.hasMoreElements()) { directories.add(new File(URLDecoder.decode(resources.nextElement().getPath(), "UTF-8"))); } } catch (NullPointerException x) { throw new ClassNotFoundException( pckgname + " does not appear to be a valid package (Null pointer exception)"); } catch (UnsupportedEncodingException encex) { throw new ClassNotFoundException( pckgname + " does not appear to be a valid package (Unsupported encoding)"); } catch (IOException ioex) { throw new ClassNotFoundException( "IOException was thrown when trying to get all resources for " + pckgname); } Set<String> classes = new HashSet<String>(); // For every directory identified capture all the .class files while (!directories.isEmpty()) { File directory = directories.poll(); if (directory.exists()) { // Get the list of the files contained in the package File[] files = directory.listFiles(); for (File file : files) { // we are only interested in .class files if (file.getCanonicalPath().endsWith(".class")) { String fileName = file.getPath().substring(directory.getPath().length() + 1); pckgname = file.getPath() .substring(file.getPath().indexOf(File.separator + "nl" + File.separator) + 1); pckgname = pckgname.substring(0, pckgname.lastIndexOf(File.separator)) .replaceAll("\\" + File.separator, "."); // if (!fileName.matches("(.+)\\$\\d\\.class")) // removes the .class extension classes.add(fileName.substring(0, fileName.length() - 6)); } // Add subdirs if (file.isDirectory()) { directories.add(file); } } } else { throw new ClassNotFoundException( pckgname + " (" + directory.getPath() + ") does not appear to be a valid package"); } } return classes; }
From source file:org.java.plugin.standard.StandardPluginClassLoader.java
/** * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean) *//*from ww w. jav a 2 s.com*/ protected Class loadClass(final String name, final boolean resolve) throws ClassNotFoundException { Class result; boolean tryLocal = true; if (isLocalClass(name)) { if (log.isDebugEnabled()) { log.debug("loadClass: trying local class guess, name=" //$NON-NLS-1$ + name + ", this=" + this); //$NON-NLS-1$ } result = loadLocalClass(name, resolve, this); if (result != null) { if (log.isDebugEnabled()) { log.debug("loadClass: local class guess succeeds, name=" //$NON-NLS-1$ + name + ", this=" + this); //$NON-NLS-1$ } checkClassVisibility(result, this); return result; } tryLocal = false; } if (probeParentLoaderLast) { try { result = loadPluginClass(name, resolve, tryLocal, this, null); } catch (ClassNotFoundException cnfe) { result = getParent().loadClass(name); } if (result == null) { result = getParent().loadClass(name); } } else { try { result = getParent().loadClass(name); } catch (ClassNotFoundException cnfe) { result = loadPluginClass(name, resolve, tryLocal, this, null); } } if (result != null) { return result; } throw new ClassNotFoundException(name); }
From source file:com.eucalyptus.bootstrap.BootstrapClassLoader.java
protected Class findClass(String name) throws ClassNotFoundException { if (isBoundClass(name)) { try {//www. ja v a 2s .c o m ClassFile clas = (ClassFile) this.classMap.get(name); ByteArrayOutputStream bos = new ByteArrayOutputStream(); clas.writeFile(bos); byte[] bytes = bos.toByteArray(); return defineClass(name, bytes, 0, bytes.length); } catch (IOException e) { throw new ClassNotFoundException("Unable to load modified class " + name); } } else { return super.findClass(name); } }
From source file:org.exoplatform.services.cms.scripts.impl.ScriptServiceImpl.java
/** * create Groovy ClassLoader//from w w w . j ava 2 s. co m * @see SessionProvider * @return */ private GroovyClassLoader createGroovyClassLoader() { ClassLoader parentLoader = Thread.currentThread().getContextClassLoader(); return new GroovyClassLoader(parentLoader) { @SuppressWarnings("unchecked") protected Class findClass(String className) throws ClassNotFoundException { String filename = null; String nodeName = null; if (className.indexOf(":") > -1) { String[] array = className.split(":"); nodeName = array[1]; filename = array[1].replace('.', File.separatorChar) + ".groovy"; } else { nodeName = className; filename = className.replace('.', File.separatorChar) + ".groovy"; } String scriptContent = null; try { scriptContent = WCMCoreUtils.getService(BaseResourceLoaderService.class) .getResourceAsText(nodeName); } catch (Exception e) { throw new ClassNotFoundException("Could not read " + nodeName + ": " + e); } try { return parseClass(scriptContent, filename); } catch (CompilationFailedException e2) { throw new ClassNotFoundException("Syntax error in " + filename + ": " + e2); } } }; }
From source file:com.dragome.callbackevictor.serverside.DragomeContinuationClassLoader.java
/** * Searches for and load a class on the classpath of this class loader. * * @param name The name of the class to be loaded. Must not be * <code>null</code>. * * @return the required Class object/* w w w . j a v a2 s .co m*/ * * @exception ClassNotFoundException if the requested class does not exist * on this loader's classpath. */ public Class findClass(final String name) throws ClassNotFoundException { log.debug("Finding class " + name); // locate the class file String classFileName = name.replace('.', '/') + ".class"; InputStream stream = getResourceAsStream(classFileName); if (stream == null) throw new ClassNotFoundException(name); try { return getClassFromStream(stream, name); } catch (IOException e) { throw new ClassNotFoundException(name, e); } finally { try { stream.close(); } catch (IOException e) { // ignore } } }
From source file:org.java.plugin.standard.StandardPluginClassLoader.java
protected Class loadPluginClass(final String name, final boolean resolve, final boolean tryLocal, final StandardPluginClassLoader requestor, final Set seenPlugins) throws ClassNotFoundException { Set seen = seenPlugins;//from w w w .ja v a 2s . com if ((seen != null) && seen.contains(getPluginDescriptor().getId())) { return null; } if (seen == null) { seen = new HashSet(); } seen.add(getPluginDescriptor().getId()); if ((this != requestor) && !getPluginManager().isPluginActivated(getPluginDescriptor()) && !getPluginManager().isPluginActivating(getPluginDescriptor())) { String msg = "can't load class " + name + ", plug-in " //$NON-NLS-1$ //$NON-NLS-2$ + getPluginDescriptor() + " is not activated yet"; //$NON-NLS-1$ log.warn(msg); throw new ClassNotFoundException(msg); } Class result = null; boolean debugEnabled = log.isDebugEnabled(); PluginDescriptor descr = guessPlugin(name); if ((descr != null) && !seen.contains(descr.getId())) { if (debugEnabled) { log.debug("loadPluginClass: trying plug-in guess, name=" //$NON-NLS-1$ + name + ", this=" //$NON-NLS-1$ + this + ", requestor=" + requestor); //$NON-NLS-1$ } result = ((StandardPluginClassLoader) getPluginManager().getPluginClassLoader(descr)) .loadPluginClass(name, resolve, true, requestor, seen); if (result != null) { if (debugEnabled) { log.debug("loadPluginClass: plug-in guess succeeds, name=" //$NON-NLS-1$ + name + ", this=" //$NON-NLS-1$ + this + ", requestor=" + requestor); //$NON-NLS-1$ } return result; } } if (tryLocal) { result = loadLocalClass(name, resolve, requestor); if (result != null) { checkClassVisibility(result, requestor); return result; } } for (int i = 0; i < publicImports.length; i++) { if (seen.contains(publicImports[i].getId())) { continue; } result = ((StandardPluginClassLoader) getPluginManager().getPluginClassLoader(publicImports[i])) .loadPluginClass(name, resolve, true, requestor, seen); if (result != null) { break; // found class in publicly imported plug-in } } if ((this == requestor) && (result == null)) { for (int i = 0; i < privateImports.length; i++) { if (seen.contains(privateImports[i].getId())) { continue; } result = ((StandardPluginClassLoader) getPluginManager().getPluginClassLoader(privateImports[i])) .loadPluginClass(name, resolve, true, requestor, seen); if (result != null) { break; // found class in privately imported plug-in } } } if (result == null) { for (int i = 0; i < reverseLookups.length; i++) { if (seen.contains(reverseLookups[i].getId())) { continue; } if (!getPluginManager().isPluginActivated(reverseLookups[i]) && !getPluginManager().isPluginActivating(reverseLookups[i])) { continue; } result = ((StandardPluginClassLoader) getPluginManager().getPluginClassLoader(reverseLookups[i])) .loadPluginClass(name, resolve, true, requestor, seen); if (result != null) { break; // found class in plug-in that marks itself as // allowed reverse look up } } } registerPluginPackage(result); return result; }