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;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.apache.catalina.Cluster;
24 import org.apache.catalina.Container;
25 import org.apache.catalina.Lifecycle;
26 import org.apache.catalina.LifecycleListener;
27 import org.apache.catalina.Pipeline;
28 import org.apache.catalina.Realm;
29 import org.apache.catalina.Valve;
30 import org.apache.catalina.cluster.ClusterValve;
31 import org.apache.catalina.core.StandardHost;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 /**
36 * Store server.xml Element Host
37 *
38 * @author Peter Rossbach
39 */
40 public class StandardHostSF extends StoreFactoryBase {
41
42 private static Log log = LogFactory.getLog(StandardHostSF.class);
43
44 /**
45 * Store the specified Host properties and childs
46 * (Listener,Alias,Realm,Valve,Cluster, Context)
47 *
48 * @param aWriter
49 * PrintWriter to which we are storing
50 * @param indent
51 * Number of spaces to indent this element
52 * @param aHost
53 * Host whose properties are being stored
54 *
55 * @exception Exception
56 * if an exception occurs while storing
57 */
58 public void storeChilds(PrintWriter aWriter, int indent, Object aHost,
59 StoreDescription parentDesc) throws Exception {
60 if (aHost instanceof StandardHost) {
61 StandardHost host = (StandardHost) aHost;
62 // Store nested <Listener> elements
63 if (host instanceof Lifecycle) {
64 LifecycleListener listeners[] = ((Lifecycle) host)
65 .findLifecycleListeners();
66 storeElementArray(aWriter, indent, listeners);
67 }
68
69 // Store nested <Alias> elements
70 String aliases[] = host.findAliases();
71 getStoreAppender().printTagArray(aWriter, "Alias", indent + 2,
72 aliases);
73
74 // Store nested <Realm> element
75 Realm realm = host.getRealm();
76 if (realm != null) {
77 Realm parentRealm = null;
78 if (host.getParent() != null) {
79 parentRealm = host.getParent().getRealm();
80 }
81 if (realm != parentRealm) {
82 storeElement(aWriter, indent, realm);
83 }
84 }
85
86 // Store nested <Valve> elements
87 if (host instanceof Pipeline) {
88 Valve valves[] = ((Pipeline) host).getValves();
89 if(valves != null && valves.length > 0 ) {
90 List hostValves = new ArrayList() ;
91 for(int i = 0 ; i < valves.length ; i++ ) {
92 if(!( valves[i] instanceof ClusterValve))
93 hostValves.add(valves[i]);
94 }
95 storeElementArray(aWriter, indent, hostValves.toArray());
96 }
97 }
98
99 // store all <Cluster> elements
100 Cluster cluster = host.getCluster();
101 if (cluster != null) {
102 storeElement(aWriter, indent, cluster);
103 }
104
105 // store all <Context> elements
106 Container children[] = host.findChildren();
107 storeElementArray(aWriter, indent, children);
108 }
109 }
110
111 }