如何在另一个中介类中调用类中介属性值 [英] How to call Class mediator property value inside another mediator Class

查看:15
本文介绍了如何在另一个中介类中调用类中介属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在另一个中介类中调用一些类中介属性值

I need to call some Class mediator property value inside another mediator Class

这是我的 SurepayMediator 课程

This is my SurepayMediator class

package esb.cellcard.billing;    
public class SurepayMediator extends AbstractMediator{
    public boolean mediate(MessageContext context) { 
      context.setProperty("firstValue", "Run Fast");

      if(something){
          //Here I need to execute AddSubscription class 
      }
      else {
         //Here I need to execute CancleSubscription class 
      }
      return true;
   }
}

我需要在 AddSubscription 类和 CancelSubscription 类中调用这个 firstValue

I need to call this firstValue inside the AddSubscription class and CancelSubscription class

添加订阅

package esb.cellcard.billing;

public class AddSubscription extends AbstractMediator{

SurepayMediator sm = new SurepayMediator();

public boolean mediate(MessageContext context) { 
    //I need to call that firstValue in here
    return true;
  }
}

取消订阅

package esb.cellcard.billing;

public class CancelSubscription extends AbstractMediator{

 SurepayMediator sm = new SurepayMediator();

 public boolean mediate(MessageContext context) { 
   //I need to call that firstValue in here
   return true;
 }
}

推荐答案

看来只有SurepayMediator"才应该是类中介(您需要从中介中调用的唯一中介).

It seems that only "SurepayMediator" should be a class mediator (the only one you need to call from your mediation).

更改类 AddSubscription 和 CancelSubscription,使它们不扩展 AbstractMediator.

Change classes AddSubscription and CancelSubscription so that they do not extends AbstractMediator.

最终,重命名mediate"方法并从 SurepayMediator 使用 MessageContext 参数调用它:您将获得firstValue"属性的值,调用 context.getProperty("firstValue");

Eventually, rename 'mediate' method and call it from SurepayMediator with the MessageContext parameter : you will get "firstValue" property's value calling context.getProperty("firstValue");

 if(something){
          addSubscription.add(context); 
      }

.

public class AddSubscription{
  public boolean add(MessageContext context) { 
    //I need to call that firstValue in here
    String value = context.getProperty("firstValue");
    ...
    return true;
  }
}

这篇关于如何在另一个中介类中调用类中介属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