com.freebox.engeneering.application.web.common.AbstractController.java Source code

Java tutorial

Introduction

Here is the source code for com.freebox.engeneering.application.web.common.AbstractController.java

Source

/*
 * Copyright 2012 Lexaden.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package com.freebox.engeneering.application.web.common;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;

import com.freebox.engeneering.application.view.state.EventConstants;
import com.lexaden.webflow.EventProcessor;
import com.lexaden.webflow.StateEvent;
import com.lexaden.webflow.annotation.OnEnterState;
import com.lexaden.webflow.web.Controller;
import com.vaadin.server.VaadinSession;

/**
 * Interface that all main views should implement
 */
public abstract class AbstractController<A> implements Controller<A>, Serializable {
    private static final long serialVersionUID = -1420553541682132603L;
    protected EventProcessor eventProcessor;

    private A view;

    private static final String FREEBOX_TOKEN_SESSION = "freeboxTokenSession";

    /**
     * @inherited
     */
    @OnEnterState(EventConstants.INIT_VIEW)
    public abstract void initView(@SuppressWarnings("rawtypes") StateEvent event);

    /**
     * @inherited
     */
    public void setView(A content) {
        this.view = content;
    }

    /**
     * @inherited
     */
    public A getView() {
        return view;
    }

    @Autowired
    @Override
    public void setEventProcessor(EventProcessor eventProcessor) {
        this.eventProcessor = eventProcessor;
    }

    @Override
    public EventProcessor getEventProcessor() {
        return eventProcessor;
    }

    public String getFreeboxTokenSession() {
        final VaadinSession current = VaadinSession.getCurrent();
        String tokenSession = (String) current.getAttribute(FREEBOX_TOKEN_SESSION);
        return tokenSession;
    }
}