/** * Load the bytecode from the given class file. * If this project already contains the class in the given file, it will * be returned. Otherwise a new {@link BCClass} will be created from the * given bytecode. * * @throws RuntimeException on parse error */ public BCClass loadClass(File classFile) { return loadClass(classFile, null); }
/** * Renames the given class within this project. Used internally by * {@link BCClass} instances when their name is modified. * * @throws IllegalStateException if a class with the new name already exists */ void renameClass(String oldName, String newName, BCClass bc) { if (oldName.equals(newName)) return; BCClass cached = (BCClass) checkCache(newName); if (cached != null) throw new IllegalStateException("A class with name " + newName + " already exists in this project"); removeFromCache(oldName, bc); cache(newName, bc); }
/** * Remove a class from this project. After removal, the result of any * further operations on the class is undefined. * * @return true if the class belonged to this project, false otherwise */ public boolean removeClass(String type) { return removeClass(checkCache(type)); }
/** * Constructor. Supply configuration and type to enhance. This will look * up the metadata for <code>type</code> from <code>conf</code>'s * repository. */ public PCEnhancer(OpenJPAConfiguration conf, Class type) { this(conf, (BCClass) AccessController.doPrivileged(J2DoPrivHelper .loadProjectClassAction(new Project(), type)), (MetaDataRepository) null); }
BCClass cached = checkCache(name); if (cached != null) return cached; loader = Thread.currentThread().getContextClassLoader(); try { return loadClass(Strings.toClass(name, loader)); } catch (Exception e) { ret.setSuperclass(Object.class); cache(name, ret); return ret;
protected Class findClass(String name) throws ClassNotFoundException { byte[] bytes; try { BCClass type; if (!_project.containsClass(name)) type = createClass(name); else type = _project.loadClass(name); if (type == null) throw new ClassNotFoundException(name); bytes = type.toByteArray(); } catch (RuntimeException re) { throw new ClassNotFoundException(re.toString()); } return defineClass(name, bytes, 0, bytes.length); }
/** * Create a stub factory instance for the given class. */ protected DynamicStorage createFactory(BCClass bc) { try { Class cls = Class.forName(bc.getName(), false, _loader); Constructor cons = cls.getConstructor((Class[]) null); DynamicStorage data = (DynamicStorage) cons.newInstance ((Object[]) null); _project.clear(); // remove old refs return data; } catch (Throwable t) { throw new InternalException("cons-access", t).setFatal(true); } }
/** * Load the bytecode from the given stream. * If this project already contains the class in the given stream, * it will be returned. Otherwise a new {@link BCClass} will be created * from the given bytecode. * * @throws RuntimeException on parse error */ public BCClass loadClass(InputStream in, ClassLoader loader) { BCClass ret = new BCClass(this); ret.setState(new ObjectState(_names)); try { ret.read(in, loader); } catch (IOException ioe) { throw new RuntimeException(ioe.toString()); } String name = ret.getName(); BCClass cached = checkCache(name); if (cached != null) return cached; cache(name, ret); return ret; }
/** * Return true if the project already contains the given class. */ public boolean containsClass(Class type) { return (type == null) ? false : containsClass(type.getName()); }
/** * Remove a cached class. */ private boolean removeFromCache(String name, BCClass bc) { BCClass rem = (BCClass) checkCache(name); if (rem != bc) return false; _cache.remove(name); return true; } }
/** * Constructor. Supply configuration and type to enhance. This will look * up the metadata for <code>type</code> from <code>conf</code>'s * repository. */ public PCEnhancer(OpenJPAConfiguration conf, Class type) { this(conf, AccessController.doPrivileged(J2DoPrivHelper .loadProjectClassAction(new Project(), type)), (MetaDataRepository) null); }
BCClass cached = checkCache(name); if (cached != null) return cached; loader = Thread.currentThread().getContextClassLoader(); try { return loadClass(Strings.toClass(name, loader)); } catch (Exception e) { ret.setSuperclass(Object.class); cache(name, ret); return ret;
protected Class findClass(String name) throws ClassNotFoundException { byte[] bytes; try { BCClass type; if (!_project.containsClass(name)) type = createClass(name); else type = _project.loadClass(name); if (type == null) throw new ClassNotFoundException(name); bytes = type.toByteArray(); } catch (RuntimeException re) { throw new ClassNotFoundException(re.toString()); } return defineClass(name, bytes, 0, bytes.length); }
/** * Create a stub factory instance for the given class. */ protected DynamicStorage createFactory(BCClass bc) { try { Class cls = Class.forName(bc.getName(), false, _loader); Constructor cons = cls.getConstructor((Class[]) null); DynamicStorage data = (DynamicStorage) cons.newInstance ((Object[]) null); _project.clear(); // remove old refs return data; } catch (Throwable t) { throw new InternalException("cons-access", t).setFatal(true); } }
/** * Load the bytecode from the given class file. * If this project already contains the class in the given file, it will * be returned. Otherwise a new {@link BCClass} will be created from the * given bytecode. * * @throws RuntimeException on parse error */ public BCClass loadClass(File classFile, ClassLoader loader) { // parse the bytecode from the file BCClass ret = new BCClass(this); ret.setState(new ObjectState(_names)); try { ret.read(classFile, loader); } catch (IOException ioe) { throw new RuntimeException(ioe.toString()); } String name = ret.getName(); BCClass cached = checkCache(name); if (cached != null) return cached; cache(name, ret); return ret; }