001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.resolution;
020
021import org.eclipse.aether.artifact.Artifact;
022
023/**
024 * A query for the error policy for a given artifact's descriptor.
025 *
026 * @see ArtifactDescriptorPolicy
027 */
028public final class ArtifactDescriptorPolicyRequest {
029
030    private Artifact artifact;
031
032    private String context = "";
033
034    /**
035     * Creates an uninitialized request.
036     */
037    public ArtifactDescriptorPolicyRequest() {
038        // enables default constructor
039    }
040
041    /**
042     * Creates a request for the specified artifact.
043     *
044     * @param artifact The artifact for whose descriptor to determine the error policy, may be {@code null}.
045     * @param context The context in which this request is made, may be {@code null}.
046     */
047    public ArtifactDescriptorPolicyRequest(Artifact artifact, String context) {
048        setArtifact(artifact);
049        setRequestContext(context);
050    }
051
052    /**
053     * Gets the artifact for whose descriptor to determine the error policy.
054     *
055     * @return The artifact for whose descriptor to determine the error policy or {@code null} if not set.
056     */
057    public Artifact getArtifact() {
058        return artifact;
059    }
060
061    /**
062     * Sets the artifact for whose descriptor to determine the error policy.
063     *
064     * @param artifact The artifact for whose descriptor to determine the error policy, may be {@code null}.
065     * @return This request for chaining, never {@code null}.
066     */
067    public ArtifactDescriptorPolicyRequest setArtifact(Artifact artifact) {
068        this.artifact = artifact;
069        return this;
070    }
071
072    /**
073     * Gets the context in which this request is made.
074     *
075     * @return The context, never {@code null}.
076     */
077    public String getRequestContext() {
078        return context;
079    }
080
081    /**
082     * Sets the context in which this request is made.
083     *
084     * @param context The context, may be {@code null}.
085     * @return This request for chaining, never {@code null}.
086     */
087    public ArtifactDescriptorPolicyRequest setRequestContext(String context) {
088        this.context = (context != null) ? context : "";
089        return this;
090    }
091
092    @Override
093    public String toString() {
094        return String.valueOf(getArtifact());
095    }
096}