KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > instance > InstanceEnvironment


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 package com.sun.enterprise.instance;
26
27 //JDK imports
28
import java.io.File JavaDoc;
29 import java.io.IOException JavaDoc;
30 //iAS imports
31
import com.sun.enterprise.util.StringUtils;
32 import com.sun.enterprise.util.OS;
33 import com.sun.enterprise.util.io.FileUtils;
34 import com.sun.enterprise.util.diagnostics.*;
35 import com.sun.enterprise.server.Constants;
36 import com.sun.enterprise.deployment.backend.DeployableObjectType;
37 import com.sun.enterprise.config.ConfigException;
38 import com.sun.enterprise.config.ConfigContext;
39 import com.sun.enterprise.config.ConfigFactory;
40 import com.sun.enterprise.config.serverbeans.Server;
41 import com.sun.enterprise.config.serverbeans.Domain;
42 import com.sun.enterprise.config.serverbeans.EjbContainer;
43 import com.sun.enterprise.config.serverbeans.HttpService;
44 //import com.sun.enterprise.config.serverbeans.Mime;
45
//import com.sun.enterprise.config.serverbeans.VirtualServerClass;
46
import com.sun.enterprise.config.serverbeans.VirtualServer;
47
48 import com.sun.enterprise.admin.common.exception.AFRuntimeStoreException;
49
50 import com.sun.enterprise.admin.server.core.channel.AdminChannel;
51 import com.sun.enterprise.admin.server.core.channel.RMIClient;
52
53 import java.io.FileReader JavaDoc;
54 import java.io.FileWriter JavaDoc;
55 import java.util.logging.Logger JavaDoc;
56 import java.util.logging.Level JavaDoc;
57 import com.sun.logging.LogDomains;
58
59 import com.sun.enterprise.admin.server.core.ManualChangeManager;
60 /*installConfig is removed and we need better alternative */
61 //import com.iplanet.ias.installer.core.installConfig;
62

63 //ROB: config changes
64
import com.sun.enterprise.config.serverbeans.Config;
65 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
66 import com.sun.enterprise.config.serverbeans.PropertyResolver;
67
68 //Tomcat
69
import com.sun.enterprise.server.ApplicationServer;
70 import com.sun.enterprise.server.pluggable.PluggableFeatureFactory;
71 import com.sun.enterprise.server.ServerContext;
72
73 /**
74     The class that stores <code> all environment </code> of a iAS SE Server Instance
75     with a given name. The name of the instance is the same as given by the
76     (administrative) user. The class hides all the details of mapping between
77     such a name and its location on disk. Note that this class is responsible for
78     environment of a single Server Instance only.
79         Upgraded it to the new file layout. Please refer to
80     <a HREF="http://iaseng.red.iplanet.com/packages/iasse7_filelayout.html">
81     new file layout for the instance configuration. </a> This class should
82     be in unison with this document.
83
84     Please note that there is a dependency on installer code. If you make
85     any changes to this file, make sure that you visit installer code
86     at com/iplanet/ias/installer/windows/actions
87
88     @author Kedar
89     @version 1.1
90 */

