001: package net.sourceforge.squirrel_sql.fw.sql;
002:
003: /*
004: * Copyright (C) 2002-2003 Colin Bell.
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.io.Serializable;
022: import java.sql.DriverPropertyInfo;
023:
024: /**
025: * This represents a property that can be specified when connecting to the database.
026: *
027: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
028: */
029: public class SQLDriverProperty implements Cloneable, Serializable {
030: static final long serialVersionUID = -5150608132930417454L;
031:
032: /** Property names for this bean. */
033: public interface IPropertyNames {
034: /** Property Name. */
035: String NAME = "name";
036:
037: /** Property value. */
038: String VALUE = "value";
039:
040: /** Is specified. */
041: String IS_SPECIFIED = "isSpecified";
042: }
043:
044: /** Name. */
045: private String _name;
046:
047: /** Value associated with the name. */
048: private String _value;
049:
050: /** If <TT>true</TT> then this property is to be used. */
051: private boolean _isSpecified;
052:
053: private transient DriverPropertyInfo _driverPropInfo;
054:
055: /**
056: * Default ctor. Created with the name and value being <TT>null</TT>.
057: */
058: public SQLDriverProperty() {
059: super ();
060: }
061:
062: /**
063: * Create from a <TT>DriverPropertyInfo</TT> object.
064: */
065: public SQLDriverProperty(DriverPropertyInfo parm) {
066: super ();
067: if (parm == null) {
068: throw new IllegalArgumentException(
069: "DriverPropertyInfo == null");
070: }
071:
072: setName(parm.name);
073: setValue(parm.value);
074: setDriverPropertyInfo(parm);
075: }
076:
077: /**
078: * ctor specifying the name and value.
079: *
080: * @param name The name
081: * @param value The value associated with the name.
082: */
083: public SQLDriverProperty(String name, String value) {
084: super ();
085: _name = name;
086: _value = value;
087: }
088:
089: /**
090: * Return a clone of this object.
091: *
092: * @return The cloned object.
093: */
094: public Object clone() {
095: try {
096: return super .clone();
097: } catch (CloneNotSupportedException ex) {
098: throw new InternalError(ex.getMessage()); // Impossible.
099: }
100: }
101:
102: /**
103: * Retrieve the name.
104: *
105: * @return The name.
106: */
107: public String getName() {
108: return _name;
109: }
110:
111: /**
112: * Retrieve the value.
113: *
114: * @return The value.
115: */
116: public String getValue() {
117: return _value;
118: }
119:
120: public boolean isSpecified() {
121: return _isSpecified;
122: }
123:
124: public DriverPropertyInfo getDriverPropertyInfo() {
125: return _driverPropInfo;
126: }
127:
128: /**
129: * Set the name.
130: *
131: * @param name The name.
132: */
133: public synchronized void setName(String name) {
134: _name = name;
135: if (_driverPropInfo != null) {
136: _driverPropInfo.name = name;
137: }
138: }
139:
140: /**
141: * Set the value.
142: *
143: * @param value The value.
144: */
145: public synchronized void setValue(String value) {
146: _value = value;
147: if (_driverPropInfo != null) {
148: _driverPropInfo.value = value;
149: }
150: }
151:
152: public void setIsSpecified(boolean value) {
153: _isSpecified = value;
154: }
155:
156: public void setDriverPropertyInfo(DriverPropertyInfo parm) {
157: if (parm != null) {
158: if (!parm.name.equals(getName())) {
159: throw new IllegalArgumentException(
160: "DriverPropertyInfo.name != my name");
161: }
162: }
163: _driverPropInfo = parm;
164: _driverPropInfo.value = _value;
165: }
166: }
|