KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > util > DOLLoadingContextFactory


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.deployment.util;
25
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29
30 import com.sun.enterprise.deployment.WebBundleDescriptor;
31 import com.sun.logging.LogDomains;
32
33 public class DOLLoadingContextFactory {
34     private static WebBundleDescriptor defaultWebXMLWbd = null;
35     private static boolean isParsingDefaultWebXML = false;
36     private static boolean isDefaultWebXMLInitialized = false;
37     
38     private static Class JavaDoc dolLoadingContext = null;
39     private static final String JavaDoc DLC_CLASS_NAME =
40         "com.sun.enterprise.deployment.backend.DOLLoadingContext";
41     private static final String JavaDoc DLC_METHOD_NAME =
42         "initDefaultWebBundleDescriptor";
43
44     private static Logger JavaDoc _logger =
45         LogDomains.getLogger(LogDomains.DPL_LOGGER);
46
47     private static Class JavaDoc getDOLLoadingContext () {
48         try {
49             if (dolLoadingContext == null) {
50                 dolLoadingContext = Class.forName(DLC_CLASS_NAME,
51                     true, Thread.currentThread().getContextClassLoader());
52             }
53         } catch (ClassNotFoundException JavaDoc cnfe) {
54             _logger.log(Level.WARNING, "enterprise.deployment.class.not.found",
55                  new Object JavaDoc[] {DLC_CLASS_NAME});
56         }
57
58         return dolLoadingContext;
59     }
60
61     /**
62      * @return a copy of default WebBundleDescriptor populated from
63      * default-web.xml
64      */

65     public static WebBundleDescriptor getDefaultWebBundleDescriptor() {
66         // it's possible after we attempt to initialize defaultXMLWbd, it
67
// is still null, for instance, when default-web.xml does not exist
68
// for these cases, we don't want to call initialize again
69
if (defaultWebXMLWbd == null && !isDefaultWebXMLInitialized) {
70             initDefaultWebBundleDescriptor();
71         }
72
73         // when default-web.xml exists, add the default bundle descriptor
74
// as the base web bundle descriptor
75
WebBundleDescriptor defaultWebBundleDesc =
76             new WebBundleDescriptor();
77         if (defaultWebXMLWbd != null) {
78             defaultWebBundleDesc.addWebBundleDescriptor(defaultWebXMLWbd);
79         }
80         return defaultWebBundleDesc;
81     }
82
83     /**
84      * initialize the default WebBundleDescriptor from
85      * default-web.xml
86      */

87     private static void initDefaultWebBundleDescriptor() {
88         // delegate to DOLLoadingContext
89
try {
90             Class JavaDoc dlcClass = getDOLLoadingContext();
91             Method JavaDoc initWbdMethod =
92                 dlcClass.getMethod(DLC_METHOD_NAME, new Class JavaDoc[0]);
93             if (initWbdMethod != null) {
94                 defaultWebXMLWbd =
95                     (WebBundleDescriptor)initWbdMethod.invoke(dlcClass,
96                     new Object JavaDoc[0]);
97             } else {
98                 _logger.log(Level.WARNING,
99                      "enterprise.deployment.method.not.found",
100                       new Object JavaDoc[] {DLC_METHOD_NAME});
101             }
102         } catch (Exception JavaDoc e) {
103             _logger.log(Level.WARNING, e.getMessage());
104             defaultWebXMLWbd = null;
105         } finally {
106             isDefaultWebXMLInitialized = true;
107         }
108     }
109
110     /**
111      * @return the flag to indicate whether we are parsing the
112      * default-web.xml
113      */

114     public static boolean isParsingDefaultWebXML() {
115         return isParsingDefaultWebXML;
116     }
117
118     /**
119      * sets the flag to indicate whether we are parsing the
120      * default-web.xml
121      * @param isDefault
122      */

123     public static void setParsingDefaultWebXML(boolean isDefault) {
124         isParsingDefaultWebXML = isDefault;
125     }
126 }
127
Popular Tags