List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:org.gridgain.grid.kernal.managers.deployment.GridDeploymentClassLoader.java
/** * Sends class-loading request to all nodes associated with this class loader. * * @param name Class name./*from w ww .j av a 2s .c o m*/ * @param path Class path. * @return Class byte source. * @throws ClassNotFoundException If class was not found. */ private GridByteArrayList sendClassRequest(String name, String path) throws ClassNotFoundException { assert !Thread.holdsLock(mux); long endTime = computeEndTime(p2pTimeout); Collection<UUID> nodeListCp; Map<UUID, GridUuid> nodeLdrMapCp; synchronized (mux) { // Skip requests for the previously missed classes. if (missedRsrcs != null && missedRsrcs.contains(path)) throw new ClassNotFoundException("Failed to peer load class [class=" + name + ", nodeClsLdrIds=" + nodeLdrMap + ", parentClsLoader=" + getParent() + ']'); // If single-node mode, then node cannot change and we simply reuse list and map. // Otherwise, make copies that can be used outside synchronization. nodeListCp = singleNode ? nodeList : new LinkedList<>(nodeList); nodeLdrMapCp = singleNode ? nodeLdrMap : new HashMap<>(nodeLdrMap); } GridException err = null; for (UUID nodeId : nodeListCp) { if (nodeId.equals(ctx.discovery().localNode().id())) // Skip local node as it is already used as parent class loader. continue; GridUuid ldrId = nodeLdrMapCp.get(nodeId); GridNode node = ctx.discovery().node(nodeId); if (node == null) { if (log.isDebugEnabled()) log.debug("Found inactive node in class loader (will skip): " + nodeId); continue; } try { GridDeploymentResponse res = comm.sendResourceRequest(path, ldrId, node, endTime); if (res == null) { String msg = "Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ']'; if (!quiet) U.warn(log, msg); else if (log.isDebugEnabled()) log.debug(msg); err = new GridException(msg); continue; } if (res.success()) return res.byteSource(); // In case of shared resources/classes all nodes should have it. if (log.isDebugEnabled()) log.debug("Failed to find class on remote node [class=" + name + ", nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", reason=" + res.errorMessage() + ']'); synchronized (mux) { if (missedRsrcs != null) missedRsrcs.add(path); } throw new ClassNotFoundException( "Failed to peer load class [class=" + name + ", nodeClsLdrs=" + nodeLdrMapCp + ", parentClsLoader=" + getParent() + ", reason=" + res.errorMessage() + ']'); } catch (GridException e) { // This thread should be interrupted again in communication if it // got interrupted. So we assume that thread can be interrupted // by processing cancellation request. if (Thread.currentThread().isInterrupted()) { if (!quiet) U.error(log, "Failed to find class probably due to task/job cancellation: " + name, e); else if (log.isDebugEnabled()) log.debug("Failed to find class probably due to task/job cancellation [name=" + name + ", err=" + e + ']'); } else { if (!quiet) U.warn(log, "Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ", err=" + e + ']'); else if (log.isDebugEnabled()) log.debug("Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ", err=" + e + ']'); err = e; } } } throw new ClassNotFoundException("Failed to peer load class [class=" + name + ", nodeClsLdrs=" + nodeLdrMapCp + ", parentClsLoader=" + getParent() + ']', err); }
From source file:org.apache.ignite.internal.managers.deployment.GridDeploymentClassLoader.java
/** * Sends class-loading request to all nodes associated with this class loader. * * @param name Class name.// www . java 2 s .c o m * @param path Class path. * @return Class byte source. * @throws ClassNotFoundException If class was not found. */ private GridByteArrayList sendClassRequest(String name, String path) throws ClassNotFoundException { assert !Thread.holdsLock(mux); long endTime = computeEndTime(p2pTimeout); Collection<UUID> nodeListCp; Map<UUID, IgniteUuid> nodeLdrMapCp; synchronized (mux) { // Skip requests for the previously missed classes. if (missedRsrcs != null && missedRsrcs.contains(path)) throw new ClassNotFoundException("Failed to peer load class [class=" + name + ", nodeClsLdrIds=" + nodeLdrMap + ", parentClsLoader=" + getParent() + ']'); // If single-node mode, then node cannot change and we simply reuse list and map. // Otherwise, make copies that can be used outside synchronization. nodeListCp = singleNode ? nodeList : new LinkedList<>(nodeList); nodeLdrMapCp = singleNode ? nodeLdrMap : new HashMap<>(nodeLdrMap); } IgniteCheckedException err = null; for (UUID nodeId : nodeListCp) { if (nodeId.equals(ctx.discovery().localNode().id())) // Skip local node as it is already used as parent class loader. continue; IgniteUuid ldrId = nodeLdrMapCp.get(nodeId); ClusterNode node = ctx.discovery().node(nodeId); if (node == null) { if (log.isDebugEnabled()) log.debug("Found inactive node in class loader (will skip): " + nodeId); continue; } try { GridDeploymentResponse res = comm.sendResourceRequest(path, ldrId, node, endTime); if (res == null) { String msg = "Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ']'; if (!quiet) U.warn(log, msg); else if (log.isDebugEnabled()) log.debug(msg); err = new IgniteCheckedException(msg); continue; } if (res.success()) return res.byteSource(); // In case of shared resources/classes all nodes should have it. if (log.isDebugEnabled()) log.debug("Failed to find class on remote node [class=" + name + ", nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", reason=" + res.errorMessage() + ']'); synchronized (mux) { if (missedRsrcs != null) missedRsrcs.add(path); } throw new ClassNotFoundException( "Failed to peer load class [class=" + name + ", nodeClsLdrs=" + nodeLdrMapCp + ", parentClsLoader=" + getParent() + ", reason=" + res.errorMessage() + ']'); } catch (IgniteCheckedException e) { // This thread should be interrupted again in communication if it // got interrupted. So we assume that thread can be interrupted // by processing cancellation request. if (Thread.currentThread().isInterrupted()) { if (!quiet) U.error(log, "Failed to find class probably due to task/job cancellation: " + name, e); else if (log.isDebugEnabled()) log.debug("Failed to find class probably due to task/job cancellation [name=" + name + ", err=" + e + ']'); } else { if (!quiet) U.warn(log, "Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ", err=" + e + ']'); else if (log.isDebugEnabled()) log.debug("Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ", err=" + e + ']'); err = e; } } } throw new ClassNotFoundException("Failed to peer load class [class=" + name + ", nodeClsLdrs=" + nodeLdrMapCp + ", parentClsLoader=" + getParent() + ']', err); }
From source file:com.stratio.qa.specs.GivenGSpec.java
/** * Swith to the iFrame where id matches idframe * * @param idframe iframe to swith to//from w w w .j ava 2s . c o m * @throws IllegalAccessException exception * @throws NoSuchFieldException exception * @throws ClassNotFoundException exception */ @Given("^I switch to iframe with '([^:]*?):(.+?)'$") public void seleniumIdFrame(String method, String idframe) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException { assertThat(commonspec.locateElement(method, idframe, 1)); if (method.equals("id") || method.equals("name")) { commonspec.getDriver().switchTo().frame(idframe); } else { throw new ClassNotFoundException("Can not use this method to switch iframe"); } }
From source file:com.espertech.esper.epl.core.EngineImportServiceImpl.java
/** * Finds a class by class name using the auto-import information provided. * @param className is the class name to find * @return class//from w w w . j a va 2s .com * @throws ClassNotFoundException if the class cannot be loaded */ protected Class resolveClassInternal(String className, boolean requireAnnotation) throws ClassNotFoundException { // Attempt to retrieve the class with the name as-is try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); return Class.forName(className, true, cl); } catch (ClassNotFoundException e) { if (log.isDebugEnabled()) { log.debug("Class not found for resolving from name as-is '" + className + "'"); } } // Try all the imports for (String importName : imports) { boolean isClassName = isClassName(importName); boolean containsPackage = importName.indexOf('.') != -1; String classNameWithDot = "." + className; String classNameWithDollar = "$" + className; // Import is a class name if (isClassName) { if ((containsPackage && importName.endsWith(classNameWithDot)) || (containsPackage && importName.endsWith(classNameWithDollar)) || (!containsPackage && importName.equals(className)) || (!containsPackage && importName.endsWith(classNameWithDollar))) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); return Class.forName(importName, true, cl); } String prefixedClassName = importName + '$' + className; try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Class clazz = Class.forName(prefixedClassName, true, cl); if (!requireAnnotation || clazz.isAnnotation()) { return clazz; } } catch (ClassNotFoundException e) { if (log.isDebugEnabled()) { log.debug("Class not found for resolving from name '" + prefixedClassName + "'"); } } } else { // Import is a package name String prefixedClassName = getPackageName(importName) + '.' + className; try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Class clazz = Class.forName(prefixedClassName, true, cl); if (!requireAnnotation || clazz.isAnnotation()) { return clazz; } } catch (ClassNotFoundException e) { if (log.isDebugEnabled()) { log.debug("Class not found for resolving from name '" + prefixedClassName + "'"); } } } } // try to resolve from method references for (String name : methodInvocationRef.keySet()) { if (JavaClassHelper.isSimpleNameFullyQualfied(className, name)) { try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Class clazz = Class.forName(name, true, cl); if (!requireAnnotation || clazz.isAnnotation()) { return clazz; } } catch (ClassNotFoundException e1) { if (log.isDebugEnabled()) { log.debug("Class not found for resolving from method invocation ref:" + name); } } } } // No import worked, the class isn't resolved throw new ClassNotFoundException("Unknown class " + className); }
From source file:org.intermine.sql.Database.java
/** * Configures a datasource from a Properties object * * @param props the properties for configuring the Database * @throws ClassNotFoundException if the class given in the properties file cannot be found * @throws IllegalArgumentException if the configuration properties are empty * @throws NullPointerException if props is null *///from w ww .j a v a 2 s.c om protected void configure(Properties props) throws ClassNotFoundException { if (props == null) { throw new NullPointerException("Props cannot be null"); } if (props.size() == 0) { throw new IllegalArgumentException("No configuration details"); } Properties subProps = new Properties(); for (Map.Entry<Object, Object> entry : props.entrySet()) { String propertyName = (String) entry.getKey(); String propertyValue = (String) entry.getValue(); Field field = null; // Get the first part of the string - this is the attribute we are taking about String attribute = propertyName; String subAttribute = ""; int index = propertyName.indexOf("."); if (index != -1) { attribute = propertyName.substring(0, index); subAttribute = propertyName.substring(index + 1); } try { field = Database.class.getDeclaredField(attribute); } catch (Exception e) { LOG.warn("Ignoring field for Database: " + attribute); // Ignore this property - no such field continue; } if ("class".equals(subAttribute)) { // make a new instance of this class for this attribute Class<?> clazz = Class.forName(propertyValue.toString()); Object obj; try { obj = clazz.newInstance(); } catch (Exception e) { throw new ClassNotFoundException( "Cannot instantiate class " + clazz.getName() + " " + e.getMessage()); } // Set the field to this newly instantiated class try { field.set(this, obj); } catch (Exception e) { continue; } } else if ("".equals(subAttribute)) { // Set this attribute directly try { field.set(this, propertyValue); } catch (Exception e) { continue; } } else { // Set parameters on the attribute Method m = null; // Set this configuration parameter on the DataSource; try { // Strings first Object o = field.get(this); // Sometimes the class will not have been instantiated yet if (o == null) { subProps.put(propertyName, propertyValue); continue; } Class<?> clazz = o.getClass(); m = clazz.getMethod("set" + StringUtil.capitalise(subAttribute), new Class[] { String.class }); if (m != null) { m.invoke(field.get(this), new Object[] { propertyValue }); } // now integers } catch (Exception e) { // Don't do anything - either the method not found or cannot be invoked } try { if (m == null) { m = field.get(this).getClass().getMethod("set" + StringUtil.capitalise(subAttribute), new Class[] { int.class }); if (m != null) { m.invoke(field.get(this), new Object[] { Integer.valueOf(propertyValue.toString()) }); } } } catch (Exception e) { // Don't do anything - either the method not found or cannot be invoked } } if (subProps.size() > 0) { configure(subProps); } } }
From source file:org.apache.fop.render.afp.AFPFontConfig.java
private static Typeface getTypeFace(String base14Name) throws ClassNotFoundException { try {/*from ww w . java 2s. co m*/ Class<? extends Typeface> clazz = Class.forName("org.apache.fop.fonts.base14." + base14Name) .asSubclass(Typeface.class); return clazz.newInstance(); } catch (IllegalAccessException iae) { LOG.error(iae.getMessage()); } catch (ClassNotFoundException cnfe) { LOG.error(cnfe.getMessage()); } catch (InstantiationException ie) { LOG.error(ie.getMessage()); } throw new ClassNotFoundException("Couldn't load file for AFP font with base14 name: " + base14Name); }
From source file:org.eclipse.wb.internal.core.model.description.helpers.DescriptionHelper.java
/** * Loads {@link Class} from {@link Bundle}'s that contribute some toolkit. */// ww w . ja v a 2 s. c o m public static Class<?> loadModelClass(String className) throws Exception { for (IConfigurationElement toolkitElement : getToolkitElements()) { Bundle bundle = ExternalFactoriesHelper.getExtensionBundle(toolkitElement); try { return bundle.loadClass(className); } catch (ClassNotFoundException e) { } } throw new ClassNotFoundException(className); }
From source file:org.apache.openaz.xacml.admin.view.components.SQLPIPConfigurationComponent.java
protected void testJDBCConnection() { try {//from w w w. j av a2s . c o m if (this.comboBoxSQLDriver.getValue() != null) { Class.forName(this.comboBoxSQLDriver.getValue().toString()); } else { throw new ClassNotFoundException("Please select a JDBC driver to load."); } } catch (ClassNotFoundException e) { logger.error(e); new Notification("Driver Exception", "<br/>" + e.getLocalizedMessage() + "<br/>Is the JDBC driver's jar in the J2EE container path?", Type.ERROR_MESSAGE, true).show(Page.getCurrent()); return; } Connection connection = null; try { connection = DriverManager.getConnection(this.textFieldConnectionURL.getValue(), this.textFieldUser.getValue(), this.textFieldPassword.getValue()); new Notification("Success!", "Connection Established!", Type.HUMANIZED_MESSAGE, true) .show(Page.getCurrent()); } catch (SQLException e) { logger.error(e); new Notification("SQL Exception", "<br/>" + e.getLocalizedMessage() + "<br/>Are the configuration parameters correct?", Type.ERROR_MESSAGE, true).show(Page.getCurrent()); } finally { if (connection != null) { try { connection.close(); } catch (SQLException idontcare) { //NOPMD } } } }
From source file:org.apache.axis2.context.OperationContext.java
/** * Restore the contents of the object that was previously saved. * <p/>/*from w w w . j a va 2 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 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); isComplete = in.readBoolean(); key = (String) in.readObject(); logCorrelationIDString = (String) in.readObject(); // trace point if (log.isTraceEnabled()) { log.trace(myClassName + ":readExternal(): reading input stream for [" + getLogCorrelationIDString() + "] "); } //--------------------------------------------------------- // properties //--------------------------------------------------------- in.readUTF(); // read marker properties = in.readMap(new HashMap()); //--------------------------------------------------------- // axis operation meta data //--------------------------------------------------------- // axisOperation is not usable until the meta data has been reconciled axisOperation = null; in.readUTF(); // read marker metaAxisOperation = (MetaDataEntry) in.readObject(); //--------------------------------------------------------- // axis service meta data //--------------------------------------------------------- // axisService is not usable until the meta data has been reconciled in.readUTF(); // read marker metaAxisService = (MetaDataEntry) in.readObject(); //--------------------------------------------------------- // parent //--------------------------------------------------------- // ServiceContext is not usable until it has been activated in.readUTF(); // read marker metaParent = (ServiceContext) in.readObject(); //--------------------------------------------------------- // HashMap messageContexts table //--------------------------------------------------------- // set to empty until this can be activiated messageContexts = new HashMap(); in.readUTF(); // read marker workingSet = in.readHashMap(); in.readUTF(); // read marker metaMessageContextMap = in.readHashMap(); //--------------------------------------------------------- // done //--------------------------------------------------------- }
From source file:com.jk.framework.util.FakeRunnable.java
/** * list Classes inside a given package./*from w w w .jav a2 s . c o m*/ * * @author Jon Peck http://jonpeck.com (adapted from * http://www.javaworld.com/javaworld/javatips/jw-javatip113.html) * @param pckgname * String name of a Package, EG "java.lang" * @return Class[] classes inside the root of the given package * @throws ClassNotFoundException * if the Package is invalid */ public static String[] getPAckageContents(final String pckgname) throws ClassNotFoundException { // ArrayList classes = new ArrayList(); // Get a File object for the package File directory = null; try { directory = new File(Thread.currentThread().getContextClassLoader() .getResource('/' + pckgname.replace('.', '/')).getFile()); } catch (final NullPointerException x) { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } if (directory.exists()) { // Get the list of the files contained in the package final String[] files = directory.list(); return files; } return null; // for (int i = 0; i < files.length; i++) { // we are only interested in .class files // if (files.endsWith(".class")) { // // removes the .class extension // classes.add(Class.forName(pckgname + '.' + files.substring(0, // files.length() - 6))); // } // } // } else { // throw new ClassNotFoundException(pckgname + " does not appear to be a // valid package"); // } // Class[] classesA = new Class[classes.size()]; // classes.toArray(classesA); // return classesA; }