KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > services > deployment > DeploymentService


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.services.deployment;
23
24 import java.net.URL JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29
30 import org.jboss.system.ListenerServiceMBeanSupport;
31
32 /**
33  * @jmx:mbean
34  * extends="org.jboss.system.ListenerServiceMBean"
35  *
36  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
37  * @version $Revision: 42540 $
38  */

39 public class DeploymentService
40    extends ListenerServiceMBeanSupport
41    implements DeploymentServiceMBean
42 {
43    // Constants -----------------------------------------------------
44

45    /** where to look for templates */
46    public static final String JavaDoc DEFAULT_TEMPLATE_DIR = "conf/templates";
47
48    /** where modules are created/removed */
49    public static final String JavaDoc DEFAULT_UNDEPLOY_DIR = "undeploy";
50
51    /** where modules are moved for hot deployment */
52    public static final String JavaDoc DEFAULT_DEPLOY_DIR = "deploy";
53
54    // Private Data --------------------------------------------------
55

56    /** delegate responsible for doing the dirty work */
57    private DeploymentManager manager;
58
59    /** where factory templates should be found */
60    private String JavaDoc templateDir;
61
62    /** the directory to use for creating modules */
63    private String JavaDoc undeployDir;
64
65    /** the directory to use for deploying modules */
66    private String JavaDoc deployDir;
67
68    // Constructors --------------------------------------------------
69

70    /**
71     * CTOR
72    **/

73    public DeploymentService()
74    {
75       templateDir = DEFAULT_TEMPLATE_DIR;
76       undeployDir = DEFAULT_UNDEPLOY_DIR;
77       deployDir = DEFAULT_DEPLOY_DIR;
78    }
79
80    // MBean Attributes ----------------------------------------------
81

82    /**
83     * @jmx:managed-attribute
84     *
85     * @param templateDir The templateDir to set.
86     */

87    public void setTemplateDir(String JavaDoc templateDir)
88    {
89       this.templateDir = templateDir;
90    }
91
92    /**
93     * @jmx:managed-attribute
94     *
95     * @return Returns the templateDir.
96     */

97    public String JavaDoc getTemplateDir()
98    {
99       return templateDir;
100    }
101
102    /**
103     * @jmx:managed-attribute
104     */

105    public String JavaDoc getUndeployDir()
106    {
107       return undeployDir;
108    }
109
110    /**
111     * @jmx:managed-attribute
112     */

113    public void setUndeployDir(String JavaDoc undeployDir)
114    {
115       this.undeployDir = undeployDir;
116    }
117
118    /**
119     * @jmx:managed-attribute
120     */

121    public String JavaDoc getDeployDir()
122    {
123       return deployDir;
124    }
125
126    /**
127     * @jmx:managed-attribute
128     */

129    public void setDeployDir(String JavaDoc deployDir)
130    {
131       this.deployDir = deployDir;
132    }
133
134    // MBean Operations ----------------------------------------------
135

136    /**
137     * @jmx:managed-operation
138     */

139    public Set JavaDoc listModuleTemplates()
140    {
141       return manager.listModuleTemplates();
142    }
143
144    /**
145     * @jmx:managed-operation
146     */

147    public List JavaDoc getTemplatePropertyInfo(String JavaDoc template)
148       throws Exception JavaDoc
149    {
150       return manager.getTemplatePropertyInfo(template);
151    }
152
153    /**
154     * @jmx:managed-operation
155     */

156    public String JavaDoc createModule(String JavaDoc module, String JavaDoc template, HashMap JavaDoc properties)
157       throws Exception JavaDoc
158    {
159       return manager.createModule(module, template, properties);
160    }
161
162    /**
163     * Used primarily for testing through the jmx-console
164     *
165     * @jmx:managed-operation
166     */

167    public String JavaDoc createModule(String JavaDoc module, String JavaDoc template, String JavaDoc[] properties)
168       throws Exception JavaDoc
169    {
170       // load a hashmap with all key/values
171
HashMap JavaDoc map = new HashMap JavaDoc();
172
173       for (int i = 0; i < properties.length; i++)
174       {
175          StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(properties[i], "=");
176
177          String JavaDoc key = st.nextToken();
178          String JavaDoc value = st.nextToken();
179
180          if (value.indexOf('|') >= 0)
181          {
182             // treat value as a String array
183
StringTokenizer JavaDoc st2 = new StringTokenizer JavaDoc(value, "|");
184
185             int tokens = st2.countTokens();
186             String JavaDoc[] array = new String JavaDoc[tokens];
187             for (int j = 0; j < tokens; j++)
188                array[j] = st2.nextToken();
189
190             map.put(key, array);
191          }
192          else
193          {
194             map.put(key, value);
195          }
196       }
197       return manager.createModule(module, template, map);
198    }
199
200    /**
201     * @jmx:managed-operation
202     */

203    public boolean removeModule(String JavaDoc module)
204    {
205       return manager.removeModule(module);
206    }
207
208    /**
209     * @jmx:managed-operation
210     */

211    public boolean updateMBean(MBeanData data) throws Exception JavaDoc
212    {
213       return manager.updateMBean(data);
214    }
215
216    /**
217     * @jmx:managed-operation
218     */

219    public String JavaDoc updateDataSource(String JavaDoc module, String JavaDoc template, HashMap JavaDoc properties)
220       throws Exception JavaDoc
221    {
222       return manager.updateDataSource(module, template, properties);
223    }
224
225    /**
226     * @jmx:managed-operation
227     */

228    public String JavaDoc removeDataSource(String JavaDoc module, String JavaDoc template, HashMap JavaDoc properties)
229       throws Exception JavaDoc
230    {
231       return manager.removeDataSource(module, template, properties);
232    }
233
234    /**
235     * @jmx:managed-operation
236     */

237    public void deployModuleAsynch(String JavaDoc module)
238       throws Exception JavaDoc
239    {
240       manager.moveToDeployDir(module);
241    }
242
243    /**
244     * @jmx:managed-operation
245     */

246    public URL JavaDoc getDeployedURL(String JavaDoc module)
247       throws Exception JavaDoc
248    {
249       return manager.getDeployedURL(module);
250    }
251
252    /**
253     * @jmx:managed-operation
254     */

255    public void undeployModuleAsynch(String JavaDoc module)
256       throws Exception JavaDoc
257    {
258       manager.moveToModuleDir(module);
259    }
260
261    /**
262     * @jmx:managed-operation
263     */

264    public URL JavaDoc getUndeployedURL(String JavaDoc module)
265       throws Exception JavaDoc
266    {
267       return manager.getUndeployedURL(module);
268    }
269
270    /**
271     * Upload a new library to server lib dir. A different
272     * filename may be specified, when writing the library.
273     *
274     * If the target filename exists, upload is not performed.
275     *
276     * @jmx:managed-operation
277     *
278     * @param src the source url to copy
279     * @param filename the filename to use when copying (optional)
280     * @return true if upload was succesful, false otherwise
281     */

282    public boolean uploadLibrary(URL JavaDoc src, String JavaDoc filename)
283    {
284       return LibraryManager.getInstance().uploadLibrary(src, filename);
285    }
286
287    // MBean Lifecycle ----------------------------------------------
288

289    public void startService()
290       throws Exception JavaDoc
291    {
292       manager = new DeploymentManager(templateDir, undeployDir, deployDir, log);
293    }
294
295    public void stopService()
296    {
297       manager = null;
298    }
299
300 }
301
Popular Tags