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.pool;
  17. /**
  18. * A simple base impementation of {@link ObjectPool}.
  19. * All optional operations are implemented as throwing
  20. * {@link UnsupportedOperationException}.
  21. *
  22. * @author Rodney Waldhoff
  23. * @version $Revision: 1.13 $ $Date: 2004/02/28 11:46:33 $
  24. */
  25. public abstract class BaseObjectPool implements ObjectPool {
  26. public abstract Object borrowObject() throws Exception;
  27. public abstract void returnObject(Object obj) throws Exception;
  28. public abstract void invalidateObject(Object obj) throws Exception;
  29. /**
  30. * Not supported in this base implementation.
  31. */
  32. public int getNumIdle() throws UnsupportedOperationException {
  33. throw new UnsupportedOperationException();
  34. }
  35. /**
  36. * Not supported in this base implementation.
  37. */
  38. public int getNumActive() throws UnsupportedOperationException {
  39. throw new UnsupportedOperationException();
  40. }
  41. /**
  42. * Not supported in this base implementation.
  43. */
  44. public void clear() throws Exception, UnsupportedOperationException {
  45. throw new UnsupportedOperationException();
  46. }
  47. /**
  48. * Not supported in this base implementation.
  49. */
  50. public void addObject() throws Exception, UnsupportedOperationException {
  51. throw new UnsupportedOperationException();
  52. }
  53. public void close() throws Exception {
  54. assertOpen();
  55. closed = true;
  56. }
  57. /**
  58. * Not supported in this base implementation.
  59. */
  60. public void setFactory(PoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
  61. throw new UnsupportedOperationException();
  62. }
  63. protected final boolean isClosed() {
  64. return closed;
  65. }
  66. protected final void assertOpen() throws IllegalStateException {
  67. if(isClosed()) {
  68. throw new IllegalStateException("Pool not open");
  69. }
  70. }
  71. private boolean closed = false;
  72. }