KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > deployment > listener > RepositoryListenerImpl


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.listener;
18
19 import org.apache.axis2.deployment.DeploymentConstants;
20 import org.apache.axis2.deployment.DeploymentEngine;
21 import org.apache.axis2.deployment.repository.util.WSInfoList;
22
23 import java.io.File JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 public class RepositoryListenerImpl implements RepositoryListener, DeploymentConstants {
28
29     /**
30      * to store curreently checking jars
31      */

32     private List currentJars;
33     /**
34      * Referance to a WSInfoList
35      */

36     private WSInfoList wsinfoList;
37
38     /**
39      * The parent directory of the modules and services directories
40      * taht the listentner should listent
41      */

42     private String JavaDoc folderName;
43
44     /**
45      * This constructor take two argumnets folder name and referance to Deployment Engine
46      * Fisrt it initilize the syetm , by loading all the modules in the /modules directory
47      * and also create a WSInfoList to keep infor about available modules and services
48      *
49      * @param folderName path to parent directory that the listener should listent
50      * @param deploy_engine refearnce to engine registry inorder to inform the updates
51      */

52     public RepositoryListenerImpl(String JavaDoc folderName, DeploymentEngine deploy_engine) {
53         this.folderName = folderName;
54         wsinfoList = new WSInfoList(deploy_engine);
55         init();
56     }
57
58     /**
59      * this method ask serachWS to serch for the folder to caheck
60      * for updates
61      */

62     public void checkModules() {
63         String JavaDoc modulepath = folderName + MODULE_PATH;
64         String JavaDoc files[];
65         currentJars = new ArrayList JavaDoc();
66         File JavaDoc root = new File JavaDoc(modulepath);
67         // adding the root folder to the vector
68
currentJars.add(root);
69
70         while (currentJars.size() > 0) { // loop until empty
71
File JavaDoc dir = (File JavaDoc) currentJars.get(0); // get first dir
72
currentJars.remove(0); // remove it
73
files = dir.list(); // get list of files
74
if (files == null) {
75                 continue;
76             }
77             for (int i = 0; i < files.length; i++) { // iterate
78
File JavaDoc f = new File JavaDoc(dir, files[i]);
79                 if (f.isDirectory()) { // see if it's a directory
80
currentJars.add(0, f);
81                 } // add dir to start of agenda
82
else if (isModuleArchiveFile(f.getName())) {
83                     wsinfoList.addWSInfoItem(f, MODULE);
84                 }
85             }
86         }
87     }
88
89     /**
90      * this method ask serachWS to serch for the folder to caheck
91      * for updates
92      */

93     public void checkServices() {
94         String JavaDoc modulepath = folderName + SERVICE_PATH;
95         searchWS(modulepath, SERVICE);
96     }
97
98     /**
99      * call to update method of WSInfoList object
100      */

101     public void update() {
102         //todo completet this
103
// this call the update method of WSInfoList
104
wsinfoList.update();
105     }
106
107     /**
108      * First it call to initalize method of WSInfoList to initilizat that
109      * then it call to checkModules to load all the module.jar s
110      * and then it call to update() method inorder to update the Deployment engine and
111      * engine regsitry
112      */

113     public void init() {
114         wsinfoList.init();
115         checkModules();
116         checkServices();
117         update();
118     }
119
120     /**
121      * this is the actual method that is call from scheduler
122      */

123     public void startListent() {
124        // checkModules();
125
checkServices();
126         update();
127     }
128
129     /**
130      * This method is to search a given folder for jar files
131      * and added them to a list wich is in the WSInfolist class
132      */

133     private void searchWS(String JavaDoc folderName, int type) {
134         String JavaDoc files[];
135         currentJars = new ArrayList JavaDoc();
136         File JavaDoc root = new File JavaDoc(folderName);
137         // adding the root folder to the vector
138
currentJars.add(root);
139
140         while (currentJars.size() > 0) { // loop until empty
141
File JavaDoc dir = (File JavaDoc) currentJars.get(0); // get first dir
142
currentJars.remove(0); // remove it
143
files = dir.list(); // get list of files
144
if (files == null) {
145                 continue;
146             }
147             for (int i = 0; i < files.length; i++) { // iterate
148
File JavaDoc f = new File JavaDoc(dir, files[i]);
149                 if (f.isDirectory()) { // see if it's a directory
150
currentJars.add(0, f);
151                 } // add dir to start of agenda
152
else if (isServiceArchiveFile(f.getName())) {
153                     wsinfoList.addWSInfoItem(f, type);
154                 }
155             }
156         }
157     }
158
159     /**
160      * to check whthere a given file is a jar file
161      *
162      * @param filename
163      * @return
164      */

165     private boolean isServiceArchiveFile(String JavaDoc filename) {
166         if (filename.endsWith(".jar") | filename.endsWith(".aar")) {
167             return true;
168         }
169         return false;
170     }
171
172      private boolean isModuleArchiveFile(String JavaDoc filename) {
173         if (filename.endsWith(".jar") || filename.endsWith(".mar")) {
174             return true;
175         }
176         return false;
177     }
178
179 }
180
Popular Tags