package org.apache.maven.ejb;

/* ====================================================================
 *   Copyright 2001-2005 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.
 * ====================================================================
 */

import org.apache.maven.MavenException;
import org.apache.maven.project.Project;
import org.apache.maven.repository.ArtifactTypeHandler;

/**
 *  This will do until wagon debuts.
 * 
 * @author <a href="mailto:havard@tracetracker.com">Håvard Bjåstad</a>
 * @author <a href="mailto:vmassol@apache.org>Vincent Massol</a>
 * @version $Id$
 */
public class EJBArtifactTypeHandler implements ArtifactTypeHandler
{
    /**
     * Map an artifact to a repository directory path.
     * 
     * @param project the project for the artifact
     * @param type  The type of the artifact 
     * @return the path
     */
    public String constructRepositoryDirectoryPath(String type, Project project) throws MavenException
    {
        StringBuffer path = new StringBuffer();
        path.append(project.getArtifactDirectory());
        path.append("/ejbs/");
        return path.toString();
    }

    /**
     * Map an artifact to a repository path.
     * 
     * @param project the project for the artifact
     * @param type  The type of the artifact 
     * @param version  The version of the artifact (may be a snapshot)
     * @return the path
     */
    public String constructRepositoryFullPath(String type, Project project, String version) throws MavenException
    {
        StringBuffer path = new StringBuffer(constructRepositoryDirectoryPath(type, project));
        path.append(project.getArtifactId());
        path.append("-");
        path.append(version);
        
        if ( type.equals( "ejb-client" ) ) {
            path.append( "-client.jar" );
        }
        else if ( type.equals( "ejb" ) ) {
            path.append(".jar");
        }
        else {
            throw new MavenException("Unrecognised ejb type (is " + type + ")");
        }

        return path.toString();
    }
}
