KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
27 import java.util.logging.Level JavaDoc;
28 import com.sun.enterprise.deployment.Application;
29 import com.sun.enterprise.deployment.BundleDescriptor;
30 import com.sun.enterprise.deployment.EjbBundleDescriptor;
31 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
32 import com.sun.enterprise.deployment.WebBundleDescriptor;
33 import com.sun.enterprise.deployment.WebComponentDescriptor;
34 import com.sun.enterprise.deployment.EjbDescriptor;
35 import com.sun.enterprise.deployment.EjbIORConfigurationDescriptor;
36 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
37 import com.sun.enterprise.deployment.util.DOLUtils;
38 import com.sun.enterprise.deployment.util.ModuleDescriptor;
39 import java.io.File JavaDoc;
40
41 /**
42  * This class is responsible for validating the loaded DOL classes and
43  * transform some of the raw XML information into refined values used
44  * by the DOL runtime
45  *
46  * @author Jerome Dochez
47  */

48 public class ApplicationValidator extends EjbBundleValidator
49     implements ApplicationVisitor, EjbBundleVisitor, EjbVisitor {
50     
51
52     private Application application;
53     
54     /**
55      * visit an application object
56      * @param the application descriptor
57      */

58     public void accept(Application application) {
59         this.application = application;
60     }
61             
62     /**
63      * visits an ejb bundle descriptor
64      * @param an ejb bundle descriptor
65      */

66     public void accept(EjbBundleDescriptor bundleDescriptor) {
67         
68         this.bundleDescriptor = bundleDescriptor;
69         super.accept(bundleDescriptor);
70         /** set the realm name on each ejb to match the ones on this application
71          * this is required right now to pass the stringent CSIv2 criteria
72          * whereby the realm-name for the ejb being authenticated on
73          * has to match the one on the application. We look at the IORConfigurator
74          * descriptor
75          * @todo: change the csiv2 layer so that it does not look at
76          * IORConfiguratorDescriptor.
77          * @see iiop/security/SecurityMechanismSelector.evaluateClientConformance.
78          */

79         String JavaDoc rlm = application.getRealm();
80         Iterator ejbs = bundleDescriptor.getEjbs().iterator();
81         for(; ejbs.hasNext();){
82             EjbDescriptor ejb = (EjbDescriptor) ejbs.next();
83             Iterator iorconfig = ejb.getIORConfigurationDescriptors().iterator();
84             for (;iorconfig.hasNext(); ){
85                 EjbIORConfigurationDescriptor desc =
86                     (EjbIORConfigurationDescriptor)iorconfig.next();
87                 desc.setRealmName(rlm);
88             }
89         }
90     }
91     
92     
93     /**
94      * visit a web bundle descriptor
95      *
96      * @param the web bundle descriptor
97      */

98     public void accept(WebBundleDescriptor descriptor) {
99         bundleDescriptor = descriptor;
100         ModuleDescriptor md = bundleDescriptor.getModuleDescriptor( );
101         // Fix for bug: 4837982
102
String JavaDoc uri = md.getArchiveUri( );
103         if( ( md.getContextRoot() == null )
104          && ( ( uri != null ) && (uri.length() != 0) ) )
105          {
106             // Case 1: If there is a unix style file separator
107
// Example a/b/xxx.war
108
int beginIndex = uri.lastIndexOf( "/" );
109
110             // Case 2: If there is a windows style file separator
111
// Example a\b\xxx.war
112
if( beginIndex < 0 ) {
113                 beginIndex = uri.lastIndexOf( File.separator );
114             }
115
116             // Case 3: No File separator
117
// Example xxx.war
118
if( beginIndex < 0 ) {
119                 beginIndex = 0;
120             } else {
121                 // If there is a separator, we need to increment to get the
122
// string past the last separator
123
beginIndex++;
124             }
125
126             // If the context-root is not specified, AppServer will use
127
// the file name with the extension removed as the context
128
// root
129

130             // NOTE: We can safely assume that the file extension is ".war"
131
// So no need to do extra checks
132
int endIndex = uri.lastIndexOf( ".war" );
133             if (endIndex==-1) {
134                 return;
135             }
136             String JavaDoc warFileName = uri.substring( beginIndex, endIndex );
137             md.setContextRoot( warFileName );
138             if( DOLUtils.getDefaultLogger().isLoggable(Level.INFO) ) {
139                 DOLUtils.getDefaultLogger().info(
140                     "Context Root is not provided by the user, Using ["
141                     + warFileName + "] as Context Root" );
142             }
143         }
144     }
145     
146     /**
147      * visits a appclient descriptor
148      * @param appclientdescriptor
149      */

150     public void accept(ApplicationClientDescriptor appclientdescriptor) {
151         bundleDescriptor = appclientdescriptor;
152
153         // set the default lifecycle callback class
154
for (LifecycleCallbackDescriptor next :
155             appclientdescriptor.getPreDestroyDescriptors()) {
156             next.setDefaultLifecycleCallbackClass(
157                 appclientdescriptor.getMainClassName());
158         }
159
160         for (LifecycleCallbackDescriptor next :
161             appclientdescriptor.getPostConstructDescriptors()) {
162             next.setDefaultLifecycleCallbackClass(
163                 appclientdescriptor.getMainClassName());
164         }
165     }
166
167     /**
168      * visit a web component descriptor
169      *
170      * @param the web component
171      */

172     public void accept(WebComponentDescriptor descriptor) {
173         computeRuntimeDefault(descriptor);
174     }
175        
176     private void computeRuntimeDefault(WebComponentDescriptor webComp) {
177         if (!webComp.getUsesCallerIdentity()) {
178             computeRunAsPrincipalDefault(
179                 webComp.getRunAsIdentity(), webComp.getApplication());
180         }
181     }
182     
183     /**
184      * @return a vector of EjbDescriptor for this bundle
185      */

186     protected Collection getEjbDescriptors() {
187         if (application!=null)
188             return application.getEjbDescriptors();
189         return new HashSet();
190     }
191     
192     /**
193      * @return the Application object if any
194      */

195     protected Application getApplication() {
196         return application;
197     }
198     
199     /**
200      * @return the bundleDescriptor we are validating
201      */

202     protected BundleDescriptor getBundleDescriptor() {
203         return bundleDescriptor;
204     }
205     
206     
207 }
208
Popular Tags