samples/friendpackage/src/implpkg/Accessor.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:08 +0200
changeset 153 b5cbb797ec0a
parent 132 3bc4c54f4bcc
child 154 0fd5e9c500b9
permissions -rw-r--r--
up to line 2000
     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             return a;
    30         }
    31         
    32         try {
    33             Class.forName(Item.class.getName(), true, Item.class.getClassLoader());
    34         } catch (Exception ex) {
    35             ex.printStackTrace();
    36         }
    37         
    38         return DEFAULT;
    39     }
    40 
    41     public static void setDefault(Accessor accessor) {
    42         if (DEFAULT != null) {
    43             throw new IllegalStateException();
    44         }
    45         DEFAULT = accessor;
    46     }
    47     
    48     public Accessor() {
    49     }
    50 
    51     protected abstract Item newItem();
    52     protected abstract void addChangeListener(Item item, ChangeListener l);
    53 }
    54 // END: design.less.friend.Accessor