⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 containerbuilderfactory.java

📁 一个非常好的FRAMWRK!是一个外国组织做的!不!
💻 JAVA
字号:
/*
 * Copyright 2003-2005 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 com.jdon.container.factory;

import javax.servlet.ServletContext;

import com.jdon.container.ContainerWrapper;
import com.jdon.container.builder.ContainerBuilder;
import com.jdon.container.builder.DefaultContainerBuilder;
import com.jdon.container.config.ContainerComponents;
import com.jdon.util.Debug;

/**
 * fetch the all components configures, and create
 * ContainerBuilder Instance.
 * 
 * @author <a href="mailto:banqiao@jdon.com">banq</a>
 *
 */
public class ContainerBuilderFactory {
    public final static String module = ContainerBuilderFactory.class.getName();
    
    private static final String DEFAULT_CONTAINER_CONFIGURE_FILENAME = "container.xml";
    private static final String DEFAULT_ASPECT_CONFIGURE_FILENAME = "aspect.xml";    

    private static final String USER_CONTAINER_CONFIGURE_FILENAME = "mycontainer.xml";
    private static final String USER_ASPECT_CONFIGURE_FILENAME = "myaspect.xml";    
    
    
    private static final String CONTAINER_CONFIG_PARAM = "containerConfigure";    
    private static final String ASPECT_CONFIG_PARAM = "aspectConfigure";    
    
    /**
     * the main method in this class,
     * read all components include interceptors from Xml configure file.
     * 
     * create a micro container instance.
     * and then returen  a ContainerBuilder instance
     * 
     * @param context
     * @return
     */
    public ContainerBuilder createContainerBuilder(ServletContext context){
        ContainerFactory containerFactory = new ContainerFactory();
        ContainerComponents configComponents = fetchContainerConfig(context);
        ContainerComponents aspectConfigComponents = fecthAspectConfig(context);
    		
    		ContainerWrapper cw = containerFactory.create();
    		return new DefaultContainerBuilder(cw, configComponents, aspectConfigComponents);
    }
    
    /**
     * read the configure from container.xml/ServletContext initParameter/mycontainer.xml 
     * @param context
     * @return
     */
    private ContainerComponents fetchContainerConfig(ServletContext context){
        ContainerFactory containerFactory = new ContainerFactory();
        Debug.logVerbose(" 1. read container components from:" + DEFAULT_CONTAINER_CONFIGURE_FILENAME, module);        
        ContainerComponents configComponents = containerFactory.fetchBasicComponents(DEFAULT_CONTAINER_CONFIGURE_FILENAME);
        //read the configure in web.xml
        String container_configFile = context.getInitParameter(CONTAINER_CONFIG_PARAM);    		
    		if (container_configFile != null){
    		    Debug.logVerbose(" 2. read container components from:" + container_configFile, module);
    		    ContainerComponents appconfigComponents = containerFactory.fetchBasicComponents(container_configFile);
            configComponents.addComponents(appconfigComponents.getComponents());
    		}
    		
    		//read user fraemwork's configure
    		Debug.logVerbose(" 3. read container components from:" + USER_CONTAINER_CONFIGURE_FILENAME, module);    		
    		ContainerComponents userconfigComponents = containerFactory.fetchBasicComponents(USER_CONTAINER_CONFIGURE_FILENAME);    	
    		configComponents.addComponents(userconfigComponents.getComponents());
    		
    		return configComponents;
    }
    
    /**
     * read the configure from aspect.xml /ServletContext initParameter/myaspect.xml 
     * @param context
     * @return
     */
    private ContainerComponents fecthAspectConfig(ServletContext context){
        ContainerFactory containerFactory = new ContainerFactory();
        
    		//read user fraemwork's configure    		
    		Debug.logVerbose("1. read apspect interceptors from:" + USER_ASPECT_CONFIGURE_FILENAME, module);    		
    		ContainerComponents aspectConfigComponents = containerFactory.fetchAspectComponents(USER_ASPECT_CONFIGURE_FILENAME);
    		
        String aspect_configFile = context.getInitParameter(ASPECT_CONFIG_PARAM);
    		if (aspect_configFile == null){
    		    Debug.logVerbose("2. read apspect interceptors from:" + aspect_configFile, module);
        		ContainerComponents appaspectConfigComponents2 = containerFactory.fetchAspectComponents(aspect_configFile);
        		aspectConfigComponents.addComponents(appaspectConfigComponents2.getComponents());
    		}  		  
        
        Debug.logVerbose(" 3. read apspect interceptors from:" + DEFAULT_ASPECT_CONFIGURE_FILENAME, module);
        ContainerComponents aspectConfigComponents3  =containerFactory.fetchAspectComponents(DEFAULT_ASPECT_CONFIGURE_FILENAME);
        aspectConfigComponents.addComponents(aspectConfigComponents3.getComponents());    		    	    		
    		
    		
    		Debug.logVerbose(" aspectConfigComponents size:" + aspectConfigComponents.size(), module);    
    		return aspectConfigComponents;
        
    }
    
    public ContainerBuilder createContainerBuilder(String container_configFile, String aspect_configFile){    		
        ContainerFactory containerFactory = new ContainerFactory();
        ContainerWrapper cw = containerFactory.create();
        
        ContainerComponents configComponents = containerFactory.fetchBasicComponents(container_configFile);
        ContainerComponents aspectConfigComponents = containerFactory.fetchAspectComponents(aspect_configFile);     
        
        return new DefaultContainerBuilder(cw, configComponents, aspectConfigComponents);
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -