1 22 package org.enhydra.jdbc.core; 23 24 import org.enhydra.jdbc.util.Logger; 25 import org.enhydra.jdbc.util.JdbcUtil; 26 27 import java.io.Serializable ; 28 import java.io.PrintWriter ; 29 import java.util.Hashtable ; 30 import javax.naming.Context ; 31 import javax.naming.Name ; 32 import javax.naming.NamingException ; 33 import javax.naming.Reference ; 34 import javax.naming.Referenceable ; 35 import javax.naming.StringRefAddr ; 36 import javax.naming.spi.ObjectFactory ; 37 38 45 public class CoreDataSource 46 extends JdbcUtil 47 implements Referenceable , ObjectFactory , Serializable { 48 49 private int loginTimeout; transient public PrintWriter logWriter; public String user; public String password; private String description; private boolean debug; private boolean verbose; private JdbcThreadFactory threadFactory; 59 62 public CoreDataSource() { 63 loginTimeout = 60; logWriter = null; 65 user = null; 66 password = null; 67 description = null; 68 debug = false; 69 verbose = false; 70 threadFactory = null; 71 } 72 73 76 public String getDescription() { 77 return description; 78 } 79 public String getPassword() { 80 return password; 81 } 82 public String getUser() { 83 return user; 84 } 85 public JdbcThreadFactory getThreadFactory() { 86 return threadFactory; 87 } 88 public boolean isDebug() { 89 return debug; 90 } 91 public boolean isVerbose() { 92 return verbose; 93 } 94 95 public void setDescription(String description) { 96 this.description = description; 97 } 98 public void setPassword(String password) { 99 this.password = password; 100 } 101 public void setUser(String user) { 102 this.user = user; 103 } 104 public void setDebug(boolean debug) { 105 this.debug = debug; 106 } 107 public void setVerbose(boolean verbose) { 108 this.verbose = verbose; 109 } 110 public void setThreadFactory(JdbcThreadFactory f) { 111 this.threadFactory = f; 112 } 113 114 public PrintWriter getLogWriter() { 115 return log; 116 } 117 118 public void setLogWriter(PrintWriter out) { 119 log = (Logger) out; 120 } 121 122 126 public void shutdown(boolean force) { 127 } 128 129 public void setLoginTimeout(int seconds) { 130 loginTimeout = seconds; 131 } 132 133 public int getLoginTimeout() { 134 return loginTimeout; 135 } 136 137 140 public Reference getReference() throws NamingException { 141 145 Reference ref = 146 new Reference (getClass().getName(), getClass().getName(), null); 147 ref.add(new StringRefAddr ("user", getUser())); 148 ref.add(new StringRefAddr ("password", getPassword())); 149 ref.add(new StringRefAddr ("description", getDescription())); 150 ref.add( 151 new StringRefAddr ( 152 "loginTimeout", 153 Integer.toString(getLoginTimeout()))); 154 log.debug("CoreDataSource:getReference object returned"); 155 return ref; 156 } 157 158 161 public Object getObjectInstance( 162 Object refObj, 163 Name name, 164 Context nameCtx, 165 Hashtable env) 166 throws Exception { 167 Reference ref = (Reference ) refObj; 168 169 this.setUser((String ) ref.get("user").getContent()); 170 this.setPassword((String ) ref.get("password").getContent()); 171 this.setDescription((String ) ref.get("description").getContent()); 172 this.setLoginTimeout( 173 Integer.parseInt((String ) ref.get("loginTimeout").getContent())); 174 log.debug("CoreDataSource:getObjectInstance instance created"); 175 return this; 176 } 177 178 public String toString() { 179 StringBuffer sb = new StringBuffer (); 180 sb.append("CoreDataSource :\n"); 181 sb.append(" debug =<"+this.debug+">\n"); 182 sb.append(" description =<"+this.description+">\n"); 183 sb.append(" login time out =<"+this.loginTimeout+">\n"); 184 sb.append(" user =<"+this.user+">\n"); 185 sb.append(" verbose =<"+this.verbose+">\n"); 186 187 return sb.toString(); 188 } 189 } 190
| Popular Tags
|