001: // JdbcBean.java
002: // $Id: JdbcBeanAdapter.java,v 1.7 2000/09/06 11:48:17 bmahe Exp $
003: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005: package org.w3c.tools.jdbc;
006:
007: import java.io.Serializable;
008: import java.io.IOException;
009: import java.util.Properties;
010:
011: import java.beans.Beans;
012: import java.beans.PropertyChangeSupport;
013: import java.beans.PropertyChangeListener;
014:
015: /**
016: * @version $Revision: 1.7 $
017: * @author Benoît Mahé (bmahe@w3.org)
018: */
019: public class JdbcBeanAdapter implements JdbcBeanInterface, Serializable {
020:
021: protected int maxConn = -1;
022:
023: protected String jdbcDriver = null;
024: protected String jdbcUser = null;
025: protected String jdbcPassword = null;
026: protected String jdbcURI = null;
027: protected String jdbcTable = null;
028:
029: protected boolean readonly = false;
030:
031: protected PropertyChangeSupport pcs = null;
032:
033: protected JdbcBeanSerializer serializer = null;
034:
035: protected JdbcBeanInterface defaultbean = null;
036:
037: /**
038: * Add a PropertyChangeListener to the listener list. The listener
039: * is registered for all properties.
040: * @param listener The PropertyChangeListener to be added
041: */
042: public void addPropertyChangeListener(
043: PropertyChangeListener listener) {
044: pcs.addPropertyChangeListener(listener);
045: }
046:
047: /**
048: * Remove a PropertyChangeListener to the listener list.
049: * @param listener The PropertyChangeListener to be removed.
050: */
051: public void removePropertyChangeListener(
052: PropertyChangeListener listener) {
053: pcs.removePropertyChangeListener(listener);
054: }
055:
056: /**
057: * Set the JDBC driver
058: * @param jdbcDriver the jdbc driver
059: */
060: public void setJdbcDriver(String jdbcDriver) {
061: this .jdbcDriver = jdbcDriver;
062: }
063:
064: /**
065: * Get the JDBC driver
066: * @return the jdbc driver
067: */
068: public String getJdbcDriver() {
069: return jdbcDriver;
070: }
071:
072: /**
073: * Set the Jdbc username property
074: * @param jdbcUser the username
075: */
076: public void setJdbcUser(String jdbcUser) {
077: this .jdbcUser = jdbcUser;
078: }
079:
080: /**
081: * get the Jdbc username property
082: * @return the Jdbc username property
083: */
084: public String getJdbcUser() {
085: return jdbcUser;
086: }
087:
088: /**
089: * Set the password property
090: * @param jdbcPassword the password
091: */
092: public void setJdbcPassword(String jdbcPassword) {
093: this .jdbcPassword = jdbcPassword;
094: }
095:
096: /**
097: * Get the password property
098: * @return the Jdbc password
099: */
100: public String getJdbcPassword() {
101: return jdbcPassword;
102: }
103:
104: /**
105: * Set the Jdbc URI
106: * @param jdbcURI the URI (ie: <b>jdbc:protocol://host/db</b>)
107: */
108: public void setJdbcURI(String jdbcURI) {
109: this .jdbcURI = jdbcURI;
110: }
111:
112: /**
113: * Get the Jdbc URI
114: * @return the URI (ie: <b>jdbc:protocol://host/db</b>)
115: */
116: public String getJdbcURI() {
117: return jdbcURI;
118: }
119:
120: /**
121: * Set the max number os simultaneous Jdbc connections
122: * @param maxConn the max number of connections
123: */
124: public void setMaxConn(int maxConn) {
125: this .maxConn = maxConn;
126: }
127:
128: /**
129: * Get the max number os simultaneous Jdbc connections
130: * @return the max number of connections
131: */
132: public int getMaxConn() {
133: return maxConn;
134: }
135:
136: /**
137: * Set the name of the SQL table
138: * @param jdbcTable the SQL table name
139: */
140: public void setJdbcTable(String jdbcTable) {
141: this .jdbcTable = jdbcTable;
142: }
143:
144: /**
145: * Return the name of the SQL table
146: * @return the SQL table name
147: */
148: public String getJdbcTable() {
149: return jdbcTable;
150: }
151:
152: /**
153: * Set the read-only flag
154: * @param readonly
155: */
156: public void setReadOnly(boolean readonly) {
157: this .readonly = readonly;
158: }
159:
160: /**
161: * Is this table read-only? (default is false)
162: * @return a boolean
163: */
164: public boolean getReadOnly() {
165: return readonly;
166: }
167:
168: /**
169: * Get our SQL serializer
170: * @return a JdbcBeanSerializer instance
171: */
172: public JdbcBeanSerializer getSerializer() {
173: if (serializer == null) {
174: serializer = new JdbcBeanSerializer(this );
175: }
176: return serializer;
177: }
178:
179: public JdbcBeanInterface getDefault() {
180: if (defaultbean == null) {
181: Class c = getClass();
182: try {
183: defaultbean = (JdbcBeanInterface) Beans.instantiate(c
184: .getClassLoader(), c.getName());
185: } catch (IOException ex) {
186: } catch (ClassNotFoundException ex) {
187: }
188: }
189: return defaultbean;
190: }
191:
192: /**
193: * Constructor
194: */
195: public JdbcBeanAdapter() {
196: pcs = new JdbcPropertyChangeSupport(this );
197: serializer = new JdbcBeanSerializer(this);
198: }
199:
200: }
|