/* * Copyright 2004-2007 the Seasar Foundation and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.seasar.framework.container.factory; import java.io.InputStream; import org.seasar.framework.container.S2Container; import org.seasar.framework.exception.ResourceNotFoundRuntimeException; /** * S2ContainerBuilderrの抽象クラスです。 * *
* 特定の形式の定義情報から{@link org.seasar.framework.container.S2Container S2コンテナ} * を組み立てるビルダです。 *
* * @author koichk * @author n-sega */ public abstract class AbstractS2ContainerBuilder implements S2ContainerBuilder { /** * * プロパティresourceResolver
のための定数アノテーションです。
*/
public static final String resourceResolver_BINDING = "bindingType=may";
/**
* クラスパス経由でのリソースの取得方法{@link ResourceResolver ResourceResolver}を構築します。
*/
protected ResourceResolver resourceResolver = new ClassPathResourceResolver();
/**
* リソースの取得方法{@link ResourceResolver ResourceResolver}を取得します。
*
* @return resourceResolver
* リソースの取得方法
*/
public ResourceResolver getResourceResolver() {
return resourceResolver;
}
/**
* リソースの取得方法{@link ResourceResolver ResourceResolver}を設定します。
*
* @param resolver
* リソースの取得方法
*
*/
public void setResourceResolver(final ResourceResolver resolver) {
resourceResolver = resolver;
}
/**
* 指定された設定ファイルから指定されたクラスローダを使用してS2コンテナを組み立てます。
*
* @param path
* 設定ファイルのパス
* @param classLoader
* S2コンテナを組み立てるのに使用するクラスローダ
* @return S2コンテナ
*/
public S2Container build(final String path, final ClassLoader classLoader) {
final ClassLoader oldLoader = Thread.currentThread()
.getContextClassLoader();
try {
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
}
return build(path);
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
/**
* 読み込み対象となるリソースから入力ストリームを返します。
*
* @param path
* 読み込み対象となるリソースのパス
* @return is
* 入力ストリーム
*/
protected InputStream getInputStream(final String path) {
final InputStream is = resourceResolver.getInputStream(path);
if (is == null) {
throw new ResourceNotFoundRuntimeException(path);
}
return is;
}
}