91
92 public final class InstanceEnvironment {
93     
94         private static Object JavaDoc lock = new Object JavaDoc();
95     
96         /** enable/disable TimeStamp mechanism TOTALLY */
97         private static final boolean TIMESTAMP_MECHANISM_ENABLED = true;
98         
99         /** enable/disable TimeStamp mechinism for Mime.types.
100          * makes sense only if TIME_STAMP_MECHANISM_ENABLED is true;
101          */

102         private static final boolean MIMETYPE_TIMESTAMP_MECHANISM_ENABLED = true;
103
104         private static final boolean VIRTUAL_SERVER_TIMESTAMP_MECHANISM_ENABLED
105                 = true;
106         
107         private static final long INVALID_TIME_STAMP = 0;
108         
109         private static final long UNINITIALIZED_TIME_STAMP = 0;
110
111     private static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
112
113     /** folder where the configuration of this instance is stored */
114
115     public static final String JavaDoc kConfigDirName = "config";
116     
117     /** folder where the configuration of this instance is backed up */
118     
119     public static final String JavaDoc kBackupDirName = ".";
120     
121     // bnevins, Sept. 2003 -- kBackupDirName was changed to "."
122
// This String is used for creating
123
// repository backup dirs as well as the now defunct config backup dir.
124
// I created a new variable for repository. I see no good reason to make
125
// it public like the rest of these variables ?!?
126

127     private static final String JavaDoc kRepositoryBackupDirName = "backup";
128     
129     /** folder where all generated code like compiled jsps, stubs is stored */
130     
131     public static final String JavaDoc kGeneratedDirName = "generated";
132     
133     /** default folder where deployed j2ee-apps are stored */
134     public static final String JavaDoc kRepositoryDirName = "applications";
135         
136     public static final String JavaDoc kApplicationDirName = "j2ee-apps";
137     
138     /** folder where deployed modules are stored */
139     
140     public static final String JavaDoc kModuleDirName = "j2ee-modules";
141     
142     /** folder where all the deployed life cycle modules are stored */
143     
144     public static final String JavaDoc kLifecycleModuleDirName = "lifecycle-modules";
145     
146     /** folder where ejb related stuff is stored */
147     
148     public static final String JavaDoc kEJBStubDirName = "ejb";
149     
150     /** name of the configuration file */
151     /** New for 8.0 - domain.xml is config file name */
152
153     public static final String JavaDoc kConfigXMLFileName = "domain.xml";
154
155     /** New for 8.0 - domain.xml is config file name */
156
157     public static final String JavaDoc kServerXMLFileName = "server.xml";
158     
159     /** folder where the other required classes are stored */
160     
161     public static final String JavaDoc kLibDirName = "lib";
162
163     /** folder where the auto deploy monitor looks for new archives to deploy */
164     public static final String JavaDoc kAutoDeployDirName = "autodeploy";
165     
166     /** folder where the customer overridden classes are stored */
167     
168     public static final String JavaDoc kLibClassesDirName = "classes";
169     
170     /** folder where the compiled JSP pages reside */
171     
172     public static final String JavaDoc kCompileJspDirName = "jsp";
173
174     /** folder where the modified xml files reside */
175     
176     public static final String JavaDoc kGeneratedXMLDirName = "xml";
177     
178     /** folder where the session info or passivated ejbs are to be stored
179             can be overridden in the server.xml */

180     
181     public static final String JavaDoc kSessionStoreDirName = "session-store";
182     
183     /** folder to persist the HTTP session data */
184     
185     public static final String JavaDoc kHttpSessionDirName = "http";
186     
187     /** folder for docroot */
188     public static final String JavaDoc kDocRootDirName = "docroot";
189     
190     /** object file name */
191     public static final String JavaDoc kObjectFileName = "obj.conf";
192
193     /** init file name */
194     public static final String JavaDoc kInitFileName = "init.conf";
195     
196     /** name of the iWS NSS passwords file */
197     
198     public static final String JavaDoc kSecurityPasswordsFileName = "password.conf";
199     
200     /** name of the realms key file */
201     
202     public static final String JavaDoc kRealmsKeyFileName = "keyfile";
203
204     /** name of the install dir */
205
206     public static final String JavaDoc kInstallDirName = "install";
207
208     /** name of the templates dir */
209
210     public static final String JavaDoc kTemplatesDirName = "templates";
211
212     /** ACL template name */
213     public static final String JavaDoc kAclTemplate = "template.acl";
214
215     /** default orb-listener port */
216     public static final int kOrbListenerPort = 3700;
217
218     /** default jms-service (imq) port */
219     public static final int kJmsProviderPort = 7676;
220
221     /** directory where java-web-start related files are located */
222     public static final String JavaDoc kJavaWebStartDirName = "java-web-start";
223     
224     /* installRoot is the server installation root */
225     private String JavaDoc instanceRoot = null;
226
227     private String JavaDoc mLogicalName = null;
228     private String JavaDoc mConfigFilePath = null;
229     private String JavaDoc mBackupConfigFilePath = null;
230     /** mApplicationRootPath points to the application root of the server. If
231         this is unspecified, it will default to <instance_dir>/applications.
232         This is where J2EE applications, modules, life-cycle modules will be
233         created.
234     */

235     private String JavaDoc mApplicationRootPath = null;
236     
237     /** mApplicationRepositoryPath is where the j2ee-apps are stored. It is
238         possible that the applications running/deployed to an instance
239         are located at different locations. This attribute denotes the "current"
240         location where the j2ee-apps are to be stored at.
241         Same is true for other application/module related paths. This does
242         not refer to stubs or jsp pages.
243     */

244     private String JavaDoc mApplicationRepositoryPath = null;
245     private String JavaDoc mApplicationBackupRepositoryPath = null;
246     private String JavaDoc mModuleRepositoryPath = null;
247     private String JavaDoc mModuleBackupRepositoryPath = null;
248     
249     private String JavaDoc mApplicationStubRepositoryPath = null;
250     private String JavaDoc mModuleStubRepositoryPath = null;
251     private String JavaDoc mApplicationGeneratedXMLPath = null;
252     private String JavaDoc mModuleGeneratedXMLPath = null;
253     private String JavaDoc mLibPath = null;
254     private String JavaDoc mAutoDeployDirPath = null;
255     private String JavaDoc mLibClassesPath = null;
256     private String JavaDoc mApplicationPassivatedEjbPath = null;
257     private String JavaDoc mModulePassivatedEjbPath = null;
258     private String JavaDoc mApplicationCompiledJspPath = null;
259     private String JavaDoc mWebModuleCompiledJspPath = null;
260     private String JavaDoc mApplicationHttpSessionStorePath = null;
261     private String JavaDoc mModuleHttpSessionStorePath = null;
262     private String JavaDoc mDocRootPath = null;
263     private String JavaDoc mStopCommandPath = null;
264     private String JavaDoc mDefaultAccessLogPath = null;
265     private String JavaDoc mObjectFilePath = null;
266     private String JavaDoc mInitFilePath = null;
267     private String JavaDoc mBackupObjectFilePath = null;
268     private String JavaDoc mBackupInitFilePath = null;
269     private String JavaDoc mSecurityPasswordsFilePath = null;
270     private String JavaDoc mRealmsKeyFilePath = null;
271     private String JavaDoc mBackupRealmsKeyFilePath = null;
272
273     // Hamid: Added the following files for Acl: Bug 4700937
274
private String JavaDoc mAclFilePath = null;
275     private String JavaDoc mBackupAclFilePath = null;
276     private String JavaDoc kAclFilePrefix = "generated";
277     private String JavaDoc kBackupAclFilePrefix = "genwork";
278     private String JavaDoc kAclFileSuffix = "acl";
279     
280     private String JavaDoc mJavaWebStartDirPath = null;
281     
282     // Lazy initialization flag
283
private boolean mInited = false;
284     
285     private String JavaDoc mInstancesRoot = null;
286     
287     /**
288             Creates new InstanceEnvironment for Server Instance with given name.
289             Name may not be null or empty String. Name may not begin with a digit.
290             <p>
291             It is essential to note that an instance with this name
292             is <code> created /<code>indeed before creating object of this class.
293             <p>
294             @param instanceName String denoting the name of Server Instance.
295             @throws IllegalArgumentException if the name is null or empty
296             String or does not begin with a letter (in both the variants) or
297             the instance directory does not exist. Thus the examples of invalid
298             values are "6ias"
299
300             @see com.sun.enterprise.config.ServerManager#createServerInstance
301     */

302     
303     public InstanceEnvironment(String JavaDoc instanceName) {
304         this(System.getProperty(Constants.IAS_ROOT),
305              instanceName);
306     }
307
308     public InstanceEnvironment(String JavaDoc instancesRoot, String JavaDoc instanceName) {
309         if (! StringUtils.ok(instanceName)) {
310           throw new IllegalArgumentException JavaDoc(Localizer.getValue(ExceptionType.NULL_ARG));
311         }
312         mLogicalName = instanceName;
313         mInstancesRoot = instancesRoot;
314         createConfigFilePath();
315         //createBackupConfigFilePath();
316
}
317
318     private PropertyResolver mPathResolver;
319
320     private void init() {
321         if (mInited) {
322             return;
323         }
324         createPathResolver();
325         createApplicationRootPath();
326         createApplicationRepositoryPath();
327         createApplicationBackupRepositoryPath();
328         createModuleRepositoryPath();
329         createModuleBackupRepositoryPath();
330         createApplicationStubPath();
331         createModuleStubPath();
332         createApplicationGeneratedXMLPath();
333         createModuleGeneratedXMLPath();
334         createLibPath();
335         createLibClassesPath();
336         createAutoDeployDirPath();
337         createPassivatedEjbPaths();
338         createApplicationCompiledJspPath();
339         createWebModuleCompiledJspPath();
340         createHttpSessionStorePaths();
341         createDocRootPath();
342         createStopCommandPath();
343         createDefaultAccessLogPath();
344         createObjectFilePath();
345         createInitFilePath();
346         createSecurityPasswordsFilePath();
347         createRealmsKeyFilePath();
348         createAclFilePath();
349         createJavaWebStartPath();
350         mInited = true;
351     }
352     /**
353      * Apply the changes from all the files i.e. the other config files
354      * to the real one. <code>This method simply copies the files over and
355      * there is no transaction model built into it. </code>
356      * If the method throws any exception, there is a chance that the changes
357      * are not correctly applied.
358      * Note that the only UI from which the object file (obj.conf) and
359      * initialization file (init.conf) is changed is the admin cgis and some
360      * servlets. Most of the clients change the server.xml.
361      * This method will typically be called when the apply/reconfigure of
362      * clients is called.
363     */

364     public void applyChangesFromBackup() throws ConfigException {
365     }
366     
367     public void applyChangesFromBackup(boolean overwrite) throws ConfigException {
368     }
369
370     public boolean hasHotChanged() {
371         return false;
372     }
373
374     /**
375      * Has init.conf or obj.conf file changed.
376      * @return true if live init.conf or obj.conf has changed manually,
377      * or backup init.conf or obj.conf file timestamp is later than live
378      */

379     public boolean hasInitOrObjConfFileChanged() {
380         return false;
381     }
382
383     /**
384      * Has Realms keyfile changed.
385      * @return true if live keyfile has changed manually,
386      * or backup keyfile file timestamp is later than live
387      */

388     public boolean hasRealmsKeyConfFileChanged() {
389         return false;
390     }
391
392
393     /**
394      * Has configured mime file(s) changed.
395      * @return true if any of the live configured mime type file has been
396      * changed manually, or if any of the backup mime file timestamp is
397      * later than the timestamp for live files.
398      */

399     public boolean hasMimeConfFileChanged() {
400         return false;
401     }
402
403     public boolean hasVirtualServerConfFileChanged() {
404         return false;
405     }
406
407     /**
408      * Has any of config files managed by cgi scripts changed. The files
409      * managed by cgi scripts are init.conf, obj.conf and mime types files.
410      */

411     public boolean hasCGIConfigFilesChanged() {
412         return false;
413     }
414
415     public boolean hasHotInitChanged() {
416         return false;
417     }
418     
419     public boolean hasHotRealmsKeyChanged() {
420         return false;
421     }
422
423     public boolean hasHotObjectChanged() {
424         return false;
425     }
426
427     public boolean hasHotXmlChanged() {
428         return false;
429     }
430     
431     /**
432      * is used to findout if we can reload transparently
433      * i.e., reload configcontext
434      * To do this, we need to findout if xml has changed. If it has,
435      * then is backup in memory changed, i.e., has ConfigContext Changed ?
436      * return true if you can reload
437      * return false if hot has not changed or if you cannot reload
438      */

439     public boolean canReloadManualXmlChanges() {
440         return false;
441     }
442     
443     private boolean hasOnlyHotXmlChanged() {
444         return false;
445     }
446     
447     public boolean hasHotMimeChanged() {
448         return false;
449     }
450
451     public boolean hasHotVirtualServerConfChanged() {
452         return false;
453     }
454
455     public boolean hasBakupVirtualServerConfChanged() {
456         return false;
457     }
458
459     private boolean hasVirtualServerConfChanged(ConfigContext context,
460                                                 boolean isHot)
461         throws ConfigException {
462         return false;
463     }
464
465     private long getConfigFileTimeStamp(String JavaDoc configFile) {
466         //need to read xml and get the timestamp
467
long ts = UNINITIALIZED_TIME_STAMP;
468         try {
469             File JavaDoc f = new File JavaDoc(configFile);
470             ts = f.lastModified();
471         } catch(Throwable JavaDoc t) {
472             //ignore
473
}
474         return ts;
475     }
476     
477     private long getLastModifiedFromTSFile(String JavaDoc tsFileName) {
478             long ts = INVALID_TIME_STAMP; //different from getXmlFileTimeStamp for a purpose
479

480             FileReader JavaDoc fr = null;
481             try {
482                 File JavaDoc f = new File JavaDoc(tsFileName);
483         //_logger.log(Level.INFO,"ts file: " + ((f.exists())?"exists":"does not exist"));
484

485                 
486                 fr = new FileReader JavaDoc(f);
487                 
488                 char[] cbuf = new char[13]; // should be sufficint
489
fr.read(cbuf);
490         String JavaDoc s = new String JavaDoc(cbuf);
491         //_logger.log(Level.FINE,"String is:" + s +":");
492
ts = (new Long JavaDoc(s)).longValue();
493             } catch(Throwable JavaDoc t) {
494                 // _logger.log(Level.WARNING,"Exception caught in getting LastModified",t);
495
//ignore ?
496
} finally {
497                 try {
498                     fr.close();
499             fr = null;
500                 } catch(Exception JavaDoc ex){}
501             }
502             return ts;
503         }
504     
505     private String JavaDoc getTimeStampFileName(String JavaDoc fullName) {
506         return fullName + ".timestamp";
507     }
508     
509     public void useManualConfigChanges() throws ConfigException {
510     }
511
512     public void useManualServerXmlChanges() throws ConfigException {
513     }
514
515     private void useManualInitFileChanges() throws ConfigException {
516     }
517
518     private void useManualRealmsKeyFileChanges() throws ConfigException {
519     }
520
521     private void useManualObjectFileChanges() throws ConfigException {
522     }
523
524     private void useManualAllMimeFileChanges() throws ConfigException {
525     }
526
527     private void useManualVirtualServerConfFileChanges(ConfigContext bakXmlCtx)
528         throws ConfigException {
529 /*
530         ConfigContext context = ConfigFactory.
531             createConfigContext(getConfigFilePath(), true, false, false);
532         if (context == null) {
533             // this is serious. ConfigContext for
534             // this server instance should be created by now.
535             
536             throw new ConfigException(Localizer.getValue(ExceptionType.NO_XML));
537         }
538           //ROB: config changes
539         //Server rootElement = ServerBeansFactory.getServerBean(context);
540           Config rootElement = ServerBeansFactory.getConfigBean(context);
541
542         HttpService httpService = rootElement.getHttpService();
543         VirtualServerClass[] vsClasses= httpService.getVirtualServerClass();
544         for(int i = 0 ; i < vsClasses.length ; i++) {
545             VirtualServerClass aClass = vsClasses[i];
546             VirtualServer[] virtualServers = aClass.getVirtualServer();
547             for(int j = 0 ; j < virtualServers.length ; j++) {
548                 VirtualServer aServer = virtualServers[j];
549                 String file = aServer.getConfigFile();
550                 if ((file == null) || (file.length() == 0)) {
551                     continue;
552                 }
553                 String destPath = getBackupConfigDirPath() + File.separator
554                                     + file;
555                 String srcPath = getConfigDirPath() + File.separator
556                                     + file;
557                 copyFile(new File(srcPath), new File(destPath));
558                 //Chown file
559                 if (isChownNeeded(null)) {
560                     chownFile(destPath);
561                 }
562                 if(VIRTUAL_SERVER_TIMESTAMP_MECHANISM_ENABLED) {
563                     String tsFilePath = getTimeStampFileName(destPath);
564                     saveTimeStamp(tsFilePath, srcPath);
565                 }
566             }
567         }
568 */

569         /* The following code deletes the config files from the backup
570          * directory. These config files correspond to the virtual servers
571          * that would have been deleted from the hot xml.
572          */

573 /*
574         deleteVirtualServerConfigFiles(bakXmlCtx, context, false);
575 */

576     }
577
578     /**
579      * This method iterates through the virtual-server elements
580      * foreach virtual-server-class element of the 'ctx' and
581      * checks if a corresponding virtual-server element exists
582      * in 'ctx2'. If not, it assumes that the virtual-server
583      * element has been deleted from ctx2 and deletes the
584      * corresponding config file from the config directory of
585      * 'ctx'.
586      * <warning>This method assumes that virtual-server ids are
587      * unique across virtual-server-class elements. </warning>
588      */

589     private void deleteVirtualServerConfigFiles(ConfigContext ctx,
590                                                 ConfigContext ctx2,
591                                                 boolean isHot)
592         throws ConfigException
593     {
594 /*
595           //ROB: config changes
596         //Server rootElement = ServerBeansFactory.getServerBean(ctx);
597           Config rootElement = ServerBeansFactory.getConfigBean(ctx);
598
599         HttpService httpService = rootElement.getHttpService();
600
601           //ROB: config changes
602           //Server rootElement2 = ServerBeansFactory.getServerBean(ctx2);
603           Config rootElement2 = ServerBeansFactory.getConfigBean(ctx2);
604
605         HttpService httpService2 = rootElement2.getHttpService();
606
607         VirtualServerClass[] vsClasses =
608                                 httpService.getVirtualServerClass();
609         for(int i = 0 ; i < vsClasses.length ; i++) {
610             VirtualServerClass vsClass = vsClasses[i];
611             String vsClassId = vsClass.getId();
612             VirtualServerClass vsClass2 =
613                     httpService2.getVirtualServerClassById(vsClassId);
614             boolean deleteAll = false;
615             if (vsClass2 == null) {
616                 // This virtual-server-class was probably deleted
617                  // from ctx2. So delete the config files for all the
618                  // virtual servers.
619                 
620                 deleteAll = true;
621             }
622             VirtualServer[] virtualServers = vsClass.getVirtualServer();
623             for(int j = 0 ; j < virtualServers.length ; j++) {
624                VirtualServer vs = virtualServers[j];
625                String vsId = vs.getId();
626                if ((deleteAll) ||
627                    (vsClass2.getVirtualServerById(vsId) == null)) {
628                    String configFileName = vs.getConfigFile();
629                    if ((configFileName == null) ||
630                        (configFileName.length() == 0)) {
631                        continue;
632                    }
633                    String parent = (isHot) ? getConfigDirPath() :
634                                              getBackupConfigDirPath();
635                    File confFile = new File(parent, configFileName);
636                    if (confFile.exists()) {
637                        confFile.delete();
638                    }
639                    if (!isHot) {
640                        //Remove timestamp file
641                        File tsFile = new File(parent,
642                                               configFileName + ".timestamp");
643                        if (tsFile.exists()) {
644                            tsFile.delete();
645                        }
646                    }
647                }
648             }
649         }
650 */

651
652     }
653
654     /**
655      * init to be called from constructor
656      */

657      public void createTimeStampFiles() {
658         init();
659         if(!TIMESTAMP_MECHANISM_ENABLED) return;
660          synchronized(lock) {
661          /* TOMCAT_BEGIN Ramakanth */
662          createTSFile(getTimeStampFileName(mConfigFilePath),
663              mConfigFilePath, mConfigFilePath);
664          createTSFile(getTimeStampFileName(mBackupRealmsKeyFilePath),
665              mRealmsKeyFilePath, mBackupRealmsKeyFilePath);
666          /* TOMCAT_END Ramakanth */
667          }
668      }
669      
670      private void createTSFile(String JavaDoc tsFileName, String JavaDoc actualFile, String JavaDoc backupFile) {
671          // if the file does not exist,
672
// create ts file
673
File JavaDoc f = new File JavaDoc(tsFileName);
674             if(!f.exists()) {
675                 saveTimeStamp(tsFileName, actualFile, backupFile);
676             }
677      }
678      
679      private void createMimeTSFiles() {
680      }
681
682     private void createVirtualServersConfTSFiles() {
683 /*
684         if(!VIRTUAL_SERVER_TIMESTAMP_MECHANISM_ENABLED) return;
685          
686         try {
687             ConfigContext context = ConfigFactory.
688                 createConfigContext(mConfigFilePath, true, false, false);
689             if (context == null) {
690                 // this is serious. ConfigContext for
691                 // this server instance should be created by now.
692                 
693                 return;
694             }
695             //ROB: config changes
696             //Server rootElement = ServerBeansFactory.getServerBean(context);
697             Config rootElement = ServerBeansFactory.getConfigBean(context);
698
699             HttpService httpService = rootElement.getHttpService();
700             VirtualServerClass[] vsClasses = httpService.getVirtualServerClass();
701             for(int i = 0 ; i < vsClasses.length ; i ++) {
702                 VirtualServerClass aClass = vsClasses[i];
703                 VirtualServer[] virtualServers = aClass.getVirtualServer();
704                 for(int j = 0 ; j < virtualServers.length ; j++) {
705                     VirtualServer aServer = virtualServers[j];
706                     String file = aServer.getConfigFile();
707                     if ((file == null) || (file.length() == 0)) {
708                         continue;
709                     }
710                     String backPath = getBackupConfigDirPath() + File.separator
711                                         + file;
712                     String hotPath = getConfigDirPath() + File.separator
713                                         + file;
714                     String tsFileName = getTimeStampFileName(backPath);
715                     File f = new File(tsFileName);
716                     if(!f.exists()) {
717                         saveTimeStamp(tsFileName, hotPath, backPath);
718                     }
719                 }
720             }
721         } catch(Throwable t) {
722             _logger.log(Level.WARNING,"core.create_mime_ts_file_exception",t);
723             //ignore. go ahead.
724         }
725 */

726     }
727
728     /**
729     * saves timestamp and resets backup dir to the value of ts
730     */

731         private void saveTimeStamp(String JavaDoc tsFileName, String JavaDoc actualFile, String JavaDoc backupFile) {
732             if(!TIMESTAMP_MECHANISM_ENABLED) return;
733         long ts = saveTimeStamp(tsFileName, actualFile);
734         new File JavaDoc(backupFile).setLastModified(ts);
735     }
736
737         /**
738          * set the value of timestamp in a new file
739          * the name of timestamp file is name of this xml + .timestamp
740          * always create this file even if readonly
741          */

742         private long saveTimeStamp(String JavaDoc tsFileName, String JavaDoc actualFile) {
743             if(!TIMESTAMP_MECHANISM_ENABLED) return INVALID_TIME_STAMP;
744             
745             long timestamp = getConfigFileTimeStamp(actualFile);
746         //_logger.log(Level.FINE,"writing TS file");
747
File JavaDoc f = null;
748             FileWriter JavaDoc fw = null;
749             try {
750                 f = new File JavaDoc(tsFileName);
751                 fw = new FileWriter JavaDoc(f);
752                 fw.write("" + timestamp);
753             } catch(Throwable JavaDoc t) {
754              _logger.log(Level.WARNING,"core.file_io_exception",t);
755                 //ignore
756
} finally {
757                 try {
758                     fw.close();
759                 } catch(Throwable JavaDoc ex){}
760             }
761             return timestamp;
762         }
763
764     /** overwrite the "live" server.xml with the contents of the
765      * backup server.xml file
766      */

767         /*
768     public void applyServerXmlChanges() throws ConfigException {
769         applyServerXmlChanges(false);
770     }
771          */

772     
773     public void applyServerXmlChanges(boolean overwrite) throws ConfigException {
774     }
775
776     /** overwrite the "live" init.conf with the contents of the
777      * backup init.conf file
778      */

779     
780     public void applyInitFileChanges() throws ConfigException {
781     }
782
783     /** overwrite the "live" keyfile with the contents of the
784      * backup init.conf file
785      */

786     
787     public void applyRealmsKeyFileChanges() throws ConfigException {
788     }
789
790     /** overwrite the "live" obj.conf with the contents of the
791      * backup obj.conf file
792      */

793     
794     public void applyObjectFileChanges() throws ConfigException {
795     }
796
797     /** Overwrite all mime.types files for the instance.
798         These are the files that are <code> mime </code>
799         elements on the <code> http-service </code> element.
800         Note, there is no transactional model.
801         @throws ConfigException if copy fails.
802     */

803     public void applyAllMimeFileChanges() throws ConfigException {
804     }
805
806 // Hamid: BugId: 4700937: Start
807
/** overwrite the generated.<serverId>.acl file with the contents of the
808      * genwork.<serverId>.acl file
809      */

810
811     public void applyAclFileChanges() throws ConfigException {
812     }
813 // Hamid: BugId: 4700937: End
814

815     public void applyVirtualServersConfFileChanges(ConfigContext hotXmlCtx)
816             throws ConfigException {
817 /*
818         init();
819             synchronized(lock) {
820         ConfigContext context = ConfigFactory.createConfigContext(
821                                     mBackupConfigFilePath);
822         if (context == null) {
823             // this is serious. ConfigContext for
824             //this server instance should be created by now.
825             
826             throw new ConfigException(
827                     Localizer.getValue(ExceptionType.NO_XML_BU));
828         }
829           //ROB: config changes
830         //Server rootElement = ServerBeansFactory.getServerBean(context);
831           Config rootElement = ServerBeansFactory.getConfigBean(context);
832  
833         HttpService httpService = rootElement.getHttpService();
834         VirtualServerClass[] vsClasses = httpService.getVirtualServerClass();
835         for(int i = 0 ; i < vsClasses.length ; i++) {
836             VirtualServerClass vsClass = vsClasses[i];
837             VirtualServer[] virtualServers = vsClass.getVirtualServer();
838             for(int j = 0 ; j < virtualServers.length ; j++) {
839                 VirtualServer virtualServer = virtualServers[j];
840                 String configFileName = virtualServer.getConfigFile();
841                 File srcFile = null;
842                 if (configFileName != null) {
843                     srcFile = new File(getBackupConfigDirPath(),
844                                        configFileName);
845                 }
846                 if ((srcFile == null) || (!srcFile.exists())) {
847                     continue;
848                 }
849                 File destFile = new File(getConfigDirPath(), configFileName);
850                 copyFile(srcFile, destFile);
851                 //Chown file
852                 if (isChownNeeded(null)) {
853                     chownFile(destFile.getAbsolutePath());
854                 }
855                 if(VIRTUAL_SERVER_TIMESTAMP_MECHANISM_ENABLED) {
856                     String tsFilePath =
857                             getTimeStampFileName(srcFile.getAbsolutePath());
858                     saveTimeStamp(tsFilePath, destFile.getAbsolutePath());
859                 }
860             }
861                
862             }
863 */

864         /* The following code deletes the config files from the config
865          * directory. These config files correspond to the virtual servers
866          * that would have been deleted from the backup xml.
867          */

868 /*
869             deleteVirtualServerConfigFiles(hotXmlCtx, context, true);
870          }
871 */

872         }
873
874     /**
875      * Copies the <code> offline </code> file on <code> real </code> one.
876      * @throws ConfigException in case copy fails for various reasons.
877      * @param hot java.io.File that is real one (target).
878      * @param cold java.io.File that is backup/offline (source).
879     */

880     private void copyFile(File JavaDoc fromFile, File JavaDoc toFile) throws ConfigException
881     {
882         if(!fromFile.exists())
883                 throw new ConfigException(Localizer.getValue(ExceptionType.FROM_NOT_EXIST, fromFile.getPath()));
884
885         if(fromFile.isDirectory())
886                 throw new ConfigException(Localizer.getValue(ExceptionType.FROM_IS_DIR, fromFile.getPath()));
887
888         /** WBN March 14, 2002
889          * There is a very strange problem -- Windows will sometimes return 0 for
890          * the length of a file that is NOT zero-length. I tested and proved beyond
891          * any doubt that length() is *wrong*.
892          * This is probably a JVM bug. So I've commented-out the following code.
893         if(cold.length() <= 0)
894         {
895                 throw new ConfigException(err + coldErr + "is zero length");
896         }
897         */

898
899         if(toFile.isDirectory())
900                 throw new ConfigException(Localizer.getValue(ExceptionType.TO_IS_DIR, toFile.getPath()));
901
902         if(toFile.exists() && !toFile.canWrite())
903                 throw new ConfigException(Localizer.getValue(ExceptionType.TO_READ_ONLY, toFile.getPath()));
904
905         try
906         {
907                 FileUtils.copy(fromFile, toFile);
908         }
909         catch(Exception JavaDoc e)
910         {
911             Object JavaDoc[] objs = new Object JavaDoc[] { fromFile.getPath(), toFile.getPath(), e.toString() };
912             throw new ConfigException(Localizer.getValue(ExceptionType.FAILED_COPY, objs), e);
913         }
914     }
915     
916     /**
917             Creates the path for server.xml pertaining to this Instance.
918     */

919     
920     private void createConfigFilePath() {
921         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot,
922                                          kConfigDirName,
923                                          kConfigXMLFileName};
924         mConfigFilePath = StringUtils.makeFilePath(onlyFolderNames, false);
925     }
926
927     /**
928             Creates the path for backup server.xml pertaining to this Instance.
929     */

