001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.host;
031:
032: import com.caucho.config.Config;
033: import com.caucho.log.Log;
034: import com.caucho.server.deploy.DeployContainer;
035: import com.caucho.server.deploy.DeployGenerator;
036:
037: import java.util.Set;
038: import java.util.logging.Logger;
039:
040: /**
041: * The generator for the host deploy
042: */
043: public class HostSingleDeployGenerator extends
044: DeployGenerator<HostController> {
045: private static final Logger log = Log
046: .open(HostSingleDeployGenerator.class);
047:
048: private HostContainer _container;
049:
050: private HostConfig _config;
051:
052: private HostController _controller;
053:
054: /**
055: * Creates the new host deploy.
056: */
057: public HostSingleDeployGenerator(
058: DeployContainer<HostController> container) {
059: super (container);
060: }
061:
062: /**
063: * Creates the new host deploy.
064: */
065: public HostSingleDeployGenerator(
066: DeployContainer<HostController> container,
067: HostContainer hostContainer, HostConfig config)
068: throws Exception {
069: super (container);
070:
071: _container = hostContainer;
072:
073: _config = config;
074:
075: init();
076: }
077:
078: /**
079: * Gets the host container.
080: */
081: public HostContainer getContainer() {
082: return _container;
083: }
084:
085: /**
086: * Gets the parent loader.
087: */
088: public ClassLoader getParentClassLoader() {
089: return _container.getClassLoader();
090: }
091:
092: /**
093: * Returns the log.
094: */
095: protected Logger getLog() {
096: return log;
097: }
098:
099: /**
100: * Initializes the entry.
101: */
102: @Override
103: public void initImpl() {
104: super .initImpl();
105:
106: String hostName = null;
107: String id = null;
108:
109: String rawId = _config.getId();
110: String rawHostName = _config.getHostName();
111:
112: if (rawId != null) {
113: id = Config.evalString(rawId);
114:
115: if (id.equals("*")) // server/1f20
116: id = "";
117: }
118:
119: if (rawHostName != null) {
120: hostName = Config.evalString(rawHostName);
121:
122: if (rawHostName.equals("*")) // server/1f20
123: hostName = "";
124: }
125:
126: if (hostName != null) {
127: _controller = new HostController(hostName, _config,
128: _container, null);
129:
130: if (id != null)
131: _controller.addHostAlias(id);
132: } else if (id != null)
133: _controller = new HostController(id, _config, _container,
134: null);
135: else
136: _controller = new HostController("", _config, _container,
137: null);
138: }
139:
140: /**
141: * Returns the deployed keys.
142: */
143: protected void fillDeployedKeys(Set<String> keys) {
144: keys.add(_controller.getName());
145: }
146:
147: /**
148: * Returns the current array of application entries.
149: */
150: public HostController generateController(String name) {
151: if (_controller.isNameMatch(name)) {
152: return new HostController(_controller.getName(), _config,
153: _container, null);
154: } else
155: return null;
156: }
157:
158: /**
159: * Merges the controllers.
160: */
161: public HostController mergeController(HostController controller,
162: String name) {
163: /*
164: // if directory matches, merge them
165: if (controller.getRootDirectory().equals(_controller.getRootDirectory()))
166: return controller.merge(_controller);
167: */
168: // If the names match, merge the controller
169: if (_controller.isNameMatch(name))
170: return controller.merge(_controller);
171: else
172: return controller;
173: }
174:
175: public Throwable getConfigException() {
176: Throwable configException = super .getConfigException();
177:
178: if (configException == null && _controller != null)
179: configException = _controller.getConfigException();
180:
181: return configException;
182: }
183:
184: public String toString() {
185: if (_config == null)
186: return "HostSingleDeployGenerator[]";
187: else
188: return "HostSingleDeployGenerator[" + _config.getHostName()
189: + "]";
190: }
191: }
|