KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > components > DaisyComponentManager


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

16 package org.outerj.daisy.frontend.components;
17
18 import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
19 import org.apache.avalon.framework.activity.Initializable;
20 import org.apache.avalon.framework.activity.Disposable;
21 import org.apache.avalon.framework.component.Component;
22 import org.apache.avalon.framework.component.ComponentException;
23 import org.apache.avalon.framework.component.ComponentManager;
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
26 import org.apache.avalon.framework.context.DefaultContext;
27 import org.apache.avalon.framework.context.Contextualizable;
28 import org.apache.avalon.framework.context.Context;
29 import org.apache.avalon.framework.context.ContextException;
30 import org.apache.avalon.framework.logger.LogEnabled;
31 import org.apache.avalon.framework.logger.Logger;
32 import org.outerj.daisy.configutil.PropertyResolver;
33 import org.outerj.daisy.frontend.util.WikiDataDirHelper;
34
35 /**
36  * This component manager gets configured as 'parent component manager' in Cocoon.
37  * It is initialized with the daisy.xconf from the wikidata directory.
38  */

39 public class DaisyComponentManager implements ComponentManager, Initializable, LogEnabled, Disposable, Contextualizable {
40
41     private final String JavaDoc confFileName;
42     private Logger logger;
43     private Context context;
44
45     private final ExcaliburComponentManager delegate;
46
47     public DaisyComponentManager (String JavaDoc confFileName) {
48         this.confFileName = confFileName;;
49         delegate = new ExcaliburComponentManager();
50     }
51
52     public void contextualize(Context context) throws ContextException {
53         this.context = context;
54     }
55
56     public Component lookup(String JavaDoc role) throws ComponentException {
57         return this.delegate.lookup(role);
58     }
59
60     public boolean hasComponent(String JavaDoc role) {
61         return delegate.hasComponent(role);
62     }
63
64     public void release(Component component) {
65         this.delegate.release(component);
66     }
67
68     public void initialize() throws Exception JavaDoc {
69         DefaultConfigurationBuilder configBuilder = new DefaultConfigurationBuilder();
70         String JavaDoc resolvedConfFileName = PropertyResolver.resolveProperties(confFileName, WikiDataDirHelper.getResolveProperties(context));
71         Configuration config = configBuilder.buildFromFile(resolvedConfFileName);
72
73         this.delegate.enableLogging(logger);
74         this.delegate.contextualize(context);
75         this.delegate.configure(config);
76         this.delegate.initialize();
77
78         this.logger.debug("Daisy Component manager successfully initialized.");
79     }
80
81     public void enableLogging(Logger logger) {
82         this.logger = logger;
83     }
84
85     public void dispose() {
86         delegate.dispose();
87     }
88 }
89
Popular Tags