View Javadoc
1   package org.apache.maven.resolver.internal.ant.types;
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 java.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.tools.ant.Task;
26  import org.apache.tools.ant.types.DataType;
27  import org.apache.tools.ant.types.Reference;
28  
29  /**
30   */
31  public class RemoteRepositories
32      extends DataType
33      implements RemoteRepositoryContainer
34  {
35  
36      private List<RemoteRepositoryContainer> containers = new ArrayList<RemoteRepositoryContainer>();
37  
38      protected RemoteRepositories getRef()
39      {
40          return (RemoteRepositories) getCheckedRef();
41      }
42  
43      public void validate( Task task )
44      {
45          if ( isReference() )
46          {
47              getRef().validate( task );
48          }
49          else
50          {
51              for ( RemoteRepositoryContainer container : containers )
52              {
53                  container.validate( task );
54              }
55          }
56      }
57  
58      public void setRefid( Reference ref )
59      {
60          if ( !containers.isEmpty() )
61          {
62              throw noChildrenAllowed();
63          }
64          super.setRefid( ref );
65      }
66  
67      public void addRemoterepo( RemoteRepository repository )
68      {
69          checkChildrenAllowed();
70          containers.add( repository );
71      }
72  
73      public void addRemoterepos( RemoteRepositories repositories )
74      {
75          checkChildrenAllowed();
76          if ( repositories == this )
77          {
78              throw circularReference();
79          }
80          containers.add( repositories );
81      }
82  
83      public List<RemoteRepository> getRepositories()
84      {
85          if ( isReference() )
86          {
87              return getRef().getRepositories();
88          }
89          List<RemoteRepository> repos = new ArrayList<RemoteRepository>();
90          for ( RemoteRepositoryContainer container : containers )
91          {
92              repos.addAll( container.getRepositories() );
93          }
94          return repos;
95      }
96  
97  }