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.text.plugin;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.pde.core.plugin.IFragment;
016: import org.eclipse.pde.core.plugin.IMatchRules;
017:
018: public class FragmentNode extends PluginBaseNode implements IFragment {
019: /**
020: * Comment for <code>serialVersionUID</code>
021: */
022: private static final long serialVersionUID = 1L;
023:
024: /* (non-Javadoc)
025: * @see org.eclipse.pde.core.plugin.IFragment#getPluginId()
026: */
027: public String getPluginId() {
028: return getXMLAttributeValue(P_PLUGIN_ID);
029: }
030:
031: /* (non-Javadoc)
032: * @see org.eclipse.pde.core.plugin.IFragment#getPluginVersion()
033: */
034: public String getPluginVersion() {
035: return getXMLAttributeValue(P_PLUGIN_VERSION);
036: }
037:
038: /* (non-Javadoc)
039: * @see org.eclipse.pde.core.plugin.IFragment#getRule()
040: */
041: public int getRule() {
042: String match = getXMLAttributeValue("match"); //$NON-NLS-1$
043: if (match == null || match.trim().length() == 0)
044: return IMatchRules.NONE;
045: if (match.equals("compatible")) //$NON-NLS-1$
046: return IMatchRules.COMPATIBLE;
047: if (match.equals("perfect")) //$NON-NLS-1$
048: return IMatchRules.PERFECT;
049: if (match.equals("equivalent")) //$NON-NLS-1$
050: return IMatchRules.EQUIVALENT;
051: return IMatchRules.GREATER_OR_EQUAL;
052: }
053:
054: /* (non-Javadoc)
055: * @see org.eclipse.pde.core.plugin.IFragment#setPluginId(java.lang.String)
056: */
057: public void setPluginId(String id) throws CoreException {
058: setXMLAttribute(P_PLUGIN_ID, id);
059: }
060:
061: /* (non-Javadoc)
062: * @see org.eclipse.pde.core.plugin.IFragment#setPluginVersion(java.lang.String)
063: */
064: public void setPluginVersion(String version) throws CoreException {
065: setXMLAttribute(P_PLUGIN_VERSION, version);
066: }
067:
068: /* (non-Javadoc)
069: * @see org.eclipse.pde.core.plugin.IFragment#setRule(int)
070: */
071: public void setRule(int rule) throws CoreException {
072: String match = ""; //$NON-NLS-1$
073: switch (rule) {
074: case IMatchRules.COMPATIBLE:
075: match = "compatible"; //$NON-NLS-1$
076: break;
077: case IMatchRules.EQUIVALENT:
078: match = "equivalent"; //$NON-NLS-1$
079: break;
080: case IMatchRules.PERFECT:
081: match = "perfect"; //$NON-NLS-1$
082: break;
083: case IMatchRules.GREATER_OR_EQUAL:
084: match = "greaterOrEqual"; //$NON-NLS-1$
085: }
086: setXMLAttribute(P_RULE, match);
087: }
088:
089: /* (non-Javadoc)
090: * @see org.eclipse.pde.internal.ui.model.plugin.PluginBaseNode#getSpecificAttributes()
091: */
092: protected String[] getSpecificAttributes() {
093: ArrayList result = new ArrayList();
094:
095: String pluginID = getPluginId();
096: if (pluginID != null && pluginID.trim().length() > 0)
097: result.add(" " + P_PLUGIN_ID + "=\"" + pluginID + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
098:
099: String pluginVersion = getPluginVersion();
100: if (pluginVersion != null && pluginVersion.trim().length() > 0)
101: result
102: .add(" " + P_PLUGIN_VERSION + "=\"" + pluginVersion + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
103:
104: String match = getXMLAttributeValue(P_RULE);
105: if (match != null && match.trim().length() > 0)
106: result.add(" " + P_RULE + "=\"" + match + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
107:
108: return (String[]) result.toArray(new String[result.size()]);
109: }
110: }
|