1 11 package org.eclipse.pde.internal.ui.model.bundle; 12 13 import java.util.Iterator ; 14 import java.util.TreeMap ; 15 16 import org.eclipse.jdt.core.*; 17 import org.eclipse.osgi.util.*; 18 import org.eclipse.pde.core.IModelChangedEvent; 19 20 public class ExportPackageObject extends PackageObject { 21 22 private static final String INTERNAL = "x-internal"; private static final String FRIENDS = "x-friends"; 25 private static final long serialVersionUID = 1L; 26 27 private boolean fInternal; 28 29 private TreeMap fFriends = new TreeMap (); 30 31 public ExportPackageObject(ManifestHeader header, ManifestElement element, String versionAttribute) { 32 super(header, element, versionAttribute); 33 processFriends(element.getDirective(FRIENDS)); 34 fInternal = "true".equals(element.getDirective(INTERNAL)) || fFriends.size() > 0; } 36 37 public ExportPackageObject(ManifestHeader header, IPackageFragment fragment, String versionAttribute) { 38 super(header, fragment.getElementName(), null, versionAttribute); 39 } 40 41 private void processFriends(String value) { 42 if (value != null) { 43 String [] friends = ManifestElement.getArrayFromList(value); 44 for (int i = 0; i < friends.length; i++) { 45 PackageFriend friend = new PackageFriend(this, friends[i]); 46 fFriends.put(friend.getName(), friend); 47 } 48 } 49 } 50 51 protected void appendSupportedAttributes(StringBuffer buffer) { 52 super.appendSupportedAttributes(buffer); 53 if (!fInternal) 54 return; 55 56 if (fInternal && fFriends.size() == 0) { 57 buffer.append(";"); buffer.append(INTERNAL); 59 buffer.append(":=true"); } 61 if (fFriends.size() > 0) { 62 buffer.append(";"); buffer.append(FRIENDS); 64 buffer.append(":=\""); Iterator iter = fFriends.keySet().iterator(); 66 while (iter.hasNext()) { 67 buffer.append(iter.next().toString()); 68 if (iter.hasNext()) 69 buffer.append(","); } 71 buffer.append("\""); } 73 } 74 75 public boolean isInternal() { 76 return fInternal; 77 } 78 79 public void setInternal(boolean internal) { 80 boolean old = fInternal; 81 fInternal = internal; 82 firePropertyChanged(this, INTERNAL, Boolean.valueOf(old), Boolean.valueOf(internal)); 83 } 84 85 public PackageFriend[] getFriends() { 86 return (PackageFriend[])fFriends.values().toArray(new PackageFriend[fFriends.size()]); 87 } 88 89 public void addFriend(PackageFriend friend) { 90 fFriends.put(friend.getName(), friend); 91 fireStructureChanged(friend, IModelChangedEvent.INSERT); 92 } 93 94 public void removeFriend(PackageFriend friend) { 95 fFriends.remove(friend.getName()); 96 fireStructureChanged(friend, IModelChangedEvent.REMOVE); 97 } 98 99 public boolean hasFriend(String name) { 100 return fFriends.containsKey(name); 101 } 102 103 protected boolean skipDirective(String directive) { 104 return INTERNAL.equals(directive) || FRIENDS.equals(directive); 105 } 106 107 public boolean hasSameVisibility(ExportPackageObject object) { 108 if (object.fInternal != fInternal) 109 return false; 110 111 if (fFriends.size() != object.fFriends.size()) 112 return false; 113 114 Iterator iter = fFriends.keySet().iterator(); 115 while (iter.hasNext()) { 116 if (!object.fFriends.containsKey(iter.next())) 117 return false; 118 } 119 return true; 120 } 121 122 } 123 | Popular Tags |