001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.services.deployment;
023:
024: import java.net.URL;
025: import java.util.HashMap;
026: import java.util.List;
027: import java.util.Set;
028: import java.util.StringTokenizer;
029:
030: import org.jboss.system.ListenerServiceMBeanSupport;
031:
032: /**
033: * @jmx:mbean
034: * extends="org.jboss.system.ListenerServiceMBean"
035: *
036: * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
037: * @version $Revision: 57210 $
038: */
039: public class DeploymentService extends ListenerServiceMBeanSupport
040: implements DeploymentServiceMBean {
041: // Constants -----------------------------------------------------
042:
043: /** where to look for templates */
044: public static final String DEFAULT_TEMPLATE_DIR = "conf/templates";
045:
046: /** where modules are created/removed */
047: public static final String DEFAULT_UNDEPLOY_DIR = "undeploy";
048:
049: /** where modules are moved for hot deployment */
050: public static final String DEFAULT_DEPLOY_DIR = "deploy";
051:
052: // Private Data --------------------------------------------------
053:
054: /** delegate responsible for doing the dirty work */
055: private DeploymentManager manager;
056:
057: /** where factory templates should be found */
058: private String templateDir;
059:
060: /** the directory to use for creating modules */
061: private String undeployDir;
062:
063: /** the directory to use for deploying modules */
064: private String deployDir;
065:
066: // Constructors --------------------------------------------------
067:
068: /**
069: * CTOR
070: **/
071: public DeploymentService() {
072: templateDir = DEFAULT_TEMPLATE_DIR;
073: undeployDir = DEFAULT_UNDEPLOY_DIR;
074: deployDir = DEFAULT_DEPLOY_DIR;
075: }
076:
077: // MBean Attributes ----------------------------------------------
078:
079: /**
080: * @jmx:managed-attribute
081: *
082: * @param templateDir The templateDir to set.
083: */
084: public void setTemplateDir(String templateDir) {
085: this .templateDir = templateDir;
086: }
087:
088: /**
089: * @jmx:managed-attribute
090: *
091: * @return Returns the templateDir.
092: */
093: public String getTemplateDir() {
094: return templateDir;
095: }
096:
097: /**
098: * @jmx:managed-attribute
099: */
100: public String getUndeployDir() {
101: return undeployDir;
102: }
103:
104: /**
105: * @jmx:managed-attribute
106: */
107: public void setUndeployDir(String undeployDir) {
108: this .undeployDir = undeployDir;
109: }
110:
111: /**
112: * @jmx:managed-attribute
113: */
114: public String getDeployDir() {
115: return deployDir;
116: }
117:
118: /**
119: * @jmx:managed-attribute
120: */
121: public void setDeployDir(String deployDir) {
122: this .deployDir = deployDir;
123: }
124:
125: // MBean Operations ----------------------------------------------
126:
127: /**
128: * @jmx:managed-operation
129: */
130: public Set listModuleTemplates() {
131: return manager.listModuleTemplates();
132: }
133:
134: /**
135: * @jmx:managed-operation
136: */
137: public List getTemplatePropertyInfo(String template)
138: throws Exception {
139: return manager.getTemplatePropertyInfo(template);
140: }
141:
142: /**
143: * @jmx:managed-operation
144: */
145: public String createModule(String module, String template,
146: HashMap properties) throws Exception {
147: return manager.createModule(module, template, properties);
148: }
149:
150: /**
151: * Used primarily for testing through the jmx-console
152: *
153: * @jmx:managed-operation
154: */
155: public String createModule(String module, String template,
156: String[] properties) throws Exception {
157: // load a hashmap with all key/values
158: HashMap map = new HashMap();
159:
160: for (int i = 0; i < properties.length; i++) {
161: StringTokenizer st = new StringTokenizer(properties[i], "=");
162:
163: String key = st.nextToken();
164: String value = st.nextToken();
165:
166: if (value.indexOf('|') >= 0) {
167: // treat value as a String array
168: StringTokenizer st2 = new StringTokenizer(value, "|");
169:
170: int tokens = st2.countTokens();
171: String[] array = new String[tokens];
172: for (int j = 0; j < tokens; j++)
173: array[j] = st2.nextToken();
174:
175: map.put(key, array);
176: } else {
177: map.put(key, value);
178: }
179: }
180: return manager.createModule(module, template, map);
181: }
182:
183: /**
184: * @jmx:managed-operation
185: */
186: public boolean removeModule(String module) {
187: return manager.removeModule(module);
188: }
189:
190: /**
191: * @jmx:managed-operation
192: */
193: public void deployModuleAsynch(String module) throws Exception {
194: manager.moveToDeployDir(module);
195: }
196:
197: /**
198: * @jmx:managed-operation
199: */
200: public URL getDeployedURL(String module) throws Exception {
201: return manager.getDeployedURL(module);
202: }
203:
204: /**
205: * @jmx:managed-operation
206: */
207: public void undeployModuleAsynch(String module) throws Exception {
208: manager.moveToModuleDir(module);
209: }
210:
211: /**
212: * @jmx:managed-operation
213: */
214: public URL getUndeployedURL(String module) throws Exception {
215: return manager.getUndeployedURL(module);
216: }
217:
218: /**
219: * Upload a new library to server lib dir. A different
220: * filename may be specified, when writing the library.
221: *
222: * If the target filename exists, upload is not performed.
223: *
224: * @jmx:managed-operation
225: *
226: * @param src the source url to copy
227: * @param filename the filename to use when copying (optional)
228: * @return true if upload was succesful, false otherwise
229: */
230: public boolean uploadLibrary(URL src, String filename) {
231: return LibraryManager.getInstance()
232: .uploadLibrary(src, filename);
233: }
234:
235: // MBean Lifecycle ----------------------------------------------
236:
237: public void startService() throws Exception {
238: manager = new DeploymentManager(templateDir, undeployDir,
239: deployDir, log);
240: }
241:
242: public void stopService() {
243: manager = null;
244: }
245:
246: }
|