KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > filesystem > Activator


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.filesystem;
12
13 import java.io.File JavaDoc;
14 import org.eclipse.core.runtime.*;
15 import org.eclipse.osgi.service.datalocation.Location;
16 import org.osgi.framework.*;
17
18 /**
19  * This class abstracts away implementation details of the filesystem
20  * bundle that depend on the OSGi framework being started. All
21  * file system bundle functionality is enabled regardless of whether
22  * OSGi is running.
23  * @since org.eclipse.core.filesystem 1.1
24  */

25 public class Activator implements BundleActivator {
26     private static Activator instance;
27     private BundleContext context;
28
29     /**
30      * Returns the local file system location that should be used for
31      * caching file data.
32      */

33     public static IPath getCacheLocation() {
34         //try to put the cache in the instance location if possible (3.2 behaviour)
35
try {
36             if (instance != null) {
37                 BundleContext ctx = instance.context;
38                 if (ctx != null) {
39                     ServiceReference[] refs = ctx.getServiceReferences(Location.class.getName(), Location.INSTANCE_FILTER);
40                     if (refs != null && refs.length == 1) {
41                         Location location = (Location) ctx.getService(refs[0]);
42                         if (location != null) {
43                             IPath instancePath = new Path(new File JavaDoc(location.getURL().getFile()).toString());
44                             ctx.ungetService(refs[0]);
45                             return instancePath.append(".metadata/.plugins").append(Policy.PI_FILE_SYSTEM); //$NON-NLS-1$
46
}
47                     }
48                 }
49             }
50         } catch (InvalidSyntaxException e) {
51             Policy.log(IStatus.INFO, null, e);
52             //fall through below and use user home
53
}
54         //just put the cache in the user home directory
55
return Path.fromOSString(System.getProperty("user.home")); //$NON-NLS-1$
56
// Platform.getStateLocation(Platform.getBundle(Policy.PI_FILE_SYSTEM));
57
}
58
59     public Activator() {
60         instance = this;
61     }
62
63     public void start(BundleContext aContext) throws Exception JavaDoc {
64         this.context = aContext;
65     }
66
67     public void stop(BundleContext aContext) throws Exception JavaDoc {
68         //nothing to do
69
}
70
71 }
72
Popular Tags