KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > deployment > repository > util > WSInfoList


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis2.deployment.repository.util;
18
19 import org.apache.axis2.deployment.DeploymentConstants;
20 import org.apache.axis2.deployment.DeploymentEngine;
21
22 import java.io.File JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 public class WSInfoList implements DeploymentConstants {
28     /**
29      * This is to store all the jar files in a specified folder (WEB_INF)
30      */

31     private static List JavaDoc jarlist = new ArrayList JavaDoc();
32
33     /**
34      * All the curently updated jars
35      */

36     public List JavaDoc currentjars = new ArrayList JavaDoc();
37
38     /**
39      * Referance to DeploymentEngine to make update
40      */

41     private DeploymentEngine deplorer;
42
43     public WSInfoList(DeploymentEngine deploy_engine) {
44         deplorer = deploy_engine;
45     }
46
47     /**
48      * This method is used to initialize the vector
49      */

50     public void init() {
51         jarlist.clear();
52     }
53
54     /**
55      * First it check whether the file is already available in the
56      * system call isFileExist , if it is not deployed yet then it will add
57      * that to jarlist and to the deployment engine as new service or module
58      * in adding new item to jarlist it first create optimice and requird object to
59      * keep those infor call WSInfo and that will be added to jarist and actual
60      * jar file will be added to DeploymentEngine
61      * <p/>
62      * If it is alredy exsit then it check whether it has been updated
63      * then change the last update date of the wsInfo and added two entries to DeploymentEngine
64      * one for New Deployment and other for undeployment
65      *
66      * @param file actual jar files for either Module or service
67      * @param type indicate either Service or Module
68      */

69     public void addWSInfoItem(File JavaDoc file, int type) {
70         switch (type) {
71             case SERVICE:
72                 {
73                     if (!isFileExist(file.getName())) { // chacking whether the file is already deployed
74
WSInfo wsInfo = new WSInfo(file.getName(), file.lastModified(), SERVICE);
75                         jarlist.add(wsInfo);
76                         ArchiveFileData archiveFileData = new ArchiveFileData(file, SERVICE);
77                         deplorer.addtowsToDeploy(archiveFileData);//to inform that new web service is deployed
78
} else {
79                         if (deplorer.isHotUpdate()) {
80                             WSInfo tempWSInfo = getFileItem(file.getName());
81                             if (isModified(file, tempWSInfo)) { // caheck whether file is updated
82
tempWSInfo.setLastmodifieddate(file.lastModified());
83                                 WSInfo wsInfo = new WSInfo(tempWSInfo.getFilename(), tempWSInfo.getLastmodifieddate(), SERVICE);
84                                 deplorer.addtowstoUnDeploy(wsInfo); // add entry to undeploy list
85
ArchiveFileData archiveFileData = new ArchiveFileData(file, SERVICE);
86                                 deplorer.addtowsToDeploy(archiveFileData); // add entry to deploylist
87

88                             }
89                         }
90                     }
91                     break;
92                 }
93             case MODULE:
94                 {
95                     if (!isFileExist(file.getName())) { // chacking whether the file is already deployed
96
WSInfo wsInfo = new WSInfo(file.getName(), file.lastModified(), MODULE);
97                         jarlist.add(wsInfo);
98                         ArchiveFileData archiveFileData = new ArchiveFileData(file, MODULE);
99                         deplorer.addtowsToDeploy(archiveFileData);//to inform that new web service is deployed
100
} else {
101                         if (deplorer.isHotUpdate()) {
102                             WSInfo tempWSInfo = getFileItem(file.getName());
103                             if (isModified(file, tempWSInfo)) {
104                                 tempWSInfo.setLastmodifieddate(file.lastModified());
105                                 WSInfo wsInfo = new WSInfo(tempWSInfo.getFilename(), tempWSInfo.getLastmodifieddate(), MODULE);
106                                 deplorer.addtowstoUnDeploy(wsInfo); // add entry to undeploy list
107
ArchiveFileData archiveFileData = new ArchiveFileData(file, MODULE);
108                                 deplorer.addtowsToDeploy(archiveFileData); // add entry to deploylist
109

110                             }
111                         }
112                     }
113                     break;
114                 }
115         }
116         String JavaDoc jarname = file.getName();
117         currentjars.add(jarname);
118     }
119
120     /**
121      * This method is to use to check the file exist and if so
122      * it will return related wsinfo object to the file else return null;
123      *
124      * @param filename
125      * @return
126      */

127     public WSInfo getFileItem(String JavaDoc filename) {
128         int sise = jarlist.size();
129         for (int i = 0; i < sise; i++) {
130             WSInfo wsInfo = (WSInfo) jarlist.get(i);
131             if (wsInfo.getFilename().equals(filename)) {
132                 return wsInfo;
133             }
134         }
135         return null;
136     }
137
138     /**
139      * comapre the last update dates of both files and if those are differ
140      * that will assume as the file is been modified
141      *
142      * @param file
143      * @param wsInfo
144      * @return
145      */

146     public boolean isModified(File JavaDoc file, WSInfo wsInfo) {
147         if (wsInfo.getLastmodifieddate() != file.lastModified()) {
148             return true;
149         }
150         return false;
151     }
152
153     /**
154      * to check whether the file is alredy in the list
155      *
156      * @param filename
157      * @return
158      */

159     public boolean isFileExist(String JavaDoc filename) {
160         return !(getFileItem(filename) == null);
161     }
162
163     /**
164      * this is to check , undeploye WS
165      * what this relly does is it caheck older jars files and
166      * current jars if name of the old jar file does not exit in the currecntjar
167      * list then it is assumed that the jar file has been removed
168      * that is hot undeployment
169      */

170     public void checkForUndeploye() {
171         Iterator JavaDoc iter = jarlist.listIterator();
172         int size = currentjars.size();
173         List JavaDoc tempvector = new ArrayList JavaDoc();
174         tempvector.clear();
175         String JavaDoc filename = "";
176         boolean exist = false;
177         while (iter.hasNext()) {
178             WSInfo fileitem = (WSInfo) iter.next();
179             exist = false;
180             for (int i = 0; i < size; i++) {
181                 filename = (String JavaDoc) currentjars.get(i);
182                 if (filename.equals(fileitem.getFilename())) {
183                     exist = true;
184                     break;
185                 }
186             }
187
188             if (!exist) {
189                 tempvector.add(fileitem);
190                 WSInfo wsInfo = new WSInfo(fileitem.getFilename(), fileitem.getLastmodifieddate());
191                 deplorer.addtowstoUnDeploy(wsInfo);//this is to be undeploye
192
}
193
194         }
195
196         for (int i = 0; i < tempvector.size(); i++) {
197             WSInfo fileItem = (WSInfo) tempvector.get(i);
198             jarlist.remove(fileItem);
199         }
200         tempvector.clear();
201         currentjars.clear();
202     }
203
204
205     /**
206      *
207      */

208     public void update() {
209         checkForUndeploye();
210         if (deplorer.isHotUpdate()) {
211             deplorer.unDeploy();
212         }
213         deplorer.doDeploy();
214
215     }
216
217 }
218
Popular Tags