View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.impl.enhancer.util;
18  
19  import java.util.List;
20  import java.util.Iterator;
21  
22  import java.io.PrintWriter;
23  import java.io.InputStream;
24  
25  
26  
27  /***
28   * Searches resources among a set of files.
29   */
30  public class CombinedResourceLocator
31      extends ResourceLocatorBase
32      implements ResourceLocator
33  {
34      /***
35       * List of resource locators.
36       */
37      final List locators;
38  
39      /***
40       * Creates an intsance.
41       */
42      public CombinedResourceLocator(PrintWriter out,
43                                     boolean verbose,
44                                     List locators)
45      {
46          super(out, verbose);
47          affirm(locators != null);
48          this.locators = locators;
49      }
50      
51      /***
52       * Finds a resource with a given name.
53       */
54      public InputStream getInputStreamForResource(String resourceName)
55      {
56          affirm(resourceName != null);
57  
58          for (Iterator i = locators.iterator(); i.hasNext();) {
59              final ResourceLocator locator = (ResourceLocator)i.next();
60              affirm(locator != null);
61              final InputStream stream
62                  = locator.getInputStreamForResource(resourceName);
63              if (stream != null) {
64                  return stream;
65              }
66          }
67          return null;
68      }
69  }