KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > schema > ExternalSchemaDescriptor


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

11 package org.eclipse.pde.internal.core.schema;
12
13 import java.io.*;
14 import java.net.*;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.pde.core.plugin.*;
18 import org.eclipse.pde.internal.core.*;
19
20 public class ExternalSchemaDescriptor extends DevelopmentSchemaDescriptor {
21     private IPluginExtensionPoint info;
22     private File file;
23     private String JavaDoc fullId;
24     private boolean enabled;
25
26     public ExternalSchemaDescriptor(IPluginExtensionPoint info) {
27         this.info = info;
28         fullId = info.getFullId();
29     }
30
31     public ExternalSchemaDescriptor(File file, String JavaDoc fullId, boolean enabled) {
32         this.file = file;
33         this.fullId = fullId;
34         this.enabled = enabled;
35     }
36     
37     public String JavaDoc getPointId() {
38         return fullId;
39     }
40
41     private File getInstallLocationFile() {
42         IPluginModelBase model = info.getPluginModel();
43         String JavaDoc installLocation = model.getInstallLocation() + File.separator;
44         return new File(installLocation + info.getSchema());
45     }
46     
47     private File getSourceLocationFile() {
48         SourceLocationManager sourceManager =
49             PDECore.getDefault().getSourceLocationManager();
50         return sourceManager.findSourceFile(
51             info.getPluginBase(),
52             new Path(info.getSchema()));
53     }
54
55     public URL getSchemaURL() {
56         try {
57             if (file!=null) {
58                 return new URL("file:" + file.getPath()); //$NON-NLS-1$
59
}
60             File installFile = getInstallLocationFile();
61             if (installFile != null && installFile.exists()) {
62                 return new URL("file:" + installFile.getPath()); //$NON-NLS-1$
63
}
64             File sourceLocationFile = getSourceLocationFile();
65             if (sourceLocationFile != null && sourceLocationFile.exists()) {
66                 return new URL("file:" + sourceLocationFile.getPath()); //$NON-NLS-1$
67
}
68         } catch (MalformedURLException e) {
69         }
70         return null;
71     }
72
73     public boolean isEnabled() {
74         return (info!=null)?info.getPluginModel().isEnabled():enabled;
75     }
76 }
77
Popular Tags