KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > phasing > ApplicationConfigHelper


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  * $Id: ApplicationConfigHelper.java,v 1.6 2005/12/25 04:15:19 tcfujii Exp $
26  * @author: alexkrav
27  *
28  * $Log: ApplicationConfigHelper.java,v $
29  * Revision 1.6 2005/12/25 04:15:19 tcfujii
30  * Updated copyright text and year.
31  *
32  * Revision 1.5 2005/08/14 00:37:27 qouyang
33  *
34  *
35  * Related Files:
36  *
37  * Modified Files:
38  * M admin/mbeanapi-impl/src/java/com/sun/enterprise/management/support/UploadInfo.java
39  * M appserv-commons/src/java/com/sun/enterprise/deployment/annotation/introspection/AnnotationScanner.java
40  * M appserv-commons/src/java/com/sun/enterprise/deployment/annotation/introspection/ClassFile.java
41  * M appserv-commons/src/java/com/sun/enterprise/deployment/annotation/introspection/ConstantPoolInfo.java
42  * M appserv-commons/src/java/com/sun/enterprise/deployment/Application.java
43  * M appserv-commons/src/java/com/sun/enterprise/deployment/archivist/AppClientArchivist.java
44  * M appserv-commons/src/java/com/sun/enterprise/deployment/archivist/Archivist.java
45  * M appserv-core/src/java/com/sun/enterprise/deployment/backend/DeployableObjectType.java
46  * M appserv-core/src/java/com/sun/enterprise/deployment/backend/J2EEModuleExploder.java
47  * M appserv-core/src/java/com/sun/enterprise/deployment/client/DeployAction.java
48  * M appserv-core/src/java/com/sun/enterprise/deployment/phasing/ApplicationConfigHelper.java
49  * M appserv-core/src/java/com/sun/enterprise/deployment/phasing/DeploymentServiceUtils.java
50  * M appserv-core/src/java/com/sun/enterprise/deployment/phasing/PEDeploymentService.java
51  * M appserv-core/src/java/com/sun/enterprise/instance/DescriptorArchivist.java
52  * M appserv-core/src/java/com/sun/enterprise/loader/EJBClassPathUtils.java
53  * M appserv-core/src/java/com/sun/enterprise/server/ApplicationLoader.java
54  *
55  * Added Files:
56  * A appserv-commons/src/java/com/sun/enterprise/deployment/annotation/introspection/CustomAnnotationScanner.java
57  * A appserv-commons/src/java/com/sun/enterprise/deployment/annotation/introspection/EjbComponentAnnotationScanner.java
58  * A appserv-commons/src/java/com/sun/enterprise/deployment/util/EjbComponentAnnotationDetector.java
59  *
60  * Removed Files:
61  * R appserv-commons/src/java/com/sun/enterprise/deployment/util/DeploymentCommonUtils.java
62  *
63  * Submitters:
64  * Hong Zhang (Reviewed by Qingqing Ouyang)
65  * R appserv-commons/src/java/com/sun/enterprise/deployment/util/DeploymentCommonUtils.java
66  * M appserv-core/src/java/com/sun/enterprise/deployment/phasing/DeploymentServiceUtils.java
67  * M appserv-core/src/java/com/sun/enterprise/deployment/phasing/ApplicationConfigHelper.java
68  *
69  * Lloyd Chambers (Reviewed by Qingqing Ouyang)
70  * M admin/mbeanapi-impl/src/java/com/sun/enterprise/management/support/UploadInfo.java
71  *
72  * Qingqing Ouyang (Reviewed by Hong Zhang)
73  * Everything else
74  *
75  *
76  * Description:
77  * 1. Changes made to support deployment of application ear file without
78  * application.xml.
79  * * This checkin only supports archive file (not directory nor JSR88
80  * InputStream yet).
81  * * Use the new initiateUpload API on DeploymentMgr so that the original
82  * application name (if any) is preserved for easy identification of
83  * ear, war, and rar module type without accessing deployment descriptors.
84  * * Construct an Application object in memory if none exists, following
85  * rules defined in Java EE Platform spec section 8.4.2.
86  * * Enhanced deployment.annotation.introspect.* package to allow quick
87  * introspection of any jar file for EJB component annotations without
88  * loading the class. This allows us to correctly identify the ejb
89  * module within an ear when there is no dd exists in neither the
90  * application nor the ejb submodule.
91  *
92  * 2. Added correct license for files under deployment.annotation.introspect
93  * package.
94  *
95  * 3. Write out the application.xml when the original app does not have any,
96  * otherwise copy to generated/xml directory.
97  *
98  * 4. Fixed ApplicationLoader to load from the generated/xml if exists
99  * (since application.xml is no longer guaranteed to be under the original
100  * application repository directory).
101  *
102  * 5. Remove unnecessary disk I/O for application.xml (Hong's change).
103  *
104  * 6. Removed unused methods from EJBClassPathUtils.
105  *
106  * Tests Ran:
107  * 1. PE QL
108  * 2. PE CTS
109  * 3. PE deployment devtests
110  * 4. PE devtests/ejb/ejb30/hello
111  * 5. New devtests on ear file containg ejb jar and library jar with no application
112  * (deploy, redeploy, server restart, ran appclient).
113  * devtests/deployment/descriptor_free_zone/earwithejb
114  * devtests/deployment/descriptor_free_zone/earwithwar
115  *
116  * Revision 1.4 2005/08/09 01:29:41 hzhang_jn
117  *
118  * Update logic in comparing context root: "foo" and "/foo" should be
119  * considered same context root.
120  * Reviewed by Qingqing, passed QL and deployment dev tests.
121  *
122  * Revision 1.3 2005/08/02 15:00:28 hzhang_jn
123  *
124  * Fix CR 6264984. Fixed a typo in context roots comparison.
125  * Reviewed by Qingqing, passed QL, deployment dev tests.
126  *
127  * Revision 1.2 2005/06/27 21:29:16 tcfujii
128  * Issue number: CDDL header updates.
129  *
130  * Revision 1.1.1.1 2005/05/27 22:53:54 dpatil
131  * GlassFish first drop
132  *
133  * Revision 1.2 2005/03/17 01:40:52 kravtch
134  * Signature changed for ApplicationConfigHelper.checkContextRootUniqueness(): it now accepts "targetName" instead of "serverName" (where targets could be only cluster or server), providing uniqueness chack for bot servers and clusters.
135  * Bug #6240955
136  * Tests ran: QLT/EE
137  *
138  * Revision 1.1 2005/03/12 00:26:47 kravtch
139  * Unique contextRoots support is provided (getContextRoots/resetContextRoots/checkContextRootsUniqueness) without re-reading of application descriptor, storing it in the transientProperties of appplication config bean.
140  *
141  * Tests: QLT/EE ok.
142  *
143  */

144
145 package com.sun.enterprise.deployment.phasing;
146
147 import com.sun.enterprise.util.i18n.StringManager;
148
149 import com.sun.enterprise.config.ConfigException;
150 import com.sun.enterprise.config.ConfigContext;
151 import com.sun.enterprise.config.ConfigBean;
152
153 import com.sun.enterprise.config.serverbeans.ApplicationRef;
154 import com.sun.enterprise.config.serverbeans.WebModule;
155 import com.sun.enterprise.config.serverbeans.J2eeApplication;
156
157 import com.sun.enterprise.config.serverbeans.ServerHelper;
158 import com.sun.enterprise.config.serverbeans.ClusterHelper;
159 import com.sun.enterprise.config.serverbeans.ApplicationHelper;
160 import com.sun.enterprise.config.serverbeans.PropertyResolver;
161
162 import com.sun.enterprise.admin.config.BaseConfigMBean;
163 import com.sun.enterprise.admin.target.Target;
164 import com.sun.enterprise.admin.target.TargetType;
165 import com.sun.enterprise.admin.target.TargetBuilder;
166
167 import com.sun.enterprise.deployment.backend.IASDeploymentException;
168  
169 import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
170 /**
171  * This module provides helper methods for Application config element
172  *
173  * @author alexkrav
174  */

175 public class ApplicationConfigHelper
176 {
177     private static final String JavaDoc CONTEXT_ROOTS_PROPERTY_NAME = "context-roots";
178     private static final StringManager _strMgr =
179         StringManager.getManager(ApplicationConfigHelper.class);
180
181     private ConfigContext _configContext = null;
182     
183     /** Creates a new instance of EEApplicationsConfigMBean */
184     public ApplicationConfigHelper(ConfigContext configContext)
185     {
186         _configContext = configContext;
187     }
188         
189     private ConfigContext getConfigContext()
190     {
191         return _configContext;
192     }
193     
194     /**
195      * Get application context roots of standalone web-module or j2ee application
196      *
197      * @param appBean - config bean representing standalone web-module or j2ee application
198      * @throws ConfigException if data in trancient property has wrong type
199      * @returns String array of context roots, or null - if inapropriate bean type
200      */

201      public static String JavaDoc[] getAppContextRoots(ConfigBean appBean) throws ConfigException, IASDeploymentException
202     {
203         if (appBean instanceof WebModule)
204         {
205             return new String JavaDoc[]{((WebModule)appBean).getContextRoot()};
206         }
207         if (appBean instanceof J2eeApplication)
208         {
209             Object JavaDoc roots = appBean.getTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME);
210             if(roots==null)
211             {
212                 String JavaDoc appName = ((J2eeApplication)appBean).getName();
213
214                 //call deployment helper
215
roots = DeploymentServiceUtils.getContextRootsForEmbeddedWebApp(appName);
216                 appBean.setTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME, roots);
217             }
218             else
219             {
220                 if(!(roots instanceof String JavaDoc[]))
221                 {
222                     throw new ConfigException(_strMgr.getString("configRootsPropertyIsNotStringArray",
223                         ((J2eeApplication)appBean).getName()));
224                 }
225             }
226                 
227             return (String JavaDoc[])roots;
228         }
229         return null;
230     }
231
232      /**
233      * Get application context roots of standalone web-module or j2ee application
234      *
235      * @param ctx - config context containing application elements
236      * @param appName - name of application element
237      * @throws ConfigException if data in trancient property has wrong type
238      * @returns String array of context roots, or null - if inapropriate bean type
239      */

