1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.components.datasource;
1819import javax.naming.NamingException;
2021import org.apache.jetspeed.components.jndi.JNDIComponent;
222324/***25 * Bound DBCP Data Source26 *27 * @author <a href="mailto:sweaver@apache.org">Scott Weaver</a>28 * @version $Id: BoundDBCPDatasourceComponent.java 516448 2007-03-09 16:25:47Z ate $29 */30publicclassBoundDBCPDatasourceComponentextendsDBCPDatasourceComponent31 {
32privateJNDIComponent jndi;
33private String bindName;
343536/* (non-Javadoc)37 * @see java.lang.Object#finalize()38 */39protectedvoid finalize() throws Throwable
40 {
41 stop();
42super.finalize();
43 }
44/***45 * 46 * @param user47 * @param password48 * @param driverName49 * @param connectURI50 * @param maxActive51 * @param maxWait52 * @param whenExhausted53 * @param autoCommit54 * @param bindName JNDI name to bind this <code>javax.sql.DataSource</code>55 * created by this class to.56 * @param jndi JNDIComponent we will use to bind.57 */58publicBoundDBCPDatasourceComponent(String user, String password, String driverName, String connectURI,
59int maxActive, int maxWait, byte whenExhausted, boolean autoCommit, String bindName, JNDIComponent jndi)
60 {
61super(user, password, driverName, connectURI, maxActive, maxWait, whenExhausted, autoCommit);
62if(jndi == null)
63 {
64thrownew IllegalArgumentException("jndi argument cannot be null for BoundDBCPDatasourceComponent");
65 }
6667if(bindName == null)
68 {
69thrownew IllegalArgumentException("bindName argument cannot be null for BoundDBCPDatasourceComponent");
70 }
7172this.jndi = jndi;
73this.bindName = bindName;
7475 }
76/***77 * Same as {@link DBCPDatasourceComponent#start()}78 * but also binds these <code>javax.sql.DataSource</code>79 * created to the <code>bindName</code>.80 * 81 * @see org.picocontainer.Startable#start()82 */83publicvoid start()
84 {
85super.start();
86try87 {
88 jndi.bindObject("comp/env/jdbc/"+bindName, getDatasource());
89 jndi.bindObject("jdbc/"+bindName, getDatasource());
90 }
91catch (NamingException e)
92 {
93 IllegalStateException ise = new IllegalStateException("Naming exception "+e.toString());
94 ise.initCause(e);
95throw ise;
96 }
97 }
9899/* (non-Javadoc)100 * @see org.picocontainer.Startable#stop()101 */102publicvoid stop()
103 {
104try105 {
106 jndi.unbindObject("comp/env/jdbc/"+bindName);
107 jndi.unbindObject("jdbc/" + bindName);
108 }
109catch (NamingException e)
110 {
111thrownew IllegalStateException("Naming exception "+e.toString());
112 }
113super.stop();
114 }
115 }