KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.catalina.cluster.CatalinaCluster;
19 import org.apache.catalina.cluster.ClusterDeployer;
20 import org.apache.catalina.cluster.ClusterReceiver;
21 import org.apache.catalina.cluster.ClusterSender;
22 import org.apache.catalina.cluster.MembershipService;
23 import org.apache.catalina.deploy.ContextEjb;
24 import org.apache.catalina.deploy.ContextEnvironment;
25 import org.apache.catalina.deploy.ContextLocalEjb;
26 import org.apache.catalina.deploy.ContextResource;
27 import org.apache.catalina.deploy.ContextResourceEnvRef;
28 import org.apache.catalina.deploy.ContextResourceLink;
29 import org.apache.catalina.deploy.NamingResources;
30 import org.apache.catalina.storeconfig.IStoreFactory;
31 import org.apache.catalina.storeconfig.StoreDescription;
32 import org.apache.catalina.storeconfig.StoreRegistry;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 /**
37  * @author Peter Rossbach
38  *
39  */

40 public class DescriptorHelper {
41     private static Log log = LogFactory.getLog(DescriptorHelper.class);
42
43     public static StoreDescription registerDescriptor(
44             StoreDescription parentdesc, StoreRegistry registry, String JavaDoc tag,
45             Class JavaDoc aClass) {
46         return registerDescriptor(parentdesc, registry, aClass.getName(), tag,
47                 aClass.getName(),
48                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
49                 false);
50     }
51
52     public static StoreDescription registerDescriptor(
53             StoreDescription parentdesc, StoreRegistry registry, String JavaDoc tag,
54             String JavaDoc aClassToken, String JavaDoc factoryClass, boolean fstandard,
55             boolean fdefault) {
56         return registerDescriptor(parentdesc, registry, aClassToken, tag,
57                 aClassToken,
58                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
59                 false);
60     }
61
62     /**
63      * Generate a descriptor and register this to another parent descriptor.
64      *
65      * @param parentdesc
66      * @param registry
67      * @param id
68      * @param tag
69      * @param aClassToken
70      * @param factoryClass
71      * @param fstandard
72      * @param fdefault
73      * @return
74      */

75     public static StoreDescription registerDescriptor(
76             StoreDescription parentdesc, StoreRegistry registry, String JavaDoc id,
77             String JavaDoc tag, String JavaDoc aClassToken, String JavaDoc factoryClass,
78             boolean fstandard, boolean fdefault) {
79         // add Listener
80
StoreDescription descChild = new StoreDescription();
81         descChild.setId(id);
82         descChild.setTag(tag);
83         descChild.setTagClass(aClassToken);
84         descChild.setStandard(fstandard);
85         descChild.setDefault(fdefault);
86         descChild.setStoreFactoryClass(factoryClass);
87         Object JavaDoc factory = null;
88         try {
89             Class JavaDoc aFactoryClass = Class.forName(factoryClass);
90             factory = aFactoryClass.newInstance();
91         } catch (Exception JavaDoc e) {
92             log.error(e);
93         }
94         if (factory != null) {
95             ((IStoreFactory) factory).setRegistry(registry);
96             descChild.setStoreFactory((IStoreFactory) factory);
97         }
98         if (parentdesc != null)
99             parentdesc.setChilds(true);
100         registry.registerDescription(descChild);
101         return descChild;
102     }
103
104     /**
105      * register all Registery descriptors on naming support to context!
106      *
107      * @param parent
108      * @param registry
109      * @return
110      * @throws Exception
111      */

112     public static StoreDescription registerNamingDescriptor(
113             StoreDescription parent, StoreRegistry registry) throws Exception JavaDoc {
114
115         StoreDescription nameingDesc = DescriptorHelper.registerDescriptor(
116                 parent, registry, NamingResources.class.getName(),
117                 "NamingResources", NamingResources.class.getName(),
118                 "org.apache.catalina.storeconfig.NamingResourcesSF", true,
119                 false);
120         registerDescriptor(nameingDesc, registry, ContextEjb.class.getName(),
121                 "EJB", ContextEjb.class.getName(),
122                 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false);
123         registerDescriptor(nameingDesc, registry, ContextEnvironment.class
124                 .getName(), "Environment", ContextEnvironment.class.getName(),
125                 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false);
126         registerDescriptor(nameingDesc, registry, ContextLocalEjb.class
127                 .getName(), "LocalEjb", ContextLocalEjb.class.getName(),
128                 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false);
129         registerDescriptor(nameingDesc, registry, ContextResource.class
130                 .getName(), "Resource", ContextResource.class.getName(),
131                 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false);
132         registerDescriptor(nameingDesc, registry, ContextResourceLink.class
133                 .getName(), "ResourceLink",
134                 ContextResourceLink.class.getName(),
135                 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false);
136         registerDescriptor(nameingDesc, registry, ContextResourceEnvRef.class
137                 .getName(), "ResourceEnvRef", ContextResourceEnvRef.class
138                 .getName(), "org.apache.catalina.storeconfig.StoreFactoryBase",
139                 true, false);
140         return nameingDesc;
141     }
142
143     /**
144      * register all cluster and subelement descriptors to registery
145      *
146      * @param parent
147      * @param registry
148      * @return
149      * @throws Exception
150      */

151     public static StoreDescription registerClusterDescriptor(
152             StoreDescription parent, StoreRegistry registry) throws Exception JavaDoc {
153
154         StoreDescription clusterDesc = DescriptorHelper.registerDescriptor(
155                 parent, registry, CatalinaCluster.class.getName(), "Cluster",
156                 CatalinaCluster.class.getName(),
157                 "org.apache.catalina.storeconfig.CatalinaClusterSF", false,
158                 false);
159         registerDescriptor(clusterDesc, registry,
160                 ClusterSender.class.getName(), "Sender", ClusterSender.class
161                         .getName(),
162                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
163                 false);
164         registerDescriptor(clusterDesc, registry, ClusterReceiver.class
165                 .getName(), "Receiver", ClusterReceiver.class.getName(),
166                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
167                 false);
168         registerDescriptor(clusterDesc, registry, MembershipService.class
169                 .getName(), "Membership", MembershipService.class.getName(),
170                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
171                 false);
172         registerDescriptor(clusterDesc, registry, ClusterDeployer.class
173                 .getName(), "Deployer", ClusterDeployer.class.getName(),
174                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
175                 false);
176         return clusterDesc;
177     }
178
179 }
Popular Tags