1 11 package org.eclipse.pde.internal.core.feature; 12 13 import java.io.PrintWriter ; 14 import java.util.Locale ; 15 import java.util.Vector ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.pde.core.IModelChangedEvent; 19 import org.eclipse.pde.internal.core.ifeature.IFeatureURL; 20 import org.eclipse.pde.internal.core.ifeature.IFeatureURLElement; 21 import org.w3c.dom.Node ; 22 import org.w3c.dom.NodeList ; 23 24 public class FeatureURL extends FeatureObject implements IFeatureURL { 25 private static final long serialVersionUID = 1L; 26 private IFeatureURLElement fUpdate; 27 private Vector fDiscoveries = new Vector (); 28 29 public void addDiscovery(IFeatureURLElement discovery) throws CoreException { 30 ensureModelEditable(); 31 fDiscoveries.add(discovery); 32 ((FeatureURLElement)discovery).setInTheModel(true); 33 fireStructureChanged(discovery, IModelChangedEvent.INSERT); 34 } 35 public void setUpdate(IFeatureURLElement update) throws CoreException { 36 ensureModelEditable(); 37 if(fUpdate == update){ 38 return; 39 } 40 if(fUpdate!=null){ 41 ((FeatureURLElement)fUpdate).setInTheModel(false); 42 } 43 IFeatureURLElement oldValue = fUpdate; 44 fUpdate = update; 45 if(oldValue!=null){ 46 fireStructureChanged(oldValue, IModelChangedEvent.REMOVE); 47 } 48 if(update!=null){ 49 ((FeatureURLElement)update).setInTheModel(true); 50 fireStructureChanged(update, IModelChangedEvent.INSERT); 51 } 52 } 53 public IFeatureURLElement[] getDiscoveries() { 54 return (IFeatureURLElement[]) fDiscoveries 55 .toArray(new IFeatureURLElement[fDiscoveries.size()]); 56 } 57 public IFeatureURLElement getUpdate() { 58 return fUpdate; 59 } 60 protected void parse(Node node) { 61 NodeList children = node.getChildNodes(); 62 for (int i = 0; i < children.getLength(); i++) { 63 Node child = children.item(i); 64 if (child.getNodeType() == Node.ELEMENT_NODE) { 65 String tag = child.getNodeName().toLowerCase(Locale.ENGLISH); 66 int urlType = -1; 67 if (tag.equals("update")) { urlType = IFeatureURLElement.UPDATE; 69 } else if (tag.equals("discovery")) { urlType = IFeatureURLElement.DISCOVERY; 71 } 72 if (urlType != -1) { 73 IFeatureURLElement element = 74 getModel().getFactory().createURLElement(this, urlType); 75 ((FeatureURLElement) element).parse(child); 76 if (urlType == IFeatureURLElement.UPDATE) { 77 ((FeatureURLElement)element).setInTheModel(true); 78 fUpdate = element; 79 } 80 else if (urlType == IFeatureURLElement.DISCOVERY) { 81 ((FeatureURLElement)element).setInTheModel(true); 82 fDiscoveries.add(element); 83 } 84 } 85 } 86 } 87 } 88 public void removeDiscovery(IFeatureURLElement discovery) 89 throws CoreException { 90 ensureModelEditable(); 91 fDiscoveries.remove(discovery); 92 ((FeatureURLElement)discovery).setInTheModel(false); 93 fireStructureChanged(discovery, IModelChangedEvent.REMOVE); 94 } 95 public void write(String indent, PrintWriter writer) { 96 if(fUpdate == null && fDiscoveries.size() <=0){ 97 return; 98 } 99 writer.println(); 100 writer.println(indent + "<url>"); String indent2 = indent + Feature.INDENT; 102 if(fUpdate!=null) { 103 fUpdate.write(indent2, writer); 104 } 105 for (int i = 0; i < fDiscoveries.size(); i++) { 106 IFeatureURLElement element = (IFeatureURLElement) fDiscoveries.elementAt(i); 107 element.write(indent2, writer); 108 } 109 writer.println(indent + "</url>"); } 111 } 112 | Popular Tags |