KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > plugin > ExternalPluginModelBase


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.pde.internal.core.plugin;
12
13 import java.io.File JavaDoc;
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.osgi.service.resolver.BundleDescription;
20 import org.eclipse.pde.core.build.IBuildModel;
21 import org.eclipse.pde.internal.core.NLResourceHelper;
22 import org.eclipse.pde.internal.core.PDEManager;
23 import org.eclipse.pde.internal.core.PDEState;
24
25 public abstract class ExternalPluginModelBase extends AbstractPluginModelBase {
26
27     private String JavaDoc fInstallLocation;
28     
29     private String JavaDoc fLocalization;
30
31     public ExternalPluginModelBase() {
32         super();
33     }
34     
35     protected NLResourceHelper createNLResourceHelper() {
36         return (fLocalization == null)
37                 ? null : new NLResourceHelper(fLocalization, PDEManager.getNLLookupLocations(this)); //$NON-NLS-1$
38
}
39     
40     public URL JavaDoc getNLLookupLocation() {
41         try {
42             if (fInstallLocation != null && new File JavaDoc(fInstallLocation).isDirectory() && !fInstallLocation.endsWith("/")) //$NON-NLS-1$
43
return new URL JavaDoc("file:" + fInstallLocation + "/"); //$NON-NLS-1$ //$NON-NLS-2$
44
return new URL JavaDoc("file:" + fInstallLocation); //$NON-NLS-1$
45
} catch (MalformedURLException JavaDoc e) {
46             return null;
47         }
48     }
49
50     public IBuildModel getBuildModel() {
51         return null;
52     }
53     
54     public String JavaDoc getInstallLocation() {
55         return fInstallLocation;
56     }
57     
58     public boolean isEditable() {
59         return false;
60     }
61     
62     public void load() {
63     }
64     
65     public void load(BundleDescription description, PDEState state) {
66         IPath path = new Path(description.getLocation());
67         String JavaDoc device = path.getDevice();
68         if (device != null)
69             path = path.setDevice(device.toUpperCase());
70         setInstallLocation(path.toOSString());
71         fLocalization = state.getBundleLocalization(description.getBundleId());
72         super.load(description, state);
73     }
74         
75     public boolean isInSync() {
76         return isInSync(getLocalFile());
77     }
78
79     private File JavaDoc getLocalFile() {
80         File JavaDoc file = new File JavaDoc(getInstallLocation());
81         if (file.isFile())
82             return file;
83
84         file = new File JavaDoc(file, "META-INF/MANIFEST.MF"); //$NON-NLS-1$
85
if (!file.exists()) {
86             String JavaDoc manifest = isFragmentModel() ? "fragment.xml" : "plugin.xml"; //$NON-NLS-1$ //$NON-NLS-2$
87
file = new File JavaDoc(getInstallLocation(), manifest);
88         }
89         return file;
90     }
91
92     protected void updateTimeStamp() {
93         updateTimeStamp(getLocalFile());
94     }
95
96     public void setInstallLocation(String JavaDoc newInstallLocation) {
97         fInstallLocation = newInstallLocation;
98     }
99     
100     public String JavaDoc getLocalization() {
101         return fLocalization;
102     }
103 }
104
Popular Tags