View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  
21  package org.apache.directory.api.util;
22  
23  
24  import java.util.Arrays;
25  import java.util.Collections;
26  import java.util.LinkedList;
27  import java.util.List;
28  
29  import org.apache.directory.api.i18n.I18n;
30  
31  
32  /**
33   * Abstract implementation of a components monitor.
34   *
35   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36   */
37  public abstract class AbstractSimpleComponentsMonitor implements ComponentsMonitor
38  {
39  
40      /** The components. */
41      private List<String> components;
42  
43  
44      /**
45       * Instantiates a new abstract simple components monitor.
46       *
47       * @param components the components
48       */
49      public AbstractSimpleComponentsMonitor( String[] components )
50      {
51          // register components
52          this.components = new LinkedList<String>( Arrays.asList( components ) );
53      }
54  
55  
56      /**
57       * {@inheritDoc}
58       */
59      public ComponentsMonitor useComponent( String component )
60      {
61          if ( !components.remove( component ) )
62          {
63              throw new IllegalArgumentException( I18n.err( I18n.ERR_04336, component ) );
64          }
65  
66          return this;
67      }
68  
69  
70      /**
71       * {@inheritDoc}
72       */
73      public boolean allComponentsUsed()
74      {
75          return components.isEmpty();
76      }
77  
78  
79      /**
80       * {@inheritDoc}
81       */
82      public List<String> getRemainingComponents()
83      {
84          return Collections.unmodifiableList( components );
85      }
86  
87  }