KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.enterprise.tools.verifier.tests.ejb.runtime.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 java.util.*;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29
30 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
31 import com.sun.enterprise.deployment.ResourcePrincipal;
32
33 /** ejb [0,n]
34  * resource-ref [0,n]
35  * res-ref-name [String]
36  * jndi-name [String]
37  * default-resource-principal ?
38  * name [String]
39  * password [String]
40  *
41  * The default-resource-principal specifies the principal for the
42  * resource
43  * The name and password should not be null.
44  * The principal should be declared if the authorization type for the resource
45  * in ejb-jar.xml is "Application"
46  * @author Irfan Ahmed
47  */

48
49 public class ASEjbRRefDefResPrincipal extends ASEjbResRef {
50
51     public Result check(EjbDescriptor descriptor)
52     {
53     Result result = getInitializedResult();
54     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
55         boolean oneFailed = false;
56         try{
57             Set resRef = descriptor.getResourceReferenceDescriptors();
58             if(!(resRef.isEmpty())){
59                 Iterator it = resRef.iterator();
60                 while (it.hasNext()){
61                     ResourceReferenceDescriptor resDesc = ((ResourceReferenceDescriptor)it.next());
62                     String JavaDoc refName = resDesc.getName();
63                     String JavaDoc refJndiName = resDesc.getJndiName();
64                     ResourcePrincipal resPrinci = resDesc.getResourcePrincipal();
65                    if(resPrinci == null)
66                     {
67                         try
68                         {
69                            resDesc = descriptor.getResourceReferenceByName(refName);
70                             String JavaDoc resAuth = resDesc.getAuthorization();
71                             if(resAuth.equals(ResourceReferenceDescriptor.APPLICATION_AUTHORIZATION))
72                             {
73                                addErrorDetails(result, compName);
74                                result.failed(smh.getLocalString(getClass().getName()+".failed",
75                                     "FAILED [AS-EJB resource-ref] : res-auth for res-ref-name {0} is defined as Application." +
76                                     "Therefore the default-resource-principal should be supplied with valid properties",
77                                     new Object JavaDoc[] {refName}));
78                             }
79                             else
80                             {
81                                addNaDetails(result, compName);
82                                result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
83                                     "NOT APPLICABLE [AS-EJB resource-ref] : default-resource-principal Element not defined"));
84                             }
85                         }
86                         catch(IllegalArgumentException JavaDoc iaex)
87                         {
88                            addErrorDetails(result, compName);
89                            result.failed(smh.getLocalString(getClass().getName()+".failed2",
90                                 "FAILED [AS-EJB resource-ref] : res-ref-name {0} is not defined in the ejb-jar.xml",
91                                 new Object JavaDoc[]{refName}));
92                         }
93                     }else
94                     {
95                         String JavaDoc name = resPrinci.getName();
96                         if(name == null || name.length()==0)
97                         {
98                             oneFailed = true;
99                             addErrorDetails(result, compName);
100                             result.failed(smh.getLocalString(getClass().getName()+".failed3",
101                                 "FAILED [AS-EJB default-resource-principal] : name cannot be an empty string"));
102                         }
103                         else
104                         {
105                            addGoodDetails(result, compName);
106                            result.passed(smh.getLocalString(getClass().getName()+".passed",
107                                 "PASSED [AS-EJB default-resource-principal] : name is {0}",new Object JavaDoc[]{name}));
108                         }
109                         
110                         String JavaDoc password = resPrinci.getPassword();
111                         if(password == null || password.length()==0)
112                         {
113                            addWarningDetails(result, compName);
114                            result.warning(smh.getLocalString(getClass().getName()+".warning1",
115                                 "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
116                         }
117                         else
118                         {
119                             addGoodDetails(result, compName);
120                             result.passed(smh.getLocalString(getClass().getName()+".passed1",
121                                 "PASSED [AS-EJB default-resource-principal] : password is {0}",new Object JavaDoc[]{password}));
122                         }
123                         
124                         if(oneFailed)
125                             result.setStatus(Result.FAILED);
126                     }
127                 
128                 }
129             }
130             else
131             {
132                 addNaDetails(result, compName);
133                 result.notApplicable(smh.getLocalString
134                          (getClass().getName() + ".notApplicable",
135                           "{0} Does not define any resource-ref Elements"));
136             }
137         }catch(Exception JavaDoc ex)
138         {
139             addErrorDetails(result, compName);
140             result.addErrorDetails(smh.getLocalString
141                  (getClass().getName() + ".notRun",
142                   "NOT RUN [AS-EJB] : Could not create the descriptor object"));
143         }
144         return result;
145     }
146 }
147
Popular Tags