All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.faces.flow.FlowImpl Maven / Gradle / Ivy

/*
 * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

package com.sun.faces.flow;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import com.sun.faces.util.Util;

import jakarta.el.MethodExpression;
import jakarta.faces.application.NavigationCase;
import jakarta.faces.context.FacesContext;
import jakarta.faces.flow.Flow;
import jakarta.faces.flow.FlowCallNode;
import jakarta.faces.flow.FlowHandler;
import jakarta.faces.flow.FlowNode;
import jakarta.faces.flow.MethodCallNode;
import jakarta.faces.flow.Parameter;
import jakarta.faces.flow.ReturnNode;
import jakarta.faces.flow.SwitchNode;
import jakarta.faces.flow.ViewNode;
import jakarta.faces.lifecycle.ClientWindow;

public class FlowImpl extends Flow implements Serializable {

    private static final long serialVersionUID = 5287030395068302998L;

    public static final Flow SYNTHESIZED_RETURN_CASE_FLOW = new FlowImpl(FlowHandler.NULL_FLOW);

    public static final Flow ABANDONED_FLOW = new FlowImpl(FlowHandlerImpl.ABANDONED_FLOW);

    // 

    private String id;
    private String definingDocumentId;
    private String startNodeId;
    private final ConcurrentHashMap> _navigationCases;
    private final Map> navigationCases;
    private final CopyOnWriteArrayList _views;
    private final List views;
    private final CopyOnWriteArrayList _methodCalls;
    private final List methodCalls;
    private final ConcurrentHashMap _inboundParameters;
    private final Map inboundParameters;
    private final ConcurrentHashMap _returns;
    private final Map returns;
    private final ConcurrentHashMap _switches;
    private final Map switches;
    private final ConcurrentHashMap _facesFlowCalls;
    private final Map facesFlowCalls;
    private final ConcurrentHashMap _facesFlowCallsByTargetFlowId;
    private MethodExpression initializer;
    private MethodExpression finalizer;
    private boolean hasBeenInitialized = false;

    // 

    // 

    public FlowImpl() {
        _inboundParameters = new ConcurrentHashMap<>();
        inboundParameters = Collections.unmodifiableMap(_inboundParameters);
        _returns = new ConcurrentHashMap<>();
        returns = Collections.unmodifiableMap(_returns);
        _switches = new ConcurrentHashMap<>();
        switches = Collections.unmodifiableMap(_switches);
        _facesFlowCalls = new ConcurrentHashMap<>();
        facesFlowCalls = Collections.unmodifiableMap(_facesFlowCalls);
        _facesFlowCallsByTargetFlowId = new ConcurrentHashMap<>();
        _views = new CopyOnWriteArrayList<>();
        views = Collections.unmodifiableList(_views);
        _navigationCases = new ConcurrentHashMap<>();
        navigationCases = Collections.unmodifiableMap(_navigationCases);
        _methodCalls = new CopyOnWriteArrayList<>();
        methodCalls = Collections.unmodifiableList(_methodCalls);
    }

    private FlowImpl(String id) {
        this.id = id;
        definingDocumentId = null;
        startNodeId = null;
        _navigationCases = null;
        navigationCases = null;
        _views = null;
        views = null;
        _methodCalls = null;
        methodCalls = null;
        _inboundParameters = null;
        inboundParameters = null;
        _returns = null;
        returns = null;
        _switches = null;
        switches = null;
        _facesFlowCalls = null;
        facesFlowCalls = null;
        _facesFlowCallsByTargetFlowId = null;
        initializer = null;
        finalizer = null;
        hasBeenInitialized = true;
    }

    // 

    // 

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Flow other = (Flow) obj;
        if (id == null ? other.getId() != null : !id.equals(other.getId())) {
            return false;
        }
        if (startNodeId == null ? other.getStartNodeId() != null : !startNodeId.equals(other.getStartNodeId())) {
            return false;
        }
        if (_views != other.getViews() && (_views == null || !_views.equals(other.getViews()))) {
            return false;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        if (null != context) {
            if (_returns != other.getReturns() && (_returns == null || !_returns.equals(other.getReturns()))) {
                return false;
            }
            if (initializer != other.getInitializer() && (initializer == null || !initializer.equals(other.getInitializer()))) {
                return false;
            }
            if (finalizer != other.getFinalizer() && (finalizer == null || !finalizer.equals(other.getFinalizer()))) {
                return false;
            }
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 59 * hash + (id != null ? id.hashCode() : 0);
        hash = 59 * hash + (startNodeId != null ? startNodeId.hashCode() : 0);
        hash = 59 * hash + (_views != null ? _views.hashCode() : 0);
        hash = 59 * hash + (_returns != null ? _returns.hashCode() : 0);
        hash = 59 * hash + (initializer != null ? initializer.hashCode() : 0);
        hash = 59 * hash + (finalizer != null ? finalizer.hashCode() : 0);
        return hash;
    }

    // 

    // 

    @Override
    public String getId() {
        return id;
    }

    @Override
    public String getDefiningDocumentId() {
        return definingDocumentId;
    }

    public void setId(String definingDocumentId, String id) {
        Util.notNull("definingDocumentId", definingDocumentId);
        Util.notNull("flowId", id);
        this.id = id;
        this.definingDocumentId = definingDocumentId;
    }

    @Override
    public String getStartNodeId() {
        return startNodeId;
    }

    public void setStartNodeId(String defaultNodeId) {
        startNodeId = defaultNodeId;
    }

    @Override
    public MethodExpression getFinalizer() {
        return finalizer;
    }

    public void setFinalizer(MethodExpression finalizer) {
        this.finalizer = finalizer;
    }

    @Override
    public MethodExpression getInitializer() {
        return initializer;
    }

    public void setInitializer(MethodExpression initializer) {
        this.initializer = initializer;
    }

    @Override
    public Map getInboundParameters() {
        return inboundParameters;
    }

    public Map _getInboundParameters() {
        return _inboundParameters;
    }

    // 

    // 

    @Override
    public List getViews() {
        return views;
    }

    public List _getViews() {
        return _views;
    }

    @Override
    public Map getReturns() {
        return returns;
    }

    public Map _getReturns() {
        return _returns;
    }

    @Override
    public Map getSwitches() {
        return switches;
    }

    public Map _getSwitches() {
        return _switches;
    }

    @Override
    public Map getFlowCalls() {
        return facesFlowCalls;
    }

    public Map _getFlowCalls() {
        return _facesFlowCalls;
    }

    @Override
    public Map> getNavigationCases() {
        return navigationCases;
    }

    public Map> _getNavigationCases() {
        return _navigationCases;
    }

    @Override
    public FlowCallNode getFlowCall(Flow targetFlow) {
        String targetFlowId = targetFlow.getId();
        if (!hasBeenInitialized) {
            FacesContext context = FacesContext.getCurrentInstance();
            init(context);
        }
        FlowCallNode result = _facesFlowCallsByTargetFlowId.get(targetFlowId);

        return result;
    }

    @Override
    public List getMethodCalls() {
        return methodCalls;
    }

    public List _getMethodCalls() {
        return _methodCalls;
    }

    // 

    // 

    @Override
    public FlowNode getNode(String nodeId) {
        List myViews = getViews();
        FlowNode result = null;

        if (null != myViews) {
            for (ViewNode cur : myViews) {
                if (nodeId.equals(cur.getId())) {
                    result = cur;
                    break;
                }
            }
        }
        if (null == result) {
            Map mySwitches = getSwitches();
            result = mySwitches.get(nodeId);
        }
        if (null == result) {
            List myMethods = getMethodCalls();
            for (MethodCallNode cur : myMethods) {
                if (nodeId.equals(cur.getId())) {
                    result = cur;
                    break;
                }
            }
        }
        if (null == result) {
            Map myCalls = getFlowCalls();
            result = myCalls.get(nodeId);
        }

        if (null == result) {
            Map myReturns = getReturns();
            result = myReturns.get(nodeId);
        }

        return result;

    }

    // 

    // 

    @Override
    public String getClientWindowFlowId(ClientWindow curWindow) {
        String result = null;

        result = curWindow.getId() + "_" + getId();

        return result;
    }

    // 

    // 

    public void init(FacesContext context) {
        if (hasBeenInitialized) {
            return;
        }
        hasBeenInitialized = true;

        // Populate lookup data structures.
        FlowCallNode curNode = null;
        String curTargetFlowId = null;
        for (Map.Entry cur : _facesFlowCalls.entrySet()) {
            curNode = cur.getValue();
            curTargetFlowId = curNode.getCalledFlowId(context);
            _facesFlowCallsByTargetFlowId.put(curTargetFlowId, curNode);
        }
    }

    // 

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy