Package org.apache.agila.impl.dao

Source Code of org.apache.agila.impl.dao.TokenServiceImpl

/*
* Copyright 2004 The Apache Software Foundation.
*
* 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 org.apache.agila.impl.dao;

import org.apache.agila.impl.TokenImpl;
import org.apache.agila.engine.InstanceID;
import org.apache.agila.engine.Token;
import org.apache.agila.engine.TokenID;
import org.apache.agila.model.Connection;
import org.apache.agila.model.NodeID;
import org.apache.agila.services.TokenService;

import org.apache.agila.util.JDBCUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
* A provide which delegates to an {@link AgilaDAO} for all of the detailed
* persistence methods.
*
* @author <a href="mailto:jstrachan@protique.com">James Strachan</a>
* @version $Id: TokenServiceImpl.java 38 2005-06-01 19:39:54Z chirino $
*/
public class TokenServiceImpl implements TokenService {

    private AgilaDAO dao;

    public TokenServiceImpl(AgilaDAO dao) {
        this.dao = dao;
    }

    public List getActiveTokensForInstance( InstanceID instanceID ) {
        return dao.getActiveTokensForInstance( instanceID );
    }

    public boolean saveToken(Token t) {
        return dao.saveToken( t );
    }

    /*
     *  creates a new token w/ no parents, starting at a given node
     *
     * @param instanceID
     * @param nodeID
     * @param state
     * @return
     */
    public Token newToken(InstanceID instanceID, NodeID nodeID, int state) {
        return dao.newToken(instanceID, nodeID, state);
    }

    /**
     * Returns a set of tokens, advanced along the connections given.  The
     * implementation is responsible for tracking 'fork trees', to provide
     * for join resolution in 'getParallelTokens()'
     *
     * @param connSet
     * @param parentToken
     * @return
     */
    public Token[] nextToken(Connection[] connSet, Token parentToken) {

        if (connSet == null || connSet.length == 0) {
            return null;
        }

        Token[] newSet = new Token[connSet.length];

        for(int i = 0; i < connSet.length; i++) {

            Connection conn = connSet[i];

            Token newToken = dao.newToken( parentToken.getInstanceID(), conn.getChildNode().getNodeId(), Token.PRE );

            conn.traverse(newToken);
            newSet[i] = newToken;
        }

        return newSet;
    }

    public Token getTokenByID(TokenID tokenID) {
        return dao.getTokenByID( tokenID );
    }

    // TODO need to implement this
    public List getParallelTokens(TokenID tokenID) {
        return null;
    }
}
TOP

Related Classes of org.apache.agila.impl.dao.TokenServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.