KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > groovy > ExoGroovyComponentAdapter


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.container.groovy;
6
7 import org.exoplatform.container.ExoContainer;
8 import org.picocontainer.PicoContainer;
9 import org.picocontainer.PicoInitializationException;
10 import org.picocontainer.defaults.AbstractComponentAdapter;
11 /**
12  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
13  * @since Nov 9, 2004
14  * @version $Id$
15  */

16 public class ExoGroovyComponentAdapter extends AbstractComponentAdapter {
17   private GroovyObject gobject_ ;
18   
19   public ExoGroovyComponentAdapter(GroovyObject gobject) {
20     super(gobject.getType(), gobject.getType()) ;
21     gobject_ = gobject ;
22   }
23   
24   public Object JavaDoc getComponentInstance(PicoContainer container) {
25     Object JavaDoc obj = gobject_.getObject() ;
26     if(obj == null) {
27       try {
28         synchronized(container) {
29           ExoContainer exoContainer = (ExoContainer) container ;
30           obj = exoContainer.createComponent(gobject_.getType());
31           gobject_.setObject(obj) ;
32         }
33       } catch (Exception JavaDoc ex) {
34         throw new PicoInitializationException("Cannot instantiate script: " + gobject_.getGroovyResource(), ex) ;
35       }
36     }
37     return obj ;
38   }
39   
40   public void verify(PicoContainer container) {
41     
42   }
43 }
44
Popular Tags