KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > model > instanciation > DefaultInstanciationStrategy


1 /**
2  * Copyright (C) 2002 Kelua SA
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package org.objectweb.kilim.model.instanciation;
20
21 import java.util.HashMap JavaDoc;
22
23 import org.objectweb.kilim.KilimException;
24
25 /**
26  * This class is a simple container dedicated to the definition of instanciation strategies. It is used by the component
27  * factory to find the instanciation manager to be associated to each application component. It is possible to redefine
28  * a default instanciation manager, and to define per template managers and per instance managers.
29  * The factory uses the following look up strategy. The search is stopped as soon as a manager is found.
30  * the component factory first looks for a manager explicitely associated to the component.
31  * If none can be found, it then looks for a manager explicitely associated to the component template.
32  * If none can be found, it recursively looks for a manager explicitely associated to super templates.
33  * If none can be found it looks for a default manager.
34  *
35  * No null value can be returned, since this class defines a NAryPreInstanciationMger as default instanciation manager
36  * and no null value is accepted by the setDefaultMger().
37  * @author horn
38  */

39
40 public class DefaultInstanciationStrategy implements InstanciationStrategy {
41     private InstanciationMger defaultMger = new BDUInstanciationMger();
42     private HashMap JavaDoc perTemplateMger;
43     private HashMap JavaDoc perInstanceMger;
44     
45     /**
46      * @see java.lang.Object#Object()
47      */

48     public DefaultInstanciationStrategy() throws KilimException {
49     }
50     
51     /**
52      * Method InstanciationStrategy.
53      * @param aMger : a default instanciation manager (this ctor just contains a call to setDefaultManager(aMger)
54      * @throws KilimException : generated if the reference is null. A NullInstanciationMger should be indicated if
55      * no action should be performed at instanciation time.
56      */

57     public DefaultInstanciationStrategy(InstanciationMger aMger) throws KilimException {
58         setDefaultMger(aMger);
59     }
60
61     /**
62      * @see org.objectweb.kilim.model.services.InstanciationStrategy#setDefaultMger(InstanciationMger)
63      */

64     public void setDefaultMger(InstanciationMger aMger) throws KilimException {
65         if (aMger == null) {
66             throw new KilimException("attempt to install a null instanciation manager as default");
67         }
68         defaultMger = aMger;
69     }
70     
71     /**
72      * @see org.objectweb.kilim.model.services.InstanciationStrategy#getDefaultMger()
73      */

74     public InstanciationMger getDefaultMger() {
75         return defaultMger;
76     }
77
78     /**
79      * @see org.objectweb.kilim.model.services.InstanciationStrategy#setPerTemplateMger(String, InstanciationMger)
80      */

81     public void setPerTemplateMger(String JavaDoc aName, InstanciationMger aManager) throws KilimException {
82         if (aName == null) {
83             throw new KilimException("attempt to install a manager for template through a null name");
84         }
85
86         if (perTemplateMger == null) {
87             perTemplateMger = new HashMap JavaDoc();
88         }
89         perTemplateMger.put(aName, aManager);
90     }
91     
92     /**
93      * @see org.objectweb.kilim.model.services.InstanciationStrategy#getPerTemplateMger(String)
94      */

95     public InstanciationMger getPerTemplateMger(String JavaDoc aName) throws KilimException {
96         if (aName == null) {
97             throw new KilimException("attempt to get a template manager through a null name ");
98         }
99         
100         if (perTemplateMger == null) {
101             return null;
102         }
103         return (InstanciationMger) perTemplateMger.get(aName);
104     }
105
106     /**
107      * @see org.objectweb.kilim.model.services.InstanciationStrategy#setPerInstanceMger(String, InstanciationMger)
108      */

109     public void setPerInstanceMger(String JavaDoc aName, InstanciationMger aManager) throws KilimException {
110         if (aManager == null) {
111             throw new KilimException("attempt to install a null instanciation manager for template " + aName);
112         }
113
114         if (perInstanceMger == null) {
115             perInstanceMger = new HashMap JavaDoc();
116         }
117         perInstanceMger.put(aName, aManager);
118     }
119     
120     /**
121      * @see org.objectweb.kilim.model.services.InstanciationStrategy#getPerInstanceMger(String)
122      */

123     public InstanciationMger getPerInstanceMger(String JavaDoc aName) throws KilimException {
124         if (aName == null) {
125             throw new KilimException("attempt to get a instance manager through a null name ");
126         }
127         
128         if (perInstanceMger == null) {
129             return null;
130         }
131         return (InstanciationMger) perInstanceMger.get(aName);
132     }
133 }
134
Popular Tags