*/
public static LayoutLibrary load(String layoutLibJarOsPath, ILogger log, String toolName) {
LoadStatus status = LoadStatus.LOADING;
String message = null;
Bridge bridge = null;
ILayoutBridge legacyBridge = null;
ClassLoader classLoader = null;
try {
// get the URL for the file.
File f = new File(layoutLibJarOsPath);
if (f.isFile() == false) {
if (log != null) {
log.error(null, "layoutlib.jar is missing!"); //$NON-NLS-1$
}
} else {
URL[] urls;
// TODO: The icu jar has to be in the same location as layoutlib.jar. Get rid of
// this dependency.
File icu4j = new File(f.getParent(), FN_ICU_JAR);
if (icu4j.isFile()) {
urls = new URL[2];
urls[1] = icu4j.toURI().toURL();
} else {
urls = new URL[1];
}
urls[0] = f.toURI().toURL();
// create a class loader. Because this jar reference interfaces
// that are in the editors plugin, it's important to provide
// a parent class loader.
classLoader = new URLClassLoader(urls,
LayoutLibrary.class.getClassLoader());
// load the class
Class<?> clazz = classLoader.loadClass(CLASS_BRIDGE);
if (clazz != null) {
// instantiate an object of the class.
Constructor<?> constructor = clazz.getConstructor();
if (constructor != null) {
Object bridgeObject = constructor.newInstance();
if (bridgeObject instanceof Bridge) {
bridge = (Bridge)bridgeObject;
} else if (bridgeObject instanceof ILayoutBridge) {
legacyBridge = (ILayoutBridge) bridgeObject;
}
}
}
if (bridge == null && legacyBridge == null) {
status = LoadStatus.FAILED;
message = "Failed to load " + CLASS_BRIDGE; //$NON-NLS-1$
if (log != null) {
log.error(null,
"Failed to load " + //$NON-NLS-1$
CLASS_BRIDGE +
" from " + //$NON-NLS-1$
layoutLibJarOsPath);
}
} else {
// mark the lib as loaded, unless it's overridden below.
status = LoadStatus.LOADED;
// check the API, only if it's not a legacy bridge
if (bridge != null) {
int api = bridge.getApiLevel();
if (api > Bridge.API_CURRENT) {
status = LoadStatus.FAILED;
message = String.format(
"This version of the rendering library is more recent than your version of %1$s. Please update %1$s", toolName);
}