Moved phase ids to the seperated phase classes.

This commit is contained in:
Willem Cazander 2014-03-07 16:06:10 +01:00
parent cad493bc69
commit a3863c1637
11 changed files with 85 additions and 72 deletions

View file

@ -47,6 +47,7 @@ import org.x4o.xml.lang.X4OLanguageSession;
import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.phase.X4OPhase;
import org.x4o.xml.lang.phase.X4OPhaseException;
import org.x4o.xml.lang.phase.X4OPhaseLanguageWrite;
import org.x4o.xml.lang.phase.X4OPhaseType;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -102,7 +103,7 @@ public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> {
*/
public void writeSession(X4OLanguageSession languageSession,OutputStream output) throws X4OConnectionException,SAXException,IOException {
setProperty(OUTPUT_STREAM, output);
addPhaseSkip(X4OPhase.WRITE_RELEASE);
addPhaseSkip(X4OPhaseLanguageWrite.WRITE_RELEASE);
try {
languageSession.getLanguage().getPhaseManager().runPhases(languageSession, X4OPhaseType.XML_WRITE);
} catch (X4OPhaseException e) {

View file

@ -33,6 +33,7 @@ import java.util.logging.Logger;
import org.x4o.xml.eld.EldDriver;
import org.x4o.xml.eld.EldModuleLoader;
import org.x4o.xml.lang.phase.X4OPhaseLanguageInit;
import org.x4o.xml.lang.phase.X4OPhaseLanguageInit.X4OPhaseInitLanguageSiblings;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
@ -135,8 +136,8 @@ TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
}
loadModule(languageLocal,loader,value,versionedResources);
if (loader instanceof X4OLanguageModuleLoaderSibling) {
X4OPhaseInitLanguageSiblings sibPhase = (X4OPhaseInitLanguageSiblings)languageLocal.getPhaseManager().getPhase("INIT_LANG_SIB");
// mmm
X4OPhaseInitLanguageSiblings sibPhase = (X4OPhaseInitLanguageSiblings)languageLocal.getPhaseManager().getPhase(X4OPhaseLanguageInit.INIT_LANG_SIB);
sibPhase.addLanguageModuleLoaderSibling((X4OLanguageModuleLoaderSibling)loader);
}
}

View file

@ -209,11 +209,11 @@ PHASE_ORDER = { *startupX4OPhase,
public void doReleasePhaseManual(X4OLanguageSession languageSession) throws X4OPhaseException {
List<String> phaseSkip = languageSession.getPhaseSkip();
String releaseRequested = null;
if (phaseSkip.contains(X4OPhase.READ_RELEASE)) {
releaseRequested = X4OPhase.READ_RELEASE;
if (phaseSkip.contains(X4OPhaseLanguageRead.READ_RELEASE)) {
releaseRequested = X4OPhaseLanguageRead.READ_RELEASE;
}
if (phaseSkip.contains(X4OPhase.WRITE_RELEASE)) {
releaseRequested = X4OPhase.WRITE_RELEASE;
if (phaseSkip.contains(X4OPhaseLanguageWrite.WRITE_RELEASE)) {
releaseRequested = X4OPhaseLanguageWrite.WRITE_RELEASE;
}
if (releaseRequested==null) {
throw new IllegalStateException("No manual release requested.");

View file

@ -36,17 +36,6 @@ import org.x4o.xml.lang.X4OLanguageSession;
*/
public interface X4OPhase {
public final static String INIT_BEGIN = "INIT_BEGIN";
public final static String INIT_END = "INIT_END";
public final static String READ_BEGIN = "READ_BEGIN";
public final static String READ_END = "READ_END";
public final static String READ_RELEASE = "READ_RELEASE";
public final static String WRITE_BEGIN = "WRITE_BEGIN";
public final static String WRITE_END = "WRITE_END";
public final static String WRITE_RELEASE = "WRITE_RELEASE";
X4OPhaseType getType();
/**

View file

@ -42,6 +42,10 @@ import org.x4o.xml.lang.X4OLanguageLocal;
public class X4OPhaseLanguageInit {
private Logger logger = null;
public static final String INIT_START = "INIT_START";
public static final String INIT_LANG = "INIT_LANG";
public static final String INIT_LANG_SIB = "INIT_LANG_SIB";
public static final String INIT_END = "INIT_END";
public X4OPhaseLanguageInit() {
logger = Logger.getLogger(X4OPhaseLanguageInit.class.getName());
@ -62,7 +66,7 @@ public class X4OPhaseLanguageInit {
return X4OPhaseType.INIT;
}
public String getId() {
return "INIT_START";
return INIT_START;
}
public String[] getPhaseDependencies() {
return new String[]{};
@ -86,10 +90,10 @@ public class X4OPhaseLanguageInit {
return X4OPhaseType.INIT;
}
public String getId() {
return "INIT_LANG";
return INIT_LANG;
}
public String[] getPhaseDependencies() {
return new String[]{"INIT_START"};
return new String[]{INIT_START};
}
public boolean isElementPhase() {
return false;
@ -124,10 +128,10 @@ public class X4OPhaseLanguageInit {
return X4OPhaseType.INIT;
}
public String getId() {
return "INIT_LANG_SIB";
return INIT_LANG_SIB;
}
public String[] getPhaseDependencies() {
return new String[] {"INIT_LANG"};
return new String[] {INIT_LANG};
}
public boolean isElementPhase() {
return false;
@ -161,10 +165,10 @@ public class X4OPhaseLanguageInit {
return X4OPhaseType.INIT;
}
public String getId() {
return "INIT_END";
return INIT_END;
}
public String[] getPhaseDependencies() {
return new String[]{"INIT_LANG_SIB"};
return new String[]{INIT_LANG_SIB};
}
public boolean isElementPhase() {
return false;

View file

@ -58,6 +58,21 @@ import org.xml.sax.helpers.AttributesImpl;
public class X4OPhaseLanguageRead {
private Logger logger = null;
public static final String READ_BEGIN = "READ_BEGIN";
public static final String READ_CONFIG_ELEMENT = "READ_CONFIG_ELEMENT";
public static final String READ_CONFIG_ELEMENT_INTERFACE = "READ_CONFIG_ELEMENT_INTERFACE";
public static final String READ_CONFIG_GLOBAL_ELEMENT = "READ_CONFIG_GLOBAL_ELEMENT";
public static final String READ_CONFIG_GLOBAL_ATTRIBUTE = "READ_CONFIG_GLOBAL_ATTRIBUTE";
public static final String READ_RUN_ATTRIBUTE = "READ_RUN_ATTRIBUTE";
public static final String READ_FILL_TEMPLATE = "READ_FILL_TEMPLATE";
public static final String READ_TRANSFORM = "READ_TRANSFORM";
public static final String READ_RUN_DIRTY = "READ_RUN_DIRTY";
public static final String READ_BIND_ELEMENT = "READ_BIND_ELEMENT";
public static final String READ_RUN = "READ_RUN";
public static final String READ_RUN_CONFIGURATOR = "READ_RUN_CONFIGURATOR";
public static final String READ_RUN_DIRTY_LAST = "READ_RUN_DIRTY_LAST";
public static final String READ_END = "READ_END";
public static final String READ_RELEASE = "READ_RELEASE";
public X4OPhaseLanguageRead() {
logger = Logger.getLogger(X4OPhaseLanguageRead.class.getName());
@ -136,7 +151,7 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return X4OPhase.READ_BEGIN;
return READ_BEGIN;
}
public String[] getPhaseDependencies() {
return new String[]{};
@ -172,10 +187,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_CONFIG_ELEMENT";
return READ_CONFIG_ELEMENT;
}
public String[] getPhaseDependencies() {
return new String[] {X4OPhase.READ_BEGIN};
return new String[] {READ_BEGIN};
}
public void runElementPhase(Element element) throws X4OPhaseException {
@ -213,10 +228,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_CONFIG_ELEMENT_INTERFACE";
return READ_CONFIG_ELEMENT_INTERFACE;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_CONFIG_ELEMENT"};
return new String[] {READ_CONFIG_ELEMENT};
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.getElementObject()==null) {
@ -244,10 +259,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_CONFIG_GLOBAL_ELEMENT";
return READ_CONFIG_GLOBAL_ELEMENT;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_CONFIG_ELEMENT","READ_CONFIG_ELEMENT_INTERFACE"};
return new String[] {READ_CONFIG_ELEMENT,READ_CONFIG_ELEMENT_INTERFACE};
}
public void runElementPhase(Element element) throws X4OPhaseException {
for (X4OLanguageModule mod:element.getLanguageSession().getLanguage().getLanguageModules()) {
@ -272,10 +287,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_CONFIG_GLOBAL_ATTRIBUTE";
return READ_CONFIG_GLOBAL_ATTRIBUTE;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_CONFIG_GLOBAL_ELEMENT"};
return new String[] {READ_CONFIG_GLOBAL_ELEMENT};
}
@SuppressWarnings("unchecked")
public void runElementPhase(Element element) throws X4OPhaseException {
@ -317,10 +332,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_RUN_ATTRIBUTE";
return READ_RUN_ATTRIBUTE;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_CONFIG_GLOBAL_ATTRIBUTE"};
return new String[] {READ_CONFIG_GLOBAL_ATTRIBUTE};
}
public void runElementPhase(Element element) throws X4OPhaseException {
// we only can config ElementObjects
@ -393,10 +408,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_FILL_TEMPLATE";
return READ_FILL_TEMPLATE;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_RUN_ATTRIBUTE"};
return new String[] {READ_RUN_ATTRIBUTE};
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
@ -410,10 +425,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_TRANSFORM";
return READ_TRANSFORM;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_FILL_TEMPLATE"};
return new String[] {READ_FILL_TEMPLATE};
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.isTransformingTree()==false) {
@ -442,10 +457,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_RUN_DIRTY";
return READ_RUN_DIRTY;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_TRANSFORM"};
return new String[] {READ_TRANSFORM};
}
public void runElementPhase(Element element) throws X4OPhaseException {
Map<Element,X4OPhase> dirtyElements = element.getLanguageSession().getDirtyElements();
@ -473,10 +488,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_RUN_DIRTY_LAST";
return READ_RUN_DIRTY_LAST;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_RUN"};
return new String[] {READ_RUN};
}
public void runElementPhase(Element element) throws X4OPhaseException {
Map<Element,X4OPhase> dirtyElements = element.getLanguageSession().getDirtyElements();
@ -500,10 +515,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_BIND_ELEMENT";
return READ_BIND_ELEMENT;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_RUN_DIRTY"};
return new String[] {READ_RUN_DIRTY};
}
public void runElementPhase(Element element) throws X4OPhaseException {
Element parentElement = element.getParent();
@ -545,10 +560,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_RUN";
return READ_RUN;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_BIND_ELEMENT"};
return new String[] {READ_BIND_ELEMENT};
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.isTransformingTree()) {
@ -574,10 +589,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_RUN_CONFIGURATOR";
return READ_RUN_CONFIGURATOR;
}
public String[] getPhaseDependencies() {
return new String[] {"READ_RUN"};
return new String[] {READ_RUN};
}
public boolean isElementPhase() {
return false;
@ -634,10 +649,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return X4OPhase.READ_END;
return READ_END;
}
public String[] getPhaseDependencies() {
return new String[]{"READ_RUN_CONFIGURATOR"};
return new String[]{READ_RUN_CONFIGURATOR};
}
public boolean isElementPhase() {
return false;
@ -701,10 +716,10 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ;
}
public String getId() {
return X4OPhase.READ_RELEASE;
return READ_RELEASE;
}
public String[] getPhaseDependencies() {
return new String[] {X4OPhase.READ_END};
return new String[] {READ_END};
}
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
}

View file

@ -43,6 +43,10 @@ import org.x4o.xml.lang.X4OLanguageSession;
public class X4OPhaseLanguageWrite {
private Logger logger = null;
public static final String WRITE_BEGIN = "WRITE_BEGIN";
public static final String WRITE_FILL_TREE = "WRITE_FILL_TREE";
public static final String WRITE_END = "WRITE_END";
public static final String WRITE_RELEASE = "WRITE_RELEASE";
public X4OPhaseLanguageWrite() {
logger = Logger.getLogger(X4OPhaseLanguageWrite.class.getName());
@ -63,7 +67,7 @@ public class X4OPhaseLanguageWrite {
return X4OPhaseType.XML_WRITE;
}
public String getId() {
return X4OPhase.WRITE_BEGIN;
return WRITE_BEGIN;
}
public String[] getPhaseDependencies() {
return new String[]{};
@ -86,10 +90,10 @@ public class X4OPhaseLanguageWrite {
return X4OPhaseType.XML_WRITE;
}
public String getId() {
return "WRITE_FILL_TREE";
return WRITE_FILL_TREE;
}
public String[] getPhaseDependencies() {
return new String[]{X4OPhase.WRITE_BEGIN};
return new String[]{WRITE_BEGIN};
}
public boolean isElementPhase() {
return false;
@ -164,10 +168,10 @@ public class X4OPhaseLanguageWrite {
return X4OPhaseType.XML_WRITE;
}
public String getId() {
return X4OPhase.WRITE_END;
return WRITE_END;
}
public String[] getPhaseDependencies() {
return new String[]{"WRITE_FILL_TREE"};
return new String[]{WRITE_FILL_TREE};
}
public boolean isElementPhase() {
return false;
@ -184,10 +188,10 @@ public class X4OPhaseLanguageWrite {
return X4OPhaseType.XML_WRITE;
}
public String getId() {
return X4OPhase.WRITE_RELEASE;
return WRITE_RELEASE;
}
public String[] getPhaseDependencies() {
return new String[] {X4OPhase.WRITE_END};
return new String[] {WRITE_END};
}
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
}

View file

@ -29,7 +29,6 @@ import org.x4o.xml.io.X4OReader;
import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import junit.framework.TestCase;
/**

View file

@ -25,7 +25,7 @@ package org.x4o.xml.core;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.X4OReaderSession;
import org.x4o.xml.lang.X4OLanguageSession;
import org.x4o.xml.lang.phase.X4OPhase;
import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot;
@ -43,7 +43,7 @@ public class NamespaceUriTest extends TestCase {
X4OLanguageSession context = null;
TestDriver driver = TestDriver.getInstance();
X4OReaderSession<TestObjectRoot> reader = driver.createReaderSession();
reader.addPhaseSkip(X4OPhase.READ_RELEASE);
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
try {
context = reader.readResourceSession("tests/namespace/uri-simple.xml");
assertEquals(true,context.getRootElement().getChilderen().size()==1);
@ -56,7 +56,7 @@ public class NamespaceUriTest extends TestCase {
X4OLanguageSession context = null;
TestDriver driver = TestDriver.getInstance();
X4OReaderSession<TestObjectRoot> reader = driver.createReaderSession();
reader.addPhaseSkip(X4OPhase.READ_RELEASE);
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
reader.setProperty(DefaultX4OReader.DOC_EMPTY_NAMESPACE_URI, "http://test.x4o.org/xml/ns/test-lang");
try {
context = reader.readResourceSession("tests/namespace/uri-empty.xml");
@ -70,7 +70,7 @@ public class NamespaceUriTest extends TestCase {
X4OLanguageSession context = null;
TestDriver driver = TestDriver.getInstance();
X4OReaderSession<TestObjectRoot> reader = driver.createReaderSession();
reader.addPhaseSkip(X4OPhase.READ_RELEASE);
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
try {
context = reader.readResourceSession("tests/namespace/uri-schema.xml");
assertEquals(true,context.getRootElement().getChilderen().size()==1);

View file

@ -28,7 +28,7 @@ import org.x4o.xml.element.DefaultElement;
import org.x4o.xml.element.Element;
import org.x4o.xml.io.X4OReaderSession;
import org.x4o.xml.lang.X4OLanguageSession;
import org.x4o.xml.lang.phase.X4OPhase;
import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
import junit.framework.TestCase;
@ -44,7 +44,7 @@ public class ParentObjectTest extends TestCase {
X4OLanguageSession context = null;
MTestDriver driver = new MTestDriver();
X4OReaderSession<?> reader = driver.createReaderSession();
reader.addPhaseSkip(X4OPhase.READ_RELEASE);
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
try {
context = reader.readResourceSession("junit/test-meta-parent-element.xml");
assertEquals(1,context.getRootElement().getChilderen().size());

View file

@ -26,7 +26,7 @@ import java.util.Date;
import org.x4o.xml.io.X4OReaderSession;
import org.x4o.xml.lang.X4OLanguageSession;
import org.x4o.xml.lang.phase.X4OPhase;
import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
import junit.framework.TestCase;
@ -42,7 +42,7 @@ public class ReferenceStoreTest extends TestCase {
X4OLanguageSession context = null;
MTestDriver driver = new MTestDriver();
X4OReaderSession<?> reader = driver.createReaderSession();
reader.addPhaseSkip(X4OPhase.READ_RELEASE);
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
try {
context = reader.readResourceSession("junit/test-meta-generic.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
@ -55,7 +55,7 @@ public class ReferenceStoreTest extends TestCase {
X4OLanguageSession context = null;
MTestDriver driver = new MTestDriver();
X4OReaderSession<?> reader = driver.createReaderSession();
reader.addPhaseSkip(X4OPhase.READ_RELEASE);
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
try {
context = reader.readResourceSession("junit/test-meta-reference.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
@ -68,7 +68,7 @@ public class ReferenceStoreTest extends TestCase {
X4OLanguageSession context = null;
MTestDriver driver = new MTestDriver();
X4OReaderSession<?> reader = driver.createReaderSession();
reader.addPhaseSkip(X4OPhase.READ_RELEASE);
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
try {
context = reader.readResourceSession("junit/test-meta-reference.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());