KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > SimpleComponentAdapter


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. 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  * Original code by James Strachan and Mauro Talevi *
9  *****************************************************************************/

10 package org.exoplatform.container;
11
12 import org.exoplatform.container.ExoContainer;
13 import org.picocontainer.PicoContainer;
14 import org.picocontainer.ComponentAdapter;
15 import org.picocontainer.PicoVisitor;
16 /**
17  * @author James Strachan
18  * @author Mauro Talevi
19  * @author Jeppe Cramon
20  * @author Benjamin Mestrallet
21  * @version $Revision: 1.5 $
22  */

23 public class SimpleComponentAdapter implements ComponentAdapter {
24     
25   private Object JavaDoc instance_ ;
26   private Object JavaDoc key_ ;
27   private Class JavaDoc implementation_ ;
28     
29     public SimpleComponentAdapter(Object JavaDoc key, Class JavaDoc implementation) {
30     key_ = key ;
31     implementation_ = implementation ;
32     }
33     
34     public Object JavaDoc getComponentInstance(PicoContainer container) {
35     if(instance_ != null ) return instance_ ;
36     ExoContainer exocontainer = (ExoContainer) container ;
37     try {
38       synchronized(container) {
39         instance_ = exocontainer.createComponent(getComponentImplementation()) ;
40       }
41     } catch (Exception JavaDoc ex) {
42       throw new RuntimeException JavaDoc("Cannot instantiate component " + getComponentImplementation(), ex) ;
43     }
44         return instance_ ;
45     }
46   
47    public void verify(PicoContainer container) { }
48
49
50   public Object JavaDoc getComponentKey() { return key_ ; }
51   
52   public Class JavaDoc getComponentImplementation() { return implementation_; }
53
54   public void accept(PicoVisitor visitor) {
55     visitor.visitComponentAdapter(this);
56   }
57 }
Popular Tags