01 
02 /*
03  *  JScripter Standard 1.0 - To Script In Java
04  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 package jsx;
21 
22 import js.Disposable;
23 import js.Initializer;
24 import js.ObjectLike;
25 
26 /**
27  * <p>An abstract base class for configurable objects.</p>
28  * <p>A configurable object typically keeps an {@link ObjectLike} object that is initialized 
29  * in a constructor of the {@link Configurable} object and is reconfigurable later.</p>
30  * <p>With the design of this class, its objects are all configurable in any of its 
31  * subclasses and behave much like what happens in JavaScript.</p>
32  * 
33  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
34  */
35 public abstract class Configurable extends Disposable
36 {
37     /**
38      * <p>The object holding the configuration data.</p>
39      * <p>Although it is very convenient to access this field of a configurable object from 
40      * the class of the object and its subclasses, the {@link #ini(Configurable)} method 
41      * makes it possible to access this field of a configurable object from any subclasses 
42      * of the {@link Configurable} class.</p>
43      * @since 1.0
44      * @see #ini(Configurable)
45      */
46     private ObjectLike ini;
47 
48     /**
49      * <p>The default constructor that may be invoked in the constructors of the subclasses 
50      * extending this class.</p>
51      * <p>This constructor does not set the {@link #ini} field and is only intended to be 
52      * invoked for the constructors of the subclasses extending this class to access the 
53      * {@link #ini(Configurable)} method.</p>
54      * @see #Configurable(ObjectLike ini)
55      * @see #ini(Configurable)
56      * @since 1.0
57      */
58     protected Configurable() {
59     }
60     /**
61      * <p>The typical constructor that may be invoked in the constructors of the subclasses 
62      * extending this class.</p>
63      * <p>This constructor forces constructors of its subclasses to invoke and pass the 
64      * initializing objects to it.</p>
65      * @param ini The initializing object that can also be created with an object literal 
66      * (see {@link Initializer}).
67      * @see #Configurable()
68      * @see #ini(Configurable)
69      * @since 1.0
70      */
71     protected Configurable(ObjectLike ini) {
72         this.ini = ini;
73     }
74 
75     /**
76      * <p>Gets the configuration data from a configurable object.</p>
77      * <p>Although it is very convenient to access the {@link #ini} field of a configurable 
78      * object from the class of the object and its subclasses, this method makes it possible 
79      * to access the {@link #ini} field of a configurable object from any subclasses of the 
80      * {@link Configurable} class.</p>
81      * @param o The configurable object. 
82      * @return The configuration data of the configurable object. 
83      * @since 1.0
84      * @see #ini
85      */
86     protected static final ObjectLike ini(Configurable o) {
87         return o.ini;
88     }
89 }