KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > gen > AmberLoader


1 /*
2  * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.amber.gen;
31
32 import java.util.logging.Logger;
33
34 import java.security.CodeSource;
35
36 import com.caucho.java.WorkDir;
37
38 import com.caucho.log.Log;
39
40 import com.caucho.loader.Loader;
41 import com.caucho.vfs.Path;
42
43 import com.caucho.amber.AmberManager;
44
45 /**
46  * Class loader which checks for changes in class files and automatically
47  * picks up new jars.
48  */

49 public class AmberLoader extends Loader {
50   private static final Logger log = Log.open(AmberLoader.class);
51
52   private AmberManager _manager;
53   
54   // The class directory
55
private Path _path;
56   private String _prefix;
57   private String _pathPrefix;
58
59   private CodeSource _codeSource;
60
61   /**
62    * Null constructor for the simple loader.
63    */

64   public AmberLoader(AmberManager manager)
65   {
66     _manager = manager;
67   }
68
69   /**
70    * Given a class or resource name, returns a patch to that resource.
71    *
72    * @param name the class or resource name.
73    *
74    * @return the path representing the class or resource.
75    */

76   public Path getPath(String name)
77   {
78     if (! name.endsWith(".class"))
79       return null;
80
81     int p = name.lastIndexOf('$');
82     if (p < 0)
83       p = name.lastIndexOf('-');
84     if (p < 0)
85       p = name.lastIndexOf('.');
86     
87     String className = name.substring(0, p);
88     className = className.replace('/', '.');
89
90     if (_manager.getEntityByInstanceClass(className) == null)
91       return null;
92
93     Path workPath = WorkDir.getLocalWorkDir();
94
95     return workPath.lookup(name);
96   }
97
98   /**
99    * Returns the code source for the directory.
100    */

101   /*
102   protected CodeSource getCodeSource(Path path)
103   {
104     return _codeSource;
105   }
106   */

107
108   /**
109    * Returns a printable representation of the loader.
110    */

111   public String toString()
112   {
113     return "AmberLoader[]";
114   }
115 }
116
Popular Tags