Source Code Cross Referenced for JacaretoClassLoader.java in  » Testing » jacareto » jacareto » toolkit » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jacareto » jacareto.toolkit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.toolkit;
025:
026:        import jacareto.system.Environment;
027:        import jacareto.system.Language;
028:        import jacareto.system.Module;
029:        import jacareto.system.Modules;
030:        import jacareto.toolkit.io.FileUtilities;
031:
032:        import org.apache.log4j.Logger;
033:
034:        import java.io.File;
035:        import java.io.IOException;
036:
037:        import java.net.URL;
038:        import java.net.URLClassLoader;
039:
040:        import java.util.Collection;
041:        import java.util.Iterator;
042:        import java.util.Vector;
043:
044:        /**
045:         * A class loader for loading classes during run-time.
046:         *
047:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
048:         * @version 1.01
049:         */
050:        public class JacaretoClassLoader extends URLClassLoader {
051:            /*protected Class findClass (String className) throws ClassNotFoundException {
052:               System.out.println (className);
053:               return super.findClass (className);
054:            }*/
055:
056:            /** The env. */
057:            private Environment env;
058:
059:            /** The logger. */
060:            private Logger logger;
061:
062:            /** The language instance. */
063:            private Language language;
064:
065:            /** The added paths. */
066:            private Vector addedPaths;
067:
068:            /** The listeners. */
069:            private Collection listeners;
070:
071:            /** The identifier. */
072:            private String identifier;
073:
074:            /**
075:             * Creates a new Jacareto class loader.
076:             *
077:             * @param env the environment
078:             * @param identifier a string naming the class loader
079:             */
080:            public JacaretoClassLoader(Environment env, String identifier) {
081:                super (new URL[0], ClassLoader.getSystemClassLoader());
082:                this .identifier = identifier;
083:                this .env = env;
084:                this .logger = env.getLogger();
085:                this .language = env.getLanguage();
086:                addedPaths = new Vector(5, 5);
087:                listeners = new Vector(5, 5);
088:
089:                if (StringToolkit.isDefined(identifier)) {
090:                    ClassLoader parent = getParent();
091:
092:                    if ((parent != null)
093:                            && (parent instanceof  JacaretoSystemClassLoader)) {
094:                        ((JacaretoSystemClassLoader) parent)
095:                                .registerChild(this );
096:                    }
097:                }
098:            }
099:
100:            /**
101:             * Creates a new class loader without identifier. The class loader will not be registered at
102:             * the Jacareto System Class Loader
103:             *
104:             * @param env the environment
105:             */
106:            public JacaretoClassLoader(Environment env) {
107:                this (env, null);
108:            }
109:
110:            /**
111:             * Adds all elements contained in a path entry, separated by a &quot;;&quot;
112:             *
113:             * @param paths the paths, separated  by a semicolon
114:             */
115:            public void addPaths(String paths) {
116:                String[] entries = FileUtilities.getEntries(paths);
117:                boolean pathsAdded = false;
118:
119:                if (entries != null) {
120:                    for (int i = 0; i < entries.length; i++) {
121:                        String path = entries[i];
122:
123:                        try {
124:                            File pathToAdd = new File(path).getCanonicalFile();
125:                            path = pathToAdd.getAbsolutePath();
126:
127:                            if (!pathToAdd.exists()) {
128:                                logger
129:                                        .error(language
130:                                                .getString("Toolkit.JacaretoClassLoader.Error.FileNotFound")
131:                                                + " " + path);
132:                            } else if (!addedPaths.contains(pathToAdd)) {
133:                                logger
134:                                        .debug(language
135:                                                .getString("Toolkit.JacaretoClassLoader.Msg.Adding")
136:                                                + " " + path);
137:
138:                                if (!addedPaths.contains(pathToAdd)) {
139:                                    addURL(pathToAdd.toURL());
140:                                    addedPaths.add(pathToAdd);
141:                                    pathsAdded = true;
142:                                }
143:                            }
144:                        } catch (IOException iex) {
145:                            logger
146:                                    .error(language
147:                                            .getString("Toolkit.JacaretoClassLoader.Error.Path")
148:                                            + " " + path);
149:                        }
150:                    }
151:                }
152:
153:                if (pathsAdded) {
154:                    fireJacaretoClassLoaderEvent(new JacaretoClassLoaderEvent(
155:                            this , JacaretoClassLoaderEvent.PATHS_ADDED, paths));
156:                }
157:            }
158:
159:            /**
160:             * Adds the jar files of the modules to the paths.
161:             *
162:             * @param modules the modules to add
163:             */
164:            public void addModules(Modules modules) {
165:                Iterator it = modules.iterator();
166:
167:                while (it.hasNext()) {
168:                    addPaths(((Module) it.next()).getAbsolutePath());
169:                }
170:            }
171:
172:            /**
173:             * Returns an iterator on the added paths.
174:             *
175:             * @return the instance which iterates all additional paths
176:             */
177:            public Iterator getAddedPathsIterator() {
178:                return addedPaths.iterator();
179:            }
180:
181:            /*
182:             * Returns the URL of a resource with the given name.
183:             *
184:             * @return the URL of the resource
185:             */
186:            /*public URL findResource(String name) {
187:               System.out.println ("Searching for resource: " + name);
188:               URL result = super.findResource (name);
189:               System.out.println ("Result: " + result);
190:               return result;
191:            } */
192:            /* Loads a class specified by its name.
193:             */
194:            /* public Class getClass (String classname) throws ClassNotFoundException {
195:               logger.debug (language.getString ("JacaretoClassLoader.Msg.Loading") + " " + classname);
196:               Class result = findClass (classname);
197:               //Class result = super.loadClass (classname);
198:            //      Class result = Class.forName (classname, false, this);
199:               return result;
200:            }  */
201:
202:            /**
203:             * Adds a listener for Jacareto class loader events.
204:             *
205:             * @param listener the listener to add
206:             */
207:            public void addJacaretoClassLoaderListener(
208:                    JacaretoClassLoaderListener listener) {
209:                if (!listeners.contains(listener)) {
210:                    listeners.add(listener);
211:                }
212:            }
213:
214:            /**
215:             * Removes a listener for events.
216:             *
217:             * @param listener the listener to be removed
218:             */
219:            public void removeJacaretoClassLoaderListener(
220:                    JacaretoClassLoaderListener listener) {
221:                if (listeners.contains(listener)) {
222:                    listeners.remove(listener);
223:                }
224:            }
225:
226:            /**
227:             * Fires a Jacareto class loader event.
228:             *
229:             * @param event the class loader event
230:             */
231:            protected void fireJacaretoClassLoaderEvent(
232:                    JacaretoClassLoaderEvent event) {
233:                Iterator it = listeners.iterator();
234:
235:                while (it.hasNext()) {
236:                    ((JacaretoClassLoaderListener) it.next())
237:                            .classLoaderChanged(event);
238:                }
239:            }
240:
241:            /**
242:             * Prints all package names to the logger with INFO level. This method can be used for
243:             * debugging.
244:             */
245:            public void printPackages() {
246:                Package[] packages = getPackages();
247:
248:                for (int i = 0; i < packages.length; i++) {
249:                    logger.info(packages[i].getName());
250:                }
251:            }
252:
253:            /**
254:             * Returns the identifier.
255:             *
256:             * @return the identifier
257:             */
258:            public String getIdentifier() {
259:                return identifier;
260:            }
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.