KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > instance > ConnectorModulesManager


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.instance;
25
26 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
27
28 import com.sun.enterprise.config.ConfigBean;
29 import com.sun.enterprise.config.ConfigContext;
30 import com.sun.enterprise.config.ConfigException;
31 import com.sun.enterprise.config.serverbeans.*;
32 import com.sun.enterprise.deployment.Application;
33 import com.sun.enterprise.deployment.archivist.ApplicationArchivist;
34 import com.sun.enterprise.deployment.archivist.ConnectorArchivist;
35 import com.sun.enterprise.deployment.backend.DeployableObjectInfo;
36 import com.sun.enterprise.deployment.backend.DeployableObjectType;
37 import com.sun.enterprise.deployment.ConnectorDescriptor;
38 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
39 import com.sun.enterprise.deployment.RootDeploymentDescriptor;
40 import com.sun.enterprise.util.io.FileUtils;
41 import com.sun.enterprise.util.RelativePathResolver;
42 import com.sun.enterprise.util.SystemPropertyConstants;
43 import com.sun.enterprise.Switch;
44 import com.sun.enterprise.server.ResourcesUtil;
45
46 import java.io.File JavaDoc;
47 import java.io.IOException JavaDoc;
48 import java.util.ArrayList JavaDoc;
49 import java.util.Enumeration JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.logging.Level JavaDoc;
53 import java.util.Properties JavaDoc;
54 import java.util.Set JavaDoc;
55
56 public class ConnectorModulesManager extends ModulesManager {
57     public ConnectorModulesManager(InstanceEnvironment env) throws ConfigException {
58         super(env, true);
59     }
60     
61     public ConnectorModulesManager(InstanceEnvironment env, boolean useBackupServerXml) throws ConfigException {
62         super(env, useBackupServerXml);
63         //FIXME: HACK START
64
ConnectorModule[] jArray = ((Applications)configBean).getConnectorModule();
65     if(jArray!=null) {
66             for(int i=0;i<jArray.length;i++) {
67                 jArray[i].setConfigContext(configContext);
68         jArray[i].setXPath(ServerXPathHelper.getConnectorModuleIdXpathExpression(jArray[i].getName()));
69             }
70     }
71     //FIXME: HACK END
72

73     }
74     
75     /**
76      * @return the module type this class is managing
77      */

78     public ModuleType JavaDoc getModuleType() {
79         return ModuleType.RAR;
80     }
81
82     /**
83      * Returns a list of all Connector modules deployed with the server.
84      */

85     public ConnectorModule[] listConnectorModules() {
86         ConnectorModule[] mods = ((Applications)this.configBean).getConnectorModule();
87         if(mods == null) return new ConnectorModule[0];
88
89         ArrayList JavaDoc list = new ArrayList JavaDoc();
90         for (int i=0; i<mods.length; i++) {
91             // add the modules to the list if it is referenced
92
// by this server
93
if ( isReferenced(mods[i].getName()) ) {
94                 list.add(mods[i]);
95             }
96         }
97         // returns an array of modules referenced by this server
98
ConnectorModule[] refList = new ConnectorModule[list.size()];
99         return ( (ConnectorModule[]) list.toArray(refList) );
100     }
101     
102     /**
103      * Returns a list of all Connector modules deployed with the server.
104      */

105     public List JavaDoc listIds() {
106         ArrayList JavaDoc arr = new ArrayList JavaDoc();
107         ConnectorModule[] mods = ((Applications)this.configBean).getConnectorModule();
108         if(mods == null) return arr;
109         for (int i=0;i<mods.length;i++) {
110             String JavaDoc name = mods[i].getName();
111             // adds the web module to the list if
112
// it is referenced by this server
113
if ( isReferenced(name) ) {
114                 arr.add(name);
115             }
116         }
117         return arr;
118     }
119     
120     private ConnectorModule getConnectorModule(String JavaDoc modId) throws ConfigException {
121         ConnectorModule mod = (ConnectorModule)
122             ((Applications)this.configBean).getConnectorModuleByName(modId);
123         
124         if(mod == null)
125             throw new ConfigException(Localizer.getValue(ExceptionType.NO_SUCH_CON_MOD));
126         
127         return mod;
128         
129     }
130     
131     public String JavaDoc getGeneratedXMLLocation(String JavaDoc name){
132         ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name,
133                                                      DeployableObjectType.CONN);
134         return menv.getModuleGeneratedXMLPath();
135     }
136
137     public void remove(String JavaDoc modId) throws ConfigException {
138         ConnectorModule backEm = (ConnectorModule)((Applications)configBean).getConnectorModuleByName(modId);
139         ((Applications)configBean).removeConnectorModule(backEm);
140     }
141     
142     protected boolean isRegistered(String JavaDoc modId, ConfigBean bean) {
143         ConfigBean cb = null;
144         try {
145             cb = ((Applications)bean).getConnectorModuleByName(modId);
146         } catch(Exception JavaDoc cn) {
147         }
148         
149         if(cb != null) return true;
150         return false;
151     }
152     
153     public boolean isEnabled(String JavaDoc modId) throws ConfigException{
154         return getConnectorModule(modId).isEnabled();
155     }
156
157     /**
158      * Checks whether this module is a systemmodule
159      * ResourceType in domain.xml should start with "system-"
160      * @return true if resourceType starts with "system-"
161      */