240      public static String JavaDoc[] getAppContextRoots(ConfigContext ctx, String JavaDoc appName) throws ConfigException, IASDeploymentException
241     {
242         ConfigBean appBean = ApplicationHelper.findApplication(ctx, appName);
243         if(appBean==null)
244         {
245             throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appName));
246         }
247         return getAppContextRoots(appBean);
248     }
249
250     /**
251      * Resets config bean context-roots transient property value
252      * (ingnored if not j2ee-application)
253      *
254      * @param appBean - config bean representing j2ee-application
255      * @param bForceToSetActualValue - if this parameter false, correspondent
256      * transient property will be just emptied, so reading of actual values from
257      * app desctriptor will be postponed until next "AppContextRoots" operation;
258      * @throws ConfigException if data in trancient property has wrong type
259      */

260      public static void resetAppContextRoots( ConfigBean appBean,
261                         boolean bForceToSetActualValue) throws ConfigException, IASDeploymentException
262     {
263         if (appBean instanceof J2eeApplication)
264         {
265             appBean.setTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME, null);
266             if(bForceToSetActualValue)
267                 getAppContextRoots(appBean); //forces to read descriptor xml
268
}
269     }
270    
271     
272     /**
273      * Resets config bean context-roots transient property value
274      * (ingnored/no exception if not j2ee-application)
275      *
276      * @param ctx - config context containing application elements
277      * @param appName - name of application element
278      * @param bForceToSetActualValue - if this parameter false, correspondent
279      * transient property will be just emptied, so reading of actual values from
280      * app desctriptor will be postponed until next "AppContextRoots" operation;
281      * @throws ConfigException if data in trancient property has wrong type
282      */

