KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > container > builder > ContainerDirector


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7  http://www.apache.org/licenses/LICENSE-2.0
8
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15
16 package com.jdon.container.builder;
17
18 import com.jdon.container.ContainerWrapper;
19 import com.jdon.util.Debug;
20
21 /**
22  * container director register order: 1. register all components in
23  * container.xml 2. register all components in aspect.xml 3. startup above all
24  * components 3. register user services in jdonframework.xml
25  *
26  *
27  * @author banq
28  */

29 public class ContainerDirector {
30     public final static String JavaDoc module = ContainerDirector.class.getName();
31
32     private ContainerBuilder cb;
33
34     private static Object JavaDoc initLock = new Object JavaDoc();
35
36     public ContainerDirector(ContainerBuilder cb) {
37         this.cb = cb;
38     }
39
40     /**
41      * prepare the applicaition configure files
42      *
43      * @param configureFileName
44      */

45     public void prepareConfiguration(String JavaDoc configureFileName) throws Exception JavaDoc {
46         if (!cb.isStartup())
47             cb.addAppConfigureFile(configureFileName);
48     }
49
50     public void startup() throws StartupException {
51         Debug.logVerbose("[JdonFramework] <======== JdonFramework beigin to startup =========>", module);
52         if (!cb.isStartup())
53             synchronized (initLock) {
54                 if (!cb.isStartup()) {
55                     try {
56                         Debug.logVerbose("[JdonFramework] <------ register the basic components in container.xml ------> ", module);
57                         cb.registerComponents();
58
59                         ContainerWrapper cw = cb.getContainerWrapper();
60                         cw.start();
61                         cb.setStartup(true);
62                         
63                         Debug.logVerbose("[JdonFramework] <------ started micro container ------> ", module);
64                  
65                         Debug.logVerbose("[JdonFramework] <------ register the pojo services in jdonframework.xml ------> ", module);
66                         cb.registerUserService();
67                         
68                         Debug.logVerbose("[JdonFramework] <------ register the aspect components in container.xml ------> ", module);
69                         cb.registerAspectComponents();
70                                                                                                 
71                         Debug.logInfo(" <======== Jdon Framework started successfully! =========>", module);
72
73                     } catch (Exception JavaDoc ex) {
74                         Debug.logError("[JdonFramework] startup container error: " + ex, module);
75                         throw new StartupException();
76                     }
77                 }
78             }
79
80     }
81
82 }
83
Popular Tags