930
931     private void createBackupConfigFilePath() {
932         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot,
933                                          kConfigDirName,
934                                          kBackupDirName,
935                                          kConfigXMLFileName};
936         mBackupConfigFilePath = StringUtils.makeFilePath(onlyFolderNames, false);
937     }
938     
939     /**
940         Creates the ApplicationRootPath that is guaranteed to take into account
941         the changes made to server.xml. Initializes the application root to
942         a valid non-null String. Does not check whether this is a directory
943         that can be written to.
944     */

945     private void createApplicationRootPath() {
946         try {
947             ConfigContext context = ConfigFactory.
948                 createConfigContext(mConfigFilePath);
949             Domain domain = ServerBeansFactory.getDomainBean(context);
950             mApplicationRootPath = domain.getApplicationRoot();
951             if (mApplicationRootPath == null || mApplicationRootPath.length() <=0){
952                 createDefaultApplicationRootPath();
953             }
954             mApplicationRootPath = resolvePath(mApplicationRootPath);
955         }
956         catch (Exception JavaDoc e) {
957             _logger.log(Level.WARNING, "InstanceEnv.createApplicationRootPath()", e);
958         }
959     }
960     
961     /** Initializes mApplicationRootPath = <instancedir>/applications.
962     */

963     private void createDefaultApplicationRootPath() {
964         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
965                                         mInstancesRoot,
966                                         kRepositoryDirName};
967         mApplicationRootPath = StringUtils.makeFilePath(onlyFolderNames, false);
968     }
969     /**
970             Creates the path for repository of applications
971             pertaining to this Instance.
972     */

