KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > deploy > DeployConfig


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.server.deploy;
31
32 import com.caucho.config.BuilderProgram;
33 import com.caucho.config.BuilderProgramContainer;
34 import com.caucho.config.ConfigException;
35 import com.caucho.config.ObjectAttributeProgram;
36 import com.caucho.config.types.PathBuilder;
37 import com.caucho.config.types.Period;
38 import com.caucho.config.types.RawString;
39 import com.caucho.vfs.Path;
40 import com.caucho.vfs.Vfs;
41
42 import java.util.Map JavaDoc;
43 import java.util.logging.Level JavaDoc;
44 import java.util.logging.Logger JavaDoc;
45
46 /**
47  * The configuration for a deployable instance.
48  */

49 public class DeployConfig {
50   private final static Logger JavaDoc log
51     = Logger.getLogger(DeployConfig.class.getName());
52
53   // The deploy id
54
private String JavaDoc _id = "";
55
56   // The root directory
57
private String JavaDoc _rootDirectory;
58
59   // The archive path;
60
private String JavaDoc _archivePath;
61
62   // startup mode
63
private String JavaDoc _startupMode;
64
65   // redeploy mode
66
private String JavaDoc _redeployMode;
67   
68   // redeploy period
69
private Period _redeployCheckInterval;
70
71   // The configuration program
72
private BuilderProgramContainer _program = new BuilderProgramContainer();
73
74   /**
75    * Sets the id.
76    */

77   public void setId(String JavaDoc id)
78   {
79     _id = id;
80   }
81
82   /**
83    * Gets the id.
84    */

85   public String JavaDoc getId()
86   {
87     return _id;
88   }
89
90   /**
91    * Sets the root directory string
92    */

93   public void setRootDirectory(RawString rootDirectory)
94   {
95     _rootDirectory = rootDirectory.getValue();
96   }
97
98   /**
99    * Gets the app-dir.
100    */

101   public String JavaDoc getRootDirectory()
102   {
103     return _rootDirectory;
104   }
105
106   /**
107    * Sets the archive-path
108    */

109   public void setArchivePath(RawString path)
110   {
111     _archivePath = path.getValue();
112   }
113
114   /**
115    * Gets the archive-path
116    */

117   public String JavaDoc getArchivePath()
118   {
119     return _archivePath;
120   }
121
122   /**
123    * Sets the startup-mode
124    */

125   public void setStartupMode(String JavaDoc mode)
126     throws ConfigException
127   {
128     _startupMode = DeployController.toStartupCode(mode);
129   }
130
131   /**
132    * Gets the startup mode.
133    */

134   public String JavaDoc getStartupMode()
135   {
136     return _startupMode;
137   }
138
139   /**
140    * Sets the redeploy-check-interval
141    */

142   public void setRedeployCheckInterval(Period period)
143   {
144     _redeployCheckInterval = period;
145   }
146
147   /**
148    * Gets the redeploy check interval.
149    */

150   public Period getRedeployCheckInterval()
151   {
152     return _redeployCheckInterval;
153   }
154
155   /**
156    * Sets the redeploy-mode
157    */

158   public void setRedeployMode(String JavaDoc mode)
159     throws ConfigException
160   {
161     _redeployMode = DeployController.toRedeployCode(mode);
162   }
163
164   /**
165    * Gets the redeploy mode.
166    */

167   public String JavaDoc getRedeployMode()
168   {
169     return _redeployMode;
170   }
171
172   /**
173    * Returns the prologue.
174    */

175   public DeployConfig getPrologue()
176   {
177     return null;
178   }
179
180   /**
181    * Adds to the builder program.
182    */

183   public void addBuilderProgram(BuilderProgram program)
184   {
185     _program.addProgram(program);
186   }
187
188   /**
189    * Returns the program.
190    */

191   public BuilderProgram getBuilderProgram()
192   {
193     return _program;
194   }
195
196   /**
197    * Adds a program.
198    */

199   public void addPropertyProgram(String JavaDoc name, Object JavaDoc value)
200   {
201     _program.addProgram(new ObjectAttributeProgram(name, value));
202   }
203
204   /**
205    * Calculates the root directory for the config.
206    */

207   public Path calculateRootDirectory()
208   {
209     return calculateRootDirectory(null);
210   }
211
212   /**
213    * Calculates the root directory for the config.
214    */

215   public Path calculateRootDirectory(Map JavaDoc<String JavaDoc,Object JavaDoc> varMap)
216   {
217     try {
218       String JavaDoc rawPath = getRootDirectory();
219       Path rootDir = null;
220
221       if (rawPath != null)
222     rootDir = PathBuilder.lookupPath(rawPath, varMap);
223
224       if (rootDir != null)
225     return rootDir;
226
227       return Vfs.lookup();
228     } catch (Exception JavaDoc e) {
229       log.log(Level.WARNING, e.toString(), e);
230
231       return null;
232     }
233   }
234 }
235
Popular Tags