author | Jaroslav Tulach <jtulach@netbeans.org> |
Fri, 24 Oct 2008 12:07:34 +0200 | |
changeset 286 | ac16aae50d58 |
parent 154 | 0fd5e9c500b9 |
permissions | -rw-r--r-- |
jtulach@0 | 1 |
/* |
jtulach@0 | 2 |
* Sun Public License Notice |
jtulach@0 | 3 |
* |
jtulach@0 | 4 |
* The contents of this file are subject to the Sun Public License |
jtulach@0 | 5 |
* Version 1.0 (the "License"). You may not use this file except in |
jtulach@0 | 6 |
* compliance with the License. A copy of the License is available at |
jtulach@0 | 7 |
* http://www.sun.com/ |
jtulach@0 | 8 |
* |
jtulach@0 | 9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
jtulach@36 | 10 |
* Code is Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. |
jtulach@36 | 11 |
* All Rights Reserved. |
jtulach@0 | 12 |
*/ |
jtulach@0 | 13 |
|
jtulach@0 | 14 |
package implpkg; |
jtulach@0 | 15 |
|
jtulach@0 | 16 |
import apipkg.Item; |
jtulach@0 | 17 |
import javax.swing.event.ChangeListener; |
jtulach@0 | 18 |
|
jtulach@0 | 19 |
/** |
jtulach@0 | 20 |
* |
jtulach@0 | 21 |
* @author Jaroslav Tulach |
jtulach@0 | 22 |
*/ |
jtulach@3 | 23 |
// BEGIN: design.less.friend.Accessor |
jtulach@0 | 24 |
public abstract class Accessor { |
jtulach@128 | 25 |
private static volatile Accessor DEFAULT; |
jtulach@128 | 26 |
public static Accessor getDefault() { |
jtulach@128 | 27 |
Accessor a = DEFAULT; |
jtulach@286 | 28 |
if (a == null) { |
jtulach@286 | 29 |
throw new IllegalStateException("Something is wrong: " + a); |
jtulach@128 | 30 |
} |
jtulach@286 | 31 |
return a; |
jtulach@128 | 32 |
} |
jtulach@128 | 33 |
|
jtulach@128 | 34 |
public static void setDefault(Accessor accessor) { |
jtulach@128 | 35 |
if (DEFAULT != null) { |
jtulach@128 | 36 |
throw new IllegalStateException(); |
jtulach@128 | 37 |
} |
jtulach@128 | 38 |
DEFAULT = accessor; |
jtulach@0 | 39 |
} |
jtulach@0 | 40 |
|
jtulach@0 | 41 |
public Accessor() { |
jtulach@0 | 42 |
} |
jtulach@0 | 43 |
|
jtulach@0 | 44 |
protected abstract Item newItem(); |
jtulach@0 | 45 |
protected abstract void addChangeListener(Item item, ChangeListener l); |
jtulach@286 | 46 |
// FINISH: design.less.friend.Accessor |
jtulach@286 | 47 |
|
jtulach@286 | 48 |
// BEGIN: design.less.friend.InitAPI |
jtulach@286 | 49 |
private static final Class<?> INIT_API_CLASS = loadClass(Item.class.getName()); |
jtulach@286 | 50 |
private static Class<?> loadClass(String name) { |
jtulach@286 | 51 |
try { |
jtulach@286 | 52 |
return Class.forName( |
jtulach@286 | 53 |
name, true, Accessor.class.getClassLoader() |
jtulach@286 | 54 |
); |
jtulach@286 | 55 |
} catch (Exception ex) { |
jtulach@286 | 56 |
throw new RuntimeException(ex); |
jtulach@286 | 57 |
} |
jtulach@286 | 58 |
} |
jtulach@286 | 59 |
// END: design.less.friend.InitAPI |
jtulach@0 | 60 |
} |