001package org.eclipse.aether.spi.connector;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023
024import org.eclipse.aether.metadata.Metadata;
025import org.eclipse.aether.transfer.MetadataTransferException;
026
027/**
028 * A download/upload of metadata.
029 * 
030 * @noextend This class is not intended to be extended by clients.
031 */
032public abstract class MetadataTransfer
033    extends Transfer
034{
035
036    private Metadata metadata;
037
038    private File file;
039
040    private MetadataTransferException exception;
041
042    MetadataTransfer()
043    {
044        // hide
045    }
046
047    /**
048     * Gets the metadata being transferred.
049     * 
050     * @return The metadata being transferred or {@code null} if not set.
051     */
052    public Metadata getMetadata()
053    {
054        return metadata;
055    }
056
057    /**
058     * Sets the metadata to transfer.
059     * 
060     * @param metadata The metadata, may be {@code null}.
061     * @return This transfer for chaining, never {@code null}.
062     */
063    public MetadataTransfer setMetadata( Metadata metadata )
064    {
065        this.metadata = metadata;
066        return this;
067    }
068
069    /**
070     * Gets the local file the metadata is downloaded to or uploaded from. In case of a download, a connector should
071     * first transfer the bytes to a temporary file and only overwrite the target file once the entire download is
072     * completed such that an interrupted/failed download does not corrupt the current file contents.
073     * 
074     * @return The local file or {@code null} if not set.
075     */
076    public File getFile()
077    {
078        return file;
079    }
080
081    /**
082     * Sets the local file the metadata is downloaded to or uploaded from.
083     * 
084     * @param file The local file, may be {@code null}.
085     * @return This transfer for chaining, never {@code null}.
086     */
087    public MetadataTransfer setFile( File file )
088    {
089        this.file = file;
090        return this;
091    }
092
093    /**
094     * Gets the exception that occurred during the transfer (if any).
095     * 
096     * @return The exception or {@code null} if the transfer was successful.
097     */
098    public MetadataTransferException getException()
099    {
100        return exception;
101    }
102
103    /**
104     * Sets the exception that occurred during the transfer.
105     * 
106     * @param exception The exception, may be {@code null} to denote a successful transfer.
107     * @return This transfer for chaining, never {@code null}.
108     */
109    public MetadataTransfer setException( MetadataTransferException exception )
110    {
111        this.exception = exception;
112        return this;
113    }
114
115}