KickJava   Java API By Example, From Geeks To Geeks.

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


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.config.ConfigELContext;
34 import com.caucho.config.ConfigException;
35 import com.caucho.config.types.RawString;
36 import com.caucho.el.EL;
37 import com.caucho.el.MapVariableResolver;
38 import com.caucho.log.Log;
39 import com.caucho.server.deploy.DeployContainer;
40 import com.caucho.server.deploy.ExpandDeployGenerator;
41 import com.caucho.vfs.Path;
42
43 import javax.el.ELContext;
44 import javax.el.ELResolver;
45 import java.util.ArrayList JavaDoc;
46 import java.util.logging.Level JavaDoc;
47 import java.util.logging.Logger JavaDoc;
48
49 /**
50  * The generator for the host deploy
51  */

52 public class HostExpandDeployGenerator extends ExpandDeployGenerator<HostController> {
53   private static final Logger JavaDoc log = Log.open(HostExpandDeployGenerator.class);
54
55   private final HostExpandDeployGeneratorAdmin _admin = new HostExpandDeployGeneratorAdmin(this);
56
57   private HostContainer _container;
58
59   private ArrayList JavaDoc<HostConfig> _hostDefaults = new ArrayList JavaDoc<HostConfig>();
60
61   private String JavaDoc _hostName;
62
63   /**
64    * Creates the new host deploy.
65    */

66   public HostExpandDeployGenerator(DeployContainer<HostController> container,
67               HostContainer hostContainer)
68   {
69     super(container, hostContainer.getRootDirectory());
70     
71     _container = hostContainer;
72   }
73
74   /**
75    * Gets the host container.
76    */

77   public HostContainer getContainer()
78   {
79     return _container;
80   }
81
82   /**
83    * Sets the host name.
84    */

85   public void setHostName(RawString name)
86   {
87     _hostName = name.getValue();
88   }
89
90   /**
91    * Gets the host name.
92    */

93   public String JavaDoc getHostName()
94   {
95     return _hostName;
96   }
97
98   /**
99    * Sets true for a lazy-init.
100    */

101   public void setLazyInit(boolean lazyInit)
102     throws ConfigException
103   {
104     log.config("lazy-init is deprecated. Use <startup>lazy</startup> instead.");
105     if (lazyInit)
106       setStartupMode("lazy");
107     else
108       setStartupMode("automatic");
109   }
110
111   /**
112    * Adds a default.
113    */

114   public void addHostDefault(HostConfig config)
115   {
116     _hostDefaults.add(config);
117   }
118
119   @Override JavaDoc
120   protected void initImpl()
121     throws ConfigException
122   {
123     super.initImpl();
124   }
125
126   @Override JavaDoc
127   protected void startImpl()
128     throws ConfigException
129   {
130     super.startImpl();
131
132     _admin.register();
133   }
134
135   /**
136    * Returns the log.
137    */

138   protected Logger JavaDoc getLog()
139   {
140     return log;
141   }
142
143   /**
144    * Returns the current array of application entries.
145    */

146   public HostController createController(String JavaDoc name)
147   {
148     // server/13g3
149
if (name.equals(""))
150       return null;
151     
152     /*
153     if (! isDeployedKey(name))
154       return null;
155     */

156     
157     Path rootDirectory = getExpandDirectory().lookup("./" + name);
158
159     HostController controller
160       = new HostController(name, rootDirectory, _container);
161
162
163     Path jarPath = getArchiveDirectory().lookup("./" + name + ".jar");
164     controller.setArchivePath(jarPath);
165     
166     if (rootDirectory.isDirectory() &&
167     ! isValidDirectory(rootDirectory, name))
168       return null;
169     else if (! rootDirectory.isDirectory() &&
170          ! jarPath.isFile())
171       return null;
172
173     try {
174       String JavaDoc hostName = getHostName();
175
176       if (hostName != null) {
177     ELContext parentEnv = Config.getEnvironment();
178     ELResolver resolver
179       = new MapVariableResolver(controller.getVariableMap());
180
181     ELContext env = new ConfigELContext(resolver);
182     
183     controller.setHostName(EL.evalString(hostName, env));
184       }
185       else
186     controller.setHostName(name);
187
188       controller.addDepend(jarPath);
189     } catch (Throwable JavaDoc e) {
190       controller.setConfigException(e);
191       
192       log.log(Level.WARNING, e.toString(), e);
193     }
194
195     return controller;
196   }
197
198   
199   /**
200    * Adds configuration to the current controller
201    */

202   protected HostController mergeController(HostController controller,
203                        String JavaDoc key)
204   {
205     try {
206       controller.setStartupMode(getStartupMode());
207     
208       for (int i = 0; i < _hostDefaults.size(); i++)
209     controller.addConfigDefault(_hostDefaults.get(i));
210     } catch (ConfigException e) {
211       controller.setConfigException(e);
212       
213       log.warning(e.toString());
214       log.log(Level.FINER, e.toString(), e);
215     } catch (Throwable JavaDoc e) {
216       controller.setConfigException(e);
217       
218       log.log(Level.WARNING, e.toString(), e);
219     }
220
221     return controller;
222   }
223
224   @Override JavaDoc
225   protected void destroyImpl()
226   {
227     _admin.unregister();
228
229     super.destroyImpl();
230   }
231
232   public boolean equals(Object JavaDoc o)
233   {
234     if (o == null || ! getClass().equals(o.getClass()))
235       return false;
236
237     HostExpandDeployGenerator deploy = (HostExpandDeployGenerator) o;
238
239     Path expandPath = getExpandDirectory();
240     Path deployExpandPath = deploy.getExpandDirectory();
241     if (expandPath != deployExpandPath &&
242     (expandPath == null || ! expandPath.equals(deployExpandPath)))
243       return false;
244
245     return true;
246   }
247
248   public String JavaDoc toString()
249   {
250     return "HostExpandDeployGenerator[" + getExpandDirectory() + "]";
251   }
252 }
253
Popular Tags