1 11 package org.eclipse.pde.internal.core.plugin; 12 13 import java.io.PrintWriter ; 14 import java.util.ArrayList ; 15 import java.util.Locale ; 16 import java.util.Vector ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.osgi.service.resolver.BundleDescription; 20 import org.eclipse.osgi.service.resolver.ExportPackageDescription; 21 import org.eclipse.pde.core.plugin.IPluginLibrary; 22 import org.eclipse.pde.core.plugin.IPluginModelBase; 23 import org.eclipse.pde.core.plugin.IPluginObject; 24 import org.eclipse.pde.core.plugin.ISharedPluginModel; 25 import org.eclipse.pde.internal.core.ClasspathUtilCore; 26 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; 27 import org.eclipse.pde.internal.core.util.PDEXMLHelper; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.NodeList ; 30 31 public class PluginLibrary extends PluginObject implements IPluginLibrary { 32 33 private static final long serialVersionUID = 1L; 34 private String [] fContentFilters; 35 private boolean fExported = false; 36 private String fType; 37 38 public PluginLibrary() { 39 } 40 41 public boolean isValid() { 42 return fName != null; 43 } 44 45 public String [] getContentFilters() { 46 IPluginModelBase model = (IPluginModelBase)getModel(); 47 if (ClasspathUtilCore.hasBundleStructure(model)) { 48 BundleDescription desc = model.getBundleDescription(); 49 if (desc != null) { 50 ArrayList list = new ArrayList (); 51 ExportPackageDescription[] exports = desc.getExportPackages(); 52 for (int i = 0; i < exports.length; i++) { 53 list.add(exports[i].getName()); 54 } 55 return (String [])list.toArray(new String [list.size()]); 56 } 57 } 58 if (!isExported()) 59 return new String [0]; 60 return isFullyExported() ? new String [] {"**"} : fContentFilters; } 62 63 66 public void addContentFilter(String filter) throws CoreException { 67 } 68 69 72 public void removeContentFilter(String filter) throws CoreException { 73 } 74 75 public String [] getPackages() { 76 return new String [0]; 77 } 78 79 public boolean isExported() { 80 return fExported; 81 } 82 83 public boolean isFullyExported() { 84 return fExported 85 && (fContentFilters == null || fContentFilters.length == 0); 86 } 87 88 public String getType() { 89 return fType; 90 } 91 92 93 public void load(String name) { 94 fName = name; 95 fExported = true; 96 } 97 98 void load(Node node) { 99 fName = getNodeAttribute(node, "name"); fType = getNodeAttribute(node, "type"); NodeList children = node.getChildNodes(); 102 Vector exports = new Vector (); 103 boolean all = false; 104 for (int i = 0; i < children.getLength(); i++) { 105 Node child = children.item(i); 106 if (child.getNodeType() == Node.ELEMENT_NODE) { 107 String tag = child.getNodeName().toLowerCase(Locale.ENGLISH); 108 if (tag.equals("export")) { String ename = getNodeAttribute(child, "name"); if (ename != null) { 111 ename = ename.trim(); 112 if (ename.equals("*")) { all = true; 114 } else { 115 exports.add(ename); 116 } 117 } 118 } 119 } 120 } 121 if (exports.size() > 0) { 122 fContentFilters = new String [exports.size()]; 123 exports.copyInto(fContentFilters); 124 } 125 fExported = all || exports.size() > 0; 126 } 127 public void setContentFilters(String [] filters) throws CoreException { 128 ensureModelEditable(); 129 ArrayList oldValue = createArrayList(fContentFilters); 130 fContentFilters = filters; 131 firePropertyChanged( 132 P_CONTENT_FILTERS, 133 oldValue, 134 createArrayList(filters)); 135 } 136 137 public void setPackages(String [] packages) throws CoreException { 138 } 139 140 public void setExported(boolean value) throws CoreException { 141 ensureModelEditable(); 142 Boolean oldValue = new Boolean (fExported); 143 fExported = value; 144 firePropertyChanged(P_EXPORTED, oldValue, new Boolean (value)); 145 } 146 147 public void setType(String type) throws CoreException { 148 ensureModelEditable(); 149 String oldValue = fType; 150 fType = type; 151 firePropertyChanged(P_TYPE, oldValue, type); 152 } 153 154 public void restoreProperty(String name, Object oldValue, Object newValue) 155 throws CoreException { 156 if (name.equals(P_CONTENT_FILTERS)) { 157 ArrayList list = (ArrayList ) newValue; 158 if (list != null) 159 setContentFilters( 160 (String []) list.toArray(new String [list.size()])); 161 else 162 setContentFilters(null); 163 return; 164 } 165 if (name.equals(P_EXPORTED)) { 166 setExported(((Boolean ) newValue).booleanValue()); 167 return; 168 } 169 if (name.equals(P_TYPE)) { 170 setType(newValue != null ? newValue.toString() : null); 171 return; 172 } 173 super.restoreProperty(name, oldValue, newValue); 174 } 175 176 private ArrayList createArrayList(String [] array) { 177 if (array == null) 178 return null; 179 ArrayList list = new ArrayList (); 180 for (int i = 0; i < array.length; i++) { 181 list.add(array[i]); 182 } 183 return list; 184 } 185 186 189 public void write(String indent, PrintWriter writer) { 190 IPluginModelBase modelBase = getPluginModel(); 192 if ((modelBase instanceof IBundlePluginModelBase) == false) { 194 writer.print(indent); 195 writer.print("<library name=\"" + PDEXMLHelper.getWritableString(getName()) + "\""); if (fType != null) 197 writer.print(" type=\"" + fType + "\""); if (!isExported()) { 199 writer.println("/>"); } else { 201 writer.println(">"); String indent2 = indent + " "; if (isExported()) { 204 if (isFullyExported()) { 205 writer.println(indent2 + "<export name=\"*\"/>"); } else { 207 for (int i = 0; i < fContentFilters.length; i++) { 208 writer.println( 209 indent2 210 + "<export name=\"" + fContentFilters[i] 212 + "\"/>"); } 214 } 215 } 216 writer.println(indent + "</library>"); } 218 } else 219 writer.print(PDEXMLHelper.getWritableString(getName())); 220 } 221 222 225 public void reconnect(ISharedPluginModel model, IPluginObject parent) { 226 super.reconnect(model, parent); 227 } 229 230 233 public void writeDelimeter(PrintWriter writer) { 234 writer.println(','); 235 writer.print(' '); 236 } 237 238 } 239 | Popular Tags |