KickJava   Java API By Example, From Geeks To Geeks.

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


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 jndi-name specifies the JNDI name to which this resource is binded
49  * The jndi-name should not be null.
50  * The jndi-name should map to the correct subcontext and hence start with the
51  * valid subcontext
52  * URL url/
53  * Mail mail/
54  * JDBC jdbc/
55  * JMS jms/
56  *
57  * @author Irfan Ahmed
58  */

59 public class ASEjbRRefJndiName extends ASEjbResRef {
60
61     public Result check(EjbDescriptor descriptor)
62     {
63     Result result = getInitializedResult();
64     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
65
66         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
67         boolean oneFailed = false;
68         boolean oneWarning = false;
69         
70         if(ejbJar!=null)
71         {
72             Ejb ejbs[] = ejbJar.getEnterpriseBeans().getEjb();
73             Ejb testCase = null;
74             for(int i=0;i<ejbs.length;i++)
75             {
76                 if(ejbs[i].getEjbName().equals(descriptor.getName()))
77                 {
78                     testCase = ejbs[i];
79                     break;
80                 }
81             }
82             
83             ResourceRef resRefs[] = testCase.getResourceRef();
84             ResourceReferenceDescriptor resDesc;
85             if(resRefs.length > 0)
86             {
87                 for(int i=0;i<resRefs.length;i++)
88                 {
89                     String JavaDoc refName = resRefs[i].getResRefName();
90                     String JavaDoc refJndiName = resRefs[i].getJndiName();
91                     try
92                     {
93                         resDesc = descriptor.getResourceReferenceByName(refName);
94                         String JavaDoc type = resDesc.getType();
95                         if(refJndiName.equals(""))
96                         {
97                             oneFailed = true;
98                             result.failed(smh.getLocalString(getClass().getName()+".failed1","FAILED [AS-EJB resource-ref]: jndi-name is blank string"));
99                         }
100                         else
101                         {
102                         if(type.indexOf("javax.jms")>-1) //jms resource
103
{
104                             if(refJndiName.startsWith("jms/"))
105                                 result.passed(smh.getLocalString(getClass().getName()+".passed1",
106                                     "PASSED [AS-EJB resource-ref] : jndi-name {0} is valid", new Object JavaDoc[]{refJndiName}));
107                             else
108                             {
109                                 oneWarning = true;
110                                 result.warning(smh.getLocalString(getClass().getName()+".warning1",
111                                     "WARNING [AS-EJB resource-ref] : jndi-name is \"{0}\" for resource type \"{1}\"." +
112                                     "The preferred jndi-name for JMS resources should start with jms/",
113                                     new Object JavaDoc[]{refJndiName,type}));
114                             }
115                         }
116                         else if(type.indexOf("javax.sql")>-1) //jdbc resource
117
{
118                             if(refJndiName.startsWith("jdbc/"))
119                                 result.passed(smh.getLocalString(getClass().getName()+".passed1",
120                                     "PASSED [AS-EJB resource-ref] : jndi-name {0} is valid", new Object JavaDoc[]{refJndiName}));
121                             else
122                             {
123                                 oneWarning = true;
124                                 result.warning(smh.getLocalString(getClass().getName()+".warning2",
125                                     "WARNING [AS-EJB resource-ref] : jndi-name is \"{0}\" for resource type \"{1}\"." +
126                                     "The preferred jndi-name for JDBC resources should start with jdbc/",
127                                     new Object JavaDoc[]{refJndiName,type}));
128                             }
129                         }
130                         else if(type.indexOf("java.net")>-1) //url resource
131
{
132                             if(refJndiName.startsWith("http://"))//FIX should it start with http:// or url/http://
133
result.passed(smh.getLocalString(getClass().getName()+".passed1",
134                                     "PASSED [AS-EJB resource-ref] : jndi-name {0} is valid", new Object JavaDoc[]{refJndiName}));
135                             else
136                             {
137                                 oneWarning = true;
138                                 result.warning(smh.getLocalString(getClass().getName()+".warning3",
139                                     "WARNING [AS-EJB resource-ref] : jndi-name is \"{0}\" for resource type \"{1}\". " +
140                                     "The preferred jndi-name for URL resources should start with a url",
141                                     new Object JavaDoc[]{refJndiName,type}));
142                             }
143                         }
144                         else if(type.indexOf("javax.mail")>-1) //jms resource
145
{
146                             if(refJndiName.startsWith("mail/"))
147                                 result.passed(smh.getLocalString(getClass().getName()+".passed1",
148                                     "PASSED [AS-EJB resource-ref] : jndi-name {0} is valid", new Object JavaDoc[]{refJndiName}));
149                             else
150                             {
151                                 oneWarning = true;
152                                 result.warning(smh.getLocalString(getClass().getName()+".warning4",
153                                     "WARNING [AS-EJB resource-ref] : jndi-name is \"{0}\" for resource type \"{1}\"." +
154                                     "The preferred jndi-name for MAIL resources should start with mail/",
155                                     new Object JavaDoc[]{refJndiName,type}));
156                             }
157                         }
158                         else
159                         {
160                             result.passed(smh.getLocalString(getClass().getName()+".passed1","PASSED [AS-EJB resource-ref]: jndi-name {0} is valid",new Object JavaDoc[]{refJndiName}));
161                         }
162                         }
163                     }
164                     catch(IllegalArgumentException JavaDoc iex)
165                     {
166                         oneFailed = true;
167                         result.failed(smh.getLocalString(getClass().getName()+".failed2",
168                             "FAILED [AS-EJB resource-ref] : res-ref with res-ref-name {0} is not defined in the ejb-jar.xml",
169                             new Object JavaDoc[]{refName}));
170                     }
171                 }
172             }
173             else
174             {
175                  result.notApplicable(smh.getLocalString
176                          (getClass().getName() + ".notApplicable",
177                           "NOT APPLICABLE [AS-EJB] : {0} Does not define any resource-ref Elements",
178                           new Object JavaDoc[] {descriptor.getName()}));
179             }
180         }
181         else
182         {
183             result.addErrorDetails(smh.getLocalString
184                  (getClass().getName() + ".notRun",
185                   "NOT RUN [AS-EJB] : Could not create a SunEjbJar object"));
186         }
187         if(oneWarning)
188             result.setStatus(Result.WARNING);
189         if(oneFailed)
190             result.setStatus(Result.FAILED);
191         return result;
192     }
193 }
194
195
Popular Tags