1. /*
  2. * Copyright 1999-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. package org.apache.commons.dbcp.datasources;
  17. import javax.naming.RefAddr;
  18. import javax.naming.Reference;
  19. /**
  20. * A JNDI ObjectFactory which creates <code>SharedPoolDataSource</code>s
  21. * @version $Revision: 1.4 $ $Date: 2004/02/28 12:18:17 $
  22. */
  23. public class SharedPoolDataSourceFactory
  24. extends InstanceKeyObjectFactory
  25. {
  26. private static final String SHARED_POOL_CLASSNAME =
  27. SharedPoolDataSource.class.getName();
  28. protected boolean isCorrectClass(String className) {
  29. return SHARED_POOL_CLASSNAME.equals(className);
  30. }
  31. protected InstanceKeyDataSource getNewInstance(Reference ref) {
  32. SharedPoolDataSource spds = new SharedPoolDataSource();
  33. RefAddr ra = ref.get("maxActive");
  34. if (ra != null && ra.getContent() != null) {
  35. spds.setMaxActive(
  36. Integer.parseInt(ra.getContent().toString()));
  37. }
  38. ra = ref.get("maxIdle");
  39. if (ra != null && ra.getContent() != null) {
  40. spds.setMaxIdle(
  41. Integer.parseInt(ra.getContent().toString()));
  42. }
  43. ra = ref.get("maxWait");
  44. if (ra != null && ra.getContent() != null) {
  45. spds.setMaxWait(
  46. Integer.parseInt(ra.getContent().toString()));
  47. }
  48. return spds;
  49. }
  50. }