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.resin;
031:
032: import com.caucho.config.program.ConfigProgram;
033: import com.caucho.config.program.ContainerProgram;
034: import com.caucho.config.SchemaBean;
035: import com.caucho.server.cluster.Cluster;
036: import com.caucho.server.cluster.ClusterServer;
037: import com.caucho.server.port.Port;
038: import com.caucho.util.L10N;
039:
040: import javax.annotation.PostConstruct;
041: import java.util.ArrayList;
042: import java.util.logging.Logger;
043:
044: /**
045: * Compatiblity configuration for Resin 3.0-style configuration.
046: */
047: public class ServerCompatConfig implements SchemaBean {
048: private static final L10N L = new L10N(ServerCompatConfig.class);
049: private static final Logger log = Logger
050: .getLogger(ServerCompatConfig.class.getName());
051:
052: private final Resin _resin;
053:
054: private ArrayList<HttpCompatConfig> _httpList = new ArrayList<HttpCompatConfig>();
055:
056: private ContainerProgram _program = new ContainerProgram();
057:
058: /**
059: * Creates a new resin server.
060: */
061: public ServerCompatConfig(Resin resin) {
062: if (resin == null)
063: throw new NullPointerException();
064:
065: _resin = resin;
066: }
067:
068: /**
069: * Returns the relax schema.
070: */
071: public String getSchema() {
072: return "com/caucho/server/resin/server.rnc";
073: }
074:
075: public void addBuilderProgram(ConfigProgram program) {
076: _program.addProgram(program);
077: }
078:
079: /**
080: * Creates a http compat.
081: */
082:
083: public HttpCompatConfig createHttp() {
084: HttpCompatConfig http = new HttpCompatConfig();
085:
086: return http;
087: }
088:
089: /**
090: * Creates a cluster compat.
091: */
092: public ClusterCompatConfig createCluster() {
093: return new ClusterCompatConfig(_resin);
094: }
095:
096: @PostConstruct
097: public void init() {
098: try {
099: String serverId = _resin.getServerId();
100:
101: ClusterServer clusterServer = _resin
102: .findClusterServer(serverId);
103:
104: if (clusterServer != null) {
105: } else {
106: if (_resin.getClusterList().size() > 0
107: || !"".equals(serverId)) {
108: log
109: .warning(L
110: .l(
111: "-server '{0}' does not match any defined servers",
112: serverId));
113: }
114:
115: Cluster cluster = _resin.createCluster();
116: _resin.addCluster(cluster);
117:
118: clusterServer = cluster.createServer();
119:
120: clusterServer.setPort(0);
121:
122: cluster.addServer(clusterServer);
123: }
124:
125: _program.configure(clusterServer.getCluster());
126: } catch (RuntimeException e) {
127: throw e;
128: } catch (Throwable e) {
129: throw new RuntimeException(e);
130: }
131: }
132:
133: public class HttpCompatConfig {
134: private String _id = "";
135:
136: private ContainerProgram _program = new ContainerProgram();
137:
138: HttpCompatConfig() {
139: }
140:
141: public void setId(String id) {
142: _id = id;
143: }
144:
145: public void setServerId(String id) {
146: setId(id);
147: }
148:
149: public void addBuilderProgram(ConfigProgram program) {
150: _program.addProgram(program);
151: }
152:
153: @PostConstruct
154: public void init() throws Throwable {
155: ClusterServer server = _resin.findClusterServer(_id);
156:
157: if (server == null) {
158: Cluster cluster = _resin.findCluster("");
159:
160: if (cluster == null) {
161: cluster = _resin.createCluster();
162: _resin.addCluster(cluster);
163: }
164:
165: server = cluster.createServer();
166: server.setId(_id);
167: server.getClusterPort().setPort(0);
168: cluster.addServer(server);
169: }
170:
171: Port http = server.createHttp();
172: _program.configure(http);
173: }
174: }
175: }
|