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

org.ow2.util.plan.fetcher.impl.AbsResourceFetcherImpl Maven / Gradle / Ivy

There is a newer version: 1.0.37
Show newest version
/**
 * OW2 Util
 * Copyright (C) 2008 SERLI
 * Contact: [email protected]
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 *
 * --------------------------------------------------------------------------
 * $Id: AbsResourceFetcherImpl.java 5077 2009-07-29 14:09:04Z fornacif $
 * --------------------------------------------------------------------------
 */

package org.ow2.util.plan.fetcher.impl;

import java.io.File;

import org.ow2.util.plan.bindings.deploymentplan.DeploymentPlanFragment;
import org.ow2.util.plan.bindings.exceptions.InvalidDeploymentException;
import org.ow2.util.plan.fetcher.api.IResourceFetcher;
import org.ow2.util.plan.fetcher.api.exceptions.ResourceFetcherNotResolvedException;
import org.ow2.util.plan.repository.api.IRepositoryManager;

/**
 * Abstract implementation for the resource fetchers.
 * @author Mickaël LEDUQUE
 */
public abstract class AbsResourceFetcherImpl implements IResourceFetcher {

    /**
     * The deployment.
     */
    protected DeploymentPlanFragment deployment = null;

    /**
     * The repository manager the fetcher will use.
     */
    private IRepositoryManager repositoryManager = null;

    /**
     * The local directory used to store the local copy of the resource.
     */
    protected File localRepositoriesBaseDir = null;

    /**
     * The URL read timeout.
     */
    final static protected int TIMEOUT = 3000;

    /**
     * {@inheritDoc}
     */
    public IRepositoryManager getRepositoryManager() {
        return this.repositoryManager;
    }

    /**
     * {@inheritDoc}
     */
    public void setRepositoryManager(final IRepositoryManager repositoryManager) {
        this.repositoryManager = repositoryManager;
    }

    /**
     * {@inheritDoc}
     */
    public void setDeployment(final DeploymentPlanFragment deployment) throws InvalidDeploymentException {
        if (deployment == null) {
            throw new InvalidDeploymentException("null deployment");
        }
        this.deployment = deployment;
    }

    /**
     * {@inheritDoc}
     */
    public DeploymentPlanFragment getDeployment() {
        return this.deployment;
    }

    /**
     * {@inheritDoc}
     */
    public void setLocalRepositoriesBaseDir(final File localRepositoriesBaseDir) {
        this.localRepositoriesBaseDir = localRepositoriesBaseDir;

    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.getClass());
        if (this.deployment != null) {
            sb.append(":deployment=");
            sb.append(this.deployment);
        }
        return sb.toString();
    }

    /**
     * Returns a path to the local copy of the resource. The path is
     * //
     * @return a path to the local copy of the resource.
     */
    protected static File makeLocalFilePath(final File localRepositoriesBaseDir, final String repositoryName, final String pathToResource) {

        File intermediateFile = null;
        if (repositoryName != null && !repositoryName.equals("")) {
            intermediateFile = new File(localRepositoriesBaseDir, repositoryName);
        } else {
            intermediateFile = localRepositoriesBaseDir;
        }
        return new File(intermediateFile, pathToResource);

    }

    @Override
    public boolean equals(final Object object) {
        if (!(object instanceof IResourceFetcher)) {
            return false;
        }
        IResourceFetcher other = (IResourceFetcher) object;
        try {
            return this.getResource().equals(other.getResource());
        } catch (ResourceFetcherNotResolvedException e) {
            return super.equals(object);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy