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.e_app;
031:
032: import com.caucho.config.ConfigException;
033: import com.caucho.server.deploy.DeployContainer;
034: import com.caucho.server.deploy.ExpandDeployGenerator;
035: import com.caucho.server.webapp.WebAppContainer;
036: import com.caucho.vfs.Path;
037:
038: import java.util.ArrayList;
039:
040: /**
041: * The generator for the ear-deploy
042: */
043: public class EarDeployGenerator extends
044: ExpandDeployGenerator<EarDeployController> {
045: private final EarDeployGeneratorAdmin _admin = new EarDeployGeneratorAdmin(
046: this );
047:
048: private String _urlPrefix = "";
049:
050: private WebAppContainer _parentContainer;
051:
052: private EarConfig _earDefault;
053:
054: private ArrayList<EarConfig> _earDefaultList = new ArrayList<EarConfig>();
055:
056: public EarDeployGenerator(
057: DeployContainer<EarDeployController> deployContainer,
058: WebAppContainer parentContainer) {
059: super (deployContainer, parentContainer.getRootDirectory());
060:
061: try {
062: setExpandPrefix("_ear_");
063: setExtension(".ear");
064: } catch (Exception e) {
065: throw new RuntimeException(e);
066: }
067:
068: _parentContainer = parentContainer;
069:
070: _earDefaultList.addAll(parentContainer.getEarDefaultList());
071: }
072:
073: /**
074: * Returns the parent container;
075: */
076: WebAppContainer getContainer() {
077: return _parentContainer;
078: }
079:
080: /**
081: * Gets the URL prefix.
082: */
083: public String getURLPrefix() {
084: return _urlPrefix;
085: }
086:
087: /**
088: * Sets the URL prefix.
089: */
090: public void setURLPrefix(String prefix) {
091: _urlPrefix = prefix;
092: }
093:
094: /**
095: * Sets the ear default.
096: */
097: public void addEarDefault(EarConfig config) {
098: _earDefaultList.add(config);
099: }
100:
101: @Override
102: protected void initImpl() throws ConfigException {
103: super .initImpl();
104: }
105:
106: @Override
107: protected void startImpl() throws ConfigException {
108: super .startImpl();
109:
110: _admin.register();
111: }
112:
113: /**
114: * Converts the archive name to the entry name, returns null if
115: * the path name is not a valid entry name.
116: */
117: protected String archiveNameToEntryName(String archiveName) {
118: if (!archiveName.endsWith(".ear"))
119: return null;
120: else
121: return archiveName.substring(0, archiveName.length() - 4);
122: }
123:
124: /**
125: * Returns the current array of application entries.
126: */
127: public EarDeployController createController(String name) {
128: String archiveName = name + getExtension();
129: Path archivePath = getArchiveDirectory().lookup(archiveName);
130:
131: Path rootDirectory;
132:
133: if (archivePath.isDirectory()) {
134: rootDirectory = getExpandDirectory().lookup(archiveName);
135: archivePath = null;
136: } else {
137: rootDirectory = getExpandDirectory().lookup(
138: getExpandName(name));
139:
140: if (!archivePath.canRead() && !rootDirectory.canRead())
141: return null;
142: }
143:
144: EarDeployController controller = new EarDeployController(name,
145: rootDirectory, _parentContainer);
146:
147: controller.setArchivePath(archivePath);
148:
149: for (EarConfig config : _earDefaultList)
150: controller.addConfigDefault(config);
151:
152: return controller;
153: }
154:
155: @Override
156: protected void destroyImpl() {
157: _admin.unregister();
158:
159: super.destroyImpl();
160: }
161: }
|