KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > verifier > tests > JdbcResourceTest


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 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31
32 package com.sun.enterprise.admin.verifier.tests;
33
34 /* Test Case to validate the Jdbc Resource fields
35  * Author : srini@sun.com
36  **/

37
38 // 8.0 XML Verifier
39
//import com.sun.enterprise.tools.verifier.Result;
40
import com.sun.enterprise.config.serverbeans.Server;
41 import com.sun.enterprise.config.serverbeans.*;
42 import com.sun.enterprise.config.serverbeans.Resources;
43 import com.sun.enterprise.config.serverbeans.Applications;
44 import com.sun.enterprise.config.ConfigContext;
45 import com.sun.enterprise.config.ConfigContextEvent;
46 import com.sun.enterprise.config.ConfigException;
47 import com.sun.enterprise.config.serverbeans.JdbcResource;
48
49 import com.sun.enterprise.admin.verifier.*;
50
51 // Logging
52
import java.util.logging.Logger JavaDoc;
53 import java.util.logging.Level JavaDoc;
54 import com.sun.logging.LogDomains;
55
56
57 public class JdbcResourceTest extends ServerXmlTest implements ServerCheck {
58     
59      // Logging
60
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
61
62     public JdbcResourceTest() {
63     }
64  
65     // check method called by command line verifier
66
public Result check(ConfigContext context) {
67         Result result;
68         result = super.getInitializedResult();
69         // 8.0 XML Verifier
70
/*try {
71             Server server = (Server)context.getRootConfigBean();
72             Resources resource = server.getResources();
73             JdbcResource [] jdbcResources = resource.getJdbcResource();
74             JdbcConnectionPool[] connection = resource.getJdbcConnectionPool();
75             String poolName=null;
76             boolean isPool=false;
77             for(int i=0;i<jdbcResources.length;i++){
78                 poolName=jdbcResources[i].getPoolName();
79                 for(int j=0;j<connection.length;j++){
80                     if(connection[j].getName().equals(poolName))
81                             isPool=true;
82                 }
83                 if(isPool) {
84                         result.passed("Valid Connection Pool");
85                         isPool = false;
86                 }
87                 else
88                     result.failed("Connection Pool " + poolName + " Not Available for jdbc resource " + jdbcResources[i].getJndiName() );
89             }
90         }
91         catch(Exception ex) {
92             // Logging
93             _logger.log(Level.FINE, "serverxmlverifier.exception", ex);
94             result.failed("Exception : " + ex.getMessage());
95         }*/

96         return result;
97     }
98     
99     // check method called by iasadmin and adminGUI
100
public Result check(ConfigContextEvent ccce) {
101         Result result = new Result();
102         
103         String JavaDoc beanName = ccce.getBeanName();
104         if(beanName!=null) {
105                result.passed("Save to be implemented");
106                return result;
107         }
108         
109         ConfigContext context = ccce.getConfigContext();
110         Object JavaDoc value = ccce.getObject();
111         JdbcResource jdbc = (JdbcResource)value;
112         boolean isPool = false;
113         String JavaDoc pool = jdbc.getPoolName();
114         
115         // check if jdbc resource jndi-name is valid object name Bug : 4698687 : start
116
if(StaticTest.checkObjectName(jdbc.getJndiName(), result))
117             result.passed("Valid Object Name");
118         else {
119             result.failed("JDBC Resource Jndi-Name Invalid ");
120             return result;
121         }
122         // End Bug : 4698687
123

124         
125         try {
126             // 8.0 XML Verifier
127
//Server server = (Server)context.getRootConfigBean();
128
//Resources resource = server.getResources();
129
Domain domain = (Domain)context.getRootConfigBean();
130             Resources resource = domain.getResources();
131             JdbcConnectionPool[] connection = resource.getJdbcConnectionPool();
132             for(int i=0;i<connection.length;i++){
133                 if(connection[i].getName().equals(pool))
134                         isPool=true;
135             }
136             if(isPool)
137                     result.passed("Valid Connection Pool");
138             else
139                     result.failed("Connection Pool Not Available");
140         }
141         catch(Exception JavaDoc e) {
142             // Logging
143
_logger.log(Level.FINE, "serverxmlverifier.exception", e);
144             result.failed("Exception : " + e.getMessage());
145         }
146         return result;
147     }
148 }
149
Popular Tags