1 /******************************************************************************* 2 * Copyright (c) 2010, 2011 Sonatype, Inc. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Sonatype, Inc. - initial API and implementation 10 *******************************************************************************/ 11 package org.eclipse.aether.repository; 12 13 import org.eclipse.aether.RepositorySystemSession; 14 import org.eclipse.aether.metadata.Metadata; 15 16 /** 17 * A query to the local repository for the existence of metadata. 18 * 19 * @see LocalRepositoryManager#find(RepositorySystemSession, LocalMetadataRequest) 20 */ 21 public final class LocalMetadataRequest 22 { 23 24 private Metadata metadata; 25 26 private String context = ""; 27 28 private RemoteRepository repository = null; 29 30 /** 31 * Creates an uninitialized query. 32 */ 33 public LocalMetadataRequest() 34 { 35 // enables default constructor 36 } 37 38 /** 39 * Creates a query with the specified properties. 40 * 41 * @param metadata The metadata to query for, may be {@code null}. 42 * @param repository The source remote repository for the metadata, may be {@code null} for local metadata. 43 * @param context The resolution context for the metadata, may be {@code null}. 44 */ 45 public LocalMetadataRequest( Metadata metadata, RemoteRepository repository, String context ) 46 { 47 setMetadata( metadata ); 48 setRepository( repository ); 49 setContext( context ); 50 } 51 52 /** 53 * Gets the metadata to query for. 54 * 55 * @return The metadata or {@code null} if not set. 56 */ 57 public Metadata getMetadata() 58 { 59 return metadata; 60 } 61 62 /** 63 * Sets the metadata to query for. 64 * 65 * @param metadata The metadata, may be {@code null}. 66 * @return This query for chaining, never {@code null}. 67 */ 68 public LocalMetadataRequest setMetadata( Metadata metadata ) 69 { 70 this.metadata = metadata; 71 return this; 72 } 73 74 /** 75 * Gets the resolution context. 76 * 77 * @return The resolution context, never {@code null}. 78 */ 79 public String getContext() 80 { 81 return context; 82 } 83 84 /** 85 * Sets the resolution context. 86 * 87 * @param context The resolution context, may be {@code null}. 88 * @return This query for chaining, never {@code null}. 89 */ 90 public LocalMetadataRequest setContext( String context ) 91 { 92 this.context = ( context != null ) ? context : ""; 93 return this; 94 } 95 96 /** 97 * Gets the remote repository to use as source of the metadata. 98 * 99 * @return The remote repositories, may be {@code null} for local metadata. 100 */ 101 public RemoteRepository getRepository() 102 { 103 return repository; 104 } 105 106 /** 107 * Sets the remote repository to use as sources of the metadata. 108 * 109 * @param repository The remote repository, may be {@code null}. 110 * @return This query for chaining, may be {@code null} for local metadata. 111 */ 112 public LocalMetadataRequest setRepository( RemoteRepository repository ) 113 { 114 this.repository = repository; 115 return this; 116 } 117 118 @Override 119 public String toString() 120 { 121 return getMetadata() + " @ " + getRepository(); 122 } 123 124 }