final ClassFile file = new ClassFile(NAME, SerializationHackProxy.class.getName()); final ClassMethod method = file.addMethod(Modifier.PUBLIC, "read", "Ljava/lang/Object;", "Ljava/io/ObjectInputStream;"); final CodeAttribute codeAttribute = method.getCodeAttribute(); codeAttribute.aload(1); codeAttribute.returnInstruction(); ClassMethod ctor = file.addMethod(Modifier.PUBLIC, "<init>", "V"); ctor.getCodeAttribute().aload(0); ctor.getCodeAttribute().invokespecial(SerializationHackProxy.class.getName(), "<init>", "()V");
protected void createStateMachine(final String[] originalItems, final String className, final ClassFile file, final ClassMethod sctor, final AtomicInteger fieldCounter, final String methodName, final CustomStateMachine stateMachine, boolean expectNewline) { //list of all states except the initial final List<State> allStates = new ArrayList<State>(); final State initial = new State((byte) 0, ""); for (String value : originalItems) { addStates(initial, value, allStates); } //we want initial to be number 0 final AtomicInteger stateCounter = new AtomicInteger(-1); setupStateNo(initial, stateCounter, fieldCounter); for (State state : allStates) { setupStateNo(state, stateCounter, fieldCounter); createStateField(state, file, sctor.getCodeAttribute()); } final int noStates = stateCounter.get(); final ClassMethod handle = file.addMethod(Modifier.PROTECTED | Modifier.FINAL, methodName, "V", DescriptorUtils.makeDescriptor(ByteBuffer.class), parseStateDescriptor, httpExchangeDescriptor); handle.addCheckedExceptions(BAD_REQUEST_EXCEPTION); writeStateMachine(className, file, handle.getCodeAttribute(), initial, allStates, noStates, stateMachine, expectNewline); }
public byte[] createTokenizer(final String[] httpVerbs, String[] httpVersions, String[] standardHeaders) { final String className = existingClassName + CLASS_NAME_SUFFIX; final ClassFile file = new ClassFile(className, existingClassName); final ClassMethod ctor = file.addMethod(AccessFlag.PUBLIC, "<init>", "V", DescriptorUtils.parameterDescriptors(constructorDescriptor)); ctor.getCodeAttribute().aload(0); ctor.getCodeAttribute().loadMethodParameters(); ctor.getCodeAttribute().invokespecial(existingClassName, "<init>", constructorDescriptor); ctor.getCodeAttribute().returnInstruction(); final ClassMethod sctor = file.addMethod(AccessFlag.PUBLIC | AccessFlag.STATIC, "<clinit>", "V"); final AtomicInteger fieldCounter = new AtomicInteger(1); sctor.getCodeAttribute().invokestatic(existingClassName, "httpStrings", "()" + DescriptorUtils.makeDescriptor(Map.class)); sctor.getCodeAttribute().astore(CONSTRUCTOR_HTTP_STRING_MAP_VAR); createStateMachines(httpVerbs, httpVersions, standardHeaders, className, file, sctor, fieldCounter); sctor.getCodeAttribute().returnInstruction(); return file.toBytecode(); }
final ClassMethod ctor = asm.addMethod(Modifier.PUBLIC, "<init>", "V"); ctor.getCodeAttribute().aload(0); ctor.getCodeAttribute().invokespecial(superclass.getName(), "<init>", "()V"); final CodeAttribute idMethod = asm.addMethod(Modifier.PUBLIC + Modifier.FINAL, "_ids", "[Ljava/lang/String;").getCodeAttribute(); idMethod.getstatic(stubClassName, ID_FIELD_NAME, "[Ljava/lang/String;"); idMethod.returnInstruction(); final CodeAttribute clinit = asm.addMethod(Modifier.STATIC, "<clinit>", "V").getCodeAttribute(); clinit.iconst(ids.length); clinit.anewarray(String.class.getName());
/** * Construct a new instance. * * @param className the class name * @param superClass the superclass * @param classLoader the defining class loader * @param protectionDomain the protection domain */ protected AbstractProxyFactory(String className, Class<T> superClass, ClassLoader classLoader, ProtectionDomain protectionDomain, final ReflectionMetadataSource reflectionMetadataSource) { super(className, superClass, classLoader, protectionDomain, reflectionMetadataSource); staticConstructor = classFile.addMethod(AccessFlag.of(AccessFlag.PUBLIC, AccessFlag.STATIC), "<clinit>", "V"); }
private void generateWeldClientProxyMethod(ClassFile proxyClassType) { try { Method getContextualMetadata = WeldClientProxy.class.getMethod("getMetadata"); generateBodyForWeldClientProxyMethod(proxyClassType.addMethod(getContextualMetadata)); } catch (Exception e) { throw new WeldException(e); } }
private void generateWeldClientProxyMethod(ClassFile proxyClassType) { try { Method getContextualMetadata = WeldClientProxy.class.getMethod("getMetadata"); generateBodyForWeldClientProxyMethod(proxyClassType.addMethod(getContextualMetadata)); } catch (Exception e) { throw new WeldException(e); } }
private void generateWeldClientProxyMethod(ClassFile proxyClassType) { try { Method getContextualMetadata = WeldClientProxy.class.getMethod("getMetadata"); generateBodyForWeldClientProxyMethod(proxyClassType.addMethod(getContextualMetadata)); } catch (Exception e) { throw new WeldException(e); } }
private void generateWeldClientProxyMethod(ClassFile proxyClassType) { try { Method getContextualMetadata = WeldClientProxy.class.getMethod("getMetadata"); generateBodyForWeldClientProxyMethod(proxyClassType.addMethod(getContextualMetadata)); } catch (Exception e) { throw new WeldException(e); } }
private void generateWeldClientProxyMethod(ClassFile proxyClassType) { try { Method getContextualMetadata = WeldClientProxy.class.getMethod("getMetadata"); generateBodyForWeldClientProxyMethod(proxyClassType.addMethod(getContextualMetadata)); } catch (Exception e) { throw new WeldException(e); } }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
@SuppressWarnings("unchecked") private void createDelegateMethod(ClassFile proxyClassType, Method method, MethodInformation methodInformation) { int modifiers = (method.getModifiers() | AccessFlag.SYNTHETIC | AccessFlag.PRIVATE) & ~AccessFlag.PUBLIC & ~AccessFlag.PROTECTED; ClassMethod delegatingMethod = proxyClassType.addMethod(modifiers, method.getName() + SUPER_DELEGATE_SUFFIX, DescriptorUtils.makeDescriptor(method.getReturnType()), DescriptorUtils.parameterDescriptors(method.getParameterTypes())); delegatingMethod.addCheckedExceptions((Class<? extends Exception>[]) method.getExceptionTypes()); createDelegateToSuper(delegatingMethod, methodInformation); }
private void createWriteReplace() { MethodIdentifier identifier = MethodIdentifier.getIdentifier(Object.class, "writeReplace"); ClassMethod method = classFile.addMethod(AccessFlag.PROTECTED, "writeReplace", "Ljava/lang/Object;"); method.addCheckedExceptions(ObjectStreamException.class); overrideMethod(method, identifier, new WriteReplaceBodyCreator()); }
/** * Client proxies are equal to other client proxies for the same bean. * <p/> * The corresponding java code: <code> * return other instanceof MyProxyClassType.class * </code> */ @Override protected void generateEqualsMethod(ClassFile proxyClassType) { ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, "equals", BytecodeUtils.BOOLEAN_CLASS_DESCRIPTOR, LJAVA_LANG_OBJECT); CodeAttribute b = method.getCodeAttribute(); b.aload(1); b.instanceofInstruction(proxyClassType.getName()); b.returnInstruction(); }
/** * Client proxies are equal to other client proxies for the same bean. * <p/> * The corresponding java code: <code> * return other instanceof MyProxyClassType.class * </code> */ @Override protected void generateEqualsMethod(ClassFile proxyClassType) { ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, "equals", BytecodeUtils.BOOLEAN_CLASS_DESCRIPTOR, LJAVA_LANG_OBJECT); CodeAttribute b = method.getCodeAttribute(); b.aload(1); b.instanceofInstruction(proxyClassType.getName()); b.returnInstruction(); }