1 package org.apache.archiva.admin.model;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.admin.model.beans.PropertyEntry;
23 import java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
30 * @author Olivier Lamy
33 public abstract class AbstractRepositoryConnector
34 implements Serializable
37 * The Repository Source for this connector.
39 private String sourceRepoId;
42 * The Repository Target for this connector.
44 private String targetRepoId;
47 * The network proxy ID to use for this connector.
49 private String proxyId;
52 * Field blackListPatterns.
54 private List<String> blackListPatterns;
57 * Field whiteListPatterns.
59 private List<String> whiteListPatterns;
64 private Map<String, String> policies;
67 * field to ease json mapping wrapper on <code>policies</code> field
71 private List<PropertyEntry> policiesEntries;
76 private Map<String, String> properties;
79 * field to ease json mapping wrapper on <code>properties</code> field
83 private List<PropertyEntry> propertiesEntries;
86 * If the the repository proxy connector is disabled or not
88 private boolean disabled = false;
95 * Method addBlackListPattern.
99 public void addBlackListPattern( String string )
101 getBlackListPatterns().add( string );
110 public void addPolicy( String key, String value )
112 getPolicies().put( key, value );
116 * Method addProperty.
121 public void addProperty( String key, String value )
123 getProperties().put( key, value );
127 * Method addWhiteListPattern.
131 public void addWhiteListPattern( String string )
133 getWhiteListPatterns().add( string );
137 * Method getBlackListPatterns.
141 public List<String> getBlackListPatterns()
143 if ( this.blackListPatterns == null )
145 this.blackListPatterns = new ArrayList<String>( 0 );
148 return this.blackListPatterns;
152 * Method getPolicies.
156 public Map<String, String> getPolicies()
158 if ( this.policies == null )
160 this.policies = new HashMap<String, String>();
163 return this.policies;
167 * Method getProperties.
171 public Map<String, String> getProperties()
173 if ( this.properties == null )
175 this.properties = new HashMap<String, String>();
178 return this.properties;
182 * Get the network proxy ID to use for this connector.
186 public String getProxyId()
192 * Get the Repository Source for this connector.
196 public String getSourceRepoId()
198 return this.sourceRepoId;
202 * Get the Repository Target for this connector.
206 public String getTargetRepoId()
208 return this.targetRepoId;
212 * Method getWhiteListPatterns.
216 public List<String> getWhiteListPatterns()
218 if ( this.whiteListPatterns == null )
220 this.whiteListPatterns = new ArrayList<String>( 0 );
223 return this.whiteListPatterns;
227 * Get if the the repository proxy connector is disabled or not
232 public boolean isDisabled()
234 return this.disabled;
238 * Method removeBlackListPattern.
242 public void removeBlackListPattern( String string )
244 getBlackListPatterns().remove( string );
248 * Method removeWhiteListPattern.
252 public void removeWhiteListPattern( String string )
254 getWhiteListPatterns().remove( string );
258 * Set the list of blacklisted patterns for this connector.
260 * @param blackListPatterns
262 public void setBlackListPatterns( List<String> blackListPatterns )
264 this.blackListPatterns = blackListPatterns;
268 * Set if the the repository proxy connector is
274 public void setDisabled( boolean disabled )
276 this.disabled = disabled;
280 * Set policy configuration for the connector.
284 public void setPolicies( Map<String, String> policies )
286 this.policies = policies;
290 * Set configuration for the connector.
294 public void setProperties( Map<String, String> properties )
296 this.properties = properties;
300 * Set the network proxy ID to use for this connector.
304 public void setProxyId( String proxyId )
306 this.proxyId = proxyId;
310 * Set the Repository Source for this connector.
312 * @param sourceRepoId
314 public void setSourceRepoId( String sourceRepoId )
316 this.sourceRepoId = sourceRepoId;
320 * Set the Repository Target for this connector.
322 * @param targetRepoId
324 public void setTargetRepoId( String targetRepoId )
326 this.targetRepoId = targetRepoId;
331 * The list of whitelisted patterns for this
334 * @param whiteListPatterns
336 public void setWhiteListPatterns( List<String> whiteListPatterns )
338 this.whiteListPatterns = whiteListPatterns;
343 * Obtain a specific policy from the underlying connector.
345 * @param policyId the policy id to fetch.
346 * @param defaultValue the default value for the policy id.
347 * @return the configured policy value (or default value if not found).
349 public String getPolicy( String policyId, String defaultValue )
351 if ( this.getPolicies() == null )
356 String value = this.getPolicies().get( policyId );
366 public List<PropertyEntry> getPoliciesEntries()
368 policiesEntries = new ArrayList<PropertyEntry>( getPolicies().size() );
369 for ( Map.Entry<String, String> entry : getPolicies().entrySet() )
371 policiesEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
373 return policiesEntries;
376 public void setPoliciesEntries( List<PropertyEntry> policiesEntries )
378 for ( PropertyEntry propertyEntry : policiesEntries )
380 addPolicy( propertyEntry.getKey(), propertyEntry.getValue() );
384 public List<PropertyEntry> getPropertiesEntries()
386 propertiesEntries = new ArrayList<PropertyEntry>( getProperties().size() );
387 for ( Map.Entry<String, String> entry : getProperties().entrySet() )
389 propertiesEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
391 return propertiesEntries;
394 public void setPropertiesEntries( List<PropertyEntry> propertiesEntries )
396 for ( PropertyEntry propertyEntry : policiesEntries )
398 addProperty( propertyEntry.getKey(), propertyEntry.getValue() );
403 public boolean equals( Object o )
409 if ( o == null || getClass() != o.getClass() )
414 AbstractRepositoryConnector that = (AbstractRepositoryConnector) o;
416 if ( sourceRepoId != null ? !sourceRepoId.equals( that.sourceRepoId ) : that.sourceRepoId != null )
420 if ( targetRepoId != null ? !targetRepoId.equals( that.targetRepoId ) : that.targetRepoId != null )
429 public int hashCode()
431 int result = sourceRepoId != null ? sourceRepoId.hashCode() : 0;
432 result = 31 * result + ( targetRepoId != null ? targetRepoId.hashCode() : 0 );
437 public String toString()
439 final StringBuilder sb = new StringBuilder();
440 sb.append( "AbstractRepositoryConnector" );
441 sb.append( "{sourceRepoId='" ).append( sourceRepoId ).append( '\'' );
442 sb.append( ", targetRepoId='" ).append( targetRepoId ).append( '\'' );
443 sb.append( ", proxyId='" ).append( proxyId ).append( '\'' );
444 sb.append( ", blackListPatterns=" ).append( blackListPatterns );
445 sb.append( ", whiteListPatterns=" ).append( whiteListPatterns );
446 sb.append( ", policies=" ).append( policies );
447 sb.append( ", properties=" ).append( properties );
448 sb.append( ", disabled=" ).append( disabled );
450 return sb.toString();