KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > samples > parentcm > Configurator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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.apache.cocoon.samples.parentcm;
17
18 import org.apache.avalon.excalibur.naming.memory.MemoryInitialContextFactory;
19 import org.apache.avalon.framework.configuration.DefaultConfiguration;
20
21 import javax.naming.Context JavaDoc;
22 import javax.naming.InitialContext JavaDoc;
23 import java.util.Hashtable JavaDoc;
24
25 /**
26  * This class sets up the configuration used by the ParentComponentManager sample.
27  * The class also holds a reference to the initial context in which the configuration
28  * is available.
29  * <p>
30  * The configuration is bound to <code>org/apache/cocoon/samples/parentcm/ParentCMConfiguration</code>.
31  *
32  * @author <a HREF="mailto:leo.sutic@inspireinfrastructure.com">Leo Sutic</a>
33  * @version CVS $Id: Configurator.java 30932 2004-07-29 17:35:38Z vgritsenko $
34  */

35 public class Configurator {
36
37     /**
38      * The Excalibur in-memory JNDI directory. Since the directory doesn't
39      * provide any persistence we must keep a reference to the initial context
40      * as a static member to avoid passing it around.
41      */

42     public static Context JavaDoc initialContext = null;
43
44     static {
45         try {
46             //
47
// Create a new role.
48
//
49
DefaultConfiguration config = new DefaultConfiguration("roles", "");
50             DefaultConfiguration timeComponent = new DefaultConfiguration("role", "roles");
51             timeComponent.addAttribute("name", Time.ROLE);
52             timeComponent.addAttribute("default-class", TimeComponent.class.getName());
53             timeComponent.addAttribute("shorthand", "samples-parentcm-time");
54             config.addChild(timeComponent);
55
56             //
57
// Bind it - get an initial context.
58
//
59
Hashtable JavaDoc environment = new Hashtable JavaDoc();
60             environment.put(Context.INITIAL_CONTEXT_FACTORY, MemoryInitialContextFactory.class.getName());
61             initialContext = new InitialContext JavaDoc(environment);
62
63             //
64
// Create subcontexts and bind the configuration.
65
//
66
Context JavaDoc ctx = initialContext.createSubcontext("org");
67             ctx = ctx.createSubcontext("apache");
68             ctx = ctx.createSubcontext("cocoon");
69             ctx = ctx.createSubcontext("samples");
70             ctx = ctx.createSubcontext("parentcm");
71             ctx.rebind("ParentCMConfiguration", config);
72         } catch (Exception JavaDoc e) {
73             e.printStackTrace(System.err);
74         }
75     }
76 }
77
78
Popular Tags