Package mfinder.impl

Examples of mfinder.impl.DefaultActionFactory


     * 测试加载配置文件。
     */
    @Test
    public void test_load() {
        config = new Configuration();
        DefaultActionFactory factory = config.load(this.getClass().getResourceAsStream("/mfinder_test.xml")).getFactory();
        assertNotNull(factory);
        assertNotNull(factory.getActionInvocationClass());
        assertEquals("empty", factory.getDefaultInterceptorStack());
        assertEquals("empty", factory.getDefaultResultType());
        assertEquals(".", factory.getExtension());
    }
View Full Code Here


    private ObjectFactory objectFactory;

    @Before
    public void setUp() {
        //create ActionFactory not by springframework
        factory = new DefaultActionFactory();

        //SpringObjectFactory
        objectFactory = new SpringObjectFactory(context);
        factory.setObjectFactory(objectFactory);
View Full Code Here

        if (configLocation != null) {
            logger.info("Load configuration : " + configLocation.getURL());
            this.actionFactory = new Configuration().load(configLocation.getInputStream()).getFactory();
        } else {
            this.actionFactory = actionFactoryClass == null
                    ? new DefaultActionFactory()
                    : actionFactoryClass.newInstance();
        }
        afterActionFactoryCreation(actionFactory);

        this.actionFactory = buildActionFactory();
View Full Code Here

     * @throws Exception 如果初始化失败。
     */
    protected ActionFactory buildActionFactory() throws Exception {
        logger.info("Building MFinder ActionFactory [{}]", actionFactory.getClass().getName());
        if (actionFactory instanceof DefaultActionFactory) {
            DefaultActionFactory defaultFactory = (DefaultActionFactory) this.actionFactory;

            //set object factory, default use spring object facrtory
            defaultFactory.setObjectFactory(objectFactory == null
                    ? new SpringObjectFactory(applicationContext)
                    : objectFactory);

            if (StringUtil.isNotNull(defaultInterceptorStack))
                defaultFactory.setDefaultInterceptorStack(defaultInterceptorStack);
            if (StringUtil.isNotNull(defaultResultType))
                defaultFactory.setDefaultResultType(defaultResultType);
            if (actionInvocationClass != null)
                defaultFactory.setActionInvocationClass(actionInvocationClass);

            defaultFactory.setExtension(extension);
            if (actionCacheNumber > 0)
                defaultFactory.setActionCacheNumber(actionCacheNumber);

            if (interceptors != null) {
                for (Object obj : interceptors) {
                    defaultFactory.addInterceptors(
                            obj instanceof String
                            ? Class.forName((String) obj)
                            : obj);
                }
            }
            if (interceptorStacks != null) {
                for (Object obj : interceptorStacks) {
                    defaultFactory.addInterceptorStacks(
                            obj instanceof String
                            ? Class.forName((String) obj)
                            : obj);
                }
            }
            if (resultTypes != null) {
                for (Object obj : resultTypes) {
                    defaultFactory.addResultTypes(
                            obj instanceof String
                            ? Class.forName((String) obj)
                            : obj);
                }
            }
            if (results != null) {
                for (Object obj : results) {
                    defaultFactory.addResults(
                            obj instanceof String
                            ? Class.forName((String) obj)
                            : obj);
                }
            }
            if (actions != null) {
                for (Object obj : actions) {
                    defaultFactory.addActions(
                            obj instanceof String
                            ? Class.forName((String) obj)
                            : obj);
                }
            }
View Full Code Here

            if ((length = list.size()) == 1) {
                Element e = list.get(0);
                String cls = e.getAttribute(CLASS);
                //create ActionFactory
                factory = StringUtil.isNull(cls)
                        ? new DefaultActionFactory()
                        : (ActionFactory) Class.forName(cls).newInstance();

                //action factory's properties
                list = getChildNodesByTagName(e, PROPERTY);
                //inject factory's properties
                setProperties(factory, list);
            } else if (length > 1) {
                throw new ConfigurationException("More than one <" + ACTION_FACTORY + "> tag in setting.", null);
            }

            //adapt for 1.0
            /*
            if (factory == null) {
            //constant
            list = doc.getElementsByTagName(CONSTANT);
            length = list.getLength();
            if (length > 0) {
            LOG.warn("Deprecated tag <" + CONSTANT + ">, use <" + ACTION_FACTORY + "> instead.");
            } else {
            //factory = new DefaultActionFactory();
            for (int i = 0; i < length; i++) {
            e = (Element) list.item(i);
            String name = e.getAttribute(NAME);
            //加载常量
            String val = e.getAttribute(VALUE);
            if (StringUtil.isNotNull(val)) {
            variables.put(name, val);
            } else {
            String cls = e.getAttribute(CLASS);
            if (StringUtil.isNotNull(cls)) {
            variables.put(name, cls);
            }
            }
            }
            String prop = variables.get("ActionFactory");
            //create ActionFactory
            factory = StringUtil.isNull(prop)
            ? new DefaultActionFactory()
            : (ActionFactory) Class.forName(prop).newInstance();

            //set properties for ActionFactory
            prop = variables.get("DefaultInterceptorStack");
            if (StringUtil.isNotNull(prop))
            factory.setDefaultInterceptorStack(prop);
            prop = variables.get("DefaultResultType");
            if (StringUtil.isNotNull(prop))
            factory.setDefaultResultType(prop);
            }
            }
             */
            //if no ActionFactory setting
            if (factory == null)
                factory = new DefaultActionFactory();
            //give subclasses a chance to prepare factory
            afterActionFactoryCreation(factory);

            printSeparator(!list.isEmpty());

View Full Code Here

     * @throws InstantiationException 如果实例化失败。
     */
    private void addActionFactoryProperties(Element root) throws ClassNotFoundException,
            IllegalAccessException, IntrospectionException, InvocationTargetException {
        if (factory instanceof DefaultActionFactory) {
            DefaultActionFactory defaultFactory = (DefaultActionFactory) this.factory;
            List<Element> list = null;
            //interceptor
            list = getChildNodesByTagName(root, INTERCEPTOR);
            for (Element e : list) {
                //System.out.println(e.getAttribute(CLASS));
                Object obj = factory.getObjectFactory().newInstance(Class.forName(e.getAttribute(CLASS)));
                //set property nodes
                setProperties(obj, getChildNodesByTagName(e, PROPERTY));
                //add interceptor
                defaultFactory.addInterceptors(obj);
            }

            printSeparator(!list.isEmpty());

            //interceptor-stack
            list = getChildNodesByTagName(root, INTERCEPTOR_STACK);
            for (Element e : list) {
                //System.out.println(INTERCEPTOR_STACK + " : " + e.getAttribute(CLASS));
                //add interceptor stacks
                defaultFactory.addInterceptorStacks(factory.getObjectFactory().newInstance(Class.forName(e.getAttribute(CLASS))));
            }

            printSeparator(!list.isEmpty());

            //result-type
            list = getChildNodesByTagName(root, RESULT_TYPE);
            for (Element e : list) {
                Object obj = factory.getObjectFactory().newInstance(Class.forName(e.getAttribute(CLASS)));
                //set property nodes
                setProperties(obj, getChildNodesByTagName(e, PROPERTY));
                //add result types
                defaultFactory.addResultTypes(obj);
            }

            printSeparator(!list.isEmpty());

            //result
            list = getChildNodesByTagName(root, RESULT);
            for (Element e : list) {
                //add results
                Object obj = factory.getObjectFactory().newInstance(Class.forName(e.getAttribute(CLASS)));
                //set property nodes
                setProperties(obj, getChildNodesByTagName(e, PROPERTY));
                defaultFactory.addResults(obj);
            }

            printSeparator(!list.isEmpty());

            //action
            list = getChildNodesByTagName(root, ACTION);
            for (Element action : list) {
                //System.out.println(e.getAttribute(CLASS));
                Object obj = factory.getObjectFactory().newInstance(Class.forName(action.getAttribute(CLASS)));

                //action <property> nodes
                List<Element> propnodes = getChildNodesByTagName(action, PROPERTY);

                //common class properties
                Map<String, PropertyDescriptor> supports = Injector.getSupportedProperties(obj.getClass());

                //待注入相应class的Action属性列表
                Map<String, Injection> classInjections = getInjections(propnodes, obj, supports);

                //properties for action class
                if (classInjections.size() > 0) {
                    Injector.putClassProperties(obj.getClass(), classInjections.values().toArray(new Injection[classInjections.size()]));
                    //Action对象属性注入
                    Injector.injectObject(obj);
                }

                //<path> nodes
                List<Element> pathnodes = getChildNodesByTagName(action, PATH);
                for (Element path : pathnodes) {
                    //path <property> nodes
                    propnodes = getChildNodesByTagName(path, PROPERTY);
                    //待注入相应path的Action属性列表
                    Map<String, Injection> pathInjections = getInjections(propnodes, obj, supports);
                    if (pathInjections.size() > 0) {
                        //属性包含class注入属性和path注入属性
                        Map<String, Injection> allInjections = new LinkedHashMap<String, Injection>(classInjections.size() + pathInjections.size());
                        allInjections.putAll(classInjections);
                        allInjections.putAll(pathInjections);
                        //System.out.println(path.getAttribute(NAME) + "," + allInjections);
                        Injector.putActionProperties(path.getAttribute(NAME), allInjections.values().toArray(new Injection[allInjections.size()]));
                    }
                }
                //add actions
                defaultFactory.addActions(obj);
            }
            printSeparator(!list.isEmpty());
        }
    }
View Full Code Here

TOP

Related Classes of mfinder.impl.DefaultActionFactory

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.