001    package ca.discotek.feenix.classloader;
002    
003    import java.nio.ByteBuffer;
004    import java.security.ProtectionDomain;
005    
006    import ca.discotek.feenix.ClassManager;
007    import ca.discotek.feenix.Configuration;
008    import ca.discotek.rebundled.org.objectweb.asm.ClassReader;
009    import ca.discotek.rebundled.org.objectweb.asm.tree.ClassNode;
010    
011    public class ClassLoaderTargeted {
012    
013        protected final Class _feenix_defineClass(byte[] b,
014                int off,
015                int len) {
016            return null;
017        }
018        
019        protected final Class _feenix_defineClass(String name, byte[] b,
020                int off,
021                int len) {
022            return null;
023        }
024        
025        protected final Class _feenix_defineClass(String name, byte[] b,
026                int off,
027                int len, ProtectionDomain pd) {
028            return null;
029        }
030    
031        protected final Class _feenix_defineClass(String name, ByteBuffer buffer, ProtectionDomain pd) {
032            return null;
033        }
034        
035        public Class defineMyClass(String name, byte bytes[]) throws ClassFormatError {
036            return _feenix_defineClass(name, bytes, 0, bytes.length);
037        }
038        
039        protected final Class defineClass(byte[] b,
040                int off,
041                int len) throws ClassFormatError {
042    
043            ClassReader cr = new ClassReader(b);
044            ClassNode node = new ClassNode();
045            cr.accept(node, ClassReader.SKIP_CODE);
046            
047            byte feenixBytes[] = ClassManager.getConfiguration().isExcluded(node.name) ? null : ClassManager.getClassBytes(node.name.replace('.', '/'));
048            return feenixBytes == null ? _feenix_defineClass(b, off, len) : _feenix_defineClass(feenixBytes, 0, feenixBytes.length);
049        }
050        
051        protected final Class defineClass(String name,
052                byte[] b,
053                int off,
054                int len) throws ClassFormatError {
055    
056            byte feenixBytes[] = ClassManager.getConfiguration().isExcluded(name) ? null : ClassManager.getClassBytes(name.replace('.', '/'));
057            return feenixBytes == null ? _feenix_defineClass(name, b, off, len) : _feenix_defineClass(name, feenixBytes, 0, feenixBytes.length);
058        }
059        
060        protected final Class defineClass(String name,
061                byte[] b,
062                int off,
063                int len,
064                ProtectionDomain protectionDomain) throws ClassFormatError {
065    
066            byte feenixBytes[] = ClassManager.getConfiguration().isExcluded(name) ? null : ClassManager.getClassBytes(name.replace('.', '/'));
067            return feenixBytes == null ? _feenix_defineClass(name, b, off, len, protectionDomain) : _feenix_defineClass(name, feenixBytes, 0, feenixBytes.length, protectionDomain);
068        }
069        
070        protected final Class defineClass(String name,
071                ByteBuffer b,
072                ProtectionDomain protectionDomain) throws ClassFormatError {
073            
074            byte feenixBytes[] = ClassManager.getConfiguration().isExcluded(name) ? null : ClassManager.getClassBytes(name.replace('.', '/'));
075            return feenixBytes == null ? _feenix_defineClass(name, b, protectionDomain) : _feenix_defineClass(name, feenixBytes, 0, feenixBytes.length, protectionDomain);
076        }
077    
078        public Class<?> _feenix_loadClass(String name)
079                throws ClassNotFoundException {
080            return null;
081        }
082        
083        protected Class<?> _feenix_loadClass(String name,
084                boolean resolve)
085         throws ClassNotFoundException {
086            return null;
087        }
088        
089        protected final Class<?> findLoadedClass(String paramString) {
090            return null;
091        }
092        
093        protected final void resolveClass(Class<?> paramClass) {}
094        
095        public Class<?> loadClass(String name)
096                throws ClassNotFoundException {
097            return loadClass(name, false);
098        }
099        
100        protected Class<?> loadClass(String name,
101                boolean resolve)
102         throws ClassNotFoundException {
103            Class c = findLoadedClass(name);
104            if (c != null) {
105                if (resolve) resolveClass(c);
106                return c;
107            }
108            
109            Configuration configuration = ClassManager.getConfiguration();
110            byte feenixBytes[] = configuration == null ? null : (configuration.isExcluded(name) ? null : ClassManager.getClassBytes(name.replace('.', '/')));
111            return feenixBytes == null ? _feenix_loadClass(name, resolve) : defineClass(name, feenixBytes, 0, feenixBytes.length);
112        }
113         
114    }