KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.core.IModelChangedEvent;
17 import org.eclipse.pde.core.plugin.IPluginLibrary;
18 import org.eclipse.pde.internal.core.text.IDocumentAttribute;
19 import org.eclipse.pde.internal.core.text.IDocumentNode;
20
21 public class PluginLibraryNode extends PluginObjectNode implements IPluginLibrary {
22
23     private static final long serialVersionUID = 1L;
24
25     /* (non-Javadoc)
26      * @see org.eclipse.pde.core.plugin.IPluginLibrary#getContentFilters()
27      */

28     public String JavaDoc[] getContentFilters() {
29         IDocumentNode[] children = getChildNodes();
30         ArrayList JavaDoc result = new ArrayList JavaDoc();
31         for (int i = 0; i < children.length; i++) {
32             PluginObjectNode node = (PluginObjectNode)children[i];
33             if (node.getName().equals(P_EXPORTED)) {
34                 String JavaDoc name = children[i].getXMLAttributeValue(P_NAME);
35                 if (name != null && !name.equals("*")) { //$NON-NLS-1$
36
int index = name.indexOf(".*"); //$NON-NLS-1$
37
if (index != -1)
38                         name = name.substring(0, index);
39                     result.add(name);
40                 }
41             }
42         }
43         return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
44     }
45     /* (non-Javadoc)
46      * @see org.eclipse.pde.core.plugin.IPluginLibrary#getPackages()
47      */

48     public String JavaDoc[] getPackages() {
49         return new String JavaDoc[0];
50     }
51     /* (non-Javadoc)
52      * @see org.eclipse.pde.core.plugin.IPluginLibrary#isExported()
53      */

54     public boolean isExported() {
55         IDocumentNode[] children = getChildNodes();
56         for (int i = 0; i < children.length; i++) {
57             PluginObjectNode node = (PluginObjectNode)children[i];
58             if (node.getName().equals(P_EXPORTED))
59                 return true;
60         }
61         return false;
62     }
63     /* (non-Javadoc)
64      * @see org.eclipse.pde.core.plugin.IPluginLibrary#isFullyExported()
65      */

66     public boolean isFullyExported() {
67         IDocumentNode[] children = getChildNodes();
68         for (int i = 0; i < children.length; i++) {
69             PluginObjectNode node = (PluginObjectNode)children[i];
70             if (node.getName().equals(P_EXPORTED)) {
71                 String JavaDoc name = children[i].getXMLAttributeValue(P_NAME);
72                 if (name != null && name.equals("*")) //$NON-NLS-1$
73
return true;
74             }
75         }
76         return false;
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.pde.core.plugin.IPluginLibrary#getType()
81      */

82     public String JavaDoc getType() {
83         String JavaDoc type = getXMLAttributeValue(P_TYPE);
84         return (type != null && type.equals("resource")) ? IPluginLibrary.RESOURCE : IPluginLibrary.CODE; //$NON-NLS-1$
85
}
86     /* (non-Javadoc)
87      * @see org.eclipse.pde.core.plugin.IPluginLibrary#setContentFilters(java.lang.String[])
88      */

89     public void setContentFilters(String JavaDoc[] filters) throws CoreException {
90     }
91     /* (non-Javadoc)
92      * @see org.eclipse.pde.core.plugin.IPluginLibrary#addContentFilter(java.lang.String)
93      */

94     public void addContentFilter(String JavaDoc filter) throws CoreException {
95         PluginElementNode node = new PluginElementNode();
96         node.setXMLTagName(P_EXPORTED);
97         node.setParentNode(this);
98         node.setModel(getModel());
99         node.setXMLAttribute(P_NAME, "*".equals(filter) || filter.endsWith(".*") ? filter : filter + ".*"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
100
addContentFilter(node);
101     }
102     
103     public void addContentFilter(PluginElementNode node) throws CoreException {
104         addChildNode(node);
105         if (isInTheModel()) {
106             node.setInTheModel(true);
107             fireStructureChanged(node, IModelChangedEvent.INSERT);
108         }
109     }
110     
111     /* (non-Javadoc)
112      * @see org.eclipse.pde.core.plugin.IPluginLibrary#removeContentFilter(java.lang.String)
113      */

114     public void removeContentFilter(String JavaDoc filter) throws CoreException {
115         if (!filter.endsWith(".*")) //$NON-NLS-1$
116
filter += ".*"; //$NON-NLS-1$
117
IDocumentNode[] children = getChildNodes();
118         for (int i = 0; i < children.length; i++) {
119             if (children[i].getXMLTagName().equals(P_EXPORTED)
120                    && filter.equals(children[i].getXMLAttributeValue(P_NAME))) {
121                 removeContentFilter((PluginElementNode)children[i]);
122             }
123         }
124     }
125     
126     public void removeContentFilter(PluginElementNode node) {
127         removeChildNode(node);
128         if (isInTheModel()) {
129             node.setInTheModel(false);
130             fireStructureChanged(node, IModelChangedEvent.REMOVE);
131         }
132     }
133     
134     /* (non-Javadoc)
135      * @see org.eclipse.pde.core.plugin.IPluginLibrary#setPackages(java.lang.String[])
136      */

137     public void setPackages(String JavaDoc[] packages) throws CoreException {
138     }
139     /* (non-Javadoc)
140      * @see org.eclipse.pde.core.plugin.IPluginLibrary#setExported(boolean)
141      */

142     public void setExported(boolean exported) throws CoreException {
143         IDocumentNode[] children = getChildNodes();
144         boolean alreadyExported = false;
145         for (int i = 0; i < children.length; i++) {
146             if (children[i].getXMLTagName().equals(P_EXPORTED)) {
147                 if (!"*".equals(children[i].getXMLAttributeValue(P_NAME))) { //$NON-NLS-1$
148
removeContentFilter((PluginElementNode)children[i]);
149                 } else {
150                     alreadyExported = true;
151                     if (!exported) {
152                         removeContentFilter((PluginElementNode)children[i]);
153                     }
154                 }
155             }
156         }
157         if (exported && !alreadyExported) {
158             addContentFilter("*"); //$NON-NLS-1$
159
}
160     }
161     
162     /* (non-Javadoc)
163      * @see org.eclipse.pde.core.plugin.IPluginLibrary#setType(java.lang.String)
164      */

165     public void setType(String JavaDoc type) throws CoreException {
166     }
167     
168     /* (non-Javadoc)
169      * @see org.eclipse.pde.core.plugin.IPluginObject#getName()
170      */

171     public String JavaDoc getName() {
172         return getXMLAttributeValue(P_NAME);
173     }
174     
175     /* (non-Javadoc)
176      * @see org.eclipse.pde.core.plugin.IPluginObject#setName(java.lang.String)
177      */

178     public void setName(String JavaDoc name) throws CoreException {
179         setXMLAttribute(P_NAME, name);
180     }
181     
182     /* (non-Javadoc)
183      * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#write()
184      */

185     public String JavaDoc write(boolean indent) {
186         String JavaDoc sep = getLineDelimiter();
187         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
188         if (indent)
189             buffer.append(getIndent());
190         
191         IDocumentNode[] children = getChildNodes();
192         if (children.length > 0) {
193             buffer.append(writeShallow(false) + sep);
194             for (int i = 0; i < children.length; i++) {
195                 children[i].setLineIndent(getLineIndent() + 3);
196                 buffer.append(children[i].write(true) + sep);
197             }
198             buffer.append(getIndent() + "</" + getXMLTagName() + ">"); //$NON-NLS-1$ //$NON-NLS-2$
199
} else {
200             buffer.append(writeShallow(true));
201         }
202         return buffer.toString();
203     }
204     
205     /* (non-Javadoc)
206      * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#writeShallow(boolean)
207      */

208     public String JavaDoc writeShallow(boolean terminate) {
209         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("<" + getXMLTagName()); //$NON-NLS-1$
210

211         IDocumentAttribute[] attrs = getNodeAttributes();
212         for (int i = 0; i < attrs.length; i++) {
213             appendAttribute(buffer, attrs[i].getAttributeName());
214         }
215         if (terminate)
216             buffer.append("/"); //$NON-NLS-1$
217
buffer.append(">"); //$NON-NLS-1$
218
return buffer.toString();
219     }
220     
221     public String JavaDoc toString() {
222         return getName();
223     }
224
225 }
226
Popular Tags