]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.fastlz/src/org/simantics/fastlz/bundle/Activator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.fastlz / src / org / simantics / fastlz / bundle / Activator.java
diff --git a/bundles/org.simantics.fastlz/src/org/simantics/fastlz/bundle/Activator.java b/bundles/org.simantics.fastlz/src/org/simantics/fastlz/bundle/Activator.java
new file mode 100644 (file)
index 0000000..0feca01
--- /dev/null
@@ -0,0 +1,58 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.fastlz.bundle;\r
+\r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.net.URL;\r
+import java.net.URLDecoder;\r
+\r
+import org.eclipse.core.runtime.FileLocator;\r
+import org.eclipse.core.runtime.IPath;\r
+import org.eclipse.core.runtime.Path;\r
+import org.osgi.framework.BundleActivator;\r
+import org.osgi.framework.BundleContext;\r
+import org.simantics.fastlz.FastLZ;\r
+import org.simantics.fastlz.impl.FastLZConfig;\r
+import org.simantics.fastlz.impl.OS;\r
+\r
+/**\r
+ * An OSGi bundle activator for that guarantees the FastLZ library is\r
+ * initialized after this bundle is properly activated.\r
+ */\r
+public class Activator implements BundleActivator {\r
+\r
+    @Override\r
+    public void start(BundleContext context) throws Exception {\r
+        // Make sure that the FastLZ native library gets initialized properly.\r
+        FastLZConfig.attemptStaticInitialization = false;\r
+        IPath path = new Path("/" + OS.resolveLibName());\r
+        URL libURL = FileLocator.find(context.getBundle(), path, null);\r
+        if (libURL == null) {\r
+            // Fallback for the where org.simantics.fastlz is checked out in the\r
+            // development environment.\r
+            path = new Path("/bin/" + OS.resolveLibName());\r
+            libURL = FileLocator.find(context.getBundle(), path, null);\r
+            if (libURL == null)\r
+                throw new FileNotFoundException(path + " not found in bundle " + context.getBundle().getSymbolicName());\r
+        }\r
+        URL fileURL = FileLocator.toFileURL(libURL);\r
+        File filePath = new File(URLDecoder.decode(fileURL.getPath(), "UTF-8"));\r
+        FastLZ.initialize(filePath);\r
+        \r
+    }\r
+\r
+    @Override\r
+    public void stop(BundleContext context) throws Exception {\r
+    }\r
+\r
+}\r