KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > ResourcesCompatibilityHelper


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.resources;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.lang.reflect.Method JavaDoc;
15 import org.eclipse.core.filesystem.EFS;
16 import org.eclipse.core.filesystem.IFileStore;
17 import org.eclipse.core.internal.localstore.HistoryStore2;
18 import org.eclipse.core.internal.localstore.IHistoryStore;
19 import org.eclipse.core.internal.properties.IPropertyManager;
20 import org.eclipse.core.internal.properties.PropertyManager2;
21 import org.eclipse.core.resources.ResourcesPlugin;
22 import org.eclipse.core.runtime.IPath;
23
24 /**
25  * This is mostly a convenience class for accessing the ResourcesCompatibility class from the
26  * compatibility fragment using reflection.
27  *
28  * See the ResourcesCompatibility class in the compatibility fragment.
29  */

30 public class ResourcesCompatibilityHelper {
31     private static final String JavaDoc COMPATIBILITY_CLASS = "org.eclipse.core.internal.resources.ResourcesCompatibility"; //$NON-NLS-1$
32
private static final String JavaDoc CONVERT_HISTORY_STORE = ResourcesPlugin.PI_RESOURCES + ".convertHistory"; //$NON-NLS-1$
33
private static final String JavaDoc CONVERT_PROPERTY_STORE = ResourcesPlugin.PI_RESOURCES + ".convertProperties"; //$NON-NLS-1$
34
private static final String JavaDoc ENABLE_NEW_HISTORY_STORE = ResourcesPlugin.PI_RESOURCES + ".newHistory"; //$NON-NLS-1$
35
private static final String JavaDoc ENABLE_NEW_PROPERTY_STORE = ResourcesPlugin.PI_RESOURCES + ".newProperties"; //$NON-NLS-1$
36

37     /**
38      * Creates a history store. Decides which implementation of history store should be chosen, and whether
39      * conversion from the existing state should be performed by looking at some system properties.
40      */

41     public static IHistoryStore createHistoryStore(IPath location, int limit) {
42         // the default is to use new implementation
43
boolean newImpl = !Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty(ENABLE_NEW_HISTORY_STORE));
44         // the default is to convert existing state to the new implementation
45
boolean convert = !Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty(CONVERT_HISTORY_STORE));
46         try {
47             return createHistoryStore(location, limit, newImpl, convert, true);
48         } catch (ClassNotFoundException JavaDoc e) {
49             // fragment not available
50
} catch (NoSuchMethodException JavaDoc e) {
51             // unlikely
52
if (Workspace.DEBUG)
53                 e.printStackTrace();
54         } catch (IllegalAccessException JavaDoc e) {
55             // unlikely
56
if (Workspace.DEBUG)
57                 e.printStackTrace();
58         } catch (InvocationTargetException JavaDoc e) {
59             // got a runtime exception/error
60
Throwable JavaDoc target = e.getTargetException();
61             if (target instanceof RuntimeException JavaDoc)
62                 throw (RuntimeException JavaDoc) target;
63             throw (Error JavaDoc) target;
64         }
65         // default to new version
66
IFileStore store = EFS.getLocalFileSystem().getStore(location);
67         return new HistoryStore2((Workspace) ResourcesPlugin.getWorkspace(), store, limit);
68     }
69
70     public static IHistoryStore createHistoryStore(IPath location, int limit, boolean newImpl, boolean convert, boolean rename) throws ClassNotFoundException JavaDoc, NoSuchMethodException JavaDoc, IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
71         Class JavaDoc clazz = Class.forName(COMPATIBILITY_CLASS);
72         Method JavaDoc createMethod = clazz.getDeclaredMethod("createHistoryStore", new Class JavaDoc[] {IPath.class, int.class, boolean.class, boolean.class, boolean.class}); //$NON-NLS-1$
73
return (IHistoryStore) createMethod.invoke(null, new Object JavaDoc[] {location, new Integer JavaDoc(limit), Boolean.valueOf(newImpl), Boolean.valueOf(convert), Boolean.valueOf(rename)});
74     }
75
76     public static IPropertyManager createPropertyManager(boolean newImpl, boolean convert) throws ClassNotFoundException JavaDoc, NoSuchMethodException JavaDoc, IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
77         Class JavaDoc clazz = Class.forName(COMPATIBILITY_CLASS);
78         Method JavaDoc createMethod = clazz.getDeclaredMethod("createPropertyManager", new Class JavaDoc[] {boolean.class, boolean.class}); //$NON-NLS-1$
79
return (IPropertyManager) createMethod.invoke(null, new Object JavaDoc[] {Boolean.valueOf(newImpl), Boolean.valueOf(convert)});
80     }
81
82     /**
83      * Creates a property manager. Decides which implementation of property manager should be chosen, and whether
84      * conversion from the existing state should be performed by looking at some system properties.
85      */

86     public static IPropertyManager createPropertyManager() {
87         // the default is to use new implementation
88
boolean newImpl = !Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty(ENABLE_NEW_PROPERTY_STORE));
89         // the default is to convert existing state to the new implementation
90
boolean convert = !Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty(CONVERT_PROPERTY_STORE));
91         try {
92             return createPropertyManager(newImpl, convert);
93         } catch (ClassNotFoundException JavaDoc e) {
94             // fragment not available
95
} catch (NoSuchMethodException JavaDoc e) {
96             // unlikely
97
if (Workspace.DEBUG)
98                 e.printStackTrace();
99         } catch (IllegalAccessException JavaDoc e) {
100             // unlikely
101
if (Workspace.DEBUG)
102                 e.printStackTrace();
103         } catch (InvocationTargetException JavaDoc e) {
104             // got a runtime exception/error
105
Throwable JavaDoc target = e.getTargetException();
106             if (target instanceof RuntimeException JavaDoc)
107                 throw (RuntimeException JavaDoc) target;
108             throw (Error JavaDoc) target;
109         }
110         // default to new version
111
return new PropertyManager2((Workspace) ResourcesPlugin.getWorkspace());
112     }
113 }
114
Popular Tags