Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2248eab3070fe5d44e689221b81562c36a2474b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (c) 2007, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository;

import org.eclipse.core.runtime.*;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;

/**
 * Base class for all requests on an {@link IArtifactRepository}.
 */
public abstract class ArtifactRequest implements IArtifactRequest {
	private static final Status DEFAULT_STATUS = new Status(IStatus.ERROR, Activator.ID, "default"); //$NON-NLS-1$
	protected IArtifactKey artifact;
	protected String resolvedKey;
	protected IArtifactRepository source;
	protected IStatus result = DEFAULT_STATUS;

	public ArtifactRequest(IArtifactKey key) {
		artifact = key;
		// TODO do we need to make this configurable? for now set default request handler to ECF
	}

	public IArtifactKey getArtifactKey() {
		return artifact;
	}

	/**
	 * Returns the result of the previous call to {@link #perform(IArtifactRepository, IProgressMonitor)},
	 * or <code>null</code> if perform has never been called.
	 * 
	 * @return The result of the previous perform call.
	 */
	public IStatus getResult() {
		if (result == DEFAULT_STATUS)
			return new Status(IStatus.ERROR, Activator.ID, "No repository found containing: " + getArtifactKey().toString());

		return result;
	}

	protected IArtifactRepository getSourceRepository() {
		return source;
	}

	/**
	 * Performs the artifact request, and sets the result status.
	 * 
	 * @param sourceRepository the repository to download the artifact from 
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting is not desired
	 */
	abstract public void perform(IArtifactRepository sourceRepository, IProgressMonitor monitor);

	/**
	 * Sets the result of an invocation of {@link #perform(IArtifactRepository, IProgressMonitor)}.
	 * This method is called by subclasses to set the result status for
	 * this request.
	 * 
	 * @param value The result status
	 */
	protected void setResult(IStatus value) {
		result = value;
	}

	protected void setSourceRepository(IArtifactRepository value) {
		source = value;
	}
}

Back to the top