1 11 12 package org.eclipse.osgi.framework.internal.core; 13 14 import java.io.IOException ; 15 import java.net.URL ; 16 import java.util.*; 17 import org.eclipse.osgi.service.resolver.BundleDescription; 18 19 24 public class DependentPolicy implements IBuddyPolicy { 25 BundleLoader buddyRequester; 26 int lastDependentOfAdded = -1; List allDependents = null; 29 public DependentPolicy(BundleLoader requester) { 30 buddyRequester = requester; 31 32 allDependents = new ArrayList(); 34 basicAddImmediateDependents(buddyRequester.getBundle().getBundleDescription()); 35 if (allDependents.size() == 0) 37 allDependents = null; 38 } 39 40 public Class loadClass(String name) { 41 if (allDependents == null) 42 return null; 43 44 Class result = null; 45 for (int i = 0; i < allDependents.size() && result == null; i++) { 47 BundleDescription searchedBundle = (BundleDescription) allDependents.get(i); 48 try { 49 BundleLoaderProxy proxy = buddyRequester.getLoaderProxy(searchedBundle); 50 if (proxy == null) 51 continue; 52 result = proxy.getBundleLoader().findClass(name, true); 53 } catch (ClassNotFoundException e) { 54 if (result == null) 55 addDependent(i, searchedBundle); 56 } 57 } 58 return result; 59 } 60 61 private synchronized void addDependent(int i, BundleDescription searchedBundle) { 62 if (i > lastDependentOfAdded) { 63 lastDependentOfAdded = i; 64 basicAddImmediateDependents(searchedBundle); 65 } 66 } 67 68 public URL loadResource(String name) { 69 if (allDependents == null) 70 return null; 71 72 URL result = null; 73 for (int i = 0; i < allDependents.size() && result == null; i++) { 75 BundleDescription searchedBundle = (BundleDescription) allDependents.get(i); 76 BundleLoaderProxy proxy = buddyRequester.getLoaderProxy(searchedBundle); 77 if (proxy == null) 78 continue; 79 result = proxy.getBundleLoader().findResource(name, true); 80 if (result == null) { 81 addDependent(i, searchedBundle); 82 } 83 } 84 return result; 85 } 86 87 public Enumeration loadResources(String name) { 88 if (allDependents == null) 89 return null; 90 91 Enumeration results = null; 92 for (int i = 0; i < allDependents.size(); i++) { 94 BundleDescription searchedBundle = (BundleDescription) allDependents.get(i); 95 try { 96 BundleLoaderProxy proxy = buddyRequester.getLoaderProxy(searchedBundle); 97 if (proxy == null) 98 continue; 99 results = BundleLoader.compoundEnumerations(results, proxy.getBundleLoader().findResources(name)); 100 addDependent(i, searchedBundle); 101 } catch (IOException e) { 102 } 104 } 105 return results; 106 } 107 108 private void basicAddImmediateDependents(BundleDescription root) { 109 BundleDescription[] dependents = root.getDependents(); 110 for (int i = 0; i < dependents.length; i++) { 111 BundleDescription toAdd = dependents[i]; 112 if (toAdd.getHost() == null && !allDependents.contains(toAdd)) { 113 allDependents.add(toAdd); 114 } 115 } 116 } 117 } 118 | Popular Tags |