KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > ResourceRefName


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 package com.sun.enterprise.tools.verifier.tests.web;
24
25 import java.util.*;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
30 import com.sun.enterprise.deployment.WebBundleDescriptor;
31
32
33 /**
34  * Resource ref name exists test.
35  * @author Arun Jain
36  */

37 public class ResourceRefName extends WebTest implements WebCheck {
38     
39
40      /**
41      * Resource Ref Name must be of finite length.
42      *
43      * @param descriptor the Web deployment descriptor
44      *
45      * @return <code>Result</code> the results for this assertion
46      */

47     public Result check(WebBundleDescriptor descriptor) {
48
49         Set resourceRefs;
50         ResourceReferenceDescriptor resrefDes;
51         Iterator itr;
52         String JavaDoc resrefName;
53     Result result = getInitializedResult();
54     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
55         //boolean foundIt = false;
56
boolean oneFailed = false;
57         boolean notApp = false;
58         
59     if (!descriptor.getResourceReferenceDescriptors().isEmpty()) {
60             
61         // get the Resource Reference Descriptors set
62
resourceRefs = descriptor.getResourceReferenceDescriptors();
63         itr = resourceRefs.iterator();
64         // test the Resource Reference Descriptor
65
while (itr.hasNext()) {
66         resrefDes = (ResourceReferenceDescriptor)itr.next();
67         resrefName = resrefDes.getName();
68                 if (resrefName.length() != 0) {
69                     // foundIt = true;
70
result.addGoodDetails(smh.getLocalString
71                        ("tests.componentNameConstructor",
72                     "For [ {0} ]",
73                     new Object JavaDoc[] {compName.toString()}));
74                     result.addGoodDetails(smh.getLocalString
75                                           (getClass().getName() + ".passed",
76                                            "Resource Reference exists in the web application."));
77                 } else {
78                     if (!oneFailed)
79                         oneFailed = true;
80             result.addErrorDetails(smh.getLocalString
81                        ("tests.componentNameConstructor",
82                     "For [ {0} ]",
83                     new Object JavaDoc[] {compName.toString()}));
84                     result.addErrorDetails(smh.getLocalString
85                                            (getClass().getName() + ".failed",
86                                             "Error: Resource reference entry must be of finite length."));
87                 }
88             }
89             
90         } else {
91             notApp = true;
92         result.addNaDetails(smh.getLocalString
93                        ("tests.componentNameConstructor",
94                     "For [ {0} ]",
95                     new Object JavaDoc[] {compName.toString()}));
96         result.notApplicable(smh.getLocalString
97                                  (getClass().getName() + ".notApplicable",
98                                   "There are no resource references defined within the web archive [ {0} ]",
99                                   new Object JavaDoc[] {descriptor.getName()}));
100         }
101         if (oneFailed) {
102             result.setStatus(Result.FAILED);
103         } else if(notApp) {
104             result.setStatus(Result.NOT_APPLICABLE);
105         }else {
106             result.setStatus(Result.PASSED);
107         }
108     return result;
109     }
110 }
111
Popular Tags