KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > PooledComponent


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solution. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8
9 /*
10  * Created on Jun 8, 2005
11  *
12  * Author Ben Yu
13  * ZBS
14  */

15 package jfun.yan;
16
17 import jfun.yan.factory.Factory;
18 import jfun.yan.factory.Pool;
19
20 /**
21  * Zephyr Business Solution
22  *
23  * @author Ben Yu
24  *
25  */

26 final class PooledComponent extends DelegatingComponent {
27   private final Pool pool;
28   Object JavaDoc super_create(final Dependency a) {
29     return super.create(a);
30   }
31   public Object JavaDoc create(final Dependency a) {
32     return pool.getInstance(new Factory(){
33       public Object JavaDoc create(){
34         return super_create(a);
35       }
36     });
37   }
38   private static final String JavaDoc not_pooled = new String JavaDoc("pool indicator");
39   public Class JavaDoc verify(Dependency dep) {
40     final Object JavaDoc v = pool.getPooledInstance(not_pooled);
41     if(v==not_pooled){
42       return super.verify(dep);
43     }
44     else{
45       return (v==null)?void.class:v.getClass();
46     }
47   }
48
49   PooledComponent(final Component cc, Pool p) {
50     super(cc);
51     this.pool = p;
52   }
53 }
54
Popular Tags