1 11 package org.eclipse.pde.internal.core.target; 12 13 import java.io.PrintWriter ; 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.Map ; 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 ; 23 import org.w3c.dom.NodeList ; 24 25 public class ImplicitDependenciesInfo extends TargetObject implements 26 IImplicitDependenciesInfo { 27 28 private static final long serialVersionUID = 1L; 29 30 Map fPlugins = new HashMap (); 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 addedPlugins = new ArrayList (); 46 for (int i = 0; i < plugins.length; i ++ ) { 47 String 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 removedPlugins = new ArrayList (); 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 node) { 76 NodeList children = node.getChildNodes(); 77 for (int i = 0; i < children.getLength(); i++) { 78 Node child = children.item(i); 79 if (child.getNodeName().equals("plugin")) { 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 indent, PrintWriter writer) { 89 if (fPlugins.size() == 0) 90 return; 91 writer.println(); 92 writer.println(indent + "<implicitDependencies>"); Iterator it = fPlugins.values().iterator(); 94 while (it.hasNext()) { 95 TargetPlugin plugin = (TargetPlugin) it.next(); 96 plugin.write(indent + " ", writer); } 98 writer.println(indent + "</implicitDependencies>"); } 100 101 public boolean containsPlugin(String id) { 102 return fPlugins.containsKey(id); 103 } 104 105 } 106 | Popular Tags |