001/*
002 * Copyright (c) 2004-2012, Willem Cazander
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification, are permitted provided
006 * that the following conditions are met:
007 * 
008 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the
009 *   following disclaimer.
010 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
011 *   the following disclaimer in the documentation and/or other materials provided with the distribution.
012 * 
013 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
015 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
016 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
018 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
019 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
020 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
021 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
022 */
023
024package org.x4o.xml.core;
025
026/**
027 * Defines the different phases of the x4o xml parser.
028 * 
029 * @author Willem Cazander
030 * @version 1.0 Sep 1, 2008
031 */
032public enum X4OPhase {
033        
034        /** Defines this meta startup phase. */
035        startupX4OPhase(true),
036        
037        /** Load all meta info of the language we are creating. */
038        createLanguagePhase(true),
039        
040        /** Load all siblings languages.  */
041        createLanguageSiblingsPhase(true),
042        
043        /** Parse the xml from sax events. */
044        parseSAXStreamPhase(true),
045        
046        /** Optional extra config phase for injecting bean instances into the EL context. */
047        configGlobalElBeansPhase(true),
048        
049        /** emty meta phase to refer to that sax is ready and element s are waiting for processing. */
050        startX4OPhase(true),
051        
052        /** re runnable phases which config xml to beans and binds them together. */
053        configElementPhase,
054        configElementInterfacePhase,
055        configGlobalElementPhase,
056        configGlobalAttributePhase,
057        
058        /** Fill the bean attributes from the Element xml attributes. */
059        runAttributesPhase,
060        
061        /** Fill in the x4o templating objects. */
062        fillTemplatingPhase,
063        
064        /** transform phase , modifies the Element Tree. */
065        transformPhase,
066        
067        /** Run the phases which needs to be runned again from a phase. */
068        runDirtyElementPhase(true),
069        
070        /** Binds objects together */
071        bindElementPhase,
072        
073        /** Run action stuff, we are ready with it. */
074        runPhase(true),
075        
076        /** Rerun all needed phases for all element that requested it. */
077        runDirtyElementLastPhase,
078        
079        /** Releases all Elements, which clears attributes and childeren etc. */
080        releasePhase(true),
081        
082        /** write all phases and stuff to debug sax stream. */
083        debugPhase;
084        
085        /** Defines which phase we start, when context is created. */
086        public static final X4OPhase FIRST_PHASE = startupX4OPhase;
087        
088        /** The order in which the phases are executed */
089        static final X4OPhase[] PHASE_ORDER = { startupX4OPhase,
090                                                                                                createLanguagePhase,createLanguageSiblingsPhase,
091                                                                                                parseSAXStreamPhase,configGlobalElBeansPhase,
092                                                                                        startX4OPhase,
093                                                                                                configElementPhase,configElementInterfacePhase,configGlobalElementPhase,
094                                                                                                configGlobalAttributePhase,runAttributesPhase,fillTemplatingPhase,
095                                                                                                transformPhase,runDirtyElementPhase,bindElementPhase,
096                                                                                                runPhase,runDirtyElementLastPhase,
097                                                                                        releasePhase
098                                                                                        };
099        
100        /** Boolean indicating that this phase only may be run'ed once. */
101        private boolean runOnce = false;
102        
103        /**
104         * Creates an X4O Phase.
105         */
106        private X4OPhase() {
107        }
108        
109        /**
110         * Creates an X4O Phase
111         * @param runOnce       Flag indicating that this phase is runnable multiple times.
112         */
113        private X4OPhase(boolean runOnce) {
114                this.runOnce=runOnce;
115        }
116        
117        /**
118         * Returns a flag indicating that this phase is runnable multiple times.
119         * @return      True if phase is restricted to run once.
120         */
121        public boolean isRunOnce() {
122                return runOnce;
123        }
124}