283     public static void resetAppContextRoots(ConfigContext ctx, String JavaDoc appName,
284                         boolean bForceToSetActualValue) throws ConfigException, IASDeploymentException
285     {
286         ConfigBean appBean = ApplicationHelper.findApplication(ctx, appName);
287         if(appBean==null)
288         {
289             throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appName));
290         }
291         resetAppContextRoots(appBean, bForceToSetActualValue);
292     }
293     
294     
295     /**
296      * Check the uniqueness of application's context-roots
297      * among applications deployed to the given server instance's virtual servers
298      *
299      * @param appId - application name
300      * @param targetName - server instance name or cluster name
301      * @param virtualServerList coma separated list of virtual servers
302      *
303      * @throws ConfigException
304      * @returns conflicting context root and null is context roots are unique
305      * inside of virtual servers.
306      **/

307     public static String JavaDoc checkContextRootUniqueness(ConfigContext ctx, String JavaDoc appId, String JavaDoc targetName, String JavaDoc virtualServerList)
308         throws ConfigException, IASDeploymentException
309     {
310         ConfigBean appBean = ApplicationHelper.findApplication(ctx, appId);
311         if(appBean==null)
312         {
313             throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appId));
314         }
315         
316         //get context roots for testing element
317
String JavaDoc[] ctxRoots = getAppContextRoots(appBean);
318         if(ctxRoots==null || ctxRoots.length<=0)
319             return null;
320
321         //create target by name
322
final Target target = TargetBuilder.INSTANCE.createTarget(
323             new TargetType[]{TargetType.CLUSTER, TargetType.SERVER, TargetType.DAS}, targetName, ctx);
324         
325         //get apprefs for target
326
ApplicationRef[] refs = null;
327         if (target.getType() == TargetType.CLUSTER ||
328             target.getType() == TargetType.STANDALONE_CLUSTER)
329         {
330             refs = ClusterHelper.getApplicationReferences(ctx, targetName);
331         }
332         else
333         {
334             refs = ServerHelper.getApplicationReferences(ctx, targetName);
335         }
336             
337         if(refs==null)
338             return null;
339         
340         for(int i=0; i<refs.length; i++)
341         {
342             if(isVSListsIntersected(refs[i].getVirtualServers(), virtualServerList))
343             {
344                 ConfigBean appBeanToCompare = ApplicationHelper.findApplication(ctx, refs[i].getRef());
345                 if(appBeanToCompare==null)
346                 {
347                     throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", refs[i].getRef()));
348                 }
349                 if(((Object JavaDoc)appBeanToCompare)!=((Object JavaDoc)appBean))
350                 {
351                     String JavaDoc commonElement = (String JavaDoc)getFirstCommonElement(getAppContextRoots(appBeanToCompare), ctxRoots);
352                     if(commonElement!=null)
353                         return commonElement;
354                 }
355  
356             }
357         }
358         return null;
359     }
360     
361     
362     //////////////////////////////////////////////////////////////////////////////////////////
363
// private methods
364

