KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > plugin > PluginImportNode


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.text.plugin;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.pde.core.plugin.IMatchRules;
15 import org.eclipse.pde.core.plugin.IPluginImport;
16
17 public class PluginImportNode extends PluginObjectNode implements IPluginImport {
18
19     private static final long serialVersionUID = 1L;
20
21     public PluginImportNode(String JavaDoc id) {
22         super();
23         String JavaDoc name = "plugin"; //$NON-NLS-1$
24
try {
25             if (id == null)
26                 id = ""; //$NON-NLS-1$
27
PluginAttribute attr = new PluginAttribute();
28             attr.setName(name);
29             attr.setEnclosingElement(this);
30             fAttributes.put(name, attr);
31             attr.setValue(id);
32         } catch (CoreException e) {
33         }
34     }
35
36     public PluginImportNode() {
37         super();
38     }
39
40     /* (non-Javadoc)
41      * @see org.eclipse.pde.core.plugin.IPluginImport#isReexported()
42      */

43     public boolean isReexported() {
44         String JavaDoc value = getXMLAttributeValue(P_REEXPORTED);
45         return value != null && value.equals("true"); //$NON-NLS-1$
46
}
47     /* (non-Javadoc)
48      * @see org.eclipse.pde.core.plugin.IPluginImport#isOptional()
49      */

50     public boolean isOptional() {
51         String JavaDoc value = getXMLAttributeValue(P_OPTIONAL);
52         return value != null && value.equals("true"); //$NON-NLS-1$
53
}
54     /* (non-Javadoc)
55      * @see org.eclipse.pde.core.plugin.IPluginImport#setReexported(boolean)
56      */

57     public void setReexported(boolean value) throws CoreException {
58         setXMLAttribute(P_REEXPORTED, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
59
}
60     /* (non-Javadoc)
61      * @see org.eclipse.pde.core.plugin.IPluginImport#setOptional(boolean)
62      */

63     public void setOptional(boolean value) throws CoreException {
64         setXMLAttribute(P_OPTIONAL, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
65
}
66     /* (non-Javadoc)
67      * @see org.eclipse.pde.core.plugin.IPluginReference#getMatch()
68      */

69     public int getMatch() {
70         String JavaDoc match = getXMLAttributeValue(P_MATCH);
71         if (match == null || match.trim().length() == 0)
72             return IMatchRules.NONE;
73         if (match.equals("compatible")) //$NON-NLS-1$
74
return IMatchRules.COMPATIBLE;
75         if (match.equals("perfect")) //$NON-NLS-1$
76
return IMatchRules.PERFECT;
77         if (match.equals("equivalent")) //$NON-NLS-1$
78
return IMatchRules.EQUIVALENT;
79         return IMatchRules.GREATER_OR_EQUAL;
80     }
81     /* (non-Javadoc)
82      * @see org.eclipse.pde.core.plugin.IPluginReference#getVersion()
83      */

84     public String JavaDoc getVersion() {
85         return getXMLAttributeValue(P_VERSION);
86     }
87     /* (non-Javadoc)
88      * @see org.eclipse.pde.core.plugin.IPluginReference#setMatch(int)
89      */

90     public void setMatch(int match) throws CoreException {
91         switch(match) {
92             case IMatchRules.GREATER_OR_EQUAL:
93                 setXMLAttribute(P_MATCH, "greaterOrEqual"); //$NON-NLS-1$
94
break;
95             case IMatchRules.EQUIVALENT:
96                 setXMLAttribute(P_MATCH, "equivalent"); //$NON-NLS-1$
97
break;
98             case IMatchRules.COMPATIBLE:
99                 setXMLAttribute(P_MATCH, "compatible"); //$NON-NLS-1$
100
break;
101             case IMatchRules.PERFECT:
102                 setXMLAttribute(P_MATCH, "perfect"); //$NON-NLS-1$
103
break;
104             default:
105                 setXMLAttribute(P_MATCH, null);
106         }
107     }
108     /* (non-Javadoc)
109      * @see org.eclipse.pde.core.plugin.IPluginReference#setVersion(java.lang.String)
110      */

111     public void setVersion(String JavaDoc version) throws CoreException {
112         setXMLAttribute(P_VERSION, version);
113     }
114     /* (non-Javadoc)
115      * @see org.eclipse.pde.core.IIdentifiable#getId()
116      */

117     public String JavaDoc getId() {
118         return getXMLAttributeValue("plugin"); //$NON-NLS-1$
119
}
120     /* (non-Javadoc)
121      * @see org.eclipse.pde.core.IIdentifiable#setId(java.lang.String)
122      */

123     public void setId(String JavaDoc id) throws CoreException {
124         setXMLAttribute("plugin", id); //$NON-NLS-1$
125
}
126     
127     /* (non-Javadoc)
128      * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#write()
129      */

130     public String JavaDoc write(boolean indent) {
131         return indent ? getIndent() + writeShallow(true) : writeShallow(true);
132     }
133     
134     /* (non-Javadoc)
135      * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#writeShallow(boolean)
136      */

137     public String JavaDoc writeShallow(boolean terminate) {
138         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("<import"); //$NON-NLS-1$
139
appendAttribute(buffer, "plugin"); //$NON-NLS-1$
140
appendAttribute(buffer, P_VERSION);
141         appendAttribute(buffer, P_MATCH);
142         appendAttribute(buffer, P_REEXPORTED, "false"); //$NON-NLS-1$
143
appendAttribute(buffer, P_OPTIONAL, "false"); //$NON-NLS-1$
144

145         if (terminate)
146             buffer.append("/"); //$NON-NLS-1$
147
buffer.append(">"); //$NON-NLS-1$
148
return buffer.toString();
149     }
150     
151 }
152
Popular Tags