973
974     private void createApplicationRepositoryPath() {
975         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
976                                         mApplicationRootPath,
977                                         kApplicationDirName};
978         mApplicationRepositoryPath = StringUtils.makeFilePath(onlyFolderNames, false);
979     }
980
981     /**
982             Creates the path for repository of standalone modules
983             pertaining to this Instance.
984     */

985
986     private void createModuleRepositoryPath() {
987         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
988                                         mApplicationRootPath,
989                                         kModuleDirName};
990         mModuleRepositoryPath = StringUtils.makeFilePath(onlyFolderNames, false);
991     }
992
993     /**
994             Creates the path for backup repository of applications
995             pertaining to this Instance -- directory-deployed apps
996     */

997
998     private void createApplicationBackupRepositoryPath() {
999         String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
1000                                        mApplicationRootPath,
1001                                        kRepositoryBackupDirName,
1002                                        kApplicationDirName};
1003        mApplicationBackupRepositoryPath = StringUtils.makeFilePath(onlyFolderNames, false);
1004    }
1005
1006    /**
1007            Creates the path for backup repository of modules
1008            pertaining to this Instance -- directory-deployed modules
1009    */

1010
1011    private void createModuleBackupRepositoryPath() {
1012        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
1013                                        mApplicationRootPath,
1014                                        kRepositoryBackupDirName,
1015                                        kModuleDirName};
1016        mModuleBackupRepositoryPath = StringUtils.makeFilePath(onlyFolderNames, false);
1017    }
1018
1019    /**
1020     * Formulates the path to the instance auto deploy dir.
1021     */

