View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.component.factory.desc;
17  
18  import java.io.InputStream;
19  import java.net.URL;
20  
21  import org.seasar.uruma.util.resource.ResourceHandler;
22  import org.seasar.uruma.util.resource.ResourceTraverser;
23  import org.seasar.uruma.util.resource.ResourceTraverserFactory;
24  import org.seasar.uruma.util.resource.impl.ExtResourceFilter;
25  
26  /**
27   * コンポーネント・ディスクリプタを検索するためのクラスです。<br />
28   * 
29   * @author y-komori
30   */
31  public class ComponentDescriptorFinder implements ResourceHandler {
32      public void findComponentDescriptors(final ClassLoader loader) {
33          URL root = loader.getResource("");
34          URL origin = loader.getResource("components");
35          ResourceTraverser traverser = ResourceTraverserFactory
36                  .getResourceTraverser(origin);
37          ExtResourceFilter filter = new ExtResourceFilter("ucd");
38          traverser.traverse(root, origin, this, filter);
39      }
40  
41      public void handle(final String rootPath, final String path,
42              final InputStream is) {
43          System.out.println(rootPath + " " + path);
44      }
45  
46      public static void main(final String[] args) {
47          ComponentDescriptorFinder finder = new ComponentDescriptorFinder();
48          finder.findComponentDescriptors(finder.getClass().getClassLoader());
49      }
50  
51  }