001package org.eclipse.aether.spi.connector.transport;
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.net.URI;
023
024/**
025 * A transport task.
026 * 
027 * @noextend This class is not intended to be extended by clients.
028 */
029public abstract class TransportTask
030{
031
032    static final TransportListener NOOP = new TransportListener()
033    {
034    };
035
036    static final byte[] EMPTY = {};
037
038    private URI location;
039
040    private TransportListener listener = NOOP;
041
042    TransportTask()
043    {
044        // hide
045    }
046
047    /**
048     * Gets the relative location of the affected resource in the remote repository.
049     * 
050     * @return The relative location of the resource, never {@code null}.
051     */
052    public URI getLocation()
053    {
054        return location;
055    }
056
057    TransportTask setLocation( URI location )
058    {
059        if ( location == null )
060        {
061            throw new IllegalArgumentException( "resource location has not been specified" );
062        }
063        this.location = location;
064        return this;
065    }
066
067    /**
068     * Gets the listener that is to be notified during the transfer.
069     * 
070     * @return The listener to notify of progress, never {@code null}.
071     */
072    public TransportListener getListener()
073    {
074        return listener;
075    }
076
077    /**
078     * Sets the listener that is to be notified during the transfer.
079     * 
080     * @param listener The listener to notify of progress, may be {@code null}.
081     * @return This task for chaining, never {@code null}.
082     */
083    TransportTask setListener( TransportListener listener )
084    {
085        this.listener = ( listener != null ) ? listener : NOOP;
086        return this;
087    }
088
089}