KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > plugin > PluginModelBase


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.text.plugin;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.pde.core.IModel;
19 import org.eclipse.pde.core.build.IBuildModel;
20 import org.eclipse.pde.core.plugin.IExtensions;
21 import org.eclipse.pde.core.plugin.IExtensionsModelFactory;
22 import org.eclipse.pde.core.plugin.IPluginBase;
23 import org.eclipse.pde.core.plugin.IPluginModelBase;
24 import org.eclipse.pde.core.plugin.IPluginModelFactory;
25 import org.eclipse.pde.internal.core.NLResourceHelper;
26 import org.eclipse.pde.internal.core.PDEManager;
27 import org.eclipse.pde.internal.core.text.IDocumentNode;
28 import org.eclipse.pde.internal.core.text.XMLEditingModel;
29 import org.xml.sax.helpers.DefaultHandler JavaDoc;
30
31 public abstract class PluginModelBase extends XMLEditingModel implements IPluginModelBase {
32
33     private PluginBaseNode fPluginBase;
34     private boolean fIsEnabled;
35     private PluginDocumentHandler fHandler;
36     private IPluginModelFactory fFactory;
37     private String JavaDoc fLocalization;
38     
39     public PluginModelBase(IDocument document, boolean isReconciling) {
40         super(document, isReconciling);
41         fFactory = new PluginDocumentNodeFactory(this);
42     }
43     /* (non-Javadoc)
44      * @see org.eclipse.pde.core.plugin.IPluginModelBase#createPluginBase()
45      */

46     public IPluginBase createPluginBase(boolean isFragment) {
47         if (isFragment) {
48             fPluginBase = new FragmentNode();
49             fPluginBase.setXMLTagName("fragment"); //$NON-NLS-1$
50
} else {
51             fPluginBase = new PluginNode();
52             fPluginBase.setXMLTagName("plugin"); //$NON-NLS-1$
53
}
54         fPluginBase.setInTheModel(true);
55         fPluginBase.setModel(this);
56         return fPluginBase;
57     }
58     
59     public IPluginBase createPluginBase() {
60         return createPluginBase(isFragmentModel());
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getBuildModel()
65      */

66     public IBuildModel getBuildModel() {
67         return null;
68     }
69
70     /* (non-Javadoc)
71      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getPluginBase()
72      */

73     public IPluginBase getPluginBase() {
74         return getPluginBase(true);
75     }
76     
77     public IExtensions getExtensions() {
78         return getPluginBase();
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getPluginBase(boolean)
83      */

84     public IPluginBase getPluginBase(boolean createIfMissing) {
85         if (!fLoaded && createIfMissing) {
86             createPluginBase();
87             try {
88                 load();
89             } catch (CoreException e) {
90             }
91         }
92         return fPluginBase;
93     }
94     
95     public IExtensions getExtensions(boolean createIfMissing) {
96         return getPluginBase(createIfMissing);
97     }
98
99     /* (non-Javadoc)
100      * @see org.eclipse.pde.core.plugin.IPluginModelBase#isEnabled()
101      */

102     public boolean isEnabled() {
103         return fIsEnabled;
104     }
105
106     /* (non-Javadoc)
107      * @see org.eclipse.pde.core.plugin.IPluginModelBase#setEnabled(boolean)
108      */

109     public void setEnabled(boolean enabled) {
110         fIsEnabled = enabled;
111     }
112     
113     /* (non-Javadoc)
114      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getPluginFactory()
115      */

116     public IPluginModelFactory getPluginFactory() {
117         return fFactory;
118     }
119
120     /* (non-Javadoc)
121      * @see org.eclipse.pde.core.plugin.IPluginModelBase#getNLLookupLocation()
122      */

123     public URL JavaDoc getNLLookupLocation() {
124         try {
125             String JavaDoc installLocation = getInstallLocation();
126             return installLocation == null ? null : new URL JavaDoc("file:" + installLocation); //$NON-NLS-1$
127
} catch (MalformedURLException JavaDoc e) {
128         }
129         return null;
130     }
131
132     /* (non-Javadoc)
133      * @see org.eclipse.pde.core.plugin.ISharedPluginModel#getFactory()
134      */

135     public IExtensionsModelFactory getFactory() {
136         return fFactory;
137     }
138
139     /* (non-Javadoc)
140      * @see org.eclipse.pde.internal.ui.model.AbstractEditingModel#createNLResourceHelper()
141      */

142     protected NLResourceHelper createNLResourceHelper() {
143         URL JavaDoc[] locations = PDEManager.getNLLookupLocations(this);
144         return (locations.length == 0)
145                 ? null
146                 : new NLResourceHelper(fLocalization == null ? "plugin" : fLocalization, //$NON-NLS-1$
147
locations);
148     }
149     
150     /* (non-Javadoc)
151      * @see org.eclipse.pde.internal.ui.model.XMLEditingModel#createDocumentHandler(org.eclipse.pde.core.IModel)
152      */

153     protected DefaultHandler JavaDoc createDocumentHandler(IModel model, boolean reconciling) {
154         if (fHandler == null)
155             fHandler = new PluginDocumentHandler(this, reconciling);
156         return fHandler;
157     }
158         
159     public IDocumentNode getLastErrorNode() {
160         if (fHandler != null)
161             return fHandler.getLastErrorNode();
162         return null;
163     }
164     
165     public void setLocalization(String JavaDoc localization) {
166         fLocalization = localization;
167     }
168 }
169
Popular Tags