001package org.eclipse.aether.repository;
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 org.eclipse.aether.metadata.Metadata;
023
024/**
025 * A query to the local repository for the existence of metadata.
026 * 
027 * @see LocalRepositoryManager#find(org.eclipse.aether.RepositorySystemSession, LocalMetadataRequest)
028 */
029public final class LocalMetadataRequest
030{
031
032    private Metadata metadata;
033
034    private String context = "";
035
036    private RemoteRepository repository = null;
037
038    /**
039     * Creates an uninitialized query.
040     */
041    public LocalMetadataRequest()
042    {
043        // enables default constructor
044    }
045
046    /**
047     * Creates a query with the specified properties.
048     * 
049     * @param metadata The metadata to query for, may be {@code null}.
050     * @param repository The source remote repository for the metadata, may be {@code null} for local metadata.
051     * @param context The resolution context for the metadata, may be {@code null}.
052     */
053    public LocalMetadataRequest( Metadata metadata, RemoteRepository repository, String context )
054    {
055        setMetadata( metadata );
056        setRepository( repository );
057        setContext( context );
058    }
059
060    /**
061     * Gets the metadata to query for.
062     * 
063     * @return The metadata or {@code null} if not set.
064     */
065    public Metadata getMetadata()
066    {
067        return metadata;
068    }
069
070    /**
071     * Sets the metadata to query for.
072     * 
073     * @param metadata The metadata, may be {@code null}.
074     * @return This query for chaining, never {@code null}.
075     */
076    public LocalMetadataRequest setMetadata( Metadata metadata )
077    {
078        this.metadata = metadata;
079        return this;
080    }
081
082    /**
083     * Gets the resolution context.
084     * 
085     * @return The resolution context, never {@code null}.
086     */
087    public String getContext()
088    {
089        return context;
090    }
091
092    /**
093     * Sets the resolution context.
094     * 
095     * @param context The resolution context, may be {@code null}.
096     * @return This query for chaining, never {@code null}.
097     */
098    public LocalMetadataRequest setContext( String context )
099    {
100        this.context = ( context != null ) ? context : "";
101        return this;
102    }
103
104    /**
105     * Gets the remote repository to use as source of the metadata.
106     * 
107     * @return The remote repositories, may be {@code null} for local metadata.
108     */
109    public RemoteRepository getRepository()
110    {
111        return repository;
112    }
113
114    /**
115     * Sets the remote repository to use as sources of the metadata.
116     * 
117     * @param repository The remote repository, may be {@code null}.
118     * @return This query for chaining, may be {@code null} for local metadata.
119     */
120    public LocalMetadataRequest setRepository( RemoteRepository repository )
121    {
122        this.repository = repository;
123        return this;
124    }
125
126    @Override
127    public String toString()
128    {
129        return getMetadata() + " @ " + getRepository();
130    }
131
132}