KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > host > HostSingleDeployGenerator


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.server.host;
31
32 import com.caucho.config.Config;
33 import com.caucho.log.Log;
34 import com.caucho.server.deploy.DeployContainer;
35 import com.caucho.server.deploy.DeployGenerator;
36
37 import java.util.Set JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39
40 /**
41  * The generator for the host deploy
42  */

43 public class HostSingleDeployGenerator
44   extends DeployGenerator<HostController> {
45   private static final Logger JavaDoc log = Log.open(HostSingleDeployGenerator.class);
46
47   private HostContainer _container;
48
49   private HostConfig _config;
50
51   private HostController _controller;
52
53   /**
54    * Creates the new host deploy.
55    */

56   public HostSingleDeployGenerator(DeployContainer<HostController> container)
57   {
58     super(container);
59   }
60
61   /**
62    * Creates the new host deploy.
63    */

64   public HostSingleDeployGenerator(DeployContainer<HostController> container,
65               HostContainer hostContainer, HostConfig config)
66     throws Exception JavaDoc
67   {
68     super(container);
69     
70     _container = hostContainer;
71
72     _config = config;
73
74     init();
75   }
76
77   /**
78    * Gets the host container.
79    */

80   public HostContainer getContainer()
81   {
82     return _container;
83   }
84
85   /**
86    * Gets the parent loader.
87    */

88   public ClassLoader JavaDoc getParentClassLoader()
89   {
90     return _container.getClassLoader();
91   }
92
93   /**
94    * Returns the log.
95    */

96   protected Logger JavaDoc getLog()
97   {
98     return log;
99   }
100
101   /**
102    * Initializes the entry.
103    */

104   @Override JavaDoc
105   public void initImpl()
106   {
107     super.initImpl();
108
109     String JavaDoc hostName = null;
110     String JavaDoc id = null;
111     
112     String JavaDoc rawId = _config.getId();
113     String JavaDoc rawHostName = _config.getHostName();
114
115     if (rawId != null) {
116       id = Config.evalString(rawId);
117
118       if (id.equals("*")) // server/1f20
119
id = "";
120     }
121
122     if (rawHostName != null) {
123       hostName = Config.evalString(rawHostName);
124
125       if (rawHostName.equals("*")) // server/1f20
126
hostName = "";
127     }
128
129     if (hostName != null) {
130       _controller = new HostController(hostName, _config, _container, null);
131
132       if (id != null)
133     _controller.addHostAlias(id);
134     }
135     else if (id != null)
136       _controller = new HostController(id, _config, _container, null);
137     else
138       _controller = new HostController("", _config, _container, null);
139   }
140
141   /**
142    * Returns the deployed keys.
143    */

144   protected void fillDeployedKeys(Set JavaDoc<String JavaDoc> keys)
145   {
146     keys.add(_controller.getName());
147   }
148   
149   /**
150    * Returns the current array of application entries.
151    */

152   public HostController generateController(String JavaDoc name)
153   {
154     if (_controller.isNameMatch(name)) {
155       return new HostController(_controller.getName(), _config,
156                 _container, null);
157     }
158     else
159       return null;
160   }
161   
162   /**
163    * Merges the controllers.
164    */

165   public HostController mergeController(HostController controller,
166                     String JavaDoc name)
167   {
168     /*
169     // if directory matches, merge them
170     if (controller.getRootDirectory().equals(_controller.getRootDirectory()))
171       return controller.merge(_controller);
172     */

173     // If the names match, merge the controller
174
if (_controller.isNameMatch(name))
175       return controller.merge(_controller);
176     else
177       return controller;
178   }
179
180   public Throwable JavaDoc getConfigException()
181   {
182     Throwable JavaDoc configException = super.getConfigException();
183
184     if (configException == null && _controller != null)
185       configException = _controller.getConfigException();
186
187     return configException;
188   }
189
190   public String JavaDoc toString()
191   {
192     if (_config == null)
193       return "HostSingleDeployGenerator[]";
194     else
195       return "HostSingleDeployGenerator[" + _config.getHostName() + "]";
196   }
197 }
198
Popular Tags