| author | Jaroslav Tulach <jtulach@netbeans.org> |
| Fri Aug 27 14:06:39 2010 +0200 | |
| changeset 365 | 0b7ec6ef8a72 |
| parent 286 | ac16aae50d58 |
| child 376 | bb34a70d36ba |
| permissions | -rw-r--r-- |
| jtulach@287 | 1 |
package org.apidesign.friendpackage.impl; |
| jtulach@0 | 2 |
|
| jtulach@0 | 3 |
import javax.swing.event.ChangeListener; |
| jtulach@287 | 4 |
import org.apidesign.friendpackage.api.Item; |
| jtulach@0 | 5 |
|
| jtulach@0 | 6 |
/** |
| jtulach@0 | 7 |
* |
| jtulach@0 | 8 |
* @author Jaroslav Tulach |
| jtulach@0 | 9 |
*/ |
| jtulach@3 | 10 |
// BEGIN: design.less.friend.Accessor |
| jtulach@0 | 11 |
public abstract class Accessor {
|
| jtulach@128 | 12 |
private static volatile Accessor DEFAULT; |
| jtulach@128 | 13 |
public static Accessor getDefault() {
|
| jtulach@128 | 14 |
Accessor a = DEFAULT; |
| jtulach@286 | 15 |
if (a == null) {
|
| jtulach@286 | 16 |
throw new IllegalStateException("Something is wrong: " + a);
|
| jtulach@128 | 17 |
} |
| jtulach@286 | 18 |
return a; |
| jtulach@128 | 19 |
} |
| jtulach@128 | 20 |
|
| jtulach@128 | 21 |
public static void setDefault(Accessor accessor) {
|
| jtulach@128 | 22 |
if (DEFAULT != null) {
|
| jtulach@128 | 23 |
throw new IllegalStateException(); |
| jtulach@128 | 24 |
} |
| jtulach@128 | 25 |
DEFAULT = accessor; |
| jtulach@0 | 26 |
} |
| jtulach@0 | 27 |
|
| jtulach@0 | 28 |
public Accessor() {
|
| jtulach@0 | 29 |
} |
| jtulach@0 | 30 |
|
| jtulach@0 | 31 |
protected abstract Item newItem(); |
| jtulach@0 | 32 |
protected abstract void addChangeListener(Item item, ChangeListener l); |
| jtulach@286 | 33 |
// FINISH: design.less.friend.Accessor |
| jtulach@286 | 34 |
|
| jtulach@286 | 35 |
// BEGIN: design.less.friend.InitAPI |
| jtulach@286 | 36 |
private static final Class<?> INIT_API_CLASS = loadClass(Item.class.getName()); |
| jtulach@286 | 37 |
private static Class<?> loadClass(String name) {
|
| jtulach@286 | 38 |
try {
|
| jtulach@286 | 39 |
return Class.forName( |
| jtulach@286 | 40 |
name, true, Accessor.class.getClassLoader() |
| jtulach@286 | 41 |
); |
| jtulach@286 | 42 |
} catch (Exception ex) {
|
| jtulach@286 | 43 |
throw new RuntimeException(ex); |
| jtulach@286 | 44 |
} |
| jtulach@286 | 45 |
} |
| jtulach@286 | 46 |
// END: design.less.friend.InitAPI |
| jtulach@0 | 47 |
} |