1022    private void createAutoDeployDirPath() {
1023        String JavaDoc[] onlyFolderNames =
1024            new String JavaDoc[] {mInstancesRoot, kAutoDeployDirName};
1025        mAutoDeployDirPath = StringUtils.makeFilePath(onlyFolderNames, false);
1026    }
1027
1028
1029    /**
1030     * Formulates the path to the instance lib dir. Any jar files under
1031     * this dir will be included by the shared class loader.
1032     */

1033    private void createLibPath() {
1034        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot, kLibDirName};
1035        mLibPath = StringUtils.makeFilePath(onlyFolderNames, false);
1036
1037    }
1038
1039    /**
1040     * Formulates the path to the instance lib classes directory. Any class
1041     * files under this dir will be be included by the shared class loader.
1042     */

1043    private void createLibClassesPath() {
1044        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot, kLibDirName,
1045        kLibClassesDirName};
1046        mLibClassesPath = StringUtils.makeFilePath(onlyFolderNames, false);
1047    }
1048    
1049    /**
1050            Creates the path for repository of EJB stubs for all applications
1051            deployed to this Instance.
1052    */

1053
1054    private void createApplicationStubPath() {
1055        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot, kGeneratedDirName,
1056                kEJBStubDirName, kApplicationDirName};
1057        mApplicationStubRepositoryPath = StringUtils.makeFilePath(onlyFolderNames, false);
1058    }
1059    
1060    /**
1061            Creates the path for repository of EJB stubs for all standalone modules
1062            deployed to this Instance.
1063    */

1064
1065    private void createModuleStubPath() {
1066        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot, kGeneratedDirName,
1067                kEJBStubDirName, kModuleDirName};
1068        mModuleStubRepositoryPath = StringUtils.makeFilePath(onlyFolderNames, false);
1069    }
1070
1071    /**
1072            Creates the path for generated xml for all applications
1073            deployed to this Instance.
1074    */

1075
1076    private void createApplicationGeneratedXMLPath() {
1077        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot, kGeneratedDirName,
1078                kGeneratedXMLDirName, kApplicationDirName};
1079        mApplicationGeneratedXMLPath = StringUtils.makeFilePath(onlyFolderNames, false);
1080    }
1081
1082    /**
1083            Creates the path for generated xml for all standalone modules
1084            deployed to this Instance.
1085    */

1086
1087    private void createModuleGeneratedXMLPath() {
1088        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot, kGeneratedDirName,
1089                kGeneratedXMLDirName, kModuleDirName};
1090        mModuleGeneratedXMLPath = StringUtils.makeFilePath(onlyFolderNames, false);
1091    }
1092
1093    
1094    /** Path upto <instance-dir>/session-store is returned */
1095    
1096    private String JavaDoc getDefaultSessionStorePath() {
1097        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
1098                mInstancesRoot,
1099                kSessionStoreDirName
1100        };
1101        return ( StringUtils.makeFilePath(onlyFolderNames, false) );
1102    }
1103
1104    /** Creates the paths for ejbs from both application and module. The paths are
1105        like this:
1106        passivated-beans-for-modules=<session-store>/ejb/j2ee-modules
1107        passivated-beans-for-apps=<session-store>/ejb/j2ee-apps
1108    */

