Lines 48-54
Link Here
|
48 |
import java.beans.PropertyChangeListener; |
48 |
import java.beans.PropertyChangeListener; |
49 |
import java.lang.ref.Reference; |
49 |
import java.lang.ref.Reference; |
50 |
import java.lang.ref.WeakReference; |
50 |
import java.lang.ref.WeakReference; |
|
|
51 |
import java.lang.reflect.Constructor; |
52 |
import java.lang.reflect.InvocationTargetException; |
51 |
import java.util.ArrayList; |
53 |
import java.util.ArrayList; |
|
|
54 |
import java.util.Collection; |
52 |
import java.util.Collections; |
55 |
import java.util.Collections; |
53 |
import java.util.Enumeration; |
56 |
import java.util.Enumeration; |
54 |
import java.util.HashMap; |
57 |
import java.util.HashMap; |
Lines 58-69
Link Here
|
58 |
import java.util.logging.Logger; |
61 |
import java.util.logging.Logger; |
59 |
import org.openide.filesystems.FileObject; |
62 |
import org.openide.filesystems.FileObject; |
60 |
import org.openide.filesystems.FileStateInvalidException; |
63 |
import org.openide.filesystems.FileStateInvalidException; |
|
|
64 |
import org.openide.filesystems.spi.CustomInstanceFactory; |
65 |
import org.openide.util.BaseUtilities; |
61 |
import org.openide.util.Exceptions; |
66 |
import org.openide.util.Exceptions; |
62 |
import org.openide.util.Lookup; |
67 |
import org.openide.util.Lookup; |
63 |
import org.openide.util.SharedClassObject; |
|
|
64 |
import org.openide.util.Utilities; |
65 |
import org.openide.util.lookup.AbstractLookup; |
68 |
import org.openide.util.lookup.AbstractLookup; |
66 |
import org.openide.util.lookup.InstanceContent; |
69 |
import org.openide.util.lookup.InstanceContent; |
|
|
70 |
import org.openide.util.lookup.Lookups; |
67 |
|
71 |
|
68 |
/** |
72 |
/** |
69 |
* |
73 |
* |
Lines 205-210
Link Here
|
205 |
|
209 |
|
206 |
} |
210 |
} |
207 |
|
211 |
|
|
|
212 |
private static volatile Lookup.Result<CustomInstanceFactory> factories; |
213 |
|
214 |
private static Collection<? extends CustomInstanceFactory> getInstanceFactories() { |
215 |
Lookup.Result<CustomInstanceFactory> v = factories; |
216 |
if (v != null) { |
217 |
return v.allInstances(); |
218 |
} |
219 |
final Lookup.Result<CustomInstanceFactory> fr[] = new Lookup.Result[1]; |
220 |
// ensure the system - global Lookup is used |
221 |
Lookups.executeWith(null, new Runnable() { |
222 |
public void run() { |
223 |
fr[0] = factories = Lookup.getDefault().lookupResult(CustomInstanceFactory.class); |
224 |
} |
225 |
}); |
226 |
return fr[0].allInstances(); |
227 |
} |
228 |
|
229 |
public static final <T> T createInstance(Class<T> type) throws InstantiationException, |
230 |
IllegalAccessException, InvocationTargetException, NoSuchMethodException { |
231 |
T r = null; |
232 |
for (CustomInstanceFactory fif : getInstanceFactories()) { |
233 |
r = (T)fif.createInstance(type); |
234 |
if (r != null) { |
235 |
break; |
236 |
} |
237 |
} |
238 |
if (r == null) { |
239 |
Constructor<T> init = type.getDeclaredConstructor(); |
240 |
init.setAccessible(true); |
241 |
r = init.newInstance(); |
242 |
} |
243 |
return r; |
244 |
} |
208 |
|
245 |
|
209 |
/** |
246 |
/** |
210 |
* Item referencing a file object and object instance that was created from it. |
247 |
* Item referencing a file object and object instance that was created from it. |
Lines 342-355
Link Here
|
342 |
if (type == null) { |
379 |
if (type == null) { |
343 |
return null; |
380 |
return null; |
344 |
} |
381 |
} |
345 |
if (SharedClassObject.class.isAssignableFrom(type)) { |
382 |
inst = createInstance(type); |
346 |
inst = SharedClassObject.findObject(type.asSubclass(SharedClassObject.class), true); |
383 |
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { |
347 |
} else { |
|
|
348 |
inst = type.newInstance(); |
349 |
} |
350 |
} catch (InstantiationException ex) { |
351 |
Exceptions.printStackTrace(ex); |
352 |
} catch (IllegalAccessException ex) { |
353 |
Exceptions.printStackTrace(ex); |
384 |
Exceptions.printStackTrace(ex); |
354 |
} |
385 |
} |
355 |
} |
386 |
} |
Lines 373-379
Link Here
|
373 |
// first of all try "instanceClass" property of the primary file |
404 |
// first of all try "instanceClass" property of the primary file |
374 |
Object attr = fo.getAttribute ("instanceClass"); |
405 |
Object attr = fo.getAttribute ("instanceClass"); |
375 |
if (attr instanceof String) { |
406 |
if (attr instanceof String) { |
376 |
return Utilities.translate((String) attr); |
407 |
return BaseUtilities.translate((String) attr); |
377 |
} else if (attr != null) { |
408 |
} else if (attr != null) { |
378 |
LOG.warning( |
409 |
LOG.warning( |
379 |
"instanceClass was a " + attr.getClass().getName()); // NOI18N |
410 |
"instanceClass was a " + attr.getClass().getName()); // NOI18N |
Lines 411-417
Link Here
|
411 |
} |
442 |
} |
412 |
|
443 |
|
413 |
name = name.replace ('-', '.'); |
444 |
name = name.replace ('-', '.'); |
414 |
name = Utilities.translate(name); |
445 |
name = BaseUtilities.translate(name); |
415 |
|
446 |
|
416 |
return name; |
447 |
return name; |
417 |
} |
448 |
} |
Lines 423-429
Link Here
|
423 |
private final class Ref extends WeakReference<Object> implements Runnable { |
454 |
private final class Ref extends WeakReference<Object> implements Runnable { |
424 |
|
455 |
|
425 |
Ref(Object inst) { |
456 |
Ref(Object inst) { |
426 |
super(inst, Utilities.activeReferenceQueue()); |
457 |
super(inst, BaseUtilities.activeReferenceQueue()); |
427 |
} |
458 |
} |
428 |
|
459 |
|
429 |
@Override |
460 |
@Override |