001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 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.core.runtime.IExtensionPoint;
016: import org.eclipse.pde.core.plugin.IFragment;
017: import org.eclipse.pde.core.plugin.IPluginBase;
018: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
019: import org.eclipse.pde.core.plugin.IPluginModelBase;
020:
021: public class PluginExtensionPoint extends IdentifiablePluginObject
022: implements IPluginExtensionPoint {
023:
024: private static final long serialVersionUID = 1L;
025:
026: private IExtensionPoint fPoint = null;
027:
028: protected String fSchema;
029:
030: public PluginExtensionPoint() {
031: }
032:
033: public PluginExtensionPoint(IExtensionPoint point) {
034: fPoint = point;
035: }
036:
037: public boolean isValid() {
038: return getId() != null && getName() != null;
039: }
040:
041: public String getFullId() {
042: if (fPoint != null)
043: return fPoint.getUniqueIdentifier();
044: String pointId = getId();
045: IPluginModelBase modelBase = getPluginModel();
046: IPluginBase pluginBase = modelBase.getPluginBase();
047: if ("3.2".equals(pluginBase.getSchemaVersion())) { //$NON-NLS-1$
048: if (pointId.indexOf('.') > 0)
049: return pointId;
050: }
051:
052: if (pluginBase instanceof IFragment)
053: return ((IFragment) pluginBase).getPluginId() + '.'
054: + pointId;
055: return pluginBase.getId() + '.' + pointId;
056: }
057:
058: public String getSchema() {
059: if (fSchema == null && fPoint != null)
060: fSchema = fPoint.getSchemaReference();
061: return fSchema;
062: }
063:
064: public boolean equals(Object obj) {
065: if (obj == this )
066: return true;
067: if (obj instanceof IPluginExtensionPoint) {
068: IPluginExtensionPoint target = (IPluginExtensionPoint) obj;
069: // Objects from the same model must be
070: // binary equal
071: if (target.getModel().equals(getModel()))
072: return false;
073: if (stringEqualWithNull(target.getId(), getId())
074: && stringEqualWithNull(target.getName(), getName())
075: && stringEqualWithNull(target.getSchema(),
076: getSchema()))
077: return true;
078: }
079: return false;
080: }
081:
082: public void setSchema(String newSchema) throws CoreException {
083: ensureModelEditable();
084: String oldValue = fSchema;
085: fSchema = newSchema;
086: firePropertyChanged(P_SCHEMA, oldValue, fSchema);
087: }
088:
089: public void restoreProperty(String name, Object oldValue,
090: Object newValue) throws CoreException {
091: if (name.equals(P_SCHEMA)) {
092: setSchema(newValue != null ? newValue.toString() : null);
093: return;
094: }
095: super .restoreProperty(name, oldValue, newValue);
096: }
097:
098: public void write(String indent, PrintWriter writer) {
099: writer.print(indent);
100: writer.print("<extension-point"); //$NON-NLS-1$
101: if (getId() != null)
102: writer.print(" id=\"" + getWritableString(getId()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
103: if (getName() != null)
104: writer
105: .print(" name=\"" + getWritableString(getName()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
106: if (getSchema() != null)
107: writer.print(" schema=\"" + getSchema() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
108: writer.println("/>"); //$NON-NLS-1$
109: }
110:
111: public String getName() {
112: if (fName == null)
113: fName = fPoint.getLabel();
114: return fName;
115: }
116:
117: public String getId() {
118: if (fID == null) {
119: fID = fPoint.getUniqueIdentifier();
120: if (fID != null) {
121: String pluginId = getPluginBase().getId();
122: if (fID.startsWith(pluginId)) {
123: String sub = fID.substring(pluginId.length());
124: if (sub.lastIndexOf('.') == 0)
125: fID = sub.substring(1);
126: }
127: }
128: }
129: return fID;
130: }
131: }
|