KickJava   Java API By Example, From Geeks To Geeks.

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


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
32 /** ejb [0,n]
33  * resource-ref [0,n]
34  * res-ref-name [String]
35  * jndi-name [String]
36  * default-resource-principal ?
37  * name [String]
38  * password [String]
39  *
40  * The jndi-name specifies the JNDI name to which this resource is binded
41  * The jndi-name should not be null.
42  * The jndi-name should map to the correct subcontext and hence start with the
43  * valid subcontext
44  * URL url/
45  * Mail mail/
46  * JDBC jdbc/
47  * JMS jms/
48  *
49  * @author Irfan Ahmed
50  */

51
52 public class ASEjbRRefJndiName extends ASEjbResRef {
53
54     public Result check(EjbDescriptor descriptor)
55     {
56     Result result = getInitializedResult();
57     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
58         boolean oneFailed = false;
59         //boolean oneWarning = false;
60

61         try{
62         Set resRef = descriptor.getResourceReferenceDescriptors();
63         if(!(resRef.isEmpty()))
64         {
65             Iterator it = resRef.iterator();
66             while (it.hasNext())
67             {
68                 ResourceReferenceDescriptor resDesc = ((ResourceReferenceDescriptor)it.next());
69                 String JavaDoc refName = resDesc.getName();
70                 String JavaDoc refJndiName = resDesc.getJndiName();
71                 String JavaDoc type = resDesc.getType();
72                 
73                 if(refJndiName == null || refJndiName.trim().equals(""))
74                 {
75                     oneFailed = true;
76                     result.failed(smh.getLocalString(getClass().getName()+".failed",
77                             "FAILED [AS-EJB resource-ref]: jndi-name is not a non empty string"));
78                 }
79                     /* else //Fix for bug id 5018617
80                     {
81                         if(type.indexOf("javax.jms")>-1) //jms resource
82                         {
83                             if(refJndiName.startsWith("jms/")) {
84                                 addGoodDetails(result, compName);
85                                 result.passed(smh.getLocalString(getClass().getName()+".passed1",
86                                     "PASSED [AS-EJB resource-ref] : jndi-name {0} is valid", new Object[]{refJndiName}));
87                             }
88                             else
89                             {
90                                 oneWarning = true;
91                                 addWarningDetails(result, compName);
92                                 result.warning(smh.getLocalString(getClass().getName()+".warning1",
93                                     "WARNING [AS-EJB resource-ref] : jndi-name is \"{0}\" for resource type \"{1}\"." +
94                                     "The preferred jndi-name for JMS resources should start with jms/",
95                                     new Object[]{refJndiName,type}));
96                             }
97                         }
98                         else if(type.indexOf("javax.sql")>-1) //jdbc resource
99                         {
100                             if(refJndiName.startsWith("jdbc/")) {
101                                 addGoodDetails(result, compName);
102                                 result.passed(smh.getLocalString(getClass().getName()+".passed1",
103                                     "PASSED [AS-EJB resource-ref] : jndi-name {0} is valid", new Object[]{refJndiName}));
104                             }
105                             else
106                             {
107                                 oneWarning = true;
108                                 addWarningDetails(result, compName);
109                                 result.warning(smh.getLocalString(getClass().getName()+".warning2",
110                                     "WARNING [AS-EJB resource-ref] : jndi-name is \"{0}\" for resource type \"{1}\"." +
111                                     "The preferred jndi-name for JDBC resources should start with jdbc/",
112                                     new Object[]{refJndiName,type}));
113                             }
114                         }
115                         else if(type.indexOf("java.net")>-1) //url resource
116                         {
117                             if(refJndiName.startsWith("http://"))//FIX should it start with http:// or url/http://
118                             {
119                                 addGoodDetails(result, compName);
120                                 result.passed(smh.getLocalString(getClass().getName()+".passed1",
121                                     "PASSED [AS-EJB resource-ref] : jndi-name {0} is valid", new Object[]{refJndiName}));
122                             }
123                             else
124                             {
125                                 oneWarning = true;
126                                 addWarningDetails(result, compName);
127                                 result.warning(smh.getLocalString(getClass().getName()+".warning3",
128                                     "WARNING [AS-EJB resource-ref] : jndi-name is \"{0}\" for resource type \"{1}\". " +
129                                     "The preferred jndi-name for URL resources should start with a url",
130                                     new Object[]{refJndiName,type}));
131                             }
132                         }
133                         else if(type.indexOf("javax.mail")>-1) //jms resource
134                         {
135                             if(refJndiName.startsWith("mail/")) {
136                                 addGoodDetails(result, compName);
137                                 result.passed(smh.getLocalString(getClass().getName()+".passed1",
138                                     "PASSED [AS-EJB resource-ref] : jndi-name {0} is valid", new Object[]{refJndiName}));
139                             }
140                             else
141                             {
142                                 oneWarning = true;
143                                 addWarningDetails(result, compName);
144                                 result.warning(smh.getLocalString(getClass().getName()+".warning4",
145                                     "WARNING [AS-EJB resource-ref] : jndi-name is \"{0}\" for resource type \"{1}\"." +
146                                     "The preferred jndi-name for MAIL resources should start with mail/",
147                                     new Object[]{refJndiName,type}));
148                             }
149                         }
150                         else
151                         {
152                             addGoodDetails(result, compName);
153                             result.passed(smh.getLocalString(getClass().getName()+".passed1","PASSED [AS-EJB resource-ref]: jndi-name {0} is valid",new Object[]{refJndiName}));
154                         }
155                     }*/

156             }
157         }
158         else
159         {
160             addNaDetails(result, compName);
161             result.notApplicable(smh.getLocalString
162                 (getClass().getName() + ".notApplicable",
163                 "NOT APPLICABLE [AS-EJB] : {0} Does not define any resource-ref Elements",
164                 new Object JavaDoc[] {descriptor.getName()}));
165             return result;
166         }
167         }catch(Exception JavaDoc ex)
168         {
169             oneFailed = true;
170             addErrorDetails(result, compName);
171                 result.addErrorDetails(smh.getLocalString
172                  (getClass().getName() + ".notRun",
173                   "NOT RUN [AS-EJB] : Could not create the descriptor object"));
174             return result;
175         }
176         /*if(oneWarning)
177             result.setStatus(Result.WARNING);*/

178         if(oneFailed)
179             result.setStatus(Result.FAILED);
180         else {
181             addGoodDetails(result, compName);
182             result.passed(smh.getLocalString(getClass().getName() + ".passed",
183                     "PASSED [AS-EJB resource-ref]: jndi name is specified correctly for the resource-references with in the application",
184                     new Object JavaDoc[]{}));
185         }
186         return result;
187     }
188 }
189
Popular Tags