KickJava   Java API By Example, From Geeks To Geeks.

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


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 groovy.lang.GroovyClassLoader;
8 import java.net.URL JavaDoc;
9
10 /**
11  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
12  * @since Nov 8, 2004
13  * @version $Id$
14  */

15 public class GroovyObject {
16   private String JavaDoc resource_ ;
17   private Object JavaDoc object_ ;
18   private Class JavaDoc type_ ;
19   private boolean reloadable_ = false ;
20   private long loadTime_ = 1;
21   
22   public GroovyObject(String JavaDoc resource) {
23     resource_ = resource ;
24     loadTime_ = System.currentTimeMillis() ;
25   }
26   
27   public String JavaDoc getGroovyResource() { return resource_ ; }
28   
29   public Object JavaDoc getObject() { return object_ ;}
30   public void setObject(Object JavaDoc object) {
31     loadTime_ = System.currentTimeMillis() ;
32     object_ = object ;
33     if(object != null) {
34       type_ = object.getClass() ;
35     } else {
36       type_ = null ;
37     }
38   }
39   
40   public boolean isReloadable() { return reloadable_ ; }
41   public long getLoadTime() { return loadTime_ ; }
42   
43   public Class JavaDoc getType() { return type_ ; }
44   
45   synchronized public void setType(GroovyClassLoader gcl) throws Exception JavaDoc {
46     URL JavaDoc url = gcl.getResource(resource_) ;
47     if(url.toString().startsWith("file:")) reloadable_ = true ;
48     else reloadable_ = false ;
49     type_ = gcl.parseClass(url.openStream()) ;
50     object_ = null ;
51   }
52 }
Popular Tags