365     /**
366      * returns true if any of lists are empty or not intersected
367      **/

368     private static boolean isVSListsIntersected(String JavaDoc vsList1, String JavaDoc vsList2)
369     {
370         if(vsList1==null || vsList2 == null ||
371            vsList1.length()==0 || vsList2.length()==0 )
372             return true;
373         String JavaDoc[] arr1 = vsList1.split(",");
374         String JavaDoc[] arr2 = vsList2.split(",");
375         if(arr1.length==0 || arr2.length==0)
376             return true;
377         return (getFirstCommonElement(arr1, arr2)!=null);
378             
379     }
380     
381     /**
382      * returns null if arrays have equal elements
383      **/

384     private static Object JavaDoc getFirstCommonElement(Object JavaDoc[] arr1, Object JavaDoc[] arr2)
385     {
386         if(arr1!=null && arr2!=null && arr1.length!=0 && arr2.length!=0)
387         {
388             for(int i=0; i<arr1.length; i++)
389             {
390                 for(int j=0; j<arr2.length; j++)
391                 {
392                     if( ((String JavaDoc)arr1[i]).startsWith("/") ) {
393                         arr1[i] = ((String JavaDoc)arr1[i]).substring(1);
394                     }
395                     if( ((String JavaDoc)arr2[j]).startsWith("/") ) {
396                         arr2[j] = ((String JavaDoc)arr2[j]).substring(1);
397                     }
398                     if(arr1[i].equals(arr2[j])) {
399                         return arr1[i];
400                     }
401                 }
402             }
403         }
404         return null;
405     }
406     
407 }
408
Popular Tags