162     public boolean isSystem(String JavaDoc modId) throws ConfigException{
163         ConnectorModule cm = getConnectorModule(modId);
164         String JavaDoc resourceType = cm.getObjectType();
165         if(resourceType.startsWith(SYSTEM_PREFIX))
166             return true;
167         else
168             return false;
169     }
170
171     /**
172      * Checks whether this module is a system admin module
173      * ResourceType in domain.xml should start with "system-admin"
174      * @return true if resourceType starts with "system-admin"
175      */

176     public boolean isSystemAdmin(String JavaDoc modId) throws ConfigException{
177         ConnectorModule cm = getConnectorModule(modId);
178         String JavaDoc resourceType = cm.getObjectType();
179         if(resourceType.startsWith(SYSTEM_ADMIN_PREFIX))
180             return true;
181         else
182             return false;
183     }
184
185     public void setEnable(String JavaDoc modId, boolean enable) throws ConfigException{
186         getConnectorModule(modId).setEnabled(enable);
187     }
188     
189     /**
190      * Set the optional attributes for an module
191      *
192      * @param modId unique idenitifier for the module
193      * @param optionalAttributes - pairs tag/value to set
194      */

195     public void setOptionalAttributes(String JavaDoc modId, Properties JavaDoc optionalAttributes)
196             throws ConfigException {
197         if(optionalAttributes!=null) {
198             ConnectorModule cm = getConnectorModule(modId);
199             Enumeration JavaDoc tags = optionalAttributes.keys();
200             while(tags.hasMoreElements())
201             {
202                 String JavaDoc tag = (String JavaDoc)tags.nextElement();
203                 String JavaDoc value = optionalAttributes.getProperty(tag);
204                 cm.setAttributeValue(tag, value);
205             }
206         }
207     }
208     
209     public String JavaDoc getLocation(String JavaDoc name) {
210         String JavaDoc location = null;
211         if (ResourcesUtil.getInstance().belongToSystemRar(name)) {
212             location = Switch.getSwitch().
213                        getResourceInstaller().getSystemModuleLocation(name);
214         } else {
215             ConnectorModule connectorModule = (ConnectorModule)
216             ((Applications)this.configBean).getConnectorModuleByName(name);
217             location = connectorModule.getLocation();
218         }
219         return resolvePath(location);
220     }
221
222     public void setLocation(String JavaDoc modId, String JavaDoc location) throws ConfigException{
223         ConnectorModule connectorModule = (ConnectorModule)
224         ((Applications)this.configBean).getConnectorModuleByName(modId);
225         connectorModule.setLocation(location);
226     }
227     
228     public String JavaDoc getDescription(String JavaDoc modId) throws ConfigException {
229         return getConnectorModule(modId).getDescription();
230     }
231     
232     public void setDescription(String JavaDoc modId, String JavaDoc desc) throws ConfigException {
233         getConnectorModule(modId).setDescription(desc);
234     }
235
236     /**
237      * Returns the deployment descriptor object for the connector module
238      * in the specified directory.
239      *
240      * @param modId web module id
241      * @param modDir The directory containing the web module
242      * @param validateXml use validating parser when true
243      * @param verify true indicates that verifier option is ON
244      *
245      * @return the deployment descriptor object for this web module
246      *
247      * @throws ConfigException if unable to load the deployment descriptor
248      */

249     public Application getDescriptor(String JavaDoc modId, ClassLoader JavaDoc cl,
250             String JavaDoc modDir, boolean validateXml) throws ConfigException {
251
252         Application application = getRegisteredDescriptor(modId);
253         if (application!=null) {
254             application.setClassLoader(cl);
255             return application;
256         }
257         try {
258         ConnectorArchivist connectorArchivist = new ConnectorArchivist();
259         connectorArchivist.setXMLValidation(validateXml);
260             connectorArchivist.setClassLoader(cl);
261         
262             FileArchive archive = new FileArchive();
263             archive.open(modDir);
264             application = ApplicationArchivist.openArchive(modId, connectorArchivist, archive, true);
265         application.setClassLoader(cl);
266             application.setGeneratedXMLDirectory(getGeneratedXMLLocation(modId));
267             
268             registerDescriptor(modId, application);
269             
270         return application;
271         
272         } catch (IOException JavaDoc ioe) {
273             throw new ConfigException(Localizer.getValue(
274                 ExceptionType.IO_ERROR_LOADING_DD, modId), ioe);
275         } catch (Throwable JavaDoc t) {
276             throw new ConfigException(Localizer.getValue(
277                 ExceptionType.FAIL_DD_LOAD, modId), t);
278         }
279     }
280
281 }
282
Popular Tags