KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > model > JDBCDataSourceMdl


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.management.model;
25
26 //import com.sun.enterprise.resource.JdbcDataSource;
27

28 import java.util.Set JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30
31 public class JDBCDataSourceMdl extends J2EEManagedObjectMdl {
32
33     private static String JavaDoc MANAGED_OBJECT_TYPE = "JDBCDataSource";
34     private String JavaDoc jdbcDataSourceName = null;
35     private String JavaDoc driverName = null;
36     private boolean debug = false;
37     private String JavaDoc username = null;
38     private String JavaDoc password = null;
39     private String JavaDoc url = null;
40     private String JavaDoc[] propNames = null;
41     private String JavaDoc[] propValues = null;
42     
43     public JDBCDataSourceMdl(String JavaDoc dataSourceJndiName, String JavaDoc dataSourceName,
44                             String JavaDoc url,
45                             String JavaDoc username,
46                             String JavaDoc password,
47                             String JavaDoc[] propNames,
48                             String JavaDoc[] propValues) {
49         super(dataSourceJndiName,false,false,false);
50         this.jdbcDataSourceName = dataSourceName;
51         this.url = url;
52         this.username = username;
53         this.password = password;
54         this.propNames = propNames;
55         this.propValues = propValues;
56     }
57     public JDBCDataSourceMdl(String JavaDoc dataSourceJndiName, String JavaDoc serverName, String JavaDoc dataSourceName,
58                             String JavaDoc url,
59                             String JavaDoc username,
60                             String JavaDoc password,
61                             String JavaDoc[] propNames,
62                             String JavaDoc[] propValues) {
63         super(dataSourceJndiName,serverName,false,false,false);
64         this.jdbcDataSourceName = dataSourceName;
65         this.url = url;
66         this.username = username;
67         this.password = password;
68         this.propNames = propNames;
69         this.propValues = propValues;
70     }
71
72     public String JavaDoc getjdbcDriver() {
73         if (driverName == null) {
74             Set JavaDoc s;
75             try {
76                 //System.out.println("getjdbcDriver: jdbcDataSourceName = " + jdbcDataSourceName);
77
java.sql.Driver JavaDoc drv = java.sql.DriverManager.getDriver(jdbcDataSourceName);
78                 //System.out.println("java.sql.Driver = " + drv.getClass().getName());
79
s = findNames("j2eeType=JDBCDriver,name="+drv.getClass().getName());
80             } catch(java.sql.SQLException JavaDoc e) {
81                 //XADataSource
82
s = findNames("j2eeType=JDBCDriver,name="+jdbcDataSourceName);
83             }
84
85             Object JavaDoc [] objs = s.toArray();
86             if (objs.length > 0) {
87                 String JavaDoc name = ((ObjectName JavaDoc)objs[0]).toString();
88                 driverName = name;
89             }
90         }
91         return driverName;
92     }
93     
94     /**
95      * The type of the J2EEManagedObject as specified by JSR77. The class that implements a specific type must override this method and return the appropriate type string.
96      */

97     public String JavaDoc getj2eeType() {
98         return MANAGED_OBJECT_TYPE;
99     }
100     
101     /**
102      * The name of the J2EEManagedObject. All managed objects must have a unique name within the context of the management
103      * domain. The name must not be null.
104      */

105     public String JavaDoc getobjectName() {
106         Set JavaDoc s = findNames("j2eeType="+getj2eeType()+",name="+this.getname()+",JDBCResource="+getJDBC()+",J2EEServer="+this.getJ2EEServer());
107         Object JavaDoc [] objs = s.toArray();
108         if (objs.length > 0) {
109             String JavaDoc name = ((ObjectName JavaDoc)objs[0]).toString();
110             return name;
111         } else {
112             return null;
113         }
114     }
115
116     /**
117      * Accessor method for the parent key
118      */

119     public String JavaDoc getJDBC(){
120         return getname(); //matches name of JDBCResource in this impl
121
}
122     
123     public String JavaDoc geturl() {
124         return url;
125     }
126   
127     public String JavaDoc getusername() {
128         return username;
129     }
130
131     public String JavaDoc getpassword() {
132         return password;
133     }
134
135     public String JavaDoc[] getpropNames() {
136         return propNames;
137     }
138
139     public String JavaDoc[] getpropValues() {
140         return propValues;
141     }
142     
143     public String JavaDoc getjdbcDataSourceName() {
144         return jdbcDataSourceName;
145     }
146 }
147
Popular Tags