KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > autodeploy > AutoDeployControllerFactroyImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AutoDeployControllerFactroy.java
26  */

27
28 package com.sun.enterprise.deployment.autodeploy;
29
30 import java.util.logging.Logger JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import com.sun.enterprise.util.i18n.StringManager;
33 import com.sun.enterprise.admin.common.constant.AdminConstants;
34 import java.io.File JavaDoc;
35
36 import com.sun.enterprise.config.serverbeans.Server;
37 import com.sun.enterprise.config.serverbeans.Domain;
38 import com.sun.enterprise.config.serverbeans.Configs;
39 import com.sun.enterprise.config.serverbeans.Servers;
40 //import com.sun.enterprise.config.serverbeans.ConfigRefs;
41
import com.sun.enterprise.config.serverbeans.Config;
42 //import com.sun.enterprise.config.serverbeans.DasConfig;
43
import com.sun.enterprise.server.ServerContext;
44 import com.sun.enterprise.config.ConfigContext;
45 import com.sun.enterprise.config.ConfigException;
46 import com.sun.enterprise.instance.InstanceEnvironment;
47 import com.sun.enterprise.config.serverbeans.AdminService;
48 import com.sun.enterprise.config.serverbeans.DasConfig;
49 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
50 import com.sun.enterprise.config.serverbeans.PropertyResolver;
51
52 /**
53  * Implements AutoDeployControllerFactroy</br>
54  * create a instance of autodeploycontroller, depending upon the Servercontext passed</br>
55  * if autodeploy is enabled in domain.xml return a new instance else return null.</br>
56  *
57  * @author vikas
58  */

