KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > target > ImplicitDependenciesInfo


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.target;
12
13 import java.io.PrintWriter JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.pde.internal.core.itarget.IImplicitDependenciesInfo;
20 import org.eclipse.pde.internal.core.itarget.ITargetModel;
21 import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
22 import org.w3c.dom.Node JavaDoc;
23 import org.w3c.dom.NodeList JavaDoc;
24
25 public class ImplicitDependenciesInfo extends TargetObject implements
26         IImplicitDependenciesInfo {
27     
28     private static final long serialVersionUID = 1L;
29     
30     Map JavaDoc fPlugins = new HashMap JavaDoc();
31
32     public ImplicitDependenciesInfo(ITargetModel model) {
33         super(model);
34     }
35
36     public ITargetPlugin[] getPlugins() {
37         return (ITargetPlugin[]) fPlugins.values().toArray(new ITargetPlugin[fPlugins.size()]);
38     }
39
40     public void addPlugin(ITargetPlugin plugin) {
41         addPlugins(new ITargetPlugin[] {plugin});
42     }
43
44     public void addPlugins(ITargetPlugin[] plugins) {
45         ArrayList JavaDoc addedPlugins = new ArrayList JavaDoc();
46         for (int i = 0; i < plugins.length; i ++ ) {
47             String JavaDoc id = plugins[i].getId();
48             if (fPlugins.containsKey(id))
49                 continue;
50             plugins[i].setModel(getModel());
51             fPlugins.put(id, plugins[i]);
52             addedPlugins.add(plugins[i]);
53         }
54         if (isEditable() && (addedPlugins.size() > 0)) {
55             firePropertyChanged(P_IMPLICIT_PLUGINS, new ITargetPlugin[0],
56                     (ITargetPlugin[])addedPlugins.toArray(new ITargetPlugin[addedPlugins.size()]));
57         }
58
59     }
60
61     public void removePlugin(ITargetPlugin plugin) {
62         removePlugins(new ITargetPlugin[] {plugin});
63     }
64
65     public void removePlugins(ITargetPlugin[] plugins) {
66         ArrayList JavaDoc removedPlugins = new ArrayList JavaDoc();
67         for (int i =0; i < plugins.length; i++)
68             if (fPlugins.remove(plugins[i].getId()) != null)
69                 removedPlugins.add(plugins[i]);
70         if (isEditable() && (removedPlugins.size() > 0))
71             firePropertyChanged(P_IMPLICIT_PLUGINS, (ITargetPlugin[])removedPlugins.toArray(new ITargetPlugin[removedPlugins.size()]),
72                     new ITargetPlugin[0]);
73     }
74
75     public void parse(Node JavaDoc node) {
76         NodeList JavaDoc children = node.getChildNodes();
77         for (int i = 0; i < children.getLength(); i++) {
78             Node JavaDoc child = children.item(i);
79             if (child.getNodeName().equals("plugin")) { //$NON-NLS-1$
80
ITargetPlugin plugin = getModel().getFactory().createPlugin();
81                 plugin.parse(child);
82                 fPlugins.put(plugin.getId(), plugin);
83             }
84         }
85
86     }
87
88     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
89         if (fPlugins.size() == 0)
90             return;
91         writer.println();
92         writer.println(indent + "<implicitDependencies>"); //$NON-NLS-1$
93
Iterator JavaDoc it = fPlugins.values().iterator();
94         while (it.hasNext()) {
95             TargetPlugin plugin = (TargetPlugin) it.next();
96             plugin.write(indent + " ", writer); //$NON-NLS-1$
97
}
98         writer.println(indent + "</implicitDependencies>"); //$NON-NLS-1$
99
}
100
101     public boolean containsPlugin(String JavaDoc id) {
102         return fPlugins.containsKey(id);
103     }
104
105 }
106
Popular Tags