View Javadoc
1   package org.eclipse.aether.util.artifact;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.eclipse.aether.artifact.ArtifactType;
23  import org.eclipse.aether.artifact.ArtifactTypeRegistry;
24  
25  /**
26   * An artifact type registry which first consults its own mappings and in case of an unknown type falls back to another
27   * type registry.
28   */
29  public final class OverlayArtifactTypeRegistry
30      extends SimpleArtifactTypeRegistry
31  {
32  
33      private final ArtifactTypeRegistry delegate;
34  
35      /**
36       * Creates a new artifact type registry with initially no registered artifact types and the specified fallback
37       * registry. Use {@link #add(ArtifactType)} to populate the registry.
38       * 
39       * @param delegate The artifact type registry to fall back to, may be {@code null}.
40       */
41      public OverlayArtifactTypeRegistry( ArtifactTypeRegistry delegate )
42      {
43          this.delegate = delegate;
44      }
45  
46      /**
47       * Adds the specified artifact type to the registry.
48       * 
49       * @param type The artifact type to add, must not be {@code null}.
50       * @return This registry for chaining, never {@code null}.
51       */
52      public OverlayArtifactTypeRegistry add( ArtifactType type )
53      {
54          super.add( type );
55          return this;
56      }
57  
58      public ArtifactType get( String typeId )
59      {
60          ArtifactType type = super.get( typeId );
61  
62          if ( type == null && delegate != null )
63          {
64              type = delegate.get( typeId );
65          }
66  
67          return type;
68      }
69  
70  }