1109    private void createPassivatedEjbPaths() {
1110        try {
1111            ConfigContext context = ConfigFactory.createConfigContext(
1112                mConfigFilePath);
1113            EjbContainer ejbContainer = ServerBeansFactory.getConfigBean(context).getEjbContainer();
1114            String JavaDoc sessionStore = ejbContainer.getSessionStore();
1115            if (sessionStore == null || sessionStore.length() <= 0) {
1116                sessionStore = getDefaultSessionStorePath();
1117            }
1118            sessionStore = resolvePath(sessionStore);
1119            String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
1120                sessionStore,
1121                kEJBStubDirName,
1122                kApplicationDirName
1123            };
1124            mApplicationPassivatedEjbPath = StringUtils.makeFilePath(onlyFolderNames, false);
1125            onlyFolderNames[2] = kModuleDirName;
1126            mModulePassivatedEjbPath = StringUtils.makeFilePath(onlyFolderNames, false);
1127        }
1128        catch (Exception JavaDoc e) {
1129            _logger.log(Level.WARNING, "InstanceEnv.createApplicationRootPath()", e);
1130        }
1131    }
1132
1133    /** Creates the paths for ejbs from both application and module. The paths are
1134        like this:
1135        httpsession-store-for-modules=<session-store>/http/j2ee-modules
1136        httpsession-store-for-apps=<session-store>/http/j2ee-apps
1137    */

1138
1139    private void createHttpSessionStorePaths() {
1140        try {
1141            ConfigContext context = ConfigFactory.createConfigContext(
1142                mConfigFilePath);
1143            EjbContainer ejbContainer = ServerBeansFactory.getConfigBean(context).getEjbContainer();
1144            String JavaDoc sessionStore = ejbContainer.getSessionStore();
1145            if (sessionStore == null || sessionStore.length() <= 0) {
1146                sessionStore = getDefaultSessionStorePath();
1147            }
1148            sessionStore = resolvePath(sessionStore);
1149            String JavaDoc[] onlyFolderNames = new String JavaDoc[] {
1150                sessionStore,
1151                kHttpSessionDirName,
1152                kApplicationDirName
1153            };
1154            mApplicationHttpSessionStorePath = StringUtils.makeFilePath(onlyFolderNames, false);
1155            onlyFolderNames[2] = kModuleDirName;
1156            mModuleHttpSessionStorePath = StringUtils.makeFilePath(onlyFolderNames, false);
1157        }
1158        catch (Exception JavaDoc e) {
1159            _logger.log(Level.WARNING, "InstanceEnv.createApplicationRootPath()", e);
1160        }
1161    }
1162    
1163    /** Creates the path for compiled JSP pages from a J2EE application */
1164
1165    private void createApplicationCompiledJspPath() {
1166        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot,
1167            kGeneratedDirName, kCompileJspDirName, kApplicationDirName};
1168
1169        mApplicationCompiledJspPath = StringUtils.makeFilePath(onlyFolderNames, false);
1170    }
1171
1172    /** Creates the path for compiled JSP Pages from a standalone web
1173        app module.
1174    */

1175
1176    private void createWebModuleCompiledJspPath() {
1177        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot,
1178            kGeneratedDirName, kCompileJspDirName, kModuleDirName};
1179
1180        mWebModuleCompiledJspPath = StringUtils.makeFilePath(onlyFolderNames, false);
1181    }
1182
1183    /**
1184        Creates the Path for the docroot of this instance. With the
1185        new layout, the docroot is supposed to be in the folder for
1186        instance configuration by default.
1187    */

1188    private void createDocRootPath() {
1189        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot,
1190            kDocRootDirName};
1191
1192        mDocRootPath = StringUtils.makeFilePath(onlyFolderNames, false);
1193    }
1194    /**
1195        Creates the stop command path for this instance.
1196    */

1197    private void createStopCommandPath() {
1198        String JavaDoc[] onlyFolderNames = new String JavaDoc[] {mInstancesRoot};
1199        String JavaDoc execName = null;
1200        if(OS.isWindows()) {
1201            execName = InstanceDefinition.WIN_STOP_COMMAND_NAME;
1202        }
1203        else {
1204            execName = InstanceDefinition.UNIX_STOP_COMMAND_NAME;
1205        }
1206        mStopCommandPath = StringUtils.makeFilePath(onlyFolderNames, true)
1207                + execName;
1208    }
1209    
1210    /** Creates the path of default access log file */
1211    private void createDefaultAccessLogPath() {
1212        final String JavaDoc logDirName = "logs";
1213        final String JavaDoc accessLogFileName = "access";
1214        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1215           logDirName, accessLogFileName};
1216        mDefaultAccessLogPath = StringUtils.makeFilePath(fileNames, false);
1217    }
1218    
1219    /** Creates the path of object file */
1220    private void createObjectFilePath() {
1221        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1222            kConfigDirName, kObjectFileName};
1223        mObjectFilePath = StringUtils.makeFilePath(fileNames, false);
1224    }
1225
1226    /** Creates the path of initialization file */
1227    private void createInitFilePath() {
1228        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1229            kConfigDirName, kInitFileName};
1230        mInitFilePath = StringUtils.makeFilePath(fileNames, false);
1231    }
1232
1233    /** Creates the path of iWS NSS passwords file */
1234    private void createSecurityPasswordsFilePath() {
1235        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1236            kConfigDirName, kSecurityPasswordsFileName};
1237        mSecurityPasswordsFilePath = StringUtils.makeFilePath(fileNames, false);
1238    }
1239
1240    /** Creates the path of Realms key file */
1241    private void createRealmsKeyFilePath() {
1242        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1243            kConfigDirName, kRealmsKeyFileName};
1244        mRealmsKeyFilePath = StringUtils.makeFilePath(fileNames, false);
1245    }
1246
1247    /** Creates the path of backup object file */
1248    private void createBackupObjectFilePath() {
1249        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1250            kConfigDirName, kBackupDirName, kObjectFileName};
1251        mBackupObjectFilePath = StringUtils.makeFilePath(fileNames, false);
1252    }
1253
1254    /** Creates the path of backup initialization file */
1255    private void createBackupInitFilePath() {
1256        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1257            kConfigDirName, kBackupDirName, kInitFileName};
1258        mBackupInitFilePath = StringUtils.makeFilePath(fileNames, false);
1259    }
1260// Hamid: BugId: 4700937: Start
1261
/** Creates the path of acl file */
1262    private void createAclFilePath() {
1263        // aclFile is generated.<serverId>.acl
1264
String JavaDoc aclFileName = kAclFilePrefix + "." + getName() + "." + kAclFileSuffix;
1265        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1266            kConfigDirName, aclFileName};
1267        mAclFilePath = StringUtils.makeFilePath(fileNames, false);
1268    }
1269
1270    /** Creates the path of backup of acl file */
1271    private void createBackupAclFilePath() {
1272        // backupAclFile is genwork.<serverId>.acl
1273
String JavaDoc backupAclFileName = kBackupAclFilePrefix + "." + getName() + "." + kAclFileSuffix;
1274        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1275            kConfigDirName, backupAclFileName};
1276        mBackupAclFilePath = StringUtils.makeFilePath(fileNames, false);
1277    }
1278// Hamid: BugId: 4700937: End
1279

1280    /** Creates the path of backup Realms key file */
1281    private void createBackupRealmsKeyFilePath() {
1282        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1283            kConfigDirName, kBackupDirName, kRealmsKeyFileName};
1284        mBackupRealmsKeyFilePath = StringUtils.makeFilePath(fileNames, false);
1285    }
1286
1287    /** Creates the path to the java-web-start directory */
1288    private void createJavaWebStartPath() {
1289        String JavaDoc[] fileNames = new String JavaDoc[] {mInstancesRoot,
1290            kJavaWebStartDirName};
1291        mJavaWebStartDirPath = StringUtils.makeFilePath(fileNames, false);
1292    }
1293    /**
1294            A method that returns the logical name of this Server Instance.
1295    */

