Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2dc550f1a145ebd4d3470fbc65db61699c834fca (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*******************************************************************************
 *  Copyright (c) 2007, 2009 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.p2.repository.metadata.spi;

import java.net.URI;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.IRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;

/**
 * A metadata repository factory is responsible for creating and loading instances
 * of a particular type of metadata repository. Factories are provided via the 
 * <tt>org.eclipse.equinox.p2.metadata.repository.metadataRepositories</tt> extension point.
 * @since 2.0
 */
public abstract class MetadataRepositoryFactory {
	private IProvisioningAgent agent;

	/**
	 * Creates and returns a new empty metadata repository of the given type at 
	 * the given location.
	 * 
	 * @param location the location for the new repository
	 * @param name the name of the new repository
	 * @param type the kind of repository to create
	 * @param properties the properties to set on the repository
	 * @return the newly created repository
	 * @throws ProvisionException if the repository could not be created.  Reasons include:
	 * <ul>
	 * <li>The repository type is not supported by this factory.</li>
	 * <li>There was an error writing to the given repository location.</li>
	 * </ul>
	 */
	public abstract IMetadataRepository create(URI location, String name, String type, Map<String, String> properties) throws ProvisionException;

	/**
	 * Returns the provisioning agent associated with this factory, or <code>null</code>
	 * if this factory is not associated with an agent.
	 * @return The provisioning agent, or <code>null</code>
	 */
	protected IProvisioningAgent getAgent() {
		return agent;
	}

	/**
	 * Loads a repository corresponding to the given URL.
	 * <p>
	 * The error code returned in the case of failure is significant. In particular an
	 * error code of {@link ProvisionException#REPOSITORY_FAILED_READ} indicates
	 * that the location definitely identifies a repository of this type, but an error occurred
	 * while loading the repository. The repository manager will not attempt to load
	 * a repository from that location using any other factory.  An error code of
	 * {@link ProvisionException#REPOSITORY_NOT_FOUND} indicates there is no
	 * repository of this type at the given location, and the repository manager is free
	 * to try again with a different repository factory.
	 * </p>
	 * <p>
	 * The flags passed in should be taken as a hint for the type of repository to load.  If
	 * the factory knows it will not load a repository that satisfies these hints, it can fail
	 * fast and return null.<br>
	 * See {@link IRepositoryManager#REPOSITORY_HINT_MODIFIABLE}
	 * </p>
	 * @param location The location of the repository to load
	 * @param flags to consider while loading the repository
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting is not desired
	 * @return The loaded metadata repository
	 * @throws ProvisionException if the repository could not be created.  Reasons include:
	 * <ul>
	 * <li>There is no existing repository at that location.</li>
	 * <li>The repository at that location could not be read.</li>
	 * </ul>
	 */
	public abstract IMetadataRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException;

	/**
	 * Sets the provisioning agent associated with this repository factory.
	 * @param agent The provisioning agent
	 */
	public void setAgent(IProvisioningAgent agent) {
		this.agent = agent;
	}

	/**
	 * Validates a candidate repository URL and returns a status indicating the
	 * likelihood of a valid repository being located at the location.  Implementors 
	 * should make all attempts to validate the URL that can be made without 
	 * actually loading the repository.  The computation for this method must be 
	 * significantly faster than loading the repository.  Early detectable error 
	 * conditions, such as the non-existence of the location, or an inability to read 
	 * the location, should be determined in this method.
	 * 
	 * @param location The location of the repository to validate
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting is not desired
	 * @return A status indicating whether a valid repository is likely located at the
	 * location.  A status with severity <code>OK</code> indicates that the repository is
	 * likely to be loadable, or that as much validation as could be done was successful.
	 * Reasons for a non-OK status include:
	 * <ul>
	 * <li>The specified location is not a valid repository location.</li>
	 * <li>There is no existing repository at that location.</li>
	 * <li>The repository at that location could not be read.</li>
	 * </ul>
	 */
	public abstract IStatus validate(URI location, IProgressMonitor monitor);
}

Back to the top