KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > ojbmetatreemodel > OjbMetaJdbcConnectionDescriptorNode


1 /* Copyright 2002-2005 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15
16 package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
17
18 import org.apache.ojb.broker.metadata.DescriptorRepository;
19 import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
20
21 /**
22  *
23  * @author Administrator
24  */

25 public class OjbMetaJdbcConnectionDescriptorNode extends OjbMetaTreeNode
26 {
27
28     /** Key for accessing the schema name in the attributes Map */
29     public static final String JavaDoc ATT_DBALIAS = "Database Alias";
30     public static final String JavaDoc ATT_DBMS = "DBMS";
31     public static final String JavaDoc ATT_DATASOURCE_NAME = "Datasource Name";
32     public static final String JavaDoc ATT_DRIVER = "Driver";
33     public static final String JavaDoc ATT_DESCRIPTOR_PBKEY = "PBKey";
34     public static final String JavaDoc ATT_JDBC_LEVEL = "JDBC Level";
35     public static final String JavaDoc ATT_PASSWORD = "Password";
36     public static final String JavaDoc ATT_PROTOCOL = "Protocol";
37     public static final String JavaDoc ATT_SUBPROTOCOL = "Sub Protocol";
38     public static final String JavaDoc ATT_USERNAME = "Username";
39
40     private static java.util.ArrayList JavaDoc supportedActions = new java.util.ArrayList JavaDoc();
41
42     private JdbcConnectionDescriptor connDescriptor;
43     /** Creates a new instance of OjbMetaJdbcConnectionDescriptorNode */
44     public OjbMetaJdbcConnectionDescriptorNode(DescriptorRepository pRepository,
45                                        OjbMetaDataTreeModel pTreeModel,
46                                        OjbMetaTreeNode pparent,
47                                        JdbcConnectionDescriptor pConnDescriptor)
48     {
49         super(pRepository, pTreeModel, pparent);
50         this.connDescriptor = pConnDescriptor;
51     }
52
53     /** Purpose of this method is to fill the children of the node. It should
54      * replace all children in alChildren (the arraylist containing the children)
55      * of this node and notify the TreeModel that a change has occurred.
56      */

57     protected boolean _load ()
58     {
59         return true;
60     }
61
62     public boolean getAllowsChildren ()
63     {
64         return false;
65     }
66
67     public Object JavaDoc getAttribute (String JavaDoc key)
68     {
69         if (key.equals(ATT_DBALIAS))
70         {
71             return connDescriptor.getDbAlias();
72         }
73         else if (key.equals(ATT_DATASOURCE_NAME))
74         {
75             return connDescriptor.getDatasourceName();
76         }
77         else if (key.equals(ATT_DRIVER))
78         {
79             return connDescriptor.getDriver();
80         }
81         else if (key.equals(ATT_JDBC_LEVEL ))
82         {
83             return new Double JavaDoc(connDescriptor.getJdbcLevel());
84         }
85         else if (key.equals(ATT_DESCRIPTOR_PBKEY))
86         {
87             return connDescriptor.getPBKey();
88         }
89         else if (key.equals(ATT_PASSWORD))
90         {
91             return connDescriptor.getPassWord();
92         }
93         else if (key.equals(ATT_PROTOCOL))
94         {
95             return connDescriptor.getProtocol();
96         }
97         else if (key.equals(ATT_SUBPROTOCOL))
98         {
99             return connDescriptor.getSubProtocol();
100         }
101         else if (key.equals(ATT_USERNAME))
102         {
103             return connDescriptor.getUserName();
104         }
105         else if (key.equals(ATT_DBMS))
106         {
107             return connDescriptor.getDbms();
108         }
109         else
110         {
111             return super.getAttribute(key);
112         }
113     }
114
115     public Class JavaDoc getPropertyEditorClass ()
116     {
117         return org.apache.ojb.tools.mapping.reversedb2.propertyEditors.JPnlPropertyEditorOJBMetaJdbcConnectionDescriptor.class;
118     }
119
120     public boolean isLeaf ()
121     {
122         return true;
123     }
124
125     public void setAttribute (String JavaDoc key, Object JavaDoc value)
126     {
127         if (key.equals(ATT_DBALIAS))
128         {
129             Object JavaDoc oldValue = connDescriptor.getDbAlias();
130             connDescriptor.setDbAlias(value.toString());
131             propertyChangeDelegate.firePropertyChange(ATT_DBALIAS, oldValue, value);
132             // We need to send this event because the DBAlias is part of the treenode label...
133
this.getOjbMetaTreeModel().nodeChanged(this);
134         }
135         else if (key.equals(ATT_DATASOURCE_NAME))
136         {
137             Object JavaDoc oldValue = connDescriptor.getDatasourceName();
138             connDescriptor.setDatasourceName(value.toString());
139             propertyChangeDelegate.firePropertyChange(ATT_DATASOURCE_NAME, oldValue, value);
140         }
141         else if (key.equals(ATT_DRIVER))
142         {
143             Object JavaDoc oldValue = connDescriptor.getDatasourceName();
144             connDescriptor.setDriver(value.toString());
145             propertyChangeDelegate.firePropertyChange(ATT_DRIVER, oldValue, value);
146         }
147         else if (key.equals(ATT_DESCRIPTOR_PBKEY))
148         {
149 /* Readonly */
150             propertyChangeDelegate.firePropertyChange(ATT_DESCRIPTOR_PBKEY, connDescriptor.getPBKey(), connDescriptor.getPBKey());
151         }
152         else if (key.equals(ATT_JDBC_LEVEL))
153         {
154             Object JavaDoc oldValue = new Double JavaDoc(connDescriptor.getJdbcLevel());
155             connDescriptor.setJdbcLevel(value.toString());
156             propertyChangeDelegate.firePropertyChange(ATT_JDBC_LEVEL, oldValue, new Double JavaDoc(connDescriptor.getJdbcLevel()));
157         }
158         else if (key.equals(ATT_PASSWORD))
159         {
160             Object JavaDoc oldValue = connDescriptor.getPassWord();
161             connDescriptor.setPassWord(value.toString());
162             propertyChangeDelegate.firePropertyChange(ATT_PASSWORD, oldValue, value);
163         }
164         else if (key.equals(ATT_PROTOCOL))
165         {
166             Object JavaDoc oldValue = connDescriptor.getProtocol();
167             connDescriptor.setProtocol(value.toString());
168             propertyChangeDelegate.firePropertyChange(ATT_PROTOCOL, oldValue, value);
169         }
170         else if (key.equals(ATT_SUBPROTOCOL))
171         {
172             Object JavaDoc oldValue = connDescriptor.getSubProtocol();
173             connDescriptor.setSubProtocol(value.toString());
174             propertyChangeDelegate.firePropertyChange(ATT_SUBPROTOCOL, oldValue, value);
175         }
176         else if (key.equals(ATT_USERNAME))
177         {
178             Object JavaDoc oldValue = connDescriptor.getUserName();
179             connDescriptor.setUserName(value.toString());
180             propertyChangeDelegate.firePropertyChange(ATT_USERNAME, oldValue, value);
181         }
182         else if (key.equals(ATT_DBMS))
183         {
184             Object JavaDoc oldValue = connDescriptor.getDbms();
185             connDescriptor.setDbms(value.toString());
186             propertyChangeDelegate.firePropertyChange(ATT_DBMS, oldValue, value);
187         }
188         else
189         {
190             super.setAttribute(key, value);
191         }
192     }
193
194     public String JavaDoc toString()
195     {
196         return "ConnectionDescriptor: " + connDescriptor.getDbAlias();
197     }
198
199     /**
200      * @see ActionTarget#getActions()
201      */

202     public java.util.Iterator JavaDoc getActions()
203     {
204         return supportedActions.iterator();
205     }
206
207     /**
208      * @see ActionTarget#actionListCacheable()
209      */

210     public boolean actionListCachable()
211     {
212         return true;
213     }
214
215     public boolean actionListStatic()
216     {
217         return true;
218     }
219
220     /**
221      * Return the descriptor object this node is associated with. E.g. if the
222      * node displays a class descriptor, the ClassDescriptor describing the class
223      * should be returned. Used for creating a Transferable.
224      */

225     public Object JavaDoc getAssociatedDescriptor()
226     {
227         return connDescriptor;
228     }
229
230 }
231
Popular Tags