1 11 package org.eclipse.osgi.framework.internal.core; 12 13 import java.net.URL ; 14 import java.util.Enumeration ; 15 import org.eclipse.osgi.util.ManifestElement; 16 17 public class FilteredSourcePackage extends SingleSourcePackage { 18 private static final char ALL = '*'; 19 String [] includes; 20 String [] excludes; 21 String [] friends; 22 23 public FilteredSourcePackage(String name, int expid, BundleLoaderProxy supplier, String includes, String excludes, String [] friends) { 24 super(name, expid, supplier); 25 if (includes != null) 26 this.includes = ManifestElement.getArrayFromList(includes); 27 if (excludes != null) 28 this.excludes = ManifestElement.getArrayFromList(excludes); 29 this.friends = friends; 30 } 31 32 public boolean isFriend(String symbolicName) { 33 if (friends == null) 34 return true; 35 for (int i = 0; i < friends.length; i++) 36 if (friends[i].equals(symbolicName)) 37 return true; 38 return false; 39 } 40 41 public URL getResource(String name) { 42 if (isFiltered(name, getId())) 43 return null; 44 return super.getResource(name); 45 } 46 public Enumeration getResources(String name) { 47 if (isFiltered(name, getId())) 48 return null; 49 return super.getResources(name); 50 } 51 public Class loadClass(String name) throws ClassNotFoundException { 52 if (isFiltered(name, getId())) 53 return null; 54 return super.loadClass(name); 55 } 56 57 private boolean isFiltered(String name, String pkgName) { 58 String lastName = getName(name, pkgName); 59 return !isIncluded(lastName) || isExcluded(lastName); 60 } 61 62 private String getName(String name, String pkgName) { 63 if (!BundleLoader.DEFAULT_PACKAGE.equals(pkgName) && pkgName.length() + 1 <= name.length()) 64 return name.substring(pkgName.length() + 1); 65 return name; 66 } 67 68 private boolean isIncluded(String name) { 69 if (includes == null) 70 return true; 71 return isInList(name, includes); 72 } 73 74 private boolean isExcluded(String name) { 75 if (excludes == null) 76 return false; 77 return isInList(name, excludes); 78 } 79 80 private boolean isInList(String name, String [] list) { 81 for (int i = 0; i < list.length; i++) { 82 int len = list[i].length(); 83 if (len == 0) 84 continue; 85 if (list[i].charAt(0) == ALL && len == 1) 86 return true; if (list[i].charAt(len-1) == ALL) 88 if (name.startsWith(list[i].substring(0, len-1))) 89 return true; 90 if (name.equals(list[i])) 91 return true; 92 93 } 94 return false; 95 } 96 } 97 | Popular Tags |