1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.fastlz.bundle;
\r
14 import java.io.File;
\r
15 import java.io.FileNotFoundException;
\r
16 import java.net.URL;
\r
17 import java.net.URLDecoder;
\r
19 import org.eclipse.core.runtime.FileLocator;
\r
20 import org.eclipse.core.runtime.IPath;
\r
21 import org.eclipse.core.runtime.Path;
\r
22 import org.osgi.framework.BundleActivator;
\r
23 import org.osgi.framework.BundleContext;
\r
24 import org.simantics.fastlz.FastLZ;
\r
25 import org.simantics.fastlz.impl.FastLZConfig;
\r
26 import org.simantics.fastlz.impl.OS;
\r
29 * An OSGi bundle activator for that guarantees the FastLZ library is
\r
30 * initialized after this bundle is properly activated.
\r
32 public class Activator implements BundleActivator {
\r
35 public void start(BundleContext context) throws Exception {
\r
36 // Make sure that the FastLZ native library gets initialized properly.
\r
37 FastLZConfig.attemptStaticInitialization = false;
\r
38 IPath path = new Path("/" + OS.resolveLibName());
\r
39 URL libURL = FileLocator.find(context.getBundle(), path, null);
\r
40 if (libURL == null) {
\r
41 // Fallback for the where org.simantics.fastlz is checked out in the
\r
42 // development environment.
\r
43 path = new Path("/bin/" + OS.resolveLibName());
\r
44 libURL = FileLocator.find(context.getBundle(), path, null);
\r
46 throw new FileNotFoundException(path + " not found in bundle " + context.getBundle().getSymbolicName());
\r
48 URL fileURL = FileLocator.toFileURL(libURL);
\r
49 File filePath = new File(URLDecoder.decode(fileURL.getPath(), "UTF-8"));
\r
50 FastLZ.initialize(filePath);
\r
55 public void stop(BundleContext context) throws Exception {
\r