org.springframework.webflow.execution.Event类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中org.springframework.webflow.execution.Event类的一些代码示例,展示了Event类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Event类的具体详情如下:
包路径:org.springframework.webflow.execution.Event
类名称:Event

Event介绍

[英]Signals the occurrence of something an active flow execution should respond to. Each event has a string id that provides a key for identifying what happened: e.g "coinInserted", or "pinDropped". Events may have attributes that provide arbitrary payload data, e.g. "coin.amount=25", or "pinDropSpeed=25ms".

As an example, a "submit" event might signal that a Submit button was pressed in a web browser. A "success" event might signal an action executed successfully. A "finish" event might signal a subflow ended normally.

Why is this not an interface? A specific design choice. An event is not a strategy that defines a generic type or role--it is essentially an immutable value object. It is expected that specializations of this base class be "Events" and not part of some other inheritance hierarchy.
[中]指示活动流执行应响应的事件的发生。每个事件都有一个字符串id,该id提供了一个用于识别发生了什么的键:例如“coinserted”或“pindrop”。事件可能具有提供任意有效负载数据的属性,例如“coin.amount=25”或“pinDropSpeed=25ms”。
例如,“提交”事件可能表示在web浏览器中按下了提交按钮。“成功”事件可能表示操作已成功执行。“完成”事件可能表示亚流正常结束。
为什么这不是一个接口?具体的设计选择。事件不是定义泛型类型或角色的策略——它本质上是一个不可变的值对象。这个基类的专门化应该是“事件”,而不是其他继承层次结构的一部分。

代码示例

代码示例来源:origin: org.springframework.webflow/spring-webflow

/**
 * Returns a event with the specified identifier.
 * @param source the source of the event
 * @param eventId the result event identifier
 * @return the event
 */
public Event event(Object source, String eventId) {
  return new Event(source, eventId, null);
}

代码示例来源:origin: org.springframework.webflow/spring-webflow

/**
 * Get the event id to be used as grounds for a transition in the containing state, based on given result returned
 * from action execution.
 * <p>
 * If the wrapped action is named, the name will be used as a qualifier for the event (e.g. "myAction.success").
 * @param resultEvent the action result event
 */
protected Event postProcessResult(Event resultEvent) {
  if (resultEvent == null) {
    return null;
  }
  if (isNamed()) {
    // qualify result event id with action name for a named action
    String qualifiedId = getName() + "." + resultEvent.getId();
    if (logger.isDebugEnabled()) {
      logger.debug("Qualifying action result '" + resultEvent.getId() + "'; qualified result = '"
          + qualifiedId + "'");
    }
    resultEvent = new Event(resultEvent.getSource(), qualifiedId, resultEvent.getAttributes());
  }
  return resultEvent;
}

代码示例来源:origin: org.springframework.webflow/spring-webflow

public Event doExecute(RequestContext context) throws Exception {
  Action[] actions = getActions();
  String eventId = getEventFactorySupport().getSuccessEventId();
  MutableAttributeMap<Object> eventAttributes = new LocalAttributeMap<>();
  List<Event> actionResults = new ArrayList<>(actions.length);
  for (Action action : actions) {
    Event result = action.execute(context);
    actionResults.add(result);
    if (result != null) {
      eventId = result.getId();
      if (isStopOnError() && result.getId().equals(getEventFactorySupport().getErrorEventId())) {
        break;
      }
    }
  }
  eventAttributes.put(ACTION_RESULTS_ATTRIBUTE_NAME, actionResults);
  return new Event(this, eventId, eventAttributes);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testCustomResultObject() {
  Event event = action.result("custom", "result", "value");
  assertEquals("custom", event.getId());
  assertEquals("value", event.getAttributes().getString("result"));
}

代码示例来源:origin: org.springframework.webflow/spring-webflow

public String toString() {
    return getId();
  }
}

代码示例来源:origin: org.apereo.cas/cas-server-core-webflow-api

@Override
public Event resolveSingle(final RequestContext context) {
  val events = resolve(context);
  if (events == null || events.isEmpty()) {
    return null;
  }
  val event = events.iterator().next();
  LOGGER.debug("Resolved single event [{}] via [{}] for this context", event.getId(), event.getSource().getClass().getName());
  return event;
}

代码示例来源:origin: spring-projects/spring-webflow

public void testSuccessWithResult() {
  Object result = new Object();
  Event e = support.success(source, result);
  assertEquals("success", e.getId());
  assertSame(source, e.getSource());
  assertSame(result, e.getAttributes().get("result"));
}

代码示例来源:origin: spring-projects/spring-webflow

