author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 15 Oct 2011 22:11:18 +0200 | |
changeset 376 | bb34a70d36ba |
parent 287 | e1186601a720 |
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@376 | 36 |
private static final Class<?> INIT_API_CLASS = loadClass( |
jtulach@376 | 37 |
Item.class.getName() |
jtulach@376 | 38 |
); |
jtulach@286 | 39 |
private static Class<?> loadClass(String name) { |
jtulach@286 | 40 |
try { |
jtulach@286 | 41 |
return Class.forName( |
jtulach@286 | 42 |
name, true, Accessor.class.getClassLoader() |
jtulach@286 | 43 |
); |
jtulach@286 | 44 |
} catch (Exception ex) { |
jtulach@286 | 45 |
throw new RuntimeException(ex); |
jtulach@286 | 46 |
} |
jtulach@286 | 47 |
} |
jtulach@286 | 48 |
// END: design.less.friend.InitAPI |
jtulach@0 | 49 |
} |