1 16 17 package org.apache.ws.jaxme.pm.generator.jdbc; 18 19 import org.apache.ws.jaxme.pm.generator.jdbc.JaxMeJdbcSG.Mode; 20 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException; 21 import org.apache.ws.jaxme.xs.xml.XsObject; 22 import org.apache.ws.jaxme.xs.xml.impl.XsObjectImpl; 23 import org.xml.sax.SAXException ; 24 25 28 public class ConnectionDetails extends XsObjectImpl { 29 private final JaxMeJdbcSG jdbcSG; 30 protected ConnectionDetails(JaxMeJdbcSG pJdbcSG, XsObject pParent) { 31 super(pParent); 32 this.jdbcSG = pJdbcSG; 33 } 34 35 private Mode mode; 36 private String driver, url, user, password, datasource; 37 private Boolean usingDatasource; 38 40 public void setDriver(String pDriver) { driver = pDriver; } 41 43 public String getDriver() { 44 return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.driver", driver); 45 } 46 48 public void setUrl(String pUrl) { url = pUrl; } 49 51 public String getUrl() { 52 return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.url", url); 53 } 54 56 public void setUser(String pUser) { user = pUser; } 57 59 public String getUser() { 60 return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.user", user); 61 } 62 64 public void setPassword(String pPassword) { password = pPassword; } 65 67 public String getPassword() { 68 return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.password", password); 69 } 70 73 public void setDatasource(String pDatasource) { datasource = pDatasource; } 74 77 public String getDatasource() { 78 return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.datasource", datasource); 79 } 80 83 public void setUsingDatasource(Boolean pUsingDatasource) { 84 usingDatasource = pUsingDatasource; 85 } 86 89 public Boolean isUsingDatasource() { 90 String s = this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.usingDatasource"); 91 return s == null ? usingDatasource : Boolean.valueOf(s); 92 } 93 98 public void setDbMode(String pMode) { 99 mode = Mode.valueOf(pMode); 100 } 101 106 public Mode getDbMode() { 107 String s = this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.dbMode"); 108 return s == null ? mode : Mode.valueOf(s); 109 } 110 112 public void cloneFrom(ConnectionDetails pFrom) { 113 mode = pFrom.mode; 114 driver = pFrom.driver; 115 url = pFrom.url; 116 user = pFrom.user; 117 password = pFrom.password; 118 datasource = pFrom.datasource; 119 usingDatasource = pFrom.usingDatasource; 120 } 121 122 public void validate() throws SAXException { 123 boolean driverIsSet = driver != null && driver.length() > 0; 124 boolean datasourceIsSet = datasource != null && datasource.length() > 0; 125 if (driverIsSet) { 126 if (!datasourceIsSet) { 127 throw new LocSAXException("Either of the 'driver' or 'datasource' attributes must be set.", getLocator()); 128 } 129 if (url == null && url.length() == 0) { 130 throw new LocSAXException("Missing attribute: 'url'", getLocator()); 131 } 132 } else { 133 } 134 if (driverIsSet && datasourceIsSet) { 135 throw new LocSAXException("The 'driver' and 'datasource' attributes are mutually exclusive.", getLocator()); 136 } 137 } 138 } | Popular Tags |