View Javadoc

1   package org.apache.continuum.buildagent.buildcontext.manager;
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.apache.continuum.buildagent.buildcontext.BuildContext;
23  
24  import java.util.ArrayList;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  /**
30   * @author Jan Steven Ancajas
31   * @plexus.component role="org.apache.continuum.buildagent.buildcontext.manager.BuildContextManager" role-hint="default"
32   */
33  public class DefaultBuildContextManager
34      implements BuildContextManager
35  {
36      public Map<Integer, BuildContext> buildContexts;
37  
38      public BuildContext getBuildContext( int projectId )
39      {
40          if ( buildContexts != null )
41          {
42              return buildContexts.get( projectId );
43          }
44  
45          return null;
46      }
47  
48      public List<BuildContext> getBuildContexts()
49      {
50          List<BuildContext> bContexts = new ArrayList<BuildContext>();
51  
52          if ( buildContexts != null )
53          {
54              bContexts.addAll( buildContexts.values() );
55          }
56  
57          return bContexts;
58      }
59  
60      public void addBuildContexts( List<BuildContext> buildContextList )
61      {
62          if ( buildContexts == null )
63          {
64              buildContexts = new HashMap<Integer, BuildContext>();
65          }
66  
67          for ( BuildContext buildContext : buildContextList )
68          {
69              buildContexts.put( buildContext.getProjectId(), buildContext );
70          }
71      }
72  
73      public void removeBuildContext( int projectId )
74      {
75          BuildContext buildContext = getBuildContext( projectId );
76  
77          if ( buildContext != null )
78          {
79              buildContexts.remove( buildContext );
80          }
81      }
82  }