KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.resource;
25
26 import com.sun.enterprise.ManagementObjectManager;
27 import com.sun.enterprise.server.ResourceDeployer;
28 import com.sun.enterprise.config.serverbeans.Resources;
29 import com.sun.enterprise.config.serverbeans.ElementProperty;
30 import com.sun.enterprise.config.serverbeans.AdminObjectResource;
31 import com.sun.enterprise.connectors.ConnectorRuntime;
32 import com.sun.enterprise.connectors.ConnectorConnectionPool;
33 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
34 import com.sun.enterprise.repository.IASJ2EEResourceFactoryImpl;
35 import com.sun.logging.LogDomains;
36 import java.util.Properties JavaDoc;
37 import java.util.logging.*;
38
39 /**
40   *
41   * @author Srikanth P
42   * @version
43  */

44
45 public class AdminObjectResourceDeployer extends GlobalResourceDeployer
46         implements ResourceDeployer {
47
48     static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
49
50     /**
51      * Deploy the resource into the server's runtime naming context
52      *
53      * @param resoure a resource object (eg. AdminObjectResource)
54      * @exception Exception thrown if fail
55      */

56     public synchronized void deployResource(Object JavaDoc resource) throws Exception JavaDoc {
57
58         final AdminObjectResource aor =
59            (com.sun.enterprise.config.serverbeans.AdminObjectResource)resource;
60         final ConnectorRuntime crt = ConnectorRuntime.getRuntime();
61         
62         if (aor.isEnabled()) {
63             //registers the jsr77 object for the mail resource deployed
64
final ManagementObjectManager mgr =
65                 getAppServerSwitchObject().getManagementObjectManager();
66             mgr.registerAdminObjectResource(aor.getJndiName(),
67                 aor.getResAdapter(), aor.getResType(),
68                 getPropNamesAsStrArr(aor.getElementProperty()),
69                 getPropValuesAsStrArr(aor.getElementProperty()));
70         } else {
71                 _logger.log(Level.INFO, "core.resource_disabled",
72                         new Object JavaDoc[] {aor.getJndiName(),
73                         IASJ2EEResourceFactoryImpl.JMS_RES_TYPE});
74         }
75         
76         _logger.log(Level.FINE,
77             "Calling backend to add adminObject",aor.getJndiName());
78         crt.addAdminObject(null,aor.getResAdapter(),aor.getJndiName(),
79                 aor.getResType(),transformProps(aor.getElementProperty()));
80         _logger.log(Level.FINE,
81             "Added adminObject in backend",aor.getJndiName());
82     }
83     
84     /**
85      *d
86      */

87     public synchronized void undeployResource(Object JavaDoc resource)
88                         throws Exception JavaDoc {
89
90         final AdminObjectResource aor =
91            (com.sun.enterprise.config.serverbeans.AdminObjectResource)resource;
92         final ConnectorRuntime crt = ConnectorRuntime.getRuntime();
93         
94         _logger.log(Level.FINE,
95                    "Calling backend to delete adminObject",aor.getJndiName());
96         crt.deleteAdminObject(aor.getJndiName());
97         _logger.log(Level.FINE,
98                    "Deleted adminObject in backend",aor.getJndiName());
99         
100         //unregister the managed object
101
final ManagementObjectManager mgr =
102                 getAppServerSwitchObject().getManagementObjectManager();
103         mgr.unregisterAdminObjectResource(aor.getJndiName(), aor.getResType());
104
105     }
106
107     public synchronized void redeployResource(Object JavaDoc resource)
108                         throws Exception JavaDoc {
109     }
110
111     public synchronized void disableResource(Object JavaDoc resource)
112                         throws Exception JavaDoc {
113
114     }
115
116     public synchronized void enableResource(Object JavaDoc resource)
117                         throws Exception JavaDoc {
118     }
119
120     public Object JavaDoc getResource(String JavaDoc name, Resources rbeans)
121                         throws Exception JavaDoc {
122         Object JavaDoc res = rbeans.getAdminObjectResourceByJndiName(name);
123
124         if (res == null) {
125             Exception JavaDoc ex = new Exception JavaDoc("No such resource");
126             _logger.log(Level.SEVERE,"no_resource",name);
127             _logger.log(Level.SEVERE,"",ex);
128             throw ex;
129         }
130
131         return res;
132     }
133
134     Properties JavaDoc transformProps(ElementProperty[] domainProps) {
135              
136         Properties JavaDoc props = new Properties JavaDoc();
137         for(int i=0;i<domainProps.length;++i) {
138             props.setProperty(
139                     domainProps[i].getName(),domainProps[i].getValue());
140         }
141         return props;
142     }
143 }
144
Popular Tags