KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > pm > generator > jdbc > ConnectionDetails


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
24
25 /**
26  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
27  */

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 JavaDoc driver, url, user, password, datasource;
37   private Boolean JavaDoc usingDatasource;
38   /** Sets the JDBC driver.
39    */

40   public void setDriver(String JavaDoc pDriver) { driver = pDriver; }
41   /** Returns the JDBC driver.
42    */

43   public String JavaDoc getDriver() {
44     return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.driver", driver);
45   }
46   /** Sets the JDBC URL.
47    */

48   public void setUrl(String JavaDoc pUrl) { url = pUrl; }
49   /** Returns the JDBC URL.
50    */

51   public String JavaDoc getUrl() {
52     return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.url", url);
53   }
54   /** Sets the JDBC user.
55    */

56   public void setUser(String JavaDoc pUser) { user = pUser; }
57   /** Returns the JDBC user.
58    */

59   public String JavaDoc getUser() {
60     return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.user", user);
61   }
62   /** Sets the JDBC password.
63    */

64   public void setPassword(String JavaDoc pPassword) { password = pPassword; }
65   /** Returns the JDBC password.
66    */

67   public String JavaDoc getPassword() {
68     return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.password", password);
69   }
70   /** Sets the JDBC datasource.
71    * @see #setUsingDatasource(Boolean)
72    */

73   public void setDatasource(String JavaDoc pDatasource) { datasource = pDatasource; }
74   /** Returns the JDBC datasource.
75    * @see #isUsingDatasource()
76    */

77   public String JavaDoc getDatasource() {
78     return this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.datasource", datasource);
79   }
80   /** Sets, whether a JDBC datasource is being used. By default
81    * the JDBC driver and URL are used.
82    */

83   public void setUsingDatasource(Boolean JavaDoc pUsingDatasource) {
84     usingDatasource = pUsingDatasource;
85   }
86   /** Returns, whether a JDBC datasource is being used. By default
87    * the JDBC driver and URL are used.
88    */

89   public Boolean JavaDoc isUsingDatasource() {
90     String JavaDoc s = this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.usingDatasource");
91     return s == null ? usingDatasource : Boolean.valueOf(s);
92   }
93   /** Sets the database mode. Must be either of
94    * {@link org.apache.ws.jaxme.pm.generator.jdbc.JaxMeJdbcSG.Mode#GENERIC}
95    * (default), or
96    * {@link org.apache.ws.jaxme.pm.generator.jdbc.JaxMeJdbcSG.Mode#ORACLE}.
97    */

98   public void setDbMode(String JavaDoc pMode) {
99     mode = Mode.valueOf(pMode);
100   }
101   /** Returns the database mode. Either of
102    * {@link org.apache.ws.jaxme.pm.generator.jdbc.JaxMeJdbcSG.Mode#GENERIC}
103    * (default), or
104    * {@link org.apache.ws.jaxme.pm.generator.jdbc.JaxMeJdbcSG.Mode#ORACLE}.
105    */

106   public Mode getDbMode() {
107     String JavaDoc s = this.jdbcSG.getSGFactory().getGenerator().getProperty("jdbc.dbMode");
108     return s == null ? mode : Mode.valueOf(s);
109   }
110   /** Copies the given details into the current.
111    */

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