KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.catalina.storeconfig;
17
18 import java.io.PrintWriter JavaDoc;
19
20 import org.apache.catalina.deploy.ContextEjb;
21 import org.apache.catalina.deploy.ContextEnvironment;
22 import org.apache.catalina.deploy.ContextLocalEjb;
23 import org.apache.catalina.deploy.ContextResource;
24 import org.apache.catalina.deploy.ContextResourceEnvRef;
25 import org.apache.catalina.deploy.ContextResourceLink;
26 import org.apache.catalina.deploy.NamingResources;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 /**
31  * Store server.xml elements Resources at context and GlobalNamingResources
32  *
33  * @author Peter Rossbach
34  *
35  */

36 public class NamingResourcesSF extends StoreFactoryBase {
37     private static Log log = LogFactory.getLog(NamingResourcesSF.class);
38
39     /**
40      * Store the only the NamingResources elements
41      *
42      * @see NamingResourcesSF#storeChilds(PrintWriter, int, Object,
43      * RegistryDescription)
44      */

45     public void store(PrintWriter JavaDoc aWriter, int indent, Object JavaDoc aElement)
46             throws Exception JavaDoc {
47         StoreDescription elementDesc = getRegistry().findDescription(
48                 aElement.getClass());
49         if (elementDesc != null) {
50             if (log.isDebugEnabled())
51                 log.debug("store " + elementDesc.getTag() + "( " + aElement
52                         + " )");
53             storeChilds(aWriter, indent, aElement, elementDesc);
54         } else {
55             if (log.isWarnEnabled())
56                 log.warn("Descriptor for element" + aElement.getClass()
57                         + " not configured!");
58         }
59     }
60
61     /**
62      * Store the specified NamingResources properties.
63      *
64      * @param aWriter
65      * PrintWriter to which we are storing
66      * @param indent
67      * Number of spaces to indent this element
68      * @param aElement
69      * Object whose properties are being stored
70      * @param elementDesc
71      * element descriptor
72      *
73      * @exception Exception
74      * if an exception occurs while storing
75      *
76      * @see org.apache.catalina.storeconfig.StoreFactoryBase#storeChilds(java.io.PrintWriter,
77      * int, java.lang.Object,
78      * org.apache.catalina.config.RegistryDescription)
79      */

80     public void storeChilds(PrintWriter JavaDoc aWriter, int indent, Object JavaDoc aElement,
81             StoreDescription elementDesc) throws Exception JavaDoc {
82
83         if (aElement instanceof NamingResources) {
84             NamingResources resources = (NamingResources) aElement;
85             // Store nested <Ejb> elements
86
ContextEjb[] ejbs = resources.findEjbs();
87             storeElementArray(aWriter, indent, ejbs);
88             // Store nested <Environment> elements
89
ContextEnvironment[] envs = resources.findEnvironments();
90             storeElementArray(aWriter, indent, envs);
91             // Store nested <LocalEjb> elements
92
ContextLocalEjb[] lejbs = resources.findLocalEjbs();
93             storeElementArray(aWriter, indent, lejbs);
94
95             // Store nested <Resource> elements
96
ContextResource[] dresources = resources.findResources();
97             storeElementArray(aWriter, indent, dresources);
98
99             // Store nested <ResourceEnvRef> elements
100
ContextResourceEnvRef[] resEnv = resources.findResourceEnvRefs();
101             storeElementArray(aWriter, indent, resEnv);
102
103             // Store nested <ResourceLink> elements
104
ContextResourceLink[] resourceLinks = resources.findResourceLinks();
105             storeElementArray(aWriter, indent, resourceLinks);
106         }
107     }
108 }
109
110
Popular Tags