Source Code Cross Referenced for MapBackedClassLoader.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » rule » 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 » Rule Engine » drolls Rule Engine » org.drools.rule 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.rule;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.InputStream;
005:        import java.io.Serializable;
006:        import java.security.AccessController;
007:        import java.security.PrivilegedAction;
008:        import java.security.ProtectionDomain;
009:        import java.util.HashMap;
010:        import java.util.Map;
011:
012:        public class MapBackedClassLoader extends ClassLoader implements 
013:                DroolsClassLoader, Serializable {
014:
015:            private static final long serialVersionUID = 400L;
016:
017:            private static final ProtectionDomain PROTECTION_DOMAIN;
018:
019:            private Map store;
020:
021:            static {
022:                PROTECTION_DOMAIN = (ProtectionDomain) AccessController
023:                        .doPrivileged(new PrivilegedAction() {
024:                            public Object run() {
025:                                return MapBackedClassLoader.class
026:                                        .getProtectionDomain();
027:                            }
028:                        });
029:            }
030:
031:            public MapBackedClassLoader(final ClassLoader parentClassLoader) {
032:                super (parentClassLoader);
033:                this .store = new HashMap();
034:            }
035:
036:            public void addResource(String className, byte[] bytes) {
037:                addClass(className, bytes);
038:            }
039:
040:            private String convertResourcePathToClassName(final String pName) {
041:                return pName.replaceAll(".java$|.class$", "").replace('/', '.');
042:            }
043:
044:            public void addClass(final String className, byte[] bytes) {
045:
046:                this .store
047:                        .put(convertResourcePathToClassName(className), bytes);
048:            }
049:
050:            public Class fastFindClass(final String name) {
051:                final Class clazz = findLoadedClass(name);
052:
053:                if (clazz == null) {
054:                    final byte[] clazzBytes = (byte[]) this .store.get(name);
055:                    if (clazzBytes != null) {
056:                        return defineClass(name, clazzBytes, 0,
057:                                clazzBytes.length, PROTECTION_DOMAIN);
058:                    }
059:                }
060:                return clazz;
061:            }
062:
063:            /**
064:             * Javadocs recommend that this method not be overloaded. We overload this so that we can prioritise the fastFindClass 
065:             * over method calls to parent.loadClass(name, false); and c = findBootstrapClass0(name); which the default implementation
066:             * would first - hence why we call it "fastFindClass" instead of standard findClass, this indicates that we give it a 
067:             * higher priority than normal.
068:             * 
069:             */
070:            protected synchronized Class loadClass(final String name,
071:                    final boolean resolve) throws ClassNotFoundException {
072:                Class clazz = fastFindClass(name);
073:
074:                if (clazz == null) {
075:                    final ClassLoader parent = getParent();
076:                    if (parent != null) {
077:                        clazz = parent.loadClass(name);
078:                    } else {
079:                        throw new ClassNotFoundException(name);
080:                    }
081:                }
082:
083:                if (resolve) {
084:                    resolveClass(clazz);
085:                }
086:
087:                return clazz;
088:            }
089:
090:            protected Class findClass(final String name)
091:                    throws ClassNotFoundException {
092:                final Class clazz = fastFindClass(name);
093:                if (clazz == null) {
094:                    throw new ClassNotFoundException(name);
095:                }
096:                return clazz;
097:            }
098:
099:            public InputStream getResourceAsStream(final String name) {
100:                final byte[] bytes = (byte[]) this .store.get(name);
101:                if (bytes != null) {
102:                    return new ByteArrayInputStream(bytes);
103:                } else {
104:                    InputStream input = this.getParent().getResourceAsStream(
105:                            name);
106:                    if (input == null) {
107:                        input = super.getResourceAsStream(name);
108:                    }
109:                    return input;
110:                }
111:            }
112:
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.