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.container.cooldeploy;
17  
18  import java.io.IOException;
19  import java.net.URL;
20  
21  import org.seasar.framework.container.cooldeploy.CoolComponentAutoRegister;
22  import org.seasar.framework.convention.NamingConvention;
23  import org.seasar.framework.util.URLUtil;
24  import org.seasar.framework.util.ClassTraversal.ClassHandler;
25  import org.seasar.uruma.core.UrumaMessageCodes;
26  import org.seasar.uruma.log.UrumaLogger;
27  import org.seasar.uruma.rcp.util.RcpResourceUtil;
28  
29  /**
30   * Uruma COOL deploy用の {@link NamingConvention}に一致するコンポーネントを自動登録するクラスです。
31   * 
32   * @author y.sugigami
33   * 
34   */
35  public class UrumaCoolComponentAutoRegister extends CoolComponentAutoRegister
36          implements ClassHandler, UrumaMessageCodes {
37      private static final UrumaLogger logger = UrumaLogger
38              .getLogger(UrumaCoolComponentAutoRegister.class);
39  
40      /**
41       * 自動登録を行います。
42       */
43      @Override
44      public void registerAll() {
45          final String[] rootPackageNames = getNamingConvention()
46                  .getRootPackageNames();
47          if (rootPackageNames != null) {
48              for (int i = 0; i < rootPackageNames.length; ++i) {
49                  final String rootDir = rootPackageNames[i].replace('.', '/');
50                  try {
51                      URL localUrl = RcpResourceUtil.getLocalResourceUrl(rootDir);
52                      if (localUrl != null) {
53                          final Strategy strategy = getStrategy(URLUtil
54                                  .toCanonicalProtocol(localUrl.getProtocol()));
55                          strategy.registerAll(rootDir, localUrl);
56                      } else {
57                          logger.log(COOLDEPLOY_PACKAGE_NOT_FOUND, rootDir);
58                      }
59                  } catch (IOException ex) {
60                      logger.log(COOLDEPLOY_PACKAGE_NOT_FOUND, rootDir);
61                  }
62              }
63          }
64          registerdClasses.clear();
65      }
66  }