krysalis-update/src/java/org/krysalis/depot/update/download DownloadManager.java,NONE,1.1

Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:06:47 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/download
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/java/org/krysalis/depot/update/download

Added Files:
	DownloadManager.java 
Log Message:
Copied from the apache incubator.

--- NEW FILE: DownloadManager.java ---
/*
 * 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.krysalis.depot.update.download;

import java.util.Iterator;
import java.util.List;

import org.krysalis.depot.update.ArtifactInstance;
import org.krysalis.depot.update.Repository;
import org.krysalis.depot.update.UpdateException;
import org.krysalis.depot.update.impl.ArtifactUpdaterContext;
import org.krysalis.depot.update.impl.RepositoryWrapper;
import org.krysalis.depot.update.repository.RepositoryException;

/**
 * This class represents, like the name suggests, a Download Manager.
 * 
 * @author <a href="http://incubator.apache.org/depot">The Apache Incubator Depot Project</a>
 */
public class DownloadManager {

	private final ArtifactUpdaterContext m_context;

	/**
	 * Constructor
	 * Initializes a Downloadmanager with a given ArtifactUpdaterContext
	 * 
	 * @param context An ArtifactUpdaterContext 
	 */
	public DownloadManager(ArtifactUpdaterContext context) {
		m_context = context;
		initClass();
	}
	
	/**
	 * Initializes this class
	 */
	private void initClass() {
	}


	/**
	 * downloadTo - downloads the ArtifactInstances to the specified (local) 
	 * repository
	 * 
	 * Question: can this be used to upload to a remote repository??
	 * 
	 * @param instances list of artifactInstances
	 * @param targetRepository repository to which the artifacts are downloaded
	 * @throws UpdateException
	 */
	public void downloadTo(List instances, Repository targetRepository)
		throws UpdateException {

		RepositoryWrapper target =
			new RepositoryWrapper(targetRepository, m_context);

		for (Iterator i = instances.iterator(); i.hasNext();) {
			ArtifactInstance artifact = (ArtifactInstance) i.next();
			
			try {
				target.publishArtifact(artifact);
			} catch (Exception e) {
				//
				// (1) log (2) stash in result set error table
				//
				throw new RepositoryException(
					targetRepository,
					"Failed to publish resource: " + artifact,
					e);
			}
		}
	}
	
}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/