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.ServiceGroupContext.java
/** * Restore the contents of the object that was previously saved. * <p/>//from w w w . j ava 2s .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 (log.isTraceEnabled()) { log.trace( myClassName + ":readExternal(): BEGIN bytes available in stream [" + in.available() + "] "); } // 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); id = (String) in.readObject(); //--------------------------------------------------------- // properties //--------------------------------------------------------- properties = in.readMap(new HashMap()); //--------------------------------------------------------- // AxisServiceGroup //--------------------------------------------------------- // axisServiceGroup is not usable until the meta data has been reconciled axisServiceGroup = null; metaAxisServiceGroup = (MetaDataEntry) in.readObject(); //--------------------------------------------------------- // parent //--------------------------------------------------------- // the parent is the ConfigurationContext object, whic // at this time, is not being saved. // instead, we will need to register this ServiceGroupObject // with the existing ConfigurationContext object when // this object is reconstituted //--------------------------------------------------------- // other //--------------------------------------------------------- serviceContextMap = new HashMap<String, ServiceContext>(); //--------------------------------------------------------- // done //--------------------------------------------------------- }
From source file:ORG.oclc.oai.server.catalog.AbstractCatalog.java
/** * Factory method for creating an AbstractCatalog instance. The properties object must contain * the following entries://from w w w .j av a2 s.co m * <ul> * <li><b>AbstractCatalog.className</b> property which points to a class that implements the * AbstractCatalog interface. Note that this class must have a constructor that accepts a * properties object as a parameter.</li> * <li><b>Crosswalks.<supported formats></b> properties which satisfy the constructor for * the Crosswalks class</li> * </ul> * * @param properties Properties object containing entries necessary to initialize the class to * be created. * @return on object instantiating the AbstractCatalog interface. * @exception Throwable some sort of problem occurred. */ public static AbstractCatalog factory(final Properties properties, final ServletContext context) throws Throwable { AbstractCatalog oaiCatalog = null; String oaiCatalogClassName = properties.getProperty("AbstractCatalog.oaiCatalogClassName"); String recordFactoryClassName = properties.getProperty("AbstractCatalog.recordFactoryClassName"); if (oaiCatalogClassName == null) { throw new ClassNotFoundException("AbstractCatalog.oaiCatalogClassName is missing from properties file"); } if (recordFactoryClassName == null) { throw new ClassNotFoundException( "AbstractCatalog.recordFactoryClassName is missing from properties file"); } Class oaiCatalogClass = Class.forName(oaiCatalogClassName); try { Constructor oaiCatalogConstructor = null; try { oaiCatalogConstructor = oaiCatalogClass .getConstructor(new Class[] { Properties.class, ServletContext.class }); oaiCatalog = (AbstractCatalog) oaiCatalogConstructor .newInstance(new Object[] { properties, context }); } catch (NoSuchMethodException e) { oaiCatalogConstructor = oaiCatalogClass.getConstructor(new Class[] { Properties.class }); oaiCatalog = (AbstractCatalog) oaiCatalogConstructor.newInstance(new Object[] { properties }); } if (debug) { System.out.println("AbstractCatalog.factory: recordFactoryClassName=" + recordFactoryClassName); } Class recordFactoryClass = Class.forName(recordFactoryClassName); Constructor recordFactoryConstructor = recordFactoryClass .getConstructor(new Class[] { Properties.class }); oaiCatalog.recordFactory = (RecordFactory) recordFactoryConstructor .newInstance(new Object[] { properties }); if (debug) { System.out.println("AbstractCatalog.factory: recordFactory=" + oaiCatalog.recordFactory); } String harvestable = properties.getProperty("AbstractCatalog.harvestable"); if (harvestable != null && harvestable.equals("false")) { oaiCatalog.harvestable = false; } String secondsToLive = properties.getProperty("AbstractCatalog.secondsToLive"); if (secondsToLive != null) { oaiCatalog.millisecondsToLive = Integer.parseInt(secondsToLive) * 1000; } String granularity = properties.getProperty("AbstractCatalog.granularity"); for (int i = 0; granularity != null && i < VALID_GRANULARITIES.length; ++i) { if (granularity.equalsIgnoreCase(VALID_GRANULARITIES[i])) { oaiCatalog.supportedGranularityOffset = i; break; } } if (oaiCatalog.supportedGranularityOffset == -1) { oaiCatalog.supportedGranularityOffset = 0; System.err.println( "AbstractCatalog.factory: Invalid or missing AbstractCatalog.granularity property. Setting value to default: " + VALID_GRANULARITIES[oaiCatalog.supportedGranularityOffset]); } } catch (InvocationTargetException e) { throw e.getTargetException(); } return oaiCatalog; }
From source file:org.jahia.osgi.BundleUtils.java
public static Class<?> loadModuleClass(String className) throws ClassNotFoundException { Class<?> clazz = null;/* ww w . j a v a 2 s.c o m*/ String[] moduleKey = moduleForClass.get(className); // [moduleId, moduleVersion] if (moduleKey != null) { ClassLoader cl = null; Map<String, JahiaTemplatesPackage> versions = modules.get(moduleKey[0]); if (versions != null) { JahiaTemplatesPackage pkg = versions.get(moduleKey[1]); if (pkg != null) { cl = pkg.getClassLoader(); } } if (cl == null) { moduleForClass.remove(className); } else { return cl.loadClass(className); } } for (Map<String, JahiaTemplatesPackage> moduleVersions : modules.values()) { for (JahiaTemplatesPackage pkg : moduleVersions.values()) { if (pkg.getClassLoader() != null) { try { clazz = pkg.getClassLoader().loadClass(className); moduleForClass.put(className, new String[] { pkg.getId(), pkg.getVersion().toString() }); return clazz; } catch (ClassNotFoundException e) { // continue searching class in other modules } } } } throw new ClassNotFoundException( "Unable to find class '" + className + "' in the class loaders of modules"); }
From source file:org.nebulaframework.deployment.classloading.GridArchiveClassLoader.java
/** * Internal method which does the search for class inside * the {@code GridArchive}. First attempts locate the file directly in * the {@code .nar} file. If this fails, it then looks in the * {@code .jar} libraries available in the {@code .nar} * file, and attempts to locate the class inside each of the {@code .jar} * file./*from w w w.j a v a 2 s . c o m*/ * * @param fileName expected filename of Class file to be loaded * * @return the {@code byte[]} for the class file * * @throws IOException if IO errors occur during operation * @throws ClassNotFoundException if unable to locate the class */ protected byte[] findInArchive(String fileName) throws IOException, ClassNotFoundException { ZipFile archive = new ZipFile(archiveFile); ZipEntry entry = archive.getEntry(fileName); if (entry == null) { // Unable to find file in archive try { // Attempt to look in libraries Enumeration<? extends ZipEntry> enumeration = archive.entries(); while (enumeration.hasMoreElements()) { ZipEntry zipEntry = enumeration.nextElement(); if (zipEntry.getName().contains(GridArchive.NEBULA_INF) && zipEntry.getName().endsWith(".jar")) { // Look in Jar File byte[] bytes = findInJarStream(archive.getInputStream(zipEntry), fileName); // If Found if (bytes != null) { log.debug("[GridArchiveClassLoader] found class in JAR Library " + fileName); return bytes; } } } } catch (Exception e) { log.warn("[[GridArchiveClassLoader] Exception " + "while attempting class loading", e); } // Cannot Find Class throw new ClassNotFoundException("No such file as " + fileName); } else { // Entry not null, Found Class log.debug("[GridArchiveClassLoader] found class at " + fileName); // Get byte[] and return return IOSupport.readBytes(archive.getInputStream(entry)); } }
From source file:net.datenwerke.sandbox.SandboxLoader.java
@Override protected Class<?> loadClass(final String name, boolean resolve) throws ClassNotFoundException { Class clazz = null;//w ww . java2s. co m if (debug) logger.log(Level.INFO, getName() + "(" + System.identityHashCode(this) + ")" + " about to load class: " + name); if (null != enhancer) enhancer.classtoBeLoaded(this, name, resolve); boolean trustedSource = false; if (name.startsWith("java.") || bypassClazz(name)) { clazz = super.loadClass(name, resolve); /* check if it comes from an available jar */ if (!name.startsWith("java.") && null != whitelistedUcp) { String path = name.replace('.', '/').concat(".class"); Resource res = whitelistedUcp.getResource(path, false); if (res != null) trustedSource = true; } } else { /* check subcontext */ if (hasSubloaders) { SandboxLoader subLoader = doGetSubLoaderByClassContext(name); if (null != subLoader) return subLoader.loadClass(name, resolve); } /* check if we have already handeled this class */ clazz = findLoadedClass(name); if (clazz != null) { if (null != whitelistedUcp) { String path = name.replace('.', '/').concat(".class"); Resource res = whitelistedUcp.getResource(path, false); if (res != null) trustedSource = true; } } else { try { String basePath = name.replace('.', '/'); String path = basePath.concat(".class"); ProtectionDomain domain = null; try { CodeSource codeSource = new CodeSource(new URL("file", "", codesource.concat(basePath)), (java.security.cert.Certificate[]) null); domain = new ProtectionDomain(codeSource, new Permissions(), this, null); } catch (MalformedURLException e) { throw new RuntimeException("Could not create protection domain."); } /* define package */ int i = name.lastIndexOf('.'); if (i != -1) { String pkgName = name.substring(0, i); java.lang.Package pkg = getPackage(pkgName); if (pkg == null) { definePackage(pkgName, null, null, null, null, null, null, null); } } /* first strategy .. check jars */ if (null != whitelistedUcp) { Resource res = whitelistedUcp.getResource(path, false); if (res != null) { byte[] cBytes = enhance(name, res.getBytes()); clazz = defineClass(name, cBytes, 0, cBytes.length, domain); trustedSource = true; } } /* load class */ if (clazz == null) { InputStream in = null; try { /* we only load from local sources */ in = parent.getResourceAsStream(path); byte[] cBytes = null; if (in != null) cBytes = IOUtils.toByteArray(in); if (null == cBytes && null != enhancer) cBytes = enhancer.loadClass(this, name); if (null == cBytes) throw new ClassNotFoundException("Could not find " + name); /* load and define class */ cBytes = enhance(name, cBytes); clazz = defineClass(name, cBytes, 0, cBytes.length, domain); } finally { if (null != in) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } /* do we need to resolve */ if (resolve) resolveClass(clazz); } catch (IOException e) { throw new ClassNotFoundException("Could not load " + name, e); } catch (Exception e) { throw new ClassNotFoundException("Could not load " + name, e); } } } if (!trustedSource && null != clazz && null != securityManager) securityManager.checkClassAccess(name); if (null != enhancer) enhancer.classLoaded(this, name, clazz); return clazz; }
From source file:com.icesoft.faces.component.util.CustomComponentUtils.java
/** * Tries a Class.forName with the context class loader of the current thread * first and automatically falls back to the ClassUtils class loader (i.e. * the loader of the myfaces.jar lib) if necessary. * * @param type fully qualified name of a non-primitive non-array class * @return the corresponding Class//from w w w .jav a 2 s.c om * @throws NullPointerException if type is null * @throws ClassNotFoundException */ public static Class classForName(String type) throws ClassNotFoundException { if (type == null) { throw new NullPointerException("type"); } if (!EnvUtils.isValidJavaIdentifier(type)) { throw new ClassNotFoundException("not a valid identifier [" + type + "]"); } try { // Try WebApp ClassLoader first return Class.forName(type, false, // do not initialize for faster startup Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException ignore) { // fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib) return Class.forName(type, false, // do not initialize for faster startup CustomComponentUtils.class.getClassLoader()); } }
From source file:org.mule.util.ClassUtils.java
public static Object instanciateClass(String name, Object[] constructorArgs, ClassLoader classLoader) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Class<?> clazz;//w w w . j av a2 s . c o m if (classLoader != null) { clazz = loadClass(name, classLoader); } else { clazz = loadClass(name, ClassUtils.class); } if (clazz == null) { throw new ClassNotFoundException(name); } return instanciateClass(clazz, constructorArgs); }
From source file:com.netcrest.pado.tools.pado.command.put.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private Map getEntryMap(String fullPath, BufferInfo bufferInfo, List<String> list, boolean keyEnumerated, boolean valueEnumerated, int startIndex) throws Exception { String pairs = ""; for (int i = startIndex; i < list.size(); i++) { pairs += list.get(i) + " "; }/*from ww w.j a va2 s. c om*/ Map<String, Method> keySetterMap = ReflectionUtil.getAllSettersMap(padoShell.getKeyClass()); Map<String, Method> valueSetterMap = ReflectionUtil.getAllSettersMap(padoShell.getValueClass()); String gridPath = GridUtil.getChildPath(fullPath); String gridId = SharedCache.getSharedCache().getGridId(fullPath); IGridMapBiz gridMapBiz = SharedCache.getSharedCache().getPado().getCatalog().newInstance(IGridMapBiz.class, gridPath); gridMapBiz.getBizContext().getGridContextClient().setGridIds(gridId); // (x='1,2,3' and y='2',a='hello, world' and b='test') HashMap map = new HashMap(); StringBuffer buffer = new StringBuffer(pairs); boolean keySearch = false; boolean fieldSearch = false; boolean openQuote = false; boolean delimiter = false; boolean quoted = false; String fieldString = ""; String valueString = ""; String and = ""; Object key = null; Object value = null; for (int i = 0; i < buffer.length(); i++) { char c = buffer.charAt(i); if (c == '(') { if (openQuote == false) { String function = null; String functionCall = null; String functionString = null; if (valueString.length() > 0) { functionString = valueString; } else if (fieldString.length() > 0) { functionString = fieldString; } if (functionString != null) { // it's a function // get enclosed parenthesis int enclosedIndex = getEnclosingParenthesis(buffer, i); function = functionString.toLowerCase(); if (enclosedIndex == -1) { throw new ParseException("Malformed function call: " + function, i); } functionCall = function + buffer.substring(i, enclosedIndex + 1); Logger.fine("functionCall = |" + functionCall + "|"); i = enclosedIndex; } if (functionCall != null) { if (valueString.length() > 0) { valueString = functionCall; } else if (fieldString.length() > 0) { fieldString = functionCall; } } else { key = null; value = null; keySearch = true; fieldSearch = true; fieldString = ""; valueString = ""; } quoted = false; continue; } } else if (c == '=') { if (keySearch && key == null && keyEnumerated == false) { key = padoShell.getKeyClass().newInstance(); } if (keySearch == false && value == null && valueEnumerated == false) { if (padoShell.getValueClass() == null) { throw new ClassNotFoundException( "Undefined value class. Use the 'value' command to set the class name"); } value = padoShell.getValueClass().newInstance(); } fieldSearch = false; continue; } else if (c == ')') { if (openQuote == false) { Logger.fine("v: field = " + fieldString); Logger.fine("v: value = " + valueString); Logger.fine(""); if (valueEnumerated) { Object k = bufferInfo.getKey(Integer.parseInt(fieldString) - 1); if (k == null) { PadoShell.printlnError( "Error: value not found in the cache for the key number " + fieldString); PadoShell.println(" run 'key -l' to view the enumerated keys."); map.clear(); break; } value = gridMapBiz.get(k); if (key == null) { PadoShell.printlnError("Error: value not in the cache - " + fieldString); map.clear(); break; } Logger.fine("k = " + k); Logger.fine("key = " + key); Logger.fine("value = " + value); } else { if (valueString.length() == 0) { // primitive value = ObjectUtil.getPrimitive(padoShell, fieldString, quoted); } else { updateObject(valueSetterMap, value, fieldString, valueString); } } map.put(key, value); fieldSearch = true; quoted = false; fieldString = ""; valueString = ""; key = null; and = ""; continue; } } else if (c == '\\') { // ignore and treat the next character as a character delimiter = true; continue; } else if (c == '\'') { if (delimiter) { delimiter = false; } else { if (openQuote) { quoted = true; } openQuote = !openQuote; continue; } } else if (c == ' ') { if (openQuote == false) { boolean andExpected = false; if (keySearch) { Logger.fine("k: field = " + fieldString); Logger.fine("k: value = " + valueString); Logger.fine(""); if (fieldString.length() > 0) { updateObject(keySetterMap, key, fieldString, valueString); andExpected = true; } } else { Logger.fine("v: field = " + fieldString); Logger.fine("v: value = " + valueString); Logger.fine(""); if (fieldString.length() > 0) { updateObject(valueSetterMap, value, fieldString, valueString); andExpected = true; } } if (andExpected) { and = ""; int index = -1; for (int j = i; j < buffer.length(); j++) { and += buffer.charAt(j); and = and.trim().toLowerCase(); if (and.equals("and")) { index = j; break; } else if (and.length() > 3) { break; } } if (index != -1) { i = index; } } fieldSearch = true; fieldString = ""; valueString = ""; and = ""; quoted = false; continue; } } if (c == ',') { // if ',' is not enclosed in quotes... if (openQuote == false) { fieldString = fieldString.trim(); valueString = valueString.trim(); // end of key Logger.fine("k: field = " + fieldString); Logger.fine("k: value = " + valueString); Logger.fine(""); if (keySearch) { if (keyEnumerated) { key = bufferInfo.getKey(Integer.parseInt(fieldString) - 1); if (key == null) { PadoShell.printlnError( "Error: value not found in the cache for the key number " + fieldString); PadoShell.println(" run 'key -l' to view the enumerated keys."); map.clear(); break; } } else { if (valueString.length() == 0) { key = ObjectUtil.getPrimitive(padoShell, fieldString, quoted); } else { updateObject(keySetterMap, key, fieldString, valueString); } } } else { if (valueEnumerated) { Object k = bufferInfo.getKey(Integer.parseInt(fieldString) - 1); value = gridMapBiz.get(k); if (value == null) { PadoShell.printlnError("Error: undefined value num " + fieldString); map.clear(); break; } } else { if (valueString.length() == 0) { value = ObjectUtil.getPrimitive(padoShell, fieldString, quoted); } else { updateObject(valueSetterMap, value, fieldString, valueString); } } } fieldSearch = true; keySearch = false; quoted = false; fieldString = ""; valueString = ""; and = ""; continue; } } if (fieldSearch) { fieldString += c; } else if (quoted == false) { valueString += c; } } return map; }
From source file:eu.europeana.enrichment.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// w w w . j av a2 s .co m // more than one if a package is split over multiple jars/paths Queue<File> directories = new LinkedList<File>(); try { 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:com.dragome.callbackevictor.serverside.ContinuationClassLoader.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//from w w w . j av a2 s . com * * @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 } } }