public void testNewEvent() {
  Event event = new Event(this, "id");
  assertEquals("id", event.getId());
  assertTrue(event.getTimestamp() > 0);
  assertTrue(event.getAttributes().isEmpty());
}

代码示例来源:origin: spring-projects/spring-webflow

public void testDoExecute() throws Exception {
  MockRequestContext mockRequestContext = new MockRequestContext();
  LocalAttributeMap<Object> attributes = new LocalAttributeMap<>();
  attributes.put("some key", "some value");
  EasyMock.expect(actionMock.execute(mockRequestContext)).andReturn(new Event(this, "some event", attributes));
  EasyMock.replay(actionMock);
  Event result = tested.doExecute(mockRequestContext);
  EasyMock.verify(actionMock);
  assertEquals("some event", result.getId());
  assertEquals(1, result.getAttributes().size());
}

代码示例来源:origin: spring-projects/spring-webflow

public void testNewEventNullAttributes() {
  Event event = new Event(this, "id", null);
  assertTrue(event.getAttributes().isEmpty());
}

代码示例来源:origin: org.springframework.webflow/spring-webflow

/**
 * Called on completion of the subflow to handle the subflow result event as determined by the end state reached by
 * the subflow.
 */
public boolean handleEvent(RequestControlContext context) {
  if (subflowAttributeMapper != null) {
    AttributeMap<Object> subflowOutput = context.getCurrentEvent().getAttributes();
    if (logger.isDebugEnabled()) {
      logger.debug("Mapping subflow output " + subflowOutput);
    }
    subflowAttributeMapper.mapSubflowOutput(subflowOutput, context);
  }
  return super.handleEvent(context);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testDefaultAdaptionRules() {
    Event result = factory.createResultEvent(this, "result", context);
    assertEquals("success", result.getId());
    assertEquals("result", result.getAttributes().getString("result"));
  }
}

代码示例来源:origin: org.springframework.webflow/spring-webflow

public boolean test(RequestContext context) {
  Object result = expression.getValue(context);
  if (result == null) {
    return false;
  } else if (result instanceof Boolean) {
    return (Boolean) result;
  } else {
    String eventId = String.valueOf(result);
    return context.getCurrentEvent().getId().equals(eventId);
  }
}

代码示例来源:origin: spring-projects/spring-webflow

public void testSuccess() {
  Event e = support.success(source);
  assertEquals("success", e.getId());
  assertSame(source, e.getSource());
}

代码示例来源:origin: spring-projects/spring-webflow

public void testErrorWithException() {
  Exception ex = new Exception();
  Event e = support.error(source, ex);
  assertEquals("error", e.getId());
  assertSame(source, e.getSource());
  assertSame(ex, e.getAttributes().get("exception"));
}

代码示例来源:origin: spring-projects/spring-webflow

public void testDoExecuteWithError() throws Exception {
  tested.setStopOnError(true);
  MockRequestContext mockRequestContext = new MockRequestContext();
  EasyMock.expect(actionMock.execute(mockRequestContext)).andReturn(new Event(this, "error"));
  EasyMock.replay(actionMock);
  Event result = tested.doExecute(mockRequestContext);
  EasyMock.verify(actionMock);
  assertEquals("error", result.getId());
}

代码示例来源:origin: spring-projects/spring-webflow

public void testNewEventWithAttributes() {
  LocalAttributeMap<Object> attrs = new LocalAttributeMap<>();
  attrs.put("name", "value");
  Event event = new Event(this, "id", attrs);
  assertTrue(!event.getAttributes().isEmpty());
  assertEquals(1, event.getAttributes().size());
}

代码示例来源:origin: org.apereo.cas/cas-server-core-web-api

/**
 * Gets passwordless authentication account.
 *
 * @param <T>   the type parameter
 * @param event the event
 * @param clazz the clazz
 * @return the passwordless authentication account
 */
public static <T> T getPasswordlessAuthenticationAccount(final Event event, final Class<T> clazz) {
  return event.getAttributes().get("passwordlessAccount", clazz);
}

代码示例来源:origin: org.springframework.webflow/spring-webflow

/**
 * Returns a event with the specified identifier and the specified set of attributes.
 * @param source the source of the event
 * @param eventId the result event identifier
 * @param attributes the event payload attributes
 * @return the event
 */
public Event event(Object source, String eventId, AttributeMap<Object> attributes) {
  return new Event(source, eventId, attributes);
}

代码示例来源:origin: spring-projects/spring-webflow

public void testLabeledEnum() {
  Event event = factory.createResultEvent(this, MyLabeledEnum.A, new MockRequestContext());
  assertEquals("A", event.getId());
  assertSame(MyLabeledEnum.A, event.getAttributes().get("result"));
}

相关文章