Package net.hasor.core

Examples of net.hasor.core.Environment


* @author 赵永春 (zyc@byshell.org)
*/
@Plugin
public class ListenerPlugin implements Module  {
    public void loadModule(ApiBinder apiBinder) throws Throwable {
        final Environment env = apiBinder.getEnvironment();
        final Set<Class<?>> eventSet = env.findClass(Listener.class);
        if (eventSet == null || eventSet.isEmpty())
            return;
        for (final Class<?> eventClass : eventSet) {
            /*排除没有实现 EventListener 接口的类。*/
            if (EventListener.class.isAssignableFrom(eventClass) == false) {
View Full Code Here


        return new StandardEnvironment(this.mainSettings);
    }
    //
    protected void doInitialize() throws Throwable {
        //1.预先加载Module
        Environment env = this.getEnvironment();
        boolean loadModule = env.getSettings().getBoolean("hasor.modules.loadModule");
        if (loadModule) {
            XmlNode[] xmlNodes = env.getSettings().getXmlNodeArray("hasor.modules.module");
            if (xmlNodes != null) {
                for (XmlNode node : xmlNodes) {
                    String moduleTypeString = node.getAttribute("class");
                    if (StringUtils.isBlank(moduleTypeString)) {
                        continue;
View Full Code Here

public class EnvironmentVariablesTest {
    @Test
    public void environmentVariablesTest() throws Exception {
        System.out.println("--->>environmentVariablesTest<<--");
        AppContext appContext = Hasor.createAppContext();
        Environment env = appContext.getEnvironment();
        //
        //JAVA_HOME
        System.out.println(env.getEnvVar("JAVA_HOME"));
        //HASOR_WORK_HOME,该环境变量由 hasor 的配置文件提供,仅在Hasor框架内有效
        System.out.println(env.getEnvVar("HASOR_WORK_HOME"));
        //javac.exe
        System.out.println(env.evalString("%JAVA_HOME%/bin/javac.exe"));
    }
View Full Code Here

    @Test
    public void systemVariablesTest() throws Exception {
        System.out.println("--->>systemVariablesTest<<--");
        //
        AppContext appContext = Hasor.createAppContext();
        Environment env = appContext.getEnvironment();
        //
        //设置属性
        System.setProperty("MyVar", "hello");
        env.refreshVariables();/*刷新变量列表*/
        System.out.println(env.getEnvVar("MyVar"));
        System.out.println(env.evalString("i say %MyVar%."));
    }
View Full Code Here

@Plugin
public class SettingsPlugin implements Module {
    public void loadModule(ApiBinder apiBinder) {
        this.loadAnnoSettings(apiBinder);
        //
        final Environment env = apiBinder.getEnvironment();
        apiBinder.pushListener(ContextEvent_Started, new EventListener() {
            public void onEvent(String event, Object[] params) {
                AppContext appContext = (AppContext) params[0];
                List<Provider<SettingsListener>> settingProvider = appContext.findBindingProvider(SettingsListener.class);
                if (settingProvider == null)
                    return;
                for (Provider<SettingsListener> provider : settingProvider) {
                    SettingsListener target = provider.get();
                    target.reload(appContext.getSettings());
                    env.addSettingsListener(target);
                    Hasor.logInfo("%s SettingsListener created.", target);
                }
            }
        });
    }
View Full Code Here

            }
        });
    }
    /**装载注解形式的SettingsListener*/
    private void loadAnnoSettings(ApiBinder apiBinder) {
        final Environment env = apiBinder.getEnvironment();
        Set<Class<?>> settingSet = env.findClass(Settings.class);
        if (settingSet == null || settingSet.isEmpty())
            return;
        for (Class<?> settingClass : settingSet) {
            if (SettingsListener.class.isAssignableFrom(settingClass) == false) {
                Hasor.logWarn("not implemented SettingsListener :%s", settingClass);
View Full Code Here

*/
@Plugin()
public class ResourcePlugin extends WebModule {
    public void loadModule(WebApiBinder apiBinder) {
        //1.准备参数
        Environment env = apiBinder.getEnvironment();
        //3.缓存路径
        String cacheSubPath = "%HASOR_PLUGIN_PATH%/net.hasor.web.resource/";
        File cacheDir = new File(env.evalString(cacheSubPath));
        if (!chekcCacheDir(cacheDir)) {
            int i = 0;
            while (true) {
                cacheDir = new File(env.evalString(cacheSubPath + "_" + String.valueOf(i)));;
                if (chekcCacheDir(cacheDir))
                    break;
            }
        }
        ResourceHttpServlet.initCacheDir(cacheDir);
View Full Code Here

TOP

Related Classes of net.hasor.core.Environment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.