private void replaceWriteAccess(
      ClassTransformation transformation,
      String fieldName,
      String fieldType,
      String sessionKey,
      String requestField) {
    String writeMethodName = transformation.newMemberName("write", fieldName);

    TransformMethodSignature writeSignature =
        new TransformMethodSignature(
            Modifier.PRIVATE, "void", writeMethodName, new String[] {fieldType}, null);

    String body =
        String.format("%s.getSession(true).setAttribute(\"%s\", $1);", requestField, sessionKey);

    transformation.addMethod(writeSignature, body);
    transformation.replaceWriteAccess(fieldName, writeMethodName);
  }
  private void replaceReadAccess(
      ClassTransformation transformation,
      String fieldName,
      String fieldType,
      String sessionKey,
      String requestField) {
    String readMethodName = transformation.newMemberName("read", fieldName);

    TransformMethodSignature readMethodSignature =
        new TransformMethodSignature(Modifier.PRIVATE, fieldType, readMethodName, null, null);

    String body =
        String.format(
            "return (%s) %s.getSession(true).getAttribute(\"%s\");",
            fieldType, requestField, sessionKey);

    transformation.addMethod(readMethodSignature, body);
    transformation.replaceReadAccess(fieldName, readMethodName);
  }
 public void transform(ClassTransformation transformation, MutableComponentModel model) {
   for (TransformMethod tm :
       transformation.matchMethods(
           new Predicate<TransformMethod>() {
             @Override
             public boolean accept(TransformMethod arg0) {
               return arg0.getAnnotation(Transactional.class) != null;
             }
           })) {
     tm.addAdvice(advice);
   }
 }
  public void transform(ClassTransformation transformation, MutableComponentModel model) {
    List<String> names = transformation.findFieldsWithAnnotation(SessionAttribute.class);

    for (String fieldName : names) {
      SessionAttribute annotation =
          transformation.getFieldAnnotation(fieldName, SessionAttribute.class);

      String sessionKey = annotation.value();

      if ("".equals(sessionKey)) {
        sessionKey = fieldName;
      }

      String fieldType = transformation.getFieldType(fieldName);

      Request request = objectLocator.getService(Request.class);

      String requestField = transformation.addInjectedField(Request.class, "_request", request);

      replaceReadAccess(transformation, fieldName, fieldType, sessionKey, requestField);
      replaceWriteAccess(transformation, fieldName, fieldType, sessionKey, requestField);
    }
  }