001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.classloader;
020
021import java.util.EventObject;
022
023/**
024 * Event emitted by an {@link AbstractJPPFClassLoader} when a class is loaded or not found for the first time.
025 * @author Laurent Cohen
026 */
027public class ClassLoaderEvent extends EventObject
028{
029  /**
030   * The class that was successfully loaded.
031   */
032  private final Class<?> loadedClass;
033  /**
034   * The name of a class that could not be found by this class loader.
035   */
036  private final String className;
037  /**
038   * Determines whether the class was loaded from the class loader's URL classpath.
039   */
040  private final boolean foundInURLClassPath;
041
042  /**
043   * Initialize this event with the specified source and Class object.n
044   * @param classLoader the source of this event.
045   * @param loadedClass the class that was successfully loaded.
046   * @param foundInURLClassPath <code>true</code> if the class was loaded from the class loader's URL classpath,
047   * <code>false</code> if it was loaded from a remote JPPF driver or client.
048   */
049  public ClassLoaderEvent(final AbstractJPPFClassLoader classLoader, final Class<?> loadedClass, final boolean foundInURLClassPath)
050  {
051    super(classLoader);
052    this.loadedClass = loadedClass;
053    this.className = loadedClass.getName();
054    this.foundInURLClassPath = foundInURLClassPath;
055  }
056
057  /**
058   * Initialize this event with the specified source and Class object.n
059   * @param classLoader the source of this event.
060   * @param className the name of a class that could not be found by this class loader.
061   */
062  public ClassLoaderEvent(final AbstractJPPFClassLoader classLoader, final String className)
063  {
064    super(classLoader);
065    this.loadedClass = null;
066    this.className = className;
067    this.foundInURLClassPath = false;
068  }
069
070  /**
071   * Get the class that was successfully loaded.
072   * @return  a <code>Class</code> object, or null if the class was not found.
073   */
074  public Class<?> getLoadedClass()
075  {
076    return loadedClass;
077  }
078
079  /**
080   * Get the name of a class that was loaded or could not be found by this class loader.
081   * @return the class name as a string.
082   */
083  public String getClassName()
084  {
085    return className;
086  }
087
088  /**
089   * Determine whether the class was loaded from the class loader's URL classpath.
090   * @return <code>true</code> if the class was loaded from the class loader's URL classpath,
091   * <code>false</code> if it was loaded from a remote JPPF driver or client.
092   */
093  public boolean isFoundInURLClassPath()
094  {
095    return foundInURLClassPath;
096  }
097
098  /**
099   * Get the class laoder which emitted this event.
100   * @return a {@link AbstractJPPFClassLoader} instance.
101   */
102  public AbstractJPPFClassLoader getClassLoader()
103  {
104    return (AbstractJPPFClassLoader) getSource();
105  }
106}