KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > naming > DefaultContextFactory


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jérôme Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.naming;
28
29 /** The console's imports */
30 import org.objectweb.util.browser.api.Context;
31 import org.objectweb.util.browser.api.Wrapper;
32 import org.objectweb.util.browser.core.api.Decoder;
33 import org.objectweb.util.browser.core.api.SpecificContextFactory;
34
35 /**
36  * Basic implementation for Context factories.
37  *
38  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
39  * @version 0.1
40  */

41 public class DefaultContextFactory implements SpecificContextFactory {
42
43     /** The name of the class to instanciate */
44     protected Class JavaDoc class_ = null;
45
46     /** The decoder */
47     protected Decoder decoder_ = null;
48
49     /**
50      * Default Constructor
51      * @param decoder The first link of the chain of decoder
52      */

53     public DefaultContextFactory(Decoder decoder) {
54         decoder_ = decoder;
55     }
56
57     /**
58      * Fix the class to instanciate.
59      * This class has to implemente Context and Wrapper interfaces.
60      *
61      * @param theClass The class to instanciate
62      */

63     public void setClassName(Class JavaDoc theClass) {
64         class_ = theClass;
65     }
66
67     /**
68      * Creates a new {@link Context Context} associated to an object.
69      *
70      * @return The created {@link Context Context}.
71      */

72     public Context newOWContext(Object JavaDoc object) {
73         if (class_ != null) {
74             try {
75                 Wrapper wrapper = (Wrapper) class_.newInstance();
76                 wrapper.setWrapped(object);
77                 if (decoder_ != null) {
78                     ContextDecoderManager interceptor = new ContextDecoderManager();
79                     interceptor.setDecoder(decoder_);
80                     interceptor.setDelegate((Context) wrapper);
81                     return interceptor;
82                 } else {
83                     return (Context) wrapper;
84                 }
85             } catch (InstantiationException JavaDoc e) {
86                 e.printStackTrace();
87             } catch (IllegalAccessException JavaDoc e) {
88                 e.printStackTrace();
89             }
90         }
91         return null;
92     }
93
94 }
95
Popular Tags