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