59 public class AutoDeployControllerFactroyImpl implements AutoDeployControllerFactroy {
60     
61     private static final Logger JavaDoc sLogger=AutoDeployControllerImpl.sLogger;
62     private static StringManager localStrings =
63                             StringManager.getManager( AutoDeployControllerFactroyImpl.class );
64     
65     
66     /**
67      * create a instance of autodeploycontroller, depending upon the Servercontext passed</br>
68      *If autodeploy is enabled in domain.xml return a new instance else return null.</br>
69      *If autodeploydir is null/empty.-change to default with appropriate log message .</br>
70      *If autodeploydir is invalid(not a directory/not exit/not have read-write permission </br>
71      *available) continue the thread, with appropriate log message.</br>
72      *ALso both absolute and relative paths for autodeploy-dir are handled.</br>
73      *If autodeploy-polling-interval is null/empty/invalid/ less than AutoDeployConstants.DEFAULT_POLLING_INTERVAL
74      * - change to default with appropriate log message </br>
75      *
76      */

77     public AutoDeployController createAutoDeployController(ServerContext context) throws AutoDeploymentException {
78         
79         ConfigContext confContext = context.getConfigContext();
80         AutoDeployController autoDeployController = null;
81         String JavaDoc targetConfigurationName = null;
82         Domain domain = null;
83         
84         String JavaDoc autoDeployDir=null ;
85         String JavaDoc sourcedir=null;
86         String JavaDoc strPollingInterval =null ;
87         long pollingInterval;
88         boolean verifyEnabled=false ;
89         boolean preJspCompilation=false ;
90         
91         DasConfig dasConfig = null;
92         try {
93             //domain = (Domain)confContext.getRootConfigBean();
94
//Config config = ServerBeansFactory.getConfigBean(confContext);
95
//if(config != null)
96
// as = config.getAdminService();
97
dasConfig = ServerBeansFactory.getDasConfigBean(confContext);
98         }catch (Exception JavaDoc ce){
99                    sLogger.log(Level.SEVERE, "enterprise.deployment.backend.autoDeploymentStartFailure");
100                    throw new AutoDeploymentException("Failed to start autodeploy", ce);
101         }
102         
103        // targetConfigurationName= getTargetConfigName(domain);
104
//read target configuration
105
/* if(targetConfigurationName !=null && !targetConfigurationName.trim().equals("")){
106             Config config = domain.getConfigs().getConfigByName(targetConfigurationName);
107             if(config !=null){
108                 //get appconfig specific to targetConfigurationName
109                 //ApplicationConfig appConfig= config.getApplicationConfig();
110         */

111               
112                 
113         if(dasConfig != null) {
114                 boolean autodeployEnabled=dasConfig.isAutodeployEnabled();
115                 if(autodeployEnabled){
116                     autoDeployDir=dasConfig.getAutodeployDir() ;
117                     if(autoDeployDir != null) {
118                         try {
119                             autoDeployDir = new PropertyResolver(confContext,
120                                 context.getInstanceName()).
121                                     resolve(autoDeployDir);
122                             autoDeployDir=autoDeployDir.trim();
123                         } catch (ConfigException ce) {
124                             //log
125
autoDeployDir = null;
126                         }
127                     }
128                     if(autoDeployDir == null || "".equals(autoDeployDir)) {
129                         //empty path so putting default
130
autoDeployDir = AutoDeployConstants.DEFAULT_AUTODEPLOY_DIR;
131                         sourcedir= context.getInstanceEnvironment().getAutoDeployDirPath()+File.separator+autoDeployDir;
132                         String JavaDoc msg = localStrings.getString("enterprise.deployment.autodeploy.invalid_source_dir_shifting_to_default",sourcedir);
133                         sLogger.log(Level.WARNING, msg);
134                     } else if((new File JavaDoc(autoDeployDir)).isAbsolute()) {
135                         //absolute path
136
sourcedir=autoDeployDir;
137                     } else {
138                         //relative path
139
sourcedir= context.getInstanceEnvironment().getAutoDeployDirPath()+File.separator+autoDeployDir;
140                     }
141                     strPollingInterval = dasConfig.getAutodeployPollingIntervalInSeconds();
142                     verifyEnabled=dasConfig.isAutodeployVerifierEnabled() ;
143                     preJspCompilation=dasConfig.isAutodeployJspPrecompilationEnabled() ;
144                     try {
145                         try {
146                             pollingInterval= Long.parseLong(strPollingInterval) ;
147                             if(pollingInterval < AutoDeployConstants.MIN_POOLING_INTERVAL) {
148                                 String JavaDoc msg = localStrings.getString("enterprise.deployment.autodeploy.invalid_pooling_interval_shifting_to_default",strPollingInterval,AutoDeployConstants.MIN_POOLING_INTERVAL+"",AutoDeployConstants.DEFAULT_POLLING_INTERVAL+"");
149                                 sLogger.log(Level.WARNING, msg);
150                                 pollingInterval = AutoDeployConstants.DEFAULT_POLLING_INTERVAL;
151                             }
152                         } catch (NumberFormatException JavaDoc ne) {
153                             String JavaDoc msg = localStrings.getString("enterprise.deployment.autodeploy.invalid_pooling_interval_shifting_to_default",strPollingInterval,AutoDeployConstants.MIN_POOLING_INTERVAL+"",AutoDeployConstants.DEFAULT_POLLING_INTERVAL+"");
154                             sLogger.log(Level.WARNING, msg);
155                            // throw new AutoDeploymentException(ne);
156
pollingInterval = AutoDeployConstants.DEFAULT_POLLING_INTERVAL;
157                         }
158                         autoDeployController = new AutoDeployControllerImpl(sourcedir,pollingInterval);
159                         autoDeployController.setVerify(verifyEnabled);
160                         autoDeployController.setPreJspCompilation(preJspCompilation);
161                     } catch(AutoDeploymentException ae) {
162                         sLogger.log(Level.SEVERE, "enterprise.deployment.backend.autoDeploymentStartFailure");
163                         throw ae;
164
165                     }
166             // }
167
}//END if(config !=null)
168
}
169
170         return autoDeployController;
171
172     }
173     
174     /*
175      //REMOVED Since this should be resolved from ServerBeansFactory
176     private String getTargetConfigName(Domain domain) throws AutoDeploymentException {
177         
178         String targetConfigurationName = null;
179         Server svr = null;
180         String targetName = null;
181         Servers svrs = null;
182         Server[] svrArr = null;
183         svrs = domain.getServers();
184         svrArr = svrs.getServer();
185         for(int i = 0 ; i< svrArr.length; i++) {
186             if(!svrArr[i].getName().equals("")) {
187                 targetName = svrArr[i].getName();
188                 svr = svrArr[i];
189                 break;
190             }
191         }
192         //get target config name
193         if(targetName == null || svr == null ) {
194             String msg = localStrings.getString("enterprise.deployment.autodeploy.target_server_not_found");
195             sLogger.log(Level.SEVERE, msg);
196             throw new AutoDeploymentException(msg);
197         } else {
198             ConfigRefs configRefs =svr.getConfigRefs();
199             String[] refs= configRefs.getConfigRef();
200             for(int i = 0 ; i< refs.length; i++) {
201                 if(!refs[i].equals("")) {
202                     targetConfigurationName = refs[i];
203                     break;
204                 }
205             }
206          }
207         if(targetConfigurationName == null || targetConfigurationName.trim().equals("")) {
208             String msg = localStrings.getString("enterprise.deployment.autodeploy.error_in_reading_config_params");
209             sLogger.log(Level.SEVERE, msg);
210             throw new AutoDeploymentException(msg);
211             
212         }
213         return targetConfigurationName;
214     }
215     
216      */

217
218 }
219
Popular Tags