KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > resource > ExternalJndiResourceDeployer


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * @(#) ExternalJndiResourceDeployer.java
26  *
27  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  *
31  * This software is the confidential and proprietary information
32  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
33  * You shall not disclose such Confidential Information and shall
34  * use it only in accordance with the terms of the license
35  * agreement you entered into with iPlanet/Sun Microsystems.
36  */

37 package com.sun.enterprise.resource;
38
39 import com.sun.enterprise.server.ResourceDeployer;
40 import com.sun.enterprise.config.serverbeans.Resources;
41
42 import com.sun.enterprise.Switch;
43 import com.sun.enterprise.NamingManager;
44 import com.sun.enterprise.resource.ResourceInstaller;
45 import com.sun.enterprise.repository.J2EEResource;
46 import com.sun.enterprise.repository.ExternalJndiResource;
47 import com.sun.enterprise.repository.IASJ2EEResourceFactoryImpl;
48
49 import java.util.logging.Logger JavaDoc;
50 import java.util.logging.Level JavaDoc;
51 import com.sun.logging.LogDomains;
52 import com.sun.enterprise.util.i18n.StringManager;
53
54 /**
55  * Handles external-jndi resource events in the server instance.
56  *
57  * The external-jndi resource events from the admin instance are propagated
58  * to this object.
59  *
60  * The methods can potentially be called concurrently, therefore implementation
61  * need to be synchronized.
62  *
63  * @author Nazrul Islam
64  * @since JDK1.4
65  */

66 public class ExternalJndiResourceDeployer implements ResourceDeployer {
67
68     /** StringManager for this deployer */
69     private static final StringManager localStrings =
70         StringManager.getManager("com.sun.enterprise.resource");
71     /** logger for this deployer */
72     private static Logger JavaDoc _logger=LogDomains.getLogger(LogDomains.CORE_LOGGER);
73
74     /**
75      * Deploy the resource into the server's runtime naming context
76      *
77      * @param resoure a resource object (eg. JmsResource)
78      * @exception Exception thrown if fail
79      */

80     public synchronized void deployResource(Object JavaDoc resource) throws Exception JavaDoc {
81         
82         com.sun.enterprise.config.serverbeans.ExternalJndiResource jndiRes =
83             (com.sun.enterprise.config.serverbeans.ExternalJndiResource) resource;
84         
85         if (jndiRes.isEnabled()) {
86             // converts the config data to j2ee resource
87
J2EEResource j2eeRes =
88                 IASJ2EEResourceFactoryImpl.toExternalJndiJ2EEResource(jndiRes);
89
90             // resource installer
91
ResourceInstaller installer =
92                 Switch.getSwitch().getResourceInstaller();
93
94             // installs the resource
95
installer.installExternalJndiResource(
96                 (ExternalJndiResource) j2eeRes);
97
98             // adds the resource to the resource collection
99
installer.addResource(j2eeRes);
100         } else {
101             _logger.log(Level.INFO, "core.resource_disabled",
102                 new Object JavaDoc[] {jndiRes.getJndiName(),
103                               IASJ2EEResourceFactoryImpl.EXT_JNDI_RES_TYPE});
104         }
105
106     }
107
108     /**
109      * Undeploy the resource from the server's runtime naming context
110      *
111      * @param resoure a resource object (eg. JmsResource)
112      * @exception Exception thrown if fail
113      */

114     public synchronized void undeployResource(Object JavaDoc resource)
115             throws Exception JavaDoc {
116
117         com.sun.enterprise.config.serverbeans.ExternalJndiResource jndiRes =
118             (com.sun.enterprise.config.serverbeans.ExternalJndiResource) resource;
119
120         // converts the config data to j2ee resource
121
J2EEResource j2eeResource =
122             IASJ2EEResourceFactoryImpl.toExternalJndiJ2EEResource(jndiRes);
123
124         // resource installer
125
ResourceInstaller installer = Switch.getSwitch().getResourceInstaller();
126
127         // un-installs the resource
128
installer.uninstallExternalJndiResource(j2eeResource);
129     }
130
131     /**
132      * Redeploy the resource into the server's runtime naming context
133      *
134      * @param resoure a resource object (eg. JmsResource)
135      * @exception Exception thrown if fail
136      */

137     public synchronized void redeployResource(Object JavaDoc resource)
138             throws Exception JavaDoc {
139
140         undeployResource(resource);
141         deployResource(resource);
142     }
143
144     /**
145      * Enable the resource in the server's runtime naming context
146      *
147      * @param resoure a resource object (eg. JmsResource)
148      * @exception Exception thrown if fail
149      */

150     public synchronized void enableResource(Object JavaDoc resource) throws Exception JavaDoc {
151         deployResource(resource);
152     }
153
154     /**
155      * Disable the resource in the server's runtime naming context
156      *
157      * @param resoure a resource object (eg. JmsResource)
158      * @exception Exception thrown if fail
159      */

160     public synchronized void disableResource(Object JavaDoc resource) throws Exception JavaDoc {
161         undeployResource(resource);
162     }
163
164
165     /**
166      * Utility method to find a resource from Resources beans and converte
167      * it to a resource object to be used by the implemented ResourceDeployer
168      *
169      * @param name resource name (normally the jndi-name)
170      * @param rbeans Resources config-beans
171      * @exception Exception thrown if fail
172      */

173     public Object JavaDoc getResource(String JavaDoc name, Resources rbeans) throws Exception JavaDoc {
174
175         Object JavaDoc res = rbeans.getExternalJndiResourceByJndiName(name);
176
177         if (res == null) {
178             String JavaDoc msg = localStrings.getString(
179                          "resource.no_resource", name);
180             throw new Exception JavaDoc(msg);
181         }
182
183         return res;
184     }
185 }
186
Popular Tags