1 19 20 package org.openide.loaders; 21 22 import java.util.Iterator ; 23 import javax.naming.Context ; 24 import org.openide.filesystems.FileObject; 25 import org.openide.util.Lookup; 26 27 32 public final class Environment extends Object { 33 34 private static Lookup.Result result; 35 36 38 private Environment() { 39 } 40 41 45 public static Lookup find (DataObject obj) { 46 while (obj != null) { 47 Lookup l = findForOne (obj); 48 if (l != null) { 49 return l; 50 } 51 52 FileObject fo = obj.getPrimaryFile ().getParent (); 53 if (fo == null) { 54 break; 55 } 56 57 try { 58 obj = DataObject.find (fo); 59 } catch (DataObjectNotFoundException ex) { 60 break; 61 } 62 } 63 64 return Lookup.EMPTY; 66 } 67 68 74 public static javax.naming.Context findSettingsContext(DataObject obj) { 75 Iterator it = getProviders().allInstances().iterator(); 76 while (it.hasNext()) { 77 Environment.Provider ep = (Environment.Provider) it.next(); 78 Lookup lookup = ep.getEnvironment(obj); 79 if (lookup != null) { 80 Context ctx = (Context ) lookup.lookup(Context .class); 81 if (ctx != null) return ctx; 82 } 83 } 84 85 return new DefaultSettingsContext(obj); 87 } 88 89 93 static Lookup findForOne (DataObject obj) { 94 106 107 Iterator it = getProviders().allInstances().iterator(); 108 while (it.hasNext ()) { 109 Environment.Provider ep = (Environment.Provider)it.next (); 110 Lookup lookup = ep.getEnvironment (obj); 111 if (lookup != null) { 112 return lookup; 113 } 114 } 115 116 return null; 118 } 119 120 static Lookup.Result getProviders() { 121 if (result == null) { 122 result = Lookup.getDefault().lookupResult(Environment.Provider.class); 123 } 124 return result; 125 } 126 127 130 public static interface Provider { 131 134 public Lookup getEnvironment (DataObject obj); 135 } } 137 | Popular Tags |