001: /* Copyright 2002-2005 The Apache Software Foundation
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
017:
018: import org.apache.ojb.broker.metadata.DescriptorRepository;
019: import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
020:
021: /**
022: *
023: * @author Administrator
024: */
025: public class OjbMetaJdbcConnectionDescriptorNode extends
026: OjbMetaTreeNode {
027:
028: /** Key for accessing the schema name in the attributes Map */
029: public static final String ATT_DBALIAS = "Database Alias";
030: public static final String ATT_DBMS = "DBMS";
031: public static final String ATT_DATASOURCE_NAME = "Datasource Name";
032: public static final String ATT_DRIVER = "Driver";
033: public static final String ATT_DESCRIPTOR_PBKEY = "PBKey";
034: public static final String ATT_JDBC_LEVEL = "JDBC Level";
035: public static final String ATT_PASSWORD = "Password";
036: public static final String ATT_PROTOCOL = "Protocol";
037: public static final String ATT_SUBPROTOCOL = "Sub Protocol";
038: public static final String ATT_USERNAME = "Username";
039:
040: private static java.util.ArrayList supportedActions = new java.util.ArrayList();
041:
042: private JdbcConnectionDescriptor connDescriptor;
043:
044: /** Creates a new instance of OjbMetaJdbcConnectionDescriptorNode */
045: public OjbMetaJdbcConnectionDescriptorNode(
046: DescriptorRepository pRepository,
047: OjbMetaDataTreeModel pTreeModel, OjbMetaTreeNode pparent,
048: JdbcConnectionDescriptor pConnDescriptor) {
049: super (pRepository, pTreeModel, pparent);
050: this .connDescriptor = pConnDescriptor;
051: }
052:
053: /** Purpose of this method is to fill the children of the node. It should
054: * replace all children in alChildren (the arraylist containing the children)
055: * of this node and notify the TreeModel that a change has occurred.
056: */
057: protected boolean _load() {
058: return true;
059: }
060:
061: public boolean getAllowsChildren() {
062: return false;
063: }
064:
065: public Object getAttribute(String key) {
066: if (key.equals(ATT_DBALIAS)) {
067: return connDescriptor.getDbAlias();
068: } else if (key.equals(ATT_DATASOURCE_NAME)) {
069: return connDescriptor.getDatasourceName();
070: } else if (key.equals(ATT_DRIVER)) {
071: return connDescriptor.getDriver();
072: } else if (key.equals(ATT_JDBC_LEVEL)) {
073: return new Double(connDescriptor.getJdbcLevel());
074: } else if (key.equals(ATT_DESCRIPTOR_PBKEY)) {
075: return connDescriptor.getPBKey();
076: } else if (key.equals(ATT_PASSWORD)) {
077: return connDescriptor.getPassWord();
078: } else if (key.equals(ATT_PROTOCOL)) {
079: return connDescriptor.getProtocol();
080: } else if (key.equals(ATT_SUBPROTOCOL)) {
081: return connDescriptor.getSubProtocol();
082: } else if (key.equals(ATT_USERNAME)) {
083: return connDescriptor.getUserName();
084: } else if (key.equals(ATT_DBMS)) {
085: return connDescriptor.getDbms();
086: } else {
087: return super .getAttribute(key);
088: }
089: }
090:
091: public Class getPropertyEditorClass() {
092: return org.apache.ojb.tools.mapping.reversedb2.propertyEditors.JPnlPropertyEditorOJBMetaJdbcConnectionDescriptor.class;
093: }
094:
095: public boolean isLeaf() {
096: return true;
097: }
098:
099: public void setAttribute(String key, Object value) {
100: if (key.equals(ATT_DBALIAS)) {
101: Object oldValue = connDescriptor.getDbAlias();
102: connDescriptor.setDbAlias(value.toString());
103: propertyChangeDelegate.firePropertyChange(ATT_DBALIAS,
104: oldValue, value);
105: // We need to send this event because the DBAlias is part of the treenode label...
106: this .getOjbMetaTreeModel().nodeChanged(this );
107: } else if (key.equals(ATT_DATASOURCE_NAME)) {
108: Object oldValue = connDescriptor.getDatasourceName();
109: connDescriptor.setDatasourceName(value.toString());
110: propertyChangeDelegate.firePropertyChange(
111: ATT_DATASOURCE_NAME, oldValue, value);
112: } else if (key.equals(ATT_DRIVER)) {
113: Object oldValue = connDescriptor.getDatasourceName();
114: connDescriptor.setDriver(value.toString());
115: propertyChangeDelegate.firePropertyChange(ATT_DRIVER,
116: oldValue, value);
117: } else if (key.equals(ATT_DESCRIPTOR_PBKEY)) {
118: /* Readonly */
119: propertyChangeDelegate.firePropertyChange(
120: ATT_DESCRIPTOR_PBKEY, connDescriptor.getPBKey(),
121: connDescriptor.getPBKey());
122: } else if (key.equals(ATT_JDBC_LEVEL)) {
123: Object oldValue = new Double(connDescriptor.getJdbcLevel());
124: connDescriptor.setJdbcLevel(value.toString());
125: propertyChangeDelegate
126: .firePropertyChange(ATT_JDBC_LEVEL, oldValue,
127: new Double(connDescriptor.getJdbcLevel()));
128: } else if (key.equals(ATT_PASSWORD)) {
129: Object oldValue = connDescriptor.getPassWord();
130: connDescriptor.setPassWord(value.toString());
131: propertyChangeDelegate.firePropertyChange(ATT_PASSWORD,
132: oldValue, value);
133: } else if (key.equals(ATT_PROTOCOL)) {
134: Object oldValue = connDescriptor.getProtocol();
135: connDescriptor.setProtocol(value.toString());
136: propertyChangeDelegate.firePropertyChange(ATT_PROTOCOL,
137: oldValue, value);
138: } else if (key.equals(ATT_SUBPROTOCOL)) {
139: Object oldValue = connDescriptor.getSubProtocol();
140: connDescriptor.setSubProtocol(value.toString());
141: propertyChangeDelegate.firePropertyChange(ATT_SUBPROTOCOL,
142: oldValue, value);
143: } else if (key.equals(ATT_USERNAME)) {
144: Object oldValue = connDescriptor.getUserName();
145: connDescriptor.setUserName(value.toString());
146: propertyChangeDelegate.firePropertyChange(ATT_USERNAME,
147: oldValue, value);
148: } else if (key.equals(ATT_DBMS)) {
149: Object oldValue = connDescriptor.getDbms();
150: connDescriptor.setDbms(value.toString());
151: propertyChangeDelegate.firePropertyChange(ATT_DBMS,
152: oldValue, value);
153: } else {
154: super .setAttribute(key, value);
155: }
156: }
157:
158: public String toString() {
159: return "ConnectionDescriptor: " + connDescriptor.getDbAlias();
160: }
161:
162: /**
163: * @see ActionTarget#getActions()
164: */
165: public java.util.Iterator getActions() {
166: return supportedActions.iterator();
167: }
168:
169: /**
170: * @see ActionTarget#actionListCacheable()
171: */
172: public boolean actionListCachable() {
173: return true;
174: }
175:
176: public boolean actionListStatic() {
177: return true;
178: }
179:
180: /**
181: * Return the descriptor object this node is associated with. E.g. if the
182: * node displays a class descriptor, the ClassDescriptor describing the class
183: * should be returned. Used for creating a Transferable.
184: */
185: public Object getAssociatedDescriptor() {
186: return connDescriptor;
187: }
188:
189: }
|