KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > tests > AdminObjectResourceTest


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.config.serverbeans.validation.tests;
25
26 import java.util.logging.Level JavaDoc;
27
28 import com.sun.enterprise.config.ConfigBean;
29 import com.sun.enterprise.config.ConfigContext;
30 import com.sun.enterprise.config.ConfigContextEvent;
31 import com.sun.enterprise.config.ConfigException;
32 import com.sun.enterprise.config.serverbeans.AdminObjectResource;
33 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
34 import com.sun.enterprise.config.serverbeans.ServerTags;
35 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
36 import com.sun.enterprise.config.serverbeans.validation.Result;
37 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
38 import com.sun.enterprise.connectors.ConnectorRuntime;
39 import java.util.Set JavaDoc;
40
41 /**
42     Custom Test for Admin Object Resource Test which calls the Generic Validation before performing custom tests
43
44     @author Srinivas Krishnan
45     @version 2.0
46 */

47
48 public class AdminObjectResourceTest extends GenericValidator {
49     
50     static boolean checked = false;
51     
52     public AdminObjectResourceTest(ValidationDescriptor desc) {
53         super(desc);
54     }
55     
56     public Result validate(ConfigContextEvent cce) {
57         Result result = super.validate(cce); // Before doing custom validation do basic validation
58

59         if(cce.getChoice().equals(StaticTest.UPDATE)) {
60             try {
61                 ConfigContext context = cce.getConfigContext();
62                 String JavaDoc name = cce.getName();
63                 String JavaDoc value = (String JavaDoc) cce.getObject();
64                 AdminObjectResource admin = (AdminObjectResource)cce.getClassObject();
65                 validateAttribute(name, value, admin, result);
66             } catch(Exception JavaDoc e) {
67                 _logger.log(Level.FINE, "domainxmlverifier.exception", e);
68             }
69         }
70         
71         if(cce.getChoice().equals(StaticTest.ADD) || cce.getChoice().equals(StaticTest.VALIDATE)) {
72             try {
73                 ConfigContext context = cce.getConfigContext();
74                 Object JavaDoc value = cce.getObject();
75                 AdminObjectResource admin = (AdminObjectResource)value;
76                 validateAttribute(ServerTags.RES_TYPE, admin.getResType(), admin, result);
77             } catch(Exception JavaDoc e) {
78                 _logger.log(Level.FINE, "domainxmlverifier.exception", e);
79             }
80         }
81         return result;
82     }
83     
84     public void validateAttribute(String JavaDoc name, String JavaDoc value, ConfigBean admin, Result result) {
85        
86 /*
87         if(name.equals(ServerTags.RES_TYPE)) {
88             String restype = value;
89
90             String resAdapter = ((AdminObjectResource)admin).getResAdapter();
91             String resTypes[] = null;
92
93             try {
94                 resTypes = ConnectorRuntime.getRuntime().getAdminObjectInterfaceNames(resAdapter);
95             } catch(Exception e) {
96                        _logger.log(Level.FINE, "domainxmlverifier.exception", e);
97             }
98             boolean available = false;
99             if(resTypes != null) {
100                 for(int i=0;i<resTypes.length;i++) {
101                     if(restype.equals(resTypes[i])) {
102                         available = true;
103                         break;
104                     }
105                 }
106             }
107             if(!available)
108                     result.failed(smh.getLocalString(getClass().getName() + ".resAdapterNotAvl",
109                         "Attribute(restype={0}) : Invalid Resource Type ", new Object[]{restype}));
110         }
111 */

112     }
113
114 }
115
Popular Tags