net.hasor.dataql.Finder Maven / Gradle / Ivy
/*
* Copyright 2008-2009 the original author or authors.
*
* 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 net.hasor.dataql;
import net.hasor.utils.ExceptionUtils;
import net.hasor.utils.ResourcesUtils;
import java.io.IOException;
import java.io.InputStream;
/**
* 资源加载器
* @author 赵永春 ([email protected])
* @version : 2019-12-11
*/
public interface Finder {
public static final Finder DEFAULT = new Finder() {
};
/** 负责处理 import @"/net/hasor/demo.ql" as demo;
方式中 ‘/net/hasor/demo.ql’ 资源的加载 */
public default InputStream findResource(String resourceName) throws IOException {
// .加载资源
InputStream inputStream = null;
try {
inputStream = ResourcesUtils.getResourceAsStream(resourceName);
} catch (Exception e) {
throw ExceptionUtils.toRuntimeException(e, throwable -> new RuntimeException("import compiler failed -> '" + resourceName + "' not found.", throwable));
}
return inputStream;
}
/** 负责处理 import 'net.hasor.dataql.sdk.CollectionUdfSource' as collect;
方式的资源的加载。 */
public default Object findBean(Class> beanType) {
try {
return beanType.newInstance();
} catch (Exception e) {
throw ExceptionUtils.toRuntimeException(e, throwable -> new RuntimeException("load Bean failed -> '" + beanType.getName(), throwable));
}
}
public default FragmentProcess findFragmentProcess(String fragmentType) {
throw new RuntimeException(fragmentType + " fragment undefine.");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy