01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.samples.parentcm;
18:
19: import org.apache.avalon.excalibur.naming.memory.MemoryInitialContextFactory;
20: import org.apache.avalon.framework.configuration.DefaultConfiguration;
21:
22: import javax.naming.Context;
23: import javax.naming.InitialContext;
24: import java.util.Hashtable;
25:
26: /**
27: * This class sets up the configuration used by the ParentComponentManager sample.
28: * The class also holds a reference to the initial context in which the configuration
29: * is available.
30: * <p>
31: * The configuration is bound to <code>org/apache/cocoon/samples/parentcm/ParentCMConfiguration</code>.
32: *
33: * @author <a href="mailto:leo.sutic@inspireinfrastructure.com">Leo Sutic</a>
34: * @version CVS $Id: Configurator.java 433543 2006-08-22 06:22:54Z crossley $
35: */
36: public class Configurator {
37:
38: /**
39: * The Excalibur in-memory JNDI directory. Since the directory doesn't
40: * provide any persistence we must keep a reference to the initial context
41: * as a static member to avoid passing it around.
42: */
43: public static Context initialContext = null;
44:
45: static {
46: try {
47: //
48: // Create a new role.
49: //
50: DefaultConfiguration config = new DefaultConfiguration(
51: "roles", "");
52: DefaultConfiguration timeComponent = new DefaultConfiguration(
53: "role", "roles");
54: timeComponent.addAttribute("name", Time.ROLE);
55: timeComponent.addAttribute("default-class",
56: TimeComponent.class.getName());
57: timeComponent.addAttribute("shorthand",
58: "samples-parentcm-time");
59: config.addChild(timeComponent);
60:
61: //
62: // Bind it - get an initial context.
63: //
64: Hashtable environment = new Hashtable();
65: environment.put(Context.INITIAL_CONTEXT_FACTORY,
66: MemoryInitialContextFactory.class.getName());
67: initialContext = new InitialContext(environment);
68:
69: //
70: // Create subcontexts and bind the configuration.
71: //
72: Context ctx = initialContext.createSubcontext("org");
73: ctx = ctx.createSubcontext("apache");
74: ctx = ctx.createSubcontext("cocoon");
75: ctx = ctx.createSubcontext("samples");
76: ctx = ctx.createSubcontext("parentcm");
77: ctx.rebind("ParentCMConfiguration", config);
78: } catch (Exception e) {
79: e.printStackTrace(System.err);
80: }
81: }
82: }
|