KickJava   Java API By Example, From Geeks To Geeks.

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


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.Loader;
22 import org.apache.catalina.loader.WebappLoader;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /**
27  * Store Loader Element *
28  *
29  * @author Peter Rossbach
30  */

31 public class LoaderSF extends StoreFactoryBase {
32
33     private static Log log = LogFactory.getLog(LoaderSF.class);
34
35     /**
36      * Store the only the Loader elements, when not default
37      *
38      * @see NamingResourcesSF#storeChilds(PrintWriter, int, Object,
39      * RegistryDescription)
40      */

41     public void store(PrintWriter JavaDoc aWriter, int indent, Object JavaDoc aElement)
42             throws Exception JavaDoc {
43         StoreDescription elementDesc = getRegistry().findDescription(
44                 aElement.getClass());
45         if (elementDesc != null) {
46             Loader loader = (Loader) aElement;
47             if (!isDefaultLoader(loader)) {
48                 if (log.isDebugEnabled())
49                     log.debug("store " + elementDesc.getTag() + "( " + aElement
50                             + " )");
51                 getStoreAppender().printIndent(aWriter, indent + 2);
52                 getStoreAppender().printTag(aWriter, indent + 2, loader,
53                         elementDesc);
54             }
55         } else {
56             if (log.isWarnEnabled()) {
57                 log
58                         .warn("Descriptor for element"
59                                 + aElement.getClass()
60                                 + " not configured or element class not StandardManager!");
61             }
62         }
63     }
64
65     /**
66      * Is this an instance of the default <code>Loader</code> configuration,
67      * with all-default properties?
68      *
69      * @param loader
70      * Loader to be tested
71      */

72     protected boolean isDefaultLoader(Loader loader) {
73
74         if (!(loader instanceof WebappLoader)) {
75             return (false);
76         }
77         WebappLoader wloader = (WebappLoader) loader;
78         if ((wloader.getDelegate() != false)
79                 || !wloader.getLoaderClass().equals(
80                         "org.apache.catalina.loader.WebappClassLoader")) {
81             return (false);
82         }
83         return (true);
84     }
85 }
Popular Tags