KickJava   Java API By Example, From Geeks To Geeks.

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


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.log.Log;
33 import com.caucho.util.L10N;
34 import com.caucho.vfs.Dependency;
35
36 import java.util.ArrayList JavaDoc;
37 import java.util.Set JavaDoc;
38 import java.util.logging.Level JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40
41 /**
42  * A list of deploy objects.
43  */

44 public class DeployListGenerator<E extends DeployController>
45   extends DeployGenerator<E> implements Dependency {
46   private static final Logger JavaDoc log = Log.open(DeployListGenerator.class);
47   private static final L10N L = new L10N(DeployListGenerator.class);
48
49   private ArrayList JavaDoc<DeployGenerator<E>> _generatorList
50     = new ArrayList JavaDoc<DeployGenerator<E>>();
51
52   /**
53    * Creates the deploy.
54    */

55   public DeployListGenerator(DeployContainer container)
56   {
57     super(container);
58   }
59   
60   /**
61    * Adds a deploy.
62    */

63   public void add(DeployGenerator<E> deploy)
64   {
65     if (! _generatorList.contains(deploy))
66       _generatorList.add(deploy);
67   }
68   
69   /**
70    * Removes a deploy.
71    */

72   public void remove(DeployGenerator<E> deploy)
73   {
74     _generatorList.remove(deploy);
75   }
76
77   /**
78    * Returns true if the deployment has modified.
79    */

80   public boolean isModified()
81   {
82     for (int i = _generatorList.size() - 1; i >= 0; i--) {
83       if (_generatorList.get(i).isModified())
84     return true;
85     }
86
87     return false;
88   }
89
90   /**
91    * Redeploy if the deployment is modified.
92    *
93    * XXX:
94    */

95   public void request()
96   {
97     for (int i = _generatorList.size() - 1; i >= 0; i--) {
98       _generatorList.get(i).request();
99     }
100   }
101
102   /**
103    * Force an update
104    */

105   public void update()
106   {
107     for (int i = 0; i < _generatorList.size(); i++)
108       _generatorList.get(i).update();
109   }
110
111   /**
112    * Returns the deployed keys.
113    */

114   public void fillDeployedKeys(Set JavaDoc<String JavaDoc> keys)
115   {
116     for (int i = 0; i < _generatorList.size(); i++) {
117       _generatorList.get(i).fillDeployedKeys(keys);
118     }
119   }
120
121   /**
122    * Generates the controller matching the key string.
123    */

124   protected E generateController(String JavaDoc key)
125   {
126     for (int i = 0; i < _generatorList.size(); i++) {
127       E controller = _generatorList.get(i).generateController(key);
128
129       if (controller != null) {
130     // merge with the rest of the entries
131
for (int j = 0; j < _generatorList.size(); j++) {
132       DeployGenerator<E> generator = _generatorList.get(j);
133
134       // XXX: issue with server/10tl
135
controller = _generatorList.get(j).mergeController(controller, key);
136     }
137     
138     return controller;
139       }
140     }
141
142     return null;
143   }
144
145   /**
146    * Merges with other matching entries.
147    */

148   protected E mergeController(E controller, String JavaDoc key)
149   {
150     for (int i = 0; i < _generatorList.size(); i++) {
151       controller = _generatorList.get(i).mergeController(controller, key);
152     }
153
154     return controller;
155   }
156   
157   /**
158    * Starts the deploys.
159    */

160   @Override JavaDoc
161   protected void startImpl()
162   {
163     super.startImpl();
164
165     for (int i = 0; i < _generatorList.size(); i++) {
166       _generatorList.get(i).start();
167     }
168   }
169   
170   /**
171    * Stops the deploys.
172    */

173   @Override JavaDoc
174   protected void stopImpl()
175   {
176     for (int i = 0; i < _generatorList.size(); i++) {
177       _generatorList.get(i).stop();
178     }
179
180     super.stopImpl();
181   }
182   
183   /**
184    * Closes the deploys.
185    */

186   @Override JavaDoc
187   protected void destroyImpl()
188   {
189     ArrayList JavaDoc<DeployGenerator<E>> generatorList
190       = new ArrayList JavaDoc<DeployGenerator<E>>(_generatorList);
191     
192     _generatorList.clear();
193
194     for (int i = 0; i < generatorList.size(); i++) {
195       try {
196     generatorList.get(i).destroy();
197       } catch (Throwable JavaDoc e) {
198     log.log(Level.FINE, e.toString(), e);
199       }
200     }
201
202     super.destroyImpl();
203   }
204
205   public String JavaDoc toString()
206   {
207     return "DeployListGenerator[" + _generatorList + "]";
208   }
209 }
210
Popular Tags