Lines 40-47
Link Here
|
40 |
/** Name of the method used to determine whether an option is global or not. */ |
40 |
/** Name of the method used to determine whether an option is global or not. */ |
41 |
static final String GLOBAL_METHOD_NAME = "isGlobal"; // NOI18N |
41 |
static final String GLOBAL_METHOD_NAME = "isGlobal"; // NOI18N |
42 |
|
42 |
|
43 |
private byte [] defaultInstance = null; |
|
|
44 |
|
45 |
/** property change support (PropertyChangeSupport) */ |
43 |
/** property change support (PropertyChangeSupport) */ |
46 |
private static final Object PROP_SUPPORT = new Object (); |
44 |
private static final Object PROP_SUPPORT = new Object (); |
47 |
|
45 |
|
Lines 237-246
Link Here
|
237 |
throw new NullPointerException("Tried to pass null key (value=" + value + ") to putProperty"); // NOI18N |
235 |
throw new NullPointerException("Tried to pass null key (value=" + value + ") to putProperty"); // NOI18N |
238 |
} |
236 |
} |
239 |
synchronized (getLock ()) { |
237 |
synchronized (getLock ()) { |
240 |
if (key.equals ("netbeans.systemoption.hack")) { // NOI18N |
|
|
241 |
systemOption = true; |
242 |
return null; |
243 |
} |
244 |
if (waitingOnSystemOption && key != PROP_SUPPORT && |
238 |
if (waitingOnSystemOption && key != PROP_SUPPORT && |
245 |
prematureSystemOptionMutation == null && !dataEntry.isInInitialize() && !inReadExternal) { |
239 |
prematureSystemOptionMutation == null && !dataEntry.isInInitialize() && !inReadExternal) { |
246 |
// See below in findObject. Note that if we are still in initialize(), |
240 |
// See below in findObject. Note that if we are still in initialize(), |
Lines 472-479
Link Here
|
472 |
} |
466 |
} |
473 |
} |
467 |
} |
474 |
if (created) { |
468 |
if (created) { |
475 |
obj.reset (); |
|
|
476 |
|
477 |
// This hack was created due to the remove of SystemOptions deserialization |
469 |
// This hack was created due to the remove of SystemOptions deserialization |
478 |
// from project open operation, all SystemOptions are deserialized at this place |
470 |
// from project open operation, all SystemOptions are deserialized at this place |
479 |
// the first time anybody asks for the option. |
471 |
// the first time anybody asks for the option. |
Lines 481-487
Link Here
|
481 |
// otherwise it can cause deadlocks. |
473 |
// otherwise it can cause deadlocks. |
482 |
// Lookup in the active session is used to find serialized state of the option, |
474 |
// Lookup in the active session is used to find serialized state of the option, |
483 |
// if such state exists it is deserialized before the object is returned from lookup. |
475 |
// if such state exists it is deserialized before the object is returned from lookup. |
484 |
if (obj.systemOption) { |
476 |
if (obj.isSystemOption ()) { |
485 |
// Lookup will find serialized version of searched object and deserialize it |
477 |
// Lookup will find serialized version of searched object and deserialize it |
486 |
final Lookup.Result r = Lookup.getDefault().lookup(new Lookup.Template(clazz)); |
478 |
final Lookup.Result r = Lookup.getDefault().lookup(new Lookup.Template(clazz)); |
487 |
if (r.allInstances().isEmpty()) { |
479 |
if (r.allInstances().isEmpty()) { |
Lines 518-523
Link Here
|
518 |
return obj; |
510 |
return obj; |
519 |
} |
511 |
} |
520 |
} |
512 |
} |
|
|
513 |
|
514 |
/** checks whether we are instance of system option. |
515 |
*/ |
516 |
private boolean isSystemOption () { |
517 |
Class c = this.getClass (); |
518 |
while (c != SharedClassObject.class) { |
519 |
if ("org.openide.options.SystemOption".equals (c.getName ())) return true; // NOI18N |
520 |
c = c.getSuperclass (); |
521 |
} |
522 |
return false; |
523 |
} |
524 |
|
521 |
// See above: |
525 |
// See above: |
522 |
private static void warn(Throwable t) { |
526 |
private static void warn(Throwable t) { |
523 |
err.notify(ErrorManager.INFORMATIONAL, t); |
527 |
err.notify(ErrorManager.INFORMATIONAL, t); |
Lines 547-603
Link Here
|
547 |
} |
551 |
} |
548 |
} |
552 |
} |
549 |
|
553 |
|
550 |
/** Resets shared data to it default value. */ |
554 |
/** Is called by the infrastructure in cases when a clean instance is requested. |
551 |
private void reset () { |
555 |
* As instances of <code>SharedClassObject</code> are singletons, there is |
552 |
if (!systemOption || !isProjectOption ()) { |
556 |
* no way how to create new instance that would not contain the same data |
553 |
return; |
557 |
* as previously existing one. This method allows all subclasses that care |
554 |
} |
558 |
* about the ability to refresh the settings (like <code>SystemOption</code>s) |
555 |
|
559 |
* to be notified about the cleaning request and clean their settings themselves. |
556 |
synchronized (getLock ()) { |
560 |
* <p> |
557 |
// [PENDING] should be changed to next line after all options in layers will |
561 |
* Default implementation does nothing. |
558 |
// use put{get}Property and initilaize properly |
562 |
* |
559 |
// dataEntry.reset (this); |
563 |
* @since made protected in version 4.46 |
560 |
|
|
|
561 |
if (defaultInstance == null) { |
562 |
try { |
563 |
ByteArrayOutputStream baos = new ByteArrayOutputStream (1024); |
564 |
ObjectOutput oo = new org.openide.util.io.NbObjectOutputStream (baos); |
565 |
oo.writeObject (this); |
566 |
defaultInstance = baos.toByteArray (); |
567 |
} catch (IOException e) { |
568 |
defaultInstance = null; |
569 |
} |
570 |
return; |
571 |
} |
572 |
|
573 |
try { |
574 |
ByteArrayInputStream bais = new ByteArrayInputStream (defaultInstance); |
575 |
ObjectInputStream oi = new org.openide.util.io.NbObjectInputStream (bais); |
576 |
oi.readObject (); |
577 |
} catch (Exception e) { |
578 |
// ignore and leave it as it is |
579 |
} |
580 |
} |
581 |
} |
582 |
|
583 |
/** |
584 |
* Test if the object is Project specific. |
585 |
* @return true if the object is Project specific |
586 |
*/ |
564 |
*/ |
587 |
private boolean isProjectOption () { |
565 |
protected void reset () { |
588 |
try { |
|
|
589 |
Class clazz = getClass (); |
590 |
// the old hack with undocumented method isGlobal |
591 |
Method m = clazz.getMethod(GLOBAL_METHOD_NAME, new Class[] {}); |
592 |
m.setAccessible(true); |
593 |
Boolean b = (Boolean) m.invoke(this, new Object[] {}); |
594 |
return !b.booleanValue(); |
595 |
} catch (Exception ex) { |
596 |
// ignore and return default |
597 |
} |
598 |
return false; |
599 |
} |
566 |
} |
600 |
|
|
|
601 |
|
567 |
|
602 |
/** Class that is used as default write replace. |
568 |
/** Class that is used as default write replace. |
603 |
*/ |
569 |
*/ |