KickJava   Java API By Example, From Geeks To Geeks.

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


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.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.osgi.service.resolver.BundleDescription;
17 import org.eclipse.pde.core.plugin.IPlugin;
18 import org.eclipse.pde.core.plugin.IPluginExtension;
19 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
20 import org.eclipse.pde.internal.core.PDEState;
21 import org.w3c.dom.Node JavaDoc;
22
23 public class Plugin extends PluginBase implements IPlugin {
24     private static final long serialVersionUID = 1L;
25     private String JavaDoc fClassname;
26     private boolean fHasExtensibleAPI;
27
28     public String JavaDoc getClassName() {
29         return fClassname;
30     }
31
32     public IPlugin getPlugin() {
33         return this;
34     }
35
36     void load(BundleDescription bundleDescription, PDEState state) {
37         fClassname = state.getClassName(bundleDescription.getBundleId());
38         fHasExtensibleAPI = state.hasExtensibleAPI(bundleDescription.getBundleId());
39         super.load(bundleDescription, state);
40     }
41     
42     void load(Node JavaDoc node, String JavaDoc schemaVersion) {
43         fClassname = getNodeAttribute(node, "class"); //$NON-NLS-1$
44
super.load(node, schemaVersion);
45     }
46
47     public void reset() {
48         fClassname = null;
49         super.reset();
50     }
51     public void setClassName(String JavaDoc newClassName) throws CoreException {
52         ensureModelEditable();
53         String JavaDoc oldValue = fClassname;
54         fClassname = newClassName;
55         firePropertyChanged(P_CLASS_NAME, oldValue, fClassname);
56     }
57
58     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
59         throws CoreException {
60         if (name.equals(P_CLASS_NAME)) {
61             setClassName(newValue != null ? newValue.toString() : null);
62             return;
63         }
64         super.restoreProperty(name, oldValue, newValue);
65     }
66
67     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
68         writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
69
if (getSchemaVersion()!=null) {
70             writer.println("<?eclipse version=\"" + getSchemaVersion() + "\"?>"); //$NON-NLS-1$ //$NON-NLS-2$
71
}
72         writer.print("<plugin"); //$NON-NLS-1$
73
if (getId() != null) {
74             writer.println();
75             writer.print(" id=\"" + getId() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
76
}
77         if (getName() != null) {
78             writer.println();
79             writer.print(" name=\"" + getWritableString(getName()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
80
}
81         if (getVersion() != null) {
82             writer.println();
83             writer.print(" version=\"" + getVersion() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
84
}
85         if (getProviderName() != null) {
86             writer.println();
87             writer.print(
88                 " provider-name=\"" //$NON-NLS-1$
89
+ getWritableString(getProviderName())
90                     + "\""); //$NON-NLS-1$
91
}
92         if (getClassName() != null) {
93             writer.println();
94             writer.print(" class=\"" + getClassName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
95
}
96         writer.println(">"); //$NON-NLS-1$
97
writer.println();
98
99         String JavaDoc firstIndent = " "; //$NON-NLS-1$
100

101         // add runtime
102
Object JavaDoc[] children = getLibraries();
103         if (children.length > 0) {
104             writeChildren(firstIndent, "runtime", children, writer); //$NON-NLS-1$
105
writer.println();
106         }
107
108         // add requires
109
children = getImports();
110         if (children.length > 0) {
111             writeChildren(firstIndent, "requires", children, writer); //$NON-NLS-1$
112
writer.println();
113         }
114
115         children = getExtensionPoints();
116         for (int i = 0; i < children.length; i++) {
117             ((IPluginExtensionPoint) children[i]).write(firstIndent, writer);
118         }
119         if (children.length > 0)
120             writer.println();
121
122         // add extensions
123
children = getExtensions();
124         for (int i = 0; i < children.length; i++) {
125             ((IPluginExtension) children[i]).write(firstIndent, writer);
126         }
127         if (children.length > 0)
128             writer.println();
129         
130         writer.println("</plugin>"); //$NON-NLS-1$
131
}
132
133     public boolean hasExtensibleAPI() {
134         return fHasExtensibleAPI;
135     }
136 }
137
Popular Tags