001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.plugin;
011:
012: import java.io.PrintWriter;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.osgi.service.resolver.BundleDescription;
016: import org.eclipse.pde.core.plugin.IPlugin;
017: import org.eclipse.pde.core.plugin.IPluginExtension;
018: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
019: import org.eclipse.pde.internal.core.PDEState;
020: import org.w3c.dom.Node;
021:
022: public class Plugin extends PluginBase implements IPlugin {
023: private static final long serialVersionUID = 1L;
024: private String fClassname;
025: private boolean fHasExtensibleAPI;
026:
027: public Plugin(boolean readOnly) {
028: super (readOnly);
029: }
030:
031: public String getClassName() {
032: return fClassname;
033: }
034:
035: public IPlugin getPlugin() {
036: return this ;
037: }
038:
039: void load(BundleDescription bundleDescription, PDEState state) {
040: fClassname = state
041: .getClassName(bundleDescription.getBundleId());
042: fHasExtensibleAPI = state.hasExtensibleAPI(bundleDescription
043: .getBundleId());
044: super .load(bundleDescription, state);
045: }
046:
047: void load(Node node, String schemaVersion) {
048: fClassname = getNodeAttribute(node, "class"); //$NON-NLS-1$
049: super .load(node, schemaVersion);
050: }
051:
052: public void reset() {
053: fClassname = null;
054: super .reset();
055: }
056:
057: public void setClassName(String newClassName) throws CoreException {
058: ensureModelEditable();
059: String oldValue = fClassname;
060: fClassname = newClassName;
061: firePropertyChanged(P_CLASS_NAME, oldValue, fClassname);
062: }
063:
064: public void restoreProperty(String name, Object oldValue,
065: Object newValue) throws CoreException {
066: if (name.equals(P_CLASS_NAME)) {
067: setClassName(newValue != null ? newValue.toString() : null);
068: return;
069: }
070: super .restoreProperty(name, oldValue, newValue);
071: }
072:
073: public void write(String indent, PrintWriter writer) {
074: writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
075: if (getSchemaVersion() != null) {
076: writer
077: .println("<?eclipse version=\"" + getSchemaVersion() + "\"?>"); //$NON-NLS-1$ //$NON-NLS-2$
078: }
079: writer.print("<plugin"); //$NON-NLS-1$
080: if (getId() != null) {
081: writer.println();
082: writer.print(" id=\"" + getId() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
083: }
084: if (getName() != null) {
085: writer.println();
086: writer
087: .print(" name=\"" + getWritableString(getName()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
088: }
089: if (getVersion() != null) {
090: writer.println();
091: writer.print(" version=\"" + getVersion() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
092: }
093: if (getProviderName() != null) {
094: writer.println();
095: writer.print(" provider-name=\"" //$NON-NLS-1$
096: + getWritableString(getProviderName()) + "\""); //$NON-NLS-1$
097: }
098: if (getClassName() != null) {
099: writer.println();
100: writer.print(" class=\"" + getClassName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
101: }
102: writer.println(">"); //$NON-NLS-1$
103: writer.println();
104:
105: String firstIndent = " "; //$NON-NLS-1$
106:
107: // add runtime
108: Object[] children = getLibraries();
109: if (children.length > 0) {
110: writeChildren(firstIndent, "runtime", children, writer); //$NON-NLS-1$
111: writer.println();
112: }
113:
114: // add requires
115: children = getImports();
116: if (children.length > 0) {
117: writeChildren(firstIndent, "requires", children, writer); //$NON-NLS-1$
118: writer.println();
119: }
120:
121: children = getExtensionPoints();
122: for (int i = 0; i < children.length; i++) {
123: ((IPluginExtensionPoint) children[i]).write(firstIndent,
124: writer);
125: }
126: if (children.length > 0)
127: writer.println();
128:
129: // add extensions
130: children = getExtensions();
131: for (int i = 0; i < children.length; i++) {
132: ((IPluginExtension) children[i]).write(firstIndent, writer);
133: }
134: if (children.length > 0)
135: writer.println();
136:
137: writer.println("</plugin>"); //$NON-NLS-1$
138: }
139:
140: public boolean hasExtensibleAPI() {
141: return fHasExtensibleAPI;
142: }
143: }
|