KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > storeconfig > StandardServerSF


1 /*
2  * Copyright 1999-2001,2004 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.catalina.storeconfig;
18
19 import java.io.PrintWriter JavaDoc;
20
21 import org.apache.catalina.Lifecycle;
22 import org.apache.catalina.LifecycleListener;
23 import org.apache.catalina.Service;
24 import org.apache.catalina.core.StandardServer;
25 import org.apache.catalina.deploy.NamingResources;
26 import org.apache.catalina.mbeans.ServerLifecycleListener;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 /**
31  * Store server.xml Server element and childs (
32  * Listener,GlobalNamingResource,Service)
33  *
34  * @author Peter Rossbach
35  */

36 public class StandardServerSF extends StoreFactoryBase {
37
38     private static Log log = LogFactory.getLog(StandardServerSF.class);
39
40     /**
41      * Store the specified Server properties.
42      *
43      * @param aWriter
44      * PrintWriter to which we are storing
45      * @param indent
46      * Number of spaces to indent this element
47      * @param aServer
48      * Object to be stored
49      *
50      * @exception Exception
51      * if an exception occurs while storing
52      * @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter,
53      * int, java.lang.Object)
54      */

55     public void store(PrintWriter JavaDoc aWriter, int indent, Object JavaDoc aServer)
56             throws Exception JavaDoc {
57         storeXMLHead(aWriter);
58         super.store(aWriter, indent, aServer);
59     }
60
61     /**
62      * Store Childs from this StandardServer descrition
63      *
64      * @param aWriter
65      * @param indent
66      * @param server
67      * @throws Exception
68      */

69     public void storeChilds(PrintWriter JavaDoc aWriter, int indent, Object JavaDoc aObject,
70             StoreDescription parentDesc) throws Exception JavaDoc {
71         if (aObject instanceof StandardServer) {
72             StandardServer server = (StandardServer) aObject;
73             // Store nested <Listener> elements
74
if (server instanceof Lifecycle) {
75                 LifecycleListener listeners[] = ((Lifecycle) server)
76                         .findLifecycleListeners();
77                 storeElementArray(aWriter, indent, listeners);
78                 LifecycleListener listener = null;
79                 for (int i = 0; listener == null && i < listeners.length; i++)
80                     if (listeners[i] instanceof ServerLifecycleListener)
81                         listener = listeners[i];
82                 if (listener != null) {
83                     StoreDescription elementDesc = getRegistry()
84                             .findDescription(
85                                     StandardServer.class.getName()
86                                             + ".[ServerLifecycleListener]");
87                     if (elementDesc != null) {
88                         elementDesc.getStoreFactory().store(aWriter, indent,
89                                 listener);
90                     }
91                 }
92             }
93             // Store nested <GlobalNamingResources> element
94
NamingResources globalNamingResources = server
95                     .getGlobalNamingResources();
96             StoreDescription elementDesc = getRegistry().findDescription(
97                     NamingResources.class.getName()
98                             + ".[GlobalNamingResources]");
99             if (elementDesc != null) {
100                 elementDesc.getStoreFactory().store(aWriter, indent,
101                         globalNamingResources);
102             }
103             // Store nested <Service> elements
104
Service services[] = server.findServices();
105             storeElementArray(aWriter, indent, services);
106         }
107     }
108
109 }
Popular Tags