KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > runtime > FactoryFinderServiceImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.corba.runtime;
31
32 /**
33  ** <p>Default implementation of the <tt>FactoryFinderService</tt> system service.</p>
34  **/

35 public class FactoryFinderServiceImpl
36 extends org.omg.CORBA.LocalObject JavaDoc
37 implements FactoryFinderService
38 {
39     // factory finder
40
static final private String JavaDoc _class_name = "FactoryFinderServiceImpl";
41     static final private String JavaDoc _service_id = FactoryFinderService.SERVICE_ID;
42     private java.util.Hashtable JavaDoc _factories;
43
44     // default constructor
45
public
46     FactoryFinderServiceImpl()
47     {
48         // factory finder
49
_factories = null;
50     }
51
52     //
53
// entry point
54
//
55

56     static public SystemService
57     create_service()
58     {
59         return new FactoryFinderServiceImpl();
60     }
61
62     //
63
// IDL:objectweb.org/corba/runtime/SystemComponent:1.0
64
//
65

66     final public void
67     system_configuration_complete(SystemConfiguration cfg)
68     {
69         _factories = new java.util.Hashtable JavaDoc();
70     }
71
72     final public void
73     destroy()
74     {
75         // destroy all enclosed factories
76
SystemComponent[] facts = (SystemComponent[])_factories.values().toArray(new SystemComponent[0]);
77         for (int i=0;i<facts.length;i++) {
78             facts[i].destroy();
79         }
80
81         // clear the table
82
_factories.clear();
83     }
84
85     //
86
// IDL:objectweb.org/corba/runtime/SystemService:1.0
87
//
88

89     final public String JavaDoc
90     service_id()
91     {
92         return _service_id;
93     }
94
95     //
96
// IDL:objectweb.org/corba/runtime/FactoryFinderService:1.0
97
//
98

99     final public void
100     register_service_factory(String JavaDoc ssid, String JavaDoc location, String JavaDoc entrypt)
101     {
102         // check if location is set
103
if (location!=null) {
104             // add archive location to class loader
105
TheClassLoader.addResource(location);
106         }
107
108         // create the factory
109
SystemFactory fact = (SystemFactory)TheClassLoader.newInstance(entrypt);
110
111         // check if created
112
if (fact==null) {
113             // NOTE: TODO: should be reported as an exception
114
final String JavaDoc opname = "register_service_factory";
115             final String JavaDoc msg = "FAILED (factory not created)";
116             TheLogger.error(_class_name, opname, msg);
117         }
118
119         // store
120
_factories.put(ssid, fact);
121     }
122
123     final public SystemFactory
124     find_service_factory(String JavaDoc ssid)
125     {
126         return (SystemFactory)_factories.get(ssid);
127     }
128 }
129
Popular Tags