1package org.apache.archiva.proxy.model;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import org.apache.archiva.policies.Policy;
23import org.apache.archiva.policies.PolicyOption;
24import org.apache.archiva.repository.ManagedRepository;
25import org.apache.archiva.repository.RemoteRepository;
26import org.apache.archiva.repository.connector.RepositoryConnector;
2728import java.util.Iterator;
29import java.util.List;
30import java.util.Map;
3132/**33 * This represents a connector for a repository to a remote repository that is proxied.34 */35publicclassProxyConnector36implements RepositoryConnector
37 {
38private ManagedRepository sourceRepository;
3940private RemoteRepository targetRepository;
4142private List<String> blacklist;
4344private List<String> whitelist;
4546private String proxyId;
4748privateint order;
4950private Map<Policy, PolicyOption> policies;
5152privateboolean enabled;
5354private Map<String, String> properties;
5556publicProxyConnector()
57 {
58// no op59 }
6061/**62 * @see RepositoryConnector#isEnabled()63 */64 @Override
65publicboolean isEnabled()
66 {
67return enabled;
68 }
697071/**72 * @see RepositoryConnector#enable()73 */74 @Override
75publicvoid enable()
76 {
77this.enabled = true;
78 }
7980/**81 * @see RepositoryConnector#disable()82 */83 @Override
84publicvoid disable( )
85 {
86this.enabled = false;
87 }
8889/**90 * @see RepositoryConnector#getBlacklist()91 */92 @Override
93public List<String> getBlacklist()
94 {
95return blacklist;
96 }
9798/**99 * Sets the blacklist. The list is a string of paths.100 *101 * @param blacklist List of paths.102 */103publicvoid setBlacklist( List<String> blacklist )
104 {
105this.blacklist = blacklist;
106 }
107108/**109 * @see RepositoryConnector#getSourceRepository()110 */111 @Override
112public ManagedRepository getSourceRepository()
113 {
114return sourceRepository;
115 }
116117/**118 * Sets the source repository.119 * @param sourceRepository The managed repository which is the local representation of the proxy.120 */121publicvoid setSourceRepository( ManagedRepository sourceRepository )
122 {
123this.sourceRepository = sourceRepository;
124 }
125126/**127 * @see ProxyConnector#getTargetRepository()128 */129 @Override
130public RemoteRepository getTargetRepository()
131 {
132return targetRepository;
133 }
134135/**136 * Sets the target repository.137 * @param targetRepository The remote repository, where the artifacts are downloaded from.138 */139publicvoid setTargetRepository( RemoteRepository targetRepository )
140 {
141this.targetRepository = targetRepository;
142 }
143144/**145 * @see ProxyConnector#getWhitelist()146 */147 @Override
148public List<String> getWhitelist()
149 {
150return whitelist;
151 }
152153/**154 * Sets the list of paths that are proxied.155 * @param whitelist List of paths.156 */157publicvoid setWhitelist( List<String> whitelist )
158 {
159this.whitelist = whitelist;
160 }
161162/**163 * Returns the policies that are defined164 * @return165 */166public Map<Policy, PolicyOption> getPolicies()
167 {
168return policies;
169 }
170171/**172 * Sets policies that set the behaviour of this proxy connector.173 * @param policies A map of policies with each option.174 */175publicvoid setPolicies( Map<Policy, PolicyOption> policies )
176 {
177this.policies = policies;
178 }
179180/**181 * Adds a new policy.182 * @param policy The policy to add.183 * @param option The option for the policy.184 */185publicvoid addPolicy( Policy policy, PolicyOption option )
186 {
187this.policies.put( policy, option );
188 }
189190/**191 * Returns the id of this proxy connector.192 * @return The id string.193 */194public String getProxyId()
195 {
196return proxyId;
197 }
198199/**200 * Sets the id of this proxy connector.201 * @param proxyId A id string.202 */203publicvoid setProxyId( String proxyId )
204 {
205this.proxyId = proxyId;
206 }
207208 @Override
209public String toString()
210 {
211 StringBuilder sb = new StringBuilder();
212213 sb.append( "ProxyConnector[\n" );
214 sb.append( " source: [managed] " ).append( this.sourceRepository.getId() ).append( "\n" );
215 sb.append( " target: [remote] " ).append( this.targetRepository.getId() ).append( "\n" );
216 sb.append( " proxyId:" ).append( this.proxyId ).append( "\n" );
217218 Iterator<Policy> keys = this.policies.keySet().iterator();
219while ( keys.hasNext() )
220 {
221 String name = keys.next().getId();
222 sb.append( " policy[" ).append( name ).append( "]:" );
223 sb.append( this.policies.get( name ) ).append( "\n" );
224 }
225226 sb.append( "]" );
227228return sb.toString();
229 }
230231/**232 * Returns a number that orders the proxy connectors numerically.233 * @return The order number of this connector.234 */235publicint getOrder()
236 {
237return order;
238 }
239240/**241 * Set the order number of this proxy connector.242 *243 * @param order The order number.244 */245publicvoid setOrder( int order )
246 {
247this.order = order;
248 }
249250/**251 * Returns additional properties defined for this connector.252 * @return Map of key, value pairs.253 */254public Map<String, String> getProperties() {
255return properties;
256 }
257258/**259 * Sets additional properties for this connector.260 * @param properties Map of key, value pairs.261 */262publicvoid setProperties(Map<String, String> properties) {
263this.properties = properties;
264 }
265 }