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.text.plugin;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.pde.core.plugin.IMatchRules;
014: import org.eclipse.pde.core.plugin.IPluginImport;
015:
016: public class PluginImportNode extends PluginObjectNode implements
017: IPluginImport {
018:
019: private static final long serialVersionUID = 1L;
020:
021: public PluginImportNode(String id) {
022: super ();
023: String name = "plugin"; //$NON-NLS-1$
024: try {
025: if (id == null)
026: id = ""; //$NON-NLS-1$
027: PluginAttribute attr = new PluginAttribute();
028: attr.setName(name);
029: attr.setEnclosingElement(this );
030: getNodeAttributesMap().put(name, attr);
031: attr.setValue(id);
032: } catch (CoreException e) {
033: }
034: }
035:
036: public PluginImportNode() {
037: super ();
038: }
039:
040: /* (non-Javadoc)
041: * @see org.eclipse.pde.core.plugin.IPluginImport#isReexported()
042: */
043: public boolean isReexported() {
044: String value = getXMLAttributeValue(P_REEXPORTED);
045: return value != null && value.equals("true"); //$NON-NLS-1$
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.pde.core.plugin.IPluginImport#isOptional()
050: */
051: public boolean isOptional() {
052: String value = getXMLAttributeValue(P_OPTIONAL);
053: return value != null && value.equals("true"); //$NON-NLS-1$
054: }
055:
056: /* (non-Javadoc)
057: * @see org.eclipse.pde.core.plugin.IPluginImport#setReexported(boolean)
058: */
059: public void setReexported(boolean value) throws CoreException {
060: setXMLAttribute(P_REEXPORTED, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
061: }
062:
063: /* (non-Javadoc)
064: * @see org.eclipse.pde.core.plugin.IPluginImport#setOptional(boolean)
065: */
066: public void setOptional(boolean value) throws CoreException {
067: setXMLAttribute(P_OPTIONAL, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
068: }
069:
070: /* (non-Javadoc)
071: * @see org.eclipse.pde.core.plugin.IPluginReference#getMatch()
072: */
073: public int getMatch() {
074: String match = getXMLAttributeValue(P_MATCH);
075: if (match == null || match.trim().length() == 0)
076: return IMatchRules.NONE;
077: if (match.equals("compatible")) //$NON-NLS-1$
078: return IMatchRules.COMPATIBLE;
079: if (match.equals("perfect")) //$NON-NLS-1$
080: return IMatchRules.PERFECT;
081: if (match.equals("equivalent")) //$NON-NLS-1$
082: return IMatchRules.EQUIVALENT;
083: return IMatchRules.GREATER_OR_EQUAL;
084: }
085:
086: /* (non-Javadoc)
087: * @see org.eclipse.pde.core.plugin.IPluginReference#getVersion()
088: */
089: public String getVersion() {
090: return getXMLAttributeValue(P_VERSION);
091: }
092:
093: /* (non-Javadoc)
094: * @see org.eclipse.pde.core.plugin.IPluginReference#setMatch(int)
095: */
096: public void setMatch(int match) throws CoreException {
097: switch (match) {
098: case IMatchRules.GREATER_OR_EQUAL:
099: setXMLAttribute(P_MATCH, "greaterOrEqual"); //$NON-NLS-1$
100: break;
101: case IMatchRules.EQUIVALENT:
102: setXMLAttribute(P_MATCH, "equivalent"); //$NON-NLS-1$
103: break;
104: case IMatchRules.COMPATIBLE:
105: setXMLAttribute(P_MATCH, "compatible"); //$NON-NLS-1$
106: break;
107: case IMatchRules.PERFECT:
108: setXMLAttribute(P_MATCH, "perfect"); //$NON-NLS-1$
109: break;
110: default:
111: setXMLAttribute(P_MATCH, null);
112: }
113: }
114:
115: /* (non-Javadoc)
116: * @see org.eclipse.pde.core.plugin.IPluginReference#setVersion(java.lang.String)
117: */
118: public void setVersion(String version) throws CoreException {
119: setXMLAttribute(P_VERSION, version);
120: }
121:
122: /* (non-Javadoc)
123: * @see org.eclipse.pde.core.IIdentifiable#getId()
124: */
125: public String getId() {
126: return getXMLAttributeValue("plugin"); //$NON-NLS-1$
127: }
128:
129: /* (non-Javadoc)
130: * @see org.eclipse.pde.core.IIdentifiable#setId(java.lang.String)
131: */
132: public void setId(String id) throws CoreException {
133: setXMLAttribute("plugin", id); //$NON-NLS-1$
134: }
135:
136: /* (non-Javadoc)
137: * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#write()
138: */
139: public String write(boolean indent) {
140: return indent ? getIndent() + writeShallow(true)
141: : writeShallow(true);
142: }
143:
144: /* (non-Javadoc)
145: * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#writeShallow(boolean)
146: */
147: public String writeShallow(boolean terminate) {
148: StringBuffer buffer = new StringBuffer("<import"); //$NON-NLS-1$
149: appendAttribute(buffer, "plugin"); //$NON-NLS-1$
150: appendAttribute(buffer, P_VERSION);
151: appendAttribute(buffer, P_MATCH);
152: appendAttribute(buffer, P_REEXPORTED, "false"); //$NON-NLS-1$
153: appendAttribute(buffer, P_OPTIONAL, "false"); //$NON-NLS-1$
154:
155: if (terminate)
156: buffer.append("/"); //$NON-NLS-1$
157: buffer.append(">"); //$NON-NLS-1$
158: return buffer.toString();
159: }
160:
161: }
|