KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lateralnz > panther > container > Container


1 /* ====================================================================
2  * The LateralNZ Software License, Version 1.0
3  *
4  * Copyright (c) 2003 LateralNZ. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by
21  * LateralNZ (http://www.lateralnz.org/) and other third parties."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "LateralNZ" must not be used to endorse or promote
26  * products derived from this software without prior written
27  * permission. For written permission, please
28  * contact oss@lateralnz.org.
29  *
30  * 5. Products derived from this software may not be called "Panther",
31  * or "Lateral" or "LateralNZ", nor may "PANTHER" or "LATERAL" or
32  * "LATERALNZ" appear in their name, without prior written
33  * permission of LateralNZ.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of LateralNZ. For more
51  * information on Lateral, please see http://www.lateralnz.com/ or
52  * http://www.lateralnz.org
53  *
54  */

55 package org.lateralnz.panther.container;
56
57 import java.util.Properties JavaDoc;
58 import javax.naming.Context JavaDoc;
59 import javax.naming.InitialContext JavaDoc;
60
61 import org.apache.log4j.Logger;
62
63 import org.lateralnz.common.util.Constants;
64 import org.lateralnz.common.util.JNDIUtils;
65 import org.lateralnz.common.util.StringUtils;
66 import org.lateralnz.panther.util.ContextUtils;
67
68 /**
69  * base superclass for all(?) containers. This expects Properties and a parent
70  * object in the constructor.<br />
71  * Required properties are: deploy_directory, working_directory, and conf_directory<br />
72  * The parent object is required in case any container implementations require it
73  * for creating classloaders/whatever
74  *
75  * @author J R Briggs
76  */

77 public abstract class Container implements Constants {
78   private static final Logger log = Logger.getLogger(Container.class.getName());
79   
80   private static final String JavaDoc DEPLOY_DIRECTORY = "deploy_directory";
81   private static final String JavaDoc WORKING_DIRECTORY = "working_directory";
82   private static final String JavaDoc CONF_DIRECTORY = "conf_directory";
83
84  /**
85   * initial context
86   */

87   public static Context JavaDoc initContext = null;
88   
89   protected String JavaDoc pantherHome = null;
90   
91  /**
92   * working directory
93   */

94   protected String JavaDoc workingDir;
95   
96  /**
97   * files that will be deployed into the container will be found here
98   */

99   protected String JavaDoc deployDir;
100   
101  /**
102   * special configuration files for the container will be found here
103   */

104   protected String JavaDoc confDir;
105   
106   protected Context JavaDoc envContext;
107     
108  /**
109   * construct the container using the specified properties and parent object
110   */

111   public Container(Properties JavaDoc props, Object JavaDoc parent) throws Exception JavaDoc {
112     if (initContext == null) {
113       initContext = new InitialContext JavaDoc();
114     }
115     
116     envContext = ContextUtils.getCompEnv(initContext);
117     
118     workingDir = props.getProperty(WORKING_DIRECTORY);
119     if (!StringUtils.isEmpty(workingDir)) {
120       workingDir = StringUtils.toDirectory(workingDir);
121     }
122     
123     deployDir = props.getProperty(DEPLOY_DIRECTORY);
124     if (!StringUtils.isEmpty(deployDir)) {
125       deployDir = StringUtils.toDirectory(deployDir);
126     }
127     
128     confDir = props.getProperty(CONF_DIRECTORY);
129     if (!StringUtils.isEmpty(confDir)) {
130       confDir = StringUtils.toDirectory(confDir);
131     }
132
133     pantherHome = System.getProperty("PANTHER_HOME");
134     if (StringUtils.isEmpty(pantherHome)) {
135       pantherHome = System.getProperty("panther_home");
136     }
137     pantherHome = StringUtils.toDirectory(pantherHome);
138   }
139   
140 }
Popular Tags