001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: *
022: * Copyright 2005 Sun Microsystems, Inc.
023: *
024: * Licensed under the Apache License, Version 2.0 (the "License");
025: * you may not use this file except in compliance with the License.
026: * You may obtain a copy of the License at
027: *
028: * http://www.apache.org/licenses/LICENSE-2.0
029: *
030: * Unless required by applicable law or agreed to in writing, software
031: * distributed under the License is distributed on an "AS IS" BASIS,
032: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
033: * See the License for the specific language governing permissions and
034: * limitations under the License.
035: *
036: */
037: package org.netbeans.modules.jdbcwizard.builder.dbmodel.impl;
038:
039: import java.util.ResourceBundle;
040: import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBConnectionDefinition;
041: import org.openide.util.NbBundle;
042:
043: /**
044: * Implements DBConnectionDefinition interface for JDBC Database OTD.
045: *
046: * @author
047: */
048: public class DBConnectionDefinitionImpl implements
049: DBConnectionDefinition {
050:
051: private String name;
052:
053: private String driverClass;
054:
055: private String url;
056:
057: private String userName;
058:
059: private String password;
060:
061: private String description;
062:
063: private String dbType;
064:
065: /**
066: * Creates a new instance of DBConnectionDefinitionImpl with the given attributes.
067: *
068: * @param connName connection name
069: * @param driverName driver name
070: * @param connUrl JDBC URL for this connection
071: * @param uname username used to establish connection
072: * @param passwd password used to establish connection
073: * @param desc description of connection
074: * @param type String concatenation of vendor and version number of source DB (e.g., "Oracle9",
075: * "JDBC11")
076: */
077: public DBConnectionDefinitionImpl(final String connName,
078: final String driverName, final String connUrl,
079: final String uname, final String passwd, final String desc,
080: final String type) {
081: this .name = connName;
082:
083: this .driverClass = driverName;
084: this .url = connUrl;
085: this .userName = uname;
086: this .password = passwd;
087: this .description = desc;
088: this .dbType = type;
089: }
090:
091: /**
092: * Creates a new instance of DBConnectionDefinitionImpl using the values in the given
093: * DBConnectionDefinition.
094: *
095: * @param connectionDefn DBConnectionDefinition to be copied
096: */
097: public DBConnectionDefinitionImpl(
098: final DBConnectionDefinition connectionDefn) {
099: if (connectionDefn == null) {
100: final ResourceBundle cMessages = NbBundle
101: .getBundle(DBConnectionDefinitionImpl.class);
102: throw new IllegalArgumentException(cMessages
103: .getString("ERROR_NULL_DBCONNDEF")
104: + "ERROR_NULL_DBCONNDEF");// NO
105: // i18n
106: }
107:
108: this .copyFrom(connectionDefn);
109: }
110:
111: /**
112: * @see com.stc.model.database.DBConnectionDefinition#getConnectionURL()
113: */
114: public String getConnectionURL() {
115: return this .url;
116: }
117:
118: /**
119: * Sets URL used to reference and establish a connection to the data source referenced in this
120: * object.
121: *
122: * @param newUrl URL pointing to the data source
123: */
124: public void setConnectionURL(final String newUrl) {
125: this .url = newUrl;
126: }
127:
128: /**
129: * Gets user-defined description, if any, for this DBConnectionDefinition.
130: *
131: * @return user-defined description, possibly null if none was defined
132: */
133: public String getDescription() {
134: return this .description;
135: }
136:
137: /**
138: * @see com.stc.model.database.DatabaseModel#getDriverClass
139: */
140: public String getDriverClass() {
141: return this .driverClass;
142: }
143:
144: /**
145: * Sets fully-qualified class name of driver used to establish a connection to the data source
146: * referenced in this object
147: *
148: * @param newClass new fully-qualified driver class name
149: */
150: public void setDriverClass(final String newClass) {
151: this .driverClass = newClass;
152: }
153:
154: /**
155: * @see com.stc.model.database.DatabaseModel#getName
156: */
157: public String getName() {
158: return this .name;
159: }
160:
161: /**
162: * Sets new name for this DBConnectionDefinition.
163: *
164: * @param newName new name for DBConnectionDefinition
165: */
166: public void setName(final String newName) {
167: this .name = newName;
168: }
169:
170: /**
171: * @see com.stc.model.database.DatabaseModel#getUserName
172: */
173: public String getUserName() {
174: return this .userName;
175: }
176:
177: /**
178: * Sets username used in authenticating a connection to the data source referenced in this
179: * object.
180: *
181: * @param newName new username, if any, to use for authentication purposes; may be null
182: */
183: public void setUserName(final String newName) {
184: this .userName = newName;
185: }
186:
187: /**
188: * @see com.stc.model.database.DatabaseModel#getPassword
189: */
190: public String getPassword() {
191: return this .password;
192: }
193:
194: /**
195: * Sets password used in authenticating a connection to the data source referenced in this
196: * object.
197: *
198: * @param newPw new password, if any, used for authentication purposes
199: */
200: public void setPassword(final String newPw) {
201: this .password = newPw;
202: }
203:
204: /**
205: * @see com.stc.model.database.DBConnectionDefinition#getDBType
206: */
207: public String getDBType() {
208: return this .dbType;
209: }
210:
211: /**
212: * Sets descriptive name of dbType of DB data source from which this metadata content was
213: * derived, e.g., "Oracle9" for an Oracle 9i database, etc. Returns null if content was derived
214: * from a non-DB source, such such as a flatfile.
215: *
216: * @param newType vendor name of source database; null if derived from non-DB source
217: */
218: public void setType(final String newType) {
219: this .dbType = newType;
220: }
221:
222: /**
223: * Copies member values to those contained in the given DBConnectionDefinition instance. Does
224: * shallow copy of properties and flatfiles collections.
225: *
226: * @param source DBConnectionDefinition whose contents are to be copied into this instance
227: */
228: public synchronized void copyFrom(
229: final DBConnectionDefinition source) {
230: if (source == null) {
231: final ResourceBundle cMessages = NbBundle
232: .getBundle(DBConnectionDefinitionImpl.class);
233: throw new IllegalArgumentException(cMessages
234: .getString("ERROR_NULL_REF")
235: + "(ERROR_NULL_REF)");
236: } else if (source == this ) {
237: return;
238: }
239:
240: // classRef = source.getClassRef();
241: this.description = source.getDescription();
242: this.name = source.getName();
243: this.dbType = source.getDBType();
244: this.driverClass = source.getDriverClass();
245: this.url = source.getConnectionURL();
246: this.userName = source.getUserName();
247: this.password = source.getPassword();
248: }
249:
250: }
|