1296    public String JavaDoc getName() {
1297            return ( mLogicalName );
1298    }
1299    
1300    /**
1301            Returns the path where entire data/config etc. of this instance
1302            is stored on the disk.
1303
1304            @return absolute path of the instance's home.
1305    */

1306
1307    public String JavaDoc getInstancesRoot() {
1308        return (mInstancesRoot);
1309    }
1310    
1311    public String JavaDoc getConfigDirPath() {
1312        String JavaDoc[] folderNames = new String JavaDoc[] {mInstancesRoot,
1313            kConfigDirName};
1314        String JavaDoc configDirPath =
1315                StringUtils.makeFilePath(folderNames, false);
1316        return ( configDirPath );
1317    }
1318
1319    public String JavaDoc getBackupConfigDirPath() {
1320    /*
1321        String[] folderNames = new String[] {mInstancesRoot,
1322            kConfigDirName, kBackupDirName};
1323        String backupConfigDirPath =
1324                StringUtils.makeFilePath(folderNames, false);
1325        return ( backupConfigDirPath );
1326    */

1327    return getConfigDirPath();
1328    }
1329
1330    /**
1331            Returns the absolute path for the config file pertaining
1332            to this Server Instance.
1333    */

1334
1335    public String JavaDoc getConfigFilePath() {
1336            return ( mConfigFilePath );
1337    }
1338
1339    /**
1340            Returns the absolute path for the backup config file pertaining
1341            to this Server Instance.
1342    */

1343
1344    public String JavaDoc getBackupConfigFilePath() {
1345            return ( mConfigFilePath );
1346    }
1347
1348    /**
1349            Returns the absolute path for location where all the deployed
1350            applications are stored for this Server Instance.
1351    */

1352
1353    public String JavaDoc getApplicationRepositoryPath() {
1354        init();
1355            return ( mApplicationRepositoryPath );
1356    }
1357
1358    /**
1359            Returns the absolute path for location where all the backups of
1360            directory-deployed applications are stored for this Server Instance.
1361    */

1362
1363    public String JavaDoc getApplicationBackupRepositoryPath() {
1364        init();
1365            return ( mApplicationBackupRepositoryPath );
1366    }
1367
1368    /**
1369            Returns the absolute path for location where all the deployed
1370            standalone modules are stored for this Server Instance.
1371    */

1372
1373    public String JavaDoc getModuleRepositoryPath() {
1374        init();
1375            return ( mModuleRepositoryPath );
1376
1377    }
1378    /**
1379            Returns the absolute path for location where all the deployed
1380            standalone module backups are stored for this Server Instance.
1381    */

1382
1383    public String JavaDoc getModuleBackupRepositoryPath() {
1384        init();
1385            return ( mModuleBackupRepositoryPath );
1386
1387    }
1388
1389    /**
1390            Returns the absolute path for location where all ejb stubs for
1391            all applications are stored for this Server Instance.
1392    */

1393
1394    public String JavaDoc getApplicationStubPath() {
1395        init();
1396            return ( mApplicationStubRepositoryPath );
1397    }
1398
1399    /**
1400            Returns the absolute path for location where all ejb stubs for
1401            all modules are stored for this Server Instance.
1402    */

1403
1404    public String JavaDoc getModuleStubPath() {
1405        init();
1406            return ( mModuleStubRepositoryPath );
1407    }
1408
1409    /**
1410            Returns the absolute path for location where all generated xml for
1411            all applications are stored for this Server Instance.
1412    */

1413
1414    public String JavaDoc getApplicationGeneratedXMLPath() {
1415        init();
1416            return ( mApplicationGeneratedXMLPath );
1417    }
1418
1419    /**
1420            Returns the absolute path for location where all generated xml for
1421            all modules are stored for this Server Instance.
1422    */

1423
1424    public String JavaDoc getModuleGeneratedXMLPath() {
1425        init();
1426            return ( mModuleGeneratedXMLPath );
1427    }
1428
1429
1430
1431    /**
1432    * Returns the path to the instance lib directory.
1433    * @return the path to the instance lib directory
1434    */

1435    public String JavaDoc getLibPath() {
1436        init();
1437        return ( mLibPath );
1438    }
1439
1440    /**
1441     * Returns the path to the templates directory.
1442     */

1443    public static String JavaDoc getTemplatesDirPath() {
1444        final String JavaDoc installRoot = System.getProperty(Constants.INSTALL_ROOT);
1445        String JavaDoc[] dirs = new String JavaDoc[] {installRoot, kLibDirName,
1446                                      kInstallDirName, kTemplatesDirName};
1447        return StringUtils.makeFilePath(dirs, false);
1448    }
1449
1450   /**
1451    * Returns the path to the instance's auto deploy directory.
1452    *
1453    * @return the path to the instance's auto deploy directory
1454    */

1455    public String JavaDoc getAutoDeployDirPath() {
1456        init();
1457        return ( mAutoDeployDirPath );
1458    }
1459    
1460    /**
1461     * Returns the path to the instance lib/classes directory.
1462    * @return the path to the instance lib/classes directory
1463    */

1464    public String JavaDoc getLibClassesPath() {
1465        init();
1466        return ( mLibClassesPath );
1467    }
1468
1469    /**
1470        Returns the path for compiled JSP Pages from an J2EE application
1471        that is deployed on this instance. By default all such compiled JSPs
1472        should lie in the same folder.
1473    */

1474    public String JavaDoc getApplicationCompileJspPath() {
1475        init();
1476        return ( mApplicationCompiledJspPath );
1477    }
1478
1479    /**
1480        Returns the path for compiled JSP Pages from an Web application
1481        that is deployed standalone on this instance. By default all such compiled JSPs
1482        should lie in the same folder.
1483    */

1484    public String JavaDoc getWebModuleCompileJspPath() {
1485        init();
1486        return ( mWebModuleCompiledJspPath );
1487    }
1488
1489    /**
1490        Returns the path for the Session Store of where HTTP
1491        session data of the instance can be stored.
1492    */

1493    public String JavaDoc getApplicationPassivatedEjbPath() {
1494        init();
1495        return ( mApplicationPassivatedEjbPath );
1496    }
1497    public String JavaDoc getModulePassivatedEjbPath() {
1498        init();
1499        return ( mModulePassivatedEjbPath );
1500    }
1501    public String JavaDoc getApplicationHttpSessionStorePath() {
1502        init();
1503        return ( mApplicationHttpSessionStorePath );
1504    }
1505    public String JavaDoc getModuleHttpSessionStorePath() {
1506        init();
1507        return ( mModuleHttpSessionStorePath );
1508    }
1509    
1510    /**
1511        Returns the docroot path for this instance.
1512    */

1513    public String JavaDoc getDocRootPath() {
1514        init();
1515        return ( mDocRootPath );
1516    }
1517    
1518    public String JavaDoc getStopCommandPath() {
1519        init();
1520        return ( mStopCommandPath );
1521    }
1522    
1523    /**
1524     * Returns the default value of accesslog for the instance.
1525     * Returns null in case of error.
1526     * Note that this is only the default value which may be
1527     * different than the actual value of any virtual server in this instance.
1528     *
1529     * @return String representing default log file path for any virtual server
1530     * in this instance.
1531    */

1532    public String JavaDoc getDefaultAccessLogPath() {
1533        init();
1534        return ( mDefaultAccessLogPath );
1535    }
1536    
1537    /* Gets the complete path of the initialization file
1538     * for this instance */

1539    public String JavaDoc getInitFilePath() {
1540        init();
1541        return ( mInitFilePath );
1542    }
1543    /* Gets the complete path of the backup of initialization file
1544     * for this instance */

1545    public String JavaDoc getBackupInitFilePath() {
1546        init();
1547        return ( mBackupInitFilePath );
1548    }
1549
1550    /* Gets the complete path of the Security passwords file
1551     * for this instance */

1552    public String JavaDoc getSecurityPasswordsFilePath() {
1553        init();
1554        return ( mSecurityPasswordsFilePath );
1555    }
1556    /* Gets the complete path of the Realms key file
1557     * for this instance */

