/** * Write the class bytecode to the .class file in the proper directory of * the CLASSPATH. The file must exist already, so this method only works * on existing classes. */ public void write() throws IOException { String name = getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class type = getType(); // attempt to get the class file for the class as a stream; // we need to use the url decoder in case the target directory // has spaces in it OutputStream out = new FileOutputStream(URLDecoder.decode (type.getResource(name + ".class").getFile())); try { write(out); } finally { out.close(); } }
/** * Write the class bytecode to the .class file in the proper directory of * the CLASSPATH. The file must exist already, so this method only works * on existing classes. */ public void write() throws IOException { String name = getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class type = getType(); // attempt to get the class file for the class as a stream; // we need to use the url decoder in case the target directory // has spaces in it OutputStream out = new FileOutputStream(URLDecoder.decode (type.getResource(name + ".class").getFile())); try { write(out); } finally { out.close(); } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
private static void write(BCClass bc, PCEnhancer enhancer, Map<Class, byte[]> map, Class cls, List subs, List ints) throws IOException { if (bc == enhancer.getManagedTypeBytecode()) { // if it was already defined, don't put it in the map, // but do set the metadata accordingly. if (enhancer.isAlreadyRedefined()) ints.add(bc.getType()); else if (JavaVersions.VERSION >= 5) map.put(bc.getType(), bc.toByteArray()); } else { if (!enhancer.isAlreadySubclassed()) { // this is the new subclass ClassLoader loader = GeneratedClasses.getMostDerivedLoader( cls, PersistenceCapable.class); subs.add(GeneratedClasses.loadBCClass(bc, loader)); } } }
private static void write(BCClass bc, PCEnhancer enhancer, Map<Class, byte[]> map, Class cls, List subs, List ints) throws IOException { if (bc == enhancer.getManagedTypeBytecode()) { // if it was already defined, don't put it in the map, // but do set the metadata accordingly. if (enhancer.isAlreadyRedefined()) ints.add(bc.getType()); else if (JavaVersions.VERSION >= 5) map.put(bc.getType(), bc.toByteArray()); } else { if (!enhancer.isAlreadySubclassed()) { // this is the new subclass ClassLoader loader = GeneratedClasses.getMostDerivedLoader( cls, PersistenceCapable.class); subs.add(GeneratedClasses.loadBCClass(bc, loader)); } } }
private static void write(BCClass bc, PCEnhancer enhancer, Map<Class<?>, byte[]> map, Class<?> cls, List<Class<?>> subs, List<Class<?>> ints) throws IOException { if (bc == enhancer.getManagedTypeBytecode()) { // if it was already defined, don't put it in the map, // but do set the metadata accordingly. if (enhancer.isAlreadyRedefined()) ints.add(bc.getType()); else { map.put(bc.getType(), bc.toByteArray()); debugBytecodes(bc); } } else { if (!enhancer.isAlreadySubclassed()) { debugBytecodes(bc); // this is the new subclass ClassLoader loader = GeneratedClasses.getMostDerivedLoader( cls, PersistenceCapable.class); subs.add(GeneratedClasses.loadBCClass(bc, loader)); } } }
private static void write(BCClass bc, PCEnhancer enhancer, Map<Class<?>, byte[]> map, Class<?> cls, List<Class<?>> subs, List<Class<?>> ints) throws IOException { if (bc == enhancer.getManagedTypeBytecode()) { // if it was already defined, don't put it in the map, // but do set the metadata accordingly. if (enhancer.isAlreadyRedefined()) ints.add(bc.getType()); else { map.put(bc.getType(), bc.toByteArray()); debugBytecodes(bc); } } else { if (!enhancer.isAlreadySubclassed()) { debugBytecodes(bc); // this is the new subclass ClassLoader loader = GeneratedClasses.getMostDerivedLoader( cls, PersistenceCapable.class); subs.add(GeneratedClasses.loadBCClass(bc, loader)); } } }
private static void write(BCClass bc, PCEnhancer enhancer, Map<Class<?>, byte[]> map, Class<?> cls, List<Class<?>> subs, List<Class<?>> ints) throws IOException { if (bc == enhancer.getManagedTypeBytecode()) { // if it was already defined, don't put it in the map, // but do set the metadata accordingly. if (enhancer.isAlreadyRedefined()) ints.add(bc.getType()); else { map.put(bc.getType(), bc.toByteArray()); debugBytecodes(bc); } } else { if (!enhancer.isAlreadySubclassed()) { debugBytecodes(bc); // this is the new subclass ClassLoader loader = GeneratedClasses.getMostDerivedLoader( cls, PersistenceCapable.class); subs.add(GeneratedClasses.loadBCClass(bc, loader)); } } }
private static void write(BCClass bc, PCEnhancer enhancer, Map<Class, byte[]> map, Class cls, List subs, List ints) throws IOException { if (bc == enhancer.getManagedTypeBytecode()) { // if it was already defined, don't put it in the map, // but do set the metadata accordingly. if (enhancer.isAlreadyRedefined()) ints.add(bc.getType()); else if (JavaVersions.VERSION >= 5) { map.put(bc.getType(), bc.toByteArray()); debugBytecodes(bc); } } else { if (!enhancer.isAlreadySubclassed()) { debugBytecodes(bc); // this is the new subclass ClassLoader loader = GeneratedClasses.getMostDerivedLoader( cls, PersistenceCapable.class); subs.add(GeneratedClasses.loadBCClass(bc, loader)); } } }
/** * Adds a non-static getter that delegates to the super methods, and * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { String methName = "get" + StringUtils.capitalize(fmd.getName()); if (_managedType.getMethods(methName, new Class[0]).length == 0) methName = "is" + StringUtils.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); getter.makePublic(); Code code = getter.getCode(true); // if we're not already tracking field access via reflection, then we // must make the getter hook in lazy loading before accessing the super // method. if (!getRedefine()) addNotifyAccess(code, fmd); code.aload().setThis(); code.invokespecial().setMethod(_managedType.getType(), methName, fmd.getDeclaredType(), null); code.xreturn().setType(fmd.getDeclaredType()); code.calculateMaxLocals(); code.calculateMaxStack(); }
private void configureBCs() { if (!_bcsConfigured) { if (getRedefine()) { if (_managedType.getAttribute(REDEFINED_ATTRIBUTE) == null) _managedType.addAttribute(REDEFINED_ATTRIBUTE); else _isAlreadyRedefined = true; } if (getCreateSubclass()) { PCSubclassValidator val = new PCSubclassValidator( _meta, _managedType, _log, _fail); val.assertCanSubclass(); _pc = _managedType.getProject().loadClass( toPCSubclassName(_managedType.getType())); if (_pc.getSuperclassBC() != _managedType) { _pc.setSuperclass(_managedType); _pc.setAbstract(_managedType.isAbstract()); _pc.declareInterface(DynamicPersistenceCapable.class); } else { _isAlreadySubclassed = true; } } _bcsConfigured = true; } }
private void configureBCs() { if (!_bcsConfigured) { if (getRedefine()) { if (_managedType.getAttribute(REDEFINED_ATTRIBUTE) == null) _managedType.addAttribute(REDEFINED_ATTRIBUTE); else _isAlreadyRedefined = true; } if (getCreateSubclass()) { PCSubclassValidator val = new PCSubclassValidator( _meta, _managedType, _log, _fail); val.assertCanSubclass(); _pc = _managedType.getProject().loadClass( toPCSubclassName(_managedType.getType())); if (_pc.getSuperclassBC() != _managedType) { _pc.setSuperclass(_managedType); _pc.setAbstract(_managedType.isAbstract()); _pc.declareInterface(DynamicPersistenceCapable.class); } else { _isAlreadySubclassed = true; } } _bcsConfigured = true; } }
/** * Import the given bytecode from another project. If a {@link BCClass} * with the same name already exists in this project, it will be returned. * Otherwise, a new {@link BCClass} will be created from the * information in the given class. */ public BCClass loadClass(BCClass bc) { String name = bc.getName(); BCClass cached = checkCache(name); if (cached != null) return cached; BCClass ret = new BCClass(this); if (bc.isPrimitive()) ret.setState(new PrimitiveState(bc.getType(), _names)); else if (bc.isArray()) ret.setState(new ArrayState(bc.getName(), bc.getComponentName())); else { ret.setState(new ObjectState(_names)); ret.read(bc); } cache(name, ret); return ret; }
/** * Import the given bytecode from another project. If a {@link BCClass} * with the same name already exists in this project, it will be returned. * Otherwise, a new {@link BCClass} will be created from the * information in the given class. */ public BCClass loadClass(BCClass bc) { String name = bc.getName(); BCClass cached = checkCache(name); if (cached != null) return cached; BCClass ret = new BCClass(this); if (bc.isPrimitive()) ret.setState(new PrimitiveState(bc.getType(), _names)); else if (bc.isArray()) ret.setState(new ArrayState(bc.getName(), bc.getComponentName())); else { ret.setState(new ObjectState(_names)); ret.read(bc); } cache(name, ret); return ret; }
/** * Adds a non-static getter that delegates to the super methods, and * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { String methName = "get" + StringUtil.capitalize(fmd.getName()); if (_managedType.getMethods(methName, new Class[0]).length == 0) methName = "is" + StringUtil.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); getter.makePublic(); Code code = getter.getCode(true); // if we're not already tracking field access via reflection, then we // must make the getter hook in lazy loading before accessing the super // method. if (!getRedefine()) addNotifyAccess(code, fmd); code.aload().setThis(); code.invokespecial().setMethod(_managedType.getType(), methName, fmd.getDeclaredType(), null); code.xreturn().setType(fmd.getDeclaredType()); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Adds a non-static getter that delegates to the super methods, and * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { String methName = "get" + StringUtil.capitalize(fmd.getName()); if (_managedType.getMethods(methName, new Class[0]).length == 0) methName = "is" + StringUtil.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); getter.makePublic(); Code code = getter.getCode(true); // if we're not already tracking field access via reflection, then we // must make the getter hook in lazy loading before accessing the super // method. if (!getRedefine()) addNotifyAccess(code, fmd); code.aload().setThis(); code.invokespecial().setMethod(_managedType.getType(), methName, fmd.getDeclaredType(), null); code.xreturn().setType(fmd.getDeclaredType()); code.calculateMaxLocals(); code.calculateMaxStack(); }