com.sun.xml.bind.util.Which Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservices-rt Show documentation
Show all versions of webservices-rt Show documentation
This module contains the Metro runtime code.
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.bind.util;
import java.net.URL;
/**
* Finds out where a class file is loaded from.
*
* @author
* Kohsuke Kawaguchi ([email protected])
*/
public class Which {
public static String which( Class clazz ) {
return which( clazz.getName(), SecureLoader.getClassClassLoader(clazz));
}
/**
* Search the specified classloader for the given classname.
* Then give the return value.
* @param classname the fully qualified name of the class to search for
* @param loader the classloader to search
* @return the source location of the resource, or null if it wasn't found
*/
public static String which(String classname, ClassLoader loader) {
String classnameAsResource = classname.replace('.', '/') + ".class";
if(loader == null) {
loader = SecureLoader.getSystemClassLoader();
}
URL it = loader.getResource(classnameAsResource);
if (it != null) {
return it.toString();
} else {
return null;
}
}
}