1558    public String JavaDoc getRealmsKeyFilePath() {
1559        init();
1560        return ( mRealmsKeyFilePath );
1561    }
1562
1563    /* Gets the complete path of the backup of the Realms key file
1564     * for this instance */

1565    public String JavaDoc getBackupRealmsKeyFilePath() {
1566        init();
1567        return ( mRealmsKeyFilePath );
1568    }
1569
1570    /* Gets the complete path of the object file
1571     * for this instance */

1572    public String JavaDoc getObjectFilePath() {
1573        init();
1574        return ( mObjectFilePath );
1575    }
1576    /* Gets the complete path of the backup of object file
1577     * for this instance */

1578    public String JavaDoc getBackupObjectFilePath() {
1579        init();
1580        return ( mBackupObjectFilePath );
1581    }
1582
1583    public ApplicationEnvironment getApplicationEnvironment(String JavaDoc appName) {
1584
1585        init();
1586        if (appName == null) {
1587            throw new IllegalArgumentException JavaDoc();
1588        }
1589        return ( new ApplicationEnvironment(this, appName) );
1590    }
1591
1592    public ModuleEnvironment getModuleEnvironment(String JavaDoc moduleName, DeployableObjectType type) {
1593        init();
1594        if (moduleName == null) {
1595                throw new IllegalArgumentException JavaDoc();
1596        }
1597
1598        return ( new ModuleEnvironment(this, moduleName, type) );
1599    }
1600
1601    public String JavaDoc getJavaWebStartPath() {
1602        init();
1603        return mJavaWebStartDirPath;
1604    }
1605    
1606    public String JavaDoc verify()
1607    {
1608            // return a String with the error, in English, if the required
1609
// directories aren't there or have a problem.
1610
// return null if all is OK
1611
return null;
1612    }
1613
1614    public String JavaDoc toString()
1615    {
1616        init();
1617            return ObjectAnalyzer.toString(this);
1618    }
1619
1620
1621    /** return true if the given file is located somewhere in the instance's file tree
1622     **/

1623
1624    public final boolean isIASOwned(String JavaDoc filename)
1625    {
1626            return isIASOwned(new File JavaDoc(filename));
1627    }
1628
1629    /** return true if the given file is located somewhere in the instance's file tree
1630     **/

1631
1632    public final boolean isIASOwned(File JavaDoc file)
1633    {
1634        init();
1635        try
1636        {
1637            // get the names and standardize them for comparison
1638
String JavaDoc iasPath = getInstancesRoot();
1639            assert StringUtils.ok(iasPath);
1640
1641            iasPath = FileUtils.safeGetCanonicalPath(new File JavaDoc(iasPath));
1642            String JavaDoc filename = FileUtils.safeGetCanonicalPath(file);
1643
1644            if(!StringUtils.ok(iasPath))
1645                    return false;
1646
1647            if(!StringUtils.ok(filename))
1648                    return false;
1649
1650            if(filename.startsWith(iasPath))
1651                    return true;
1652
1653            return false;
1654        }
1655        catch(Exception JavaDoc e)
1656        {
1657                return false;
1658        }
1659    }
1660
1661    public boolean restartRequired() {
1662        init();
1663        //is instance stopped, return false;
1664
//is instance restarted after changes, return false;
1665
// return true;
1666
synchronized(lock) {
1667        try {
1668            RMIClient rc = AdminChannel.getRMIClient(this.mLogicalName);
1669            if(!rc.isAlive()) return false;
1670            if(rc.hasRestartedSince(getManualChangeTime())) return false;
1671            
1672            return true;
1673        } catch (Exception JavaDoc e) {
1674            //ignore
1675
}
1676        }
1677        return false;
1678    }
1679   
1680
1681    private long getManualChangeTime() {
1682        long ts = UNINITIALIZED_TIME_STAMP;
1683        long tsTmp = UNINITIALIZED_TIME_STAMP;
1684        
1685        try {
1686            ts = getConfigFileTimeStamp(mInitFilePath);
1687            tsTmp = getConfigFileTimeStamp(mObjectFilePath);
1688            
1689            if(ts < tsTmp) ts = tsTmp;
1690            
1691            tsTmp = getConfigFileTimeStamp(mConfigFilePath);
1692            
1693            if(ts < tsTmp) ts = tsTmp;
1694            
1695/*
1696            ConfigContext context = ConfigFactory.
1697            createConfigContext(mConfigFilePath, true, false, false);
1698            if (context == null) {
1699                        // this is serious. ConfigContext for
1700                        //this server instance should be created by now.
1701                throw new ConfigException(Localizer.getValue(ExceptionType.NO_XML));
1702            }
1703            //ROB: config changes
1704            //Server rootElement = ServerBeansFactory.getServerBean(context);
1705            Config rootElement = ServerBeansFactory.getConfigBean(context);
1706
1707            HttpService httpService = rootElement.getHttpService();
1708            Mime[] mimes = httpService.getMime();
1709            for(int i = 0 ; i < mimes.length ; i ++) {
1710                Mime aMime = mimes[i];
1711                String file = aMime.getFile();
1712                String hotPath = getConfigDirPath() + File.separator
1713                + file;
1714                
1715                
1716                tsTmp = getConfigFileTimeStamp(hotPath);
1717                if(ts < tsTmp) ts = tsTmp;
1718                
1719            }
1720 
1721*/

1722        } catch (Throwable JavaDoc t) {
1723            //ignore return ture;
1724
}
1725        return ts;
1726    }
1727   
1728 
1729    private boolean hasBakMimeChanged() {
1730    return false;
1731    }
1732
1733    /*
1734    public static void main(String[] args)
1735    {
1736            //Logger logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
1737            System.out.println("Use the appserv-ext.jar, appserv-rt.jar from lib area for other classes");
1738            System.setProperty("com.sun.aas.instanceRoot", "E:\\ias-build\\s1\\appserv\\domains\\domain1");
1739            InstanceEnvironment env = new InstanceEnvironment("server1");
1740            //logger.log(Level.INFO, env.toString());
1741            System.out.println(env.toString());
1742    }
1743    */

1744
1745    public String JavaDoc getInstanceUser() throws IOException JavaDoc {
1746        init();
1747        return ServerManager.instance().getInstanceUser(this);
1748    }
1749
1750    /**Ignoring the file parameter for now.
1751     */

1752    public boolean isChownNeeded(File JavaDoc f) {
1753        init();
1754/**
1755        if (OS.isUnix() || OS.isLinux()) {
1756            try {
1757                final String installUser =
1758                    ServerManager.instance().getInstanceUser(
1759                            new InstanceEnvironment("admin-server"));
1760                final String instanceUser =
1761                    ServerManager.instance().getInstanceUser(this);
1762                if (installUser.equals("root") &&
1763                    !instanceUser.equals(installUser)) {
1764                    return true;
1765                }
1766            } catch (IOException ioe) {
1767                _logger.warning(ioe.getMessage());
1768            }
1769        }
1770*/

1771        return false;
1772    }
1773
1774    private void chownFile(String JavaDoc filePath) throws ConfigException {
1775        /*installConfig is removed and we need better alternative */
1776        /*
1777        try {
1778            String error = new installConfig().chownFile(
1779                filePath, getInstanceUser());
1780            if (error != null) {
1781                throw new ConfigException(error);
1782            }
1783        } catch (IOException ioe) {
1784            throw new ConfigException(ioe.getMessage());
1785        }
1786        */

1787    }
1788
1789    private void createPathResolver() {
1790        try {
1791            mPathResolver = new PropertyResolver(
1792                ConfigFactory.createConfigContext(mConfigFilePath),
1793                mLogicalName);
1794        } catch (Exception JavaDoc e) {
1795            //log it.
1796
}
1797    }
1798
1799    private String JavaDoc resolvePath(String JavaDoc unresolved) {
1800        if (mPathResolver != null) {
1801            return mPathResolver.resolve(unresolved);
1802        }
1803        return unresolved;
1804    }
1805}
1806
Popular Tags