1 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 23 public class SimpleComponentAdapter implements ComponentAdapter { 24 25 private Object instance_ ; 26 private Object key_ ; 27 private Class implementation_ ; 28 29 public SimpleComponentAdapter(Object key, Class implementation) { 30 key_ = key ; 31 implementation_ = implementation ; 32 } 33 34 public Object 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 ex) { 42 throw new RuntimeException ("Cannot instantiate component " + getComponentImplementation(), ex) ; 43 } 44 return instance_ ; 45 } 46 47 public void verify(PicoContainer container) { } 48 49 50 public Object getComponentKey() { return key_ ; } 51 52 public Class getComponentImplementation() { return implementation_; } 53 54 public void accept(PicoVisitor visitor) { 55 visitor.visitComponentAdapter(this); 56 } 57 } | Popular Tags |