KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package com.sun.enterprise.tools.verifier.tests.web.ias;
25
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
31 import com.sun.enterprise.deployment.WebBundleDescriptor;
32 import com.sun.enterprise.tools.verifier.tests.web.*;
33 import com.sun.enterprise.tools.common.dd.webapp.*;
34
35 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
36
/* Changed the result messages to reflect consistency between the result messages generated
37  * for the EJB test cases for SunONE specific deployment descriptors*/

38 //</addition>
39

40 public class ASWebProperty extends WebTest implements WebCheck{
41
42
43 public Result check(WebBundleDescriptor descriptor) {
44
45
46     Result result = getInitializedResult();
47
48     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
49
50         boolean oneFailed = false;
51         boolean notApp = false;
52         WebProperty[] webProps = descriptor.getIasWebApp().getWebProperty();
53         //System.out.println(">>>>>>>>>>>>checking for res " +webProps);
54
if (webProps.length > 0) {
55           oneFailed=checkWebProperties(webProps,result ,descriptor, this ) ;
56
57         } else {
58             //System.out.println("There are no resource references defined within the ias-web archive");
59
notApp = true;
60         result.notApplicable(smh.getLocalString
61                                  (getClass().getName() + ".notApplicable",
62                                   "NOT APPLICABLE [AS-WEB sun-web-app] web property element not defined within the web archive [ {0} ].",
63                                   new Object JavaDoc[] {descriptor.getName()}));
64         }
65         if (oneFailed) {
66             result.setStatus(Result.FAILED);
67         } else if(notApp) {
68             result.setStatus(Result.NOT_APPLICABLE);
69         }else {
70             result.setStatus(Result.PASSED);
71         }
72
73
74
75     return result;
76     }
77    public static boolean checkWebProperties(WebProperty[] webProps, Result result ,WebBundleDescriptor descriptor, Object JavaDoc obj ) {
78         WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
79         String JavaDoc name;
80         String JavaDoc value;
81         boolean oneFailed = false;
82         String JavaDoc[] names=null;
83
84
85    if (webProps.length > 0) {
86             names=new String JavaDoc[webProps.length];
87
88
89         for (int rep=0; rep<webProps.length; rep++ ) {
90         //System.out.println(">>>>>>>>>>>> count " + webProps.length);
91

92         name = webProps[rep].getAttributeValue(MetaData.NAME);
93                 value = webProps[rep].getAttributeValue(MetaData.VALUE);
94                 names[rep]=name;
95
96                 //System.out.println("checking for name : "+ name+" value : "+ value);
97
if (name !=null && value !=null && name.length() != 0 && value.length() != 0) {
98
99                     //check if the name already exist in this web-prop
100
boolean isDuplicate=false;
101                     for(int rep1=0;rep1<rep;rep1++)
102                     {
103                         if(name.equals(names[rep1])){
104                             isDuplicate=true;
105                             break;
106                             }
107
108                     }
109
110                     if(!isDuplicate){
111                     result.passed(smh.getLocalString
112                       (obj.getClass().getName() + ".passed",
113                        "PASSED [AS-WEB property] Proper web property with name [ {0} ] and value [ {1} ] defined.",
114                        new Object JavaDoc[] {name, value}));
115                     } else {
116                     if (!oneFailed)
117                         oneFailed = true;
118
119                     result.failed(smh.getLocalString
120                                       (obj.getClass().getName() + ".failed",
121                                       "FAILED [AS-WEB property] name [ {0} ] and value [ {1} ], the name must be unique in the entire list of web property.",
122                                       new Object JavaDoc[] {name, value}));
123                    }
124
125                 } else {
126                     if (!oneFailed)
127                         oneFailed = true;
128                     result.failed(smh.getLocalString
129                                       (obj.getClass().getName() + ".failed1",
130                                       "FAILED [AS-WEB property] name [ {0} ] and value [ {1} ], attributes must be of finite length.",
131                                       new Object JavaDoc[] {name, value}));
132                 }
133             }
134
135         }
136
137         return oneFailed;
138
139    }
140
141 }
142
143
Popular Tags