javax.mvc.event.MvcEvent Java Examples

The following examples show how to use javax.mvc.event.MvcEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KrazoCdiExtension.java    From krazo with Apache License 2.0 5 votes vote down vote up
/**
 * Gather set of event types that are observed by MVC application. This info is later
 * used to optimize event creation and firing.
 *
 * @param pom process observer method object.
 * @param beanManager the bean manager.
 * @param <T> the type of the event being observed.
 * @param <X> the bean type containing the observer method.
 */
public <T, X> void processObserverMethod(@Observes ProcessObserverMethod<T, X> pom, BeanManager beanManager) {
    final Type type = pom.getObserverMethod().getObservedType();
    if (type instanceof Class<?>) {
        final Class<?> clazz = (Class<?>) type;
        if (MvcEvent.class.isAssignableFrom(clazz)) {
            addObservedEvent((Class<? extends MvcEvent>) type);
        }
    }
}
 
Example #2
Source File: KrazoCdiExtension.java    From krazo with Apache License 2.0 5 votes vote down vote up
/**
 * Add MVC event type to set of observed events.
 *
 * @param eventType event type.
 */
public static synchronized void addObservedEvent(Class<? extends MvcEvent> eventType) {
    if (observedEvents == null) {
        observedEvents = new HashSet<>();
    }
    observedEvents.add(eventType);
}
 
Example #3
Source File: OzarkCdiExtension.java    From ozark with Apache License 2.0 5 votes vote down vote up
/**
 * Gather set of event types that are observed by MVC application. This info is later
 * used to optimize event creation and firing.
 *
 * @param pom process observer method object.
 * @param beanManager the bean manager.
 * @param <T> the type of the event being observed.
 * @param <X> the bean type containing the observer method.
 */
public <T, X> void processObserverMethod(@Observes ProcessObserverMethod<T, X> pom, BeanManager beanManager) {
    final Type type = pom.getObserverMethod().getObservedType();
    if (type instanceof Class<?>) {
        final Class<?> clazz = (Class<?>) type;
        if (MvcEvent.class.isAssignableFrom(clazz)) {
            addObservedEvent((Class<? extends MvcEvent>) type);
        }
    }
}
 
Example #4
Source File: OzarkCdiExtension.java    From ozark with Apache License 2.0 5 votes vote down vote up
/**
 * Add MVC event type to set of observed events.
 *
 * @param eventType event type.
 */
public static synchronized void addObservedEvent(Class<? extends MvcEvent> eventType) {
    if (observedEvents == null) {
        observedEvents = new HashSet<>();
    }
    observedEvents.add(eventType);
}
 
Example #5
Source File: ViewableWriterTest.java    From krazo with Apache License 2.0 4 votes vote down vote up
/**
 * Test writeTo method.
 *
 * @throws Exception when a serious error occurs.
 */
@Test
public void testWriteTo() throws Exception {
    ViewableWriter writer = new ViewableWriter();

    Field mvcField = writer.getClass().getDeclaredField("mvc");
    mvcField.setAccessible(true);
    mvcField.set(writer, new MvcContextImpl());

    ViewEngineFinder finder = EasyMock.createStrictMock(ViewEngineFinder.class);
    Field finderField = writer.getClass().getDeclaredField("engineFinder");
    finderField.setAccessible(true);
    finderField.set(writer, finder);

    HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
    Field requestField = writer.getClass().getDeclaredField("injectedRequest");
    requestField.setAccessible(true);
    requestField.set(writer, request);

    Event<MvcEvent> dispatcher = EasyMock.createStrictMock(Event.class);
    Field dispatcherField = writer.getClass().getDeclaredField("dispatcher");
    dispatcherField.setAccessible(true);
    dispatcherField.set(writer, dispatcher);

    EventDispatcher eventDispatcher = EasyMock.createMock(EventDispatcher.class);
    Field eventDispatcherField = writer.getClass().getDeclaredField("eventDispatcher");
    eventDispatcherField.setAccessible(true);
    eventDispatcherField.set(writer, eventDispatcher);

    ViewEngine viewEngine = EasyMock.createStrictMock(ViewEngine.class);

    HttpServletResponse response = EasyMock.createStrictMock(HttpServletResponse.class);
    response.setContentType(eq("text/html;charset=UTF-8"));
    expect(response.getCharacterEncoding()).andReturn("UTF-8");
    Field responseField = writer.getClass().getDeclaredField("injectedResponse");
    responseField.setAccessible(true);
    responseField.set(writer, response);

    Configuration config = EasyMock.createStrictMock(Configuration.class);
    Field configField = writer.getClass().getDeclaredField("config");
    configField.setAccessible(true);
    configField.set(writer, config);

    MultivaluedHashMap map = new MultivaluedHashMap();
    ArrayList<MediaType> contentTypes = new ArrayList<>();
    contentTypes.add(MediaType.TEXT_HTML_TYPE);
    map.put("Content-Type", contentTypes);

    Viewable viewable = new Viewable("myview");
    viewable.setModels(new ModelsImpl());

    expect(finder.find(anyObject())).andReturn(viewEngine);
    viewEngine.processView((ViewEngineContext) anyObject());

    replay(finder, request, viewEngine, response);
    writer.writeTo(viewable, null, null, new Annotation[] {}, MediaType.TEXT_HTML_TYPE, map, null);
    verify(finder, request, viewEngine, response);
}
 
Example #6
Source File: ViewableWriterTest.java    From ozark with Apache License 2.0 4 votes vote down vote up
/**
 * Test writeTo method.
 *
 * @throws Exception when a serious error occurs.
 */
@Test
public void testWriteTo() throws Exception {
    ViewableWriter writer = new ViewableWriter();

    Field mvcField = writer.getClass().getDeclaredField("mvc");
    mvcField.setAccessible(true);
    mvcField.set(writer, new MvcContextImpl());
    
    ViewEngineFinder finder = EasyMock.createStrictMock(ViewEngineFinder.class);
    Field finderField = writer.getClass().getDeclaredField("engineFinder");
    finderField.setAccessible(true);
    finderField.set(writer, finder);

    HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
    Field requestField = writer.getClass().getDeclaredField("injectedRequest");
    requestField.setAccessible(true);
    requestField.set(writer, request);

    Event<MvcEvent> dispatcher = EasyMock.createStrictMock(Event.class);
    Field dispatcherField = writer.getClass().getDeclaredField("dispatcher");
    dispatcherField.setAccessible(true);
    dispatcherField.set(writer, dispatcher);

    ViewEngine viewEngine = EasyMock.createStrictMock(ViewEngine.class);

    HttpServletResponse response = EasyMock.createStrictMock(HttpServletResponse.class);
    Field responseField = writer.getClass().getDeclaredField("injectedResponse");
    responseField.setAccessible(true);
    responseField.set(writer, response);

    Configuration config = EasyMock.createStrictMock(Configuration.class);
    Field configField = writer.getClass().getDeclaredField("config");
    configField.setAccessible(true);
    configField.set(writer, config);

    MultivaluedHashMap map = new MultivaluedHashMap();
    ArrayList<MediaType> contentTypes = new ArrayList<>();
    contentTypes.add(MediaType.TEXT_HTML_TYPE);
    map.put("Content-Type", contentTypes);

    Viewable viewable = new Viewable("myview");
    viewable.setModels(new ModelsImpl());

    expect(finder.find(anyObject())).andReturn(viewEngine);
    viewEngine.processView((ViewEngineContext) anyObject());

    replay(finder, request, viewEngine, response);
    writer.writeTo(viewable, null, null, new Annotation[] {}, MediaType.WILDCARD_TYPE, map, null);
    verify(finder, request, viewEngine, response);
}
 
Example #7
Source File: MvcEventListener.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
public void mvcEventListener(@Observes MvcEvent mvcEvent) {
	logger.trace("Observed MvcEvent=[{}]", mvcEvent);
}
 
Example #8
Source File: MvcEventListener.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
public void mvcEventListener(@Observes MvcEvent mvcEvent) {
	logger.trace("Observed MvcEvent=[{}]", mvcEvent);
}
 
Example #9
Source File: KrazoCdiExtension.java    From krazo with Apache License 2.0 2 votes vote down vote up
/**
 * Determine if an event type is being observed.
 *
 * @param eventType event type.
 * @return outcome of test.
 */
public static synchronized boolean isEventObserved(Class<? extends MvcEvent> eventType) {
    return observedEvents == null ? false : observedEvents.contains(eventType);
}
 
Example #10
Source File: OzarkCdiExtension.java    From ozark with Apache License 2.0 2 votes vote down vote up
/**
 * Determine if an event type is being observed.
 *
 * @param eventType event type.
 * @return outcome of test.
 */
public static synchronized boolean isEventObserved(Class<? extends MvcEvent> eventType) {
    return observedEvents == null ? false : observedEvents.contains(eventType);
}