KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ias > resource > ASEjbRRefDefResPrincipal


1 package com.sun.enterprise.tools.verifier.tests.ejb.ias.resource;
2 /*
3  * The contents of this file are subject to the terms
4  * of the Common Development and Distribution License
5  * (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the license at
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
10  * glassfish/bootstrap/legal/CDDLv1.0.txt.
11  * See the License for the specific language governing
12  * permissions and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL
15  * Header Notice in each file and include the License file
16  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
17  * If applicable, add the following below the CDDL Header,
18  * with the fields enclosed by brackets [] replaced by
19  * you own identifying information:
20  * "Portions Copyrighted [year] [name of copyright owner]"
21  *
22  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23  */

24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.util.*;
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.deployment.EjbSessionDescriptor;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33
34 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar;
35 import com.sun.enterprise.tools.common.dd.ejb.Ejb;
36 import com.sun.enterprise.tools.common.dd.ResourceRef;
37 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal;
38 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
39
40 /** ejb [0,n]
41  * resource-ref [0,n]
42  * res-ref-name [String]
43  * jndi-name [String]
44  * default-resource-principal ?
45  * name [String]
46  * password [String]
47  *
48  * The default-resource-principal specifies the principal for the
49  * resource
50  * The name and password should not be null.
51  * The principal should be declared if the authorization type for the resource
52  * in ejb-jar.xml is "Application"
53  * @author Irfan Ahmed
54  */

55 public class ASEjbRRefDefResPrincipal extends ASEjbResRef {
56
57     public Result check(EjbDescriptor descriptor)
58     {
59     Result result = getInitializedResult();
60     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
61
62         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
63         boolean oneFailed = false;
64         
65         if(ejbJar!=null)
66         {
67             Ejb ejbs[] = ejbJar.getEnterpriseBeans().getEjb();
68             Ejb testCase = null;
69             for(int i=0;i<ejbs.length;i++)
70             {
71                 if(ejbs[i].getEjbName().equals(descriptor.getName()))
72                 {
73                     testCase = ejbs[i];
74                     break;
75                 }
76             }
77             
78             ResourceRef resRefs[] = testCase.getResourceRef();
79             ResourceReferenceDescriptor resDesc;
80             if(resRefs.length > 0)
81             {
82                 for(int i=0;i<resRefs.length;i++)
83                 {
84                     String JavaDoc refName = resRefs[i].getResRefName();
85                     String JavaDoc refJndiName = resRefs[i].getJndiName();
86                     DefaultResourcePrincipal defPrinci = resRefs[i].getDefaultResourcePrincipal();
87                     if(defPrinci == null)
88                     {
89                         try
90                         {
91                             resDesc = descriptor.getResourceReferenceByName(refName);
92                             String JavaDoc resAuth = resDesc.getAuthorization();
93                             if(resAuth.equals(ResourceReferenceDescriptor.APPLICATION_AUTHORIZATION))
94                             {
95                                 result.failed(smh.getLocalString(getClass().getName()+".failed",
96                                     "FAILED [AS-EJB resource-ref] : res-auth for res-ref-name {0} is defined as Application." +
97                                     "Therefore the default-resource-principal should be supplied with valid properties",
98                                     new Object JavaDoc[] {refName}));
99                             }
100                             else
101                             {
102                                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
103                                     "NOT APPLICABLE [AS-EJB resource-ref] : default-resource-principal Element not defined"));
104                             }
105                         }
106                         catch(IllegalArgumentException JavaDoc iaex)
107                         {
108                             result.failed(smh.getLocalString(getClass().getName()+".failed2",
109                                 "FAILED [AS-EJB resource-ref] : res-ref-name {0} is not defined in the ejb-jar.xml",
110                                 new Object JavaDoc[]{refName}));
111                         }
112                     }
113                     else
114                     {
115                         String JavaDoc name = defPrinci.getName();
116                         if(name.length()==0)
117                         {
118                             oneFailed = true;
119                             result.failed(smh.getLocalString(getClass().getName()+".failed3",
120                                 "FAILED [AS-EJB default-resource-principal] : name cannot be an empty string"));
121                         }
122                         else
123                         {
124                             result.passed(smh.getLocalString(getClass().getName()+".passed",
125                                 "PASSED [AS-EJB default-resource-principal] : name is {0}",new Object JavaDoc[]{name}));
126                         }
127                         
128                         String JavaDoc password = defPrinci.getPassword();
129                         if(password.length()==0)
130                         {
131                            // <addition> srini@sun.com
132
//oneFailed = true;
133
//result.failed(smh.getLocalString(getClass().getName()+".failed3",
134
// "FAILED [AS-EJB default-resource-principal] : password cannot be an empty string"));
135
result.warning(smh.getLocalString(getClass().getName()+".warning1",
136                                 "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
137                             // </addition>
138
}
139                         else
140                         {
141                             result.passed(smh.getLocalString(getClass().getName()+".passed",
142                                 "PASSED [AS-EJB default-resource-principal] : password is {0}",new Object JavaDoc[]{password}));
143                         }
144                         
145                         if(oneFailed)
146                             result.setStatus(Result.FAILED);
147                     }
148                 }//end for
149
}
150             else
151             {
152                  result.notApplicable(smh.getLocalString
153                          (getClass().getName() + ".notApplicable",
154                           "{0} Does not define any resource-ref Elements",
155                           new Object JavaDoc[] {descriptor.getName()}));
156             }
157         }
158         else
159         {
160             result.addErrorDetails(smh.getLocalString
161                  (getClass().getName() + ".notRun",
162                   "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));
163         }
164         return result;
165     }
166 }
167
168
Popular Tags