X4O: Fixed recursief debugging xml output
This commit is contained in:
parent
889e4b9eb8
commit
2819b36a45
37 changed files with 592 additions and 570 deletions
|
|
@ -148,22 +148,6 @@ public abstract class X4ODriver<T> {
|
|||
return buildLanguage(getLanguageVersionDefault());
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates the X4OLanguageSession for the default language version.
|
||||
* @return The created X4OLanguageSession.
|
||||
*
|
||||
final public X4OLanguageSession createLanguageSession() {
|
||||
return createLanguageSession(getLanguageVersionDefault());
|
||||
}
|
||||
|
||||
*
|
||||
* Creates the X4OLanguageSession for the specified version.
|
||||
* @param version The language version to create the context for.
|
||||
* @return The created X4OLanguageSession.
|
||||
*
|
||||
final public X4OLanguageSession createLanguageSession(String version) {
|
||||
return createLanguage(version).createLanguageSession();
|
||||
}*/
|
||||
|
||||
|
||||
// =============== Language Tasks
|
||||
|
|
|
|||
|
|
@ -43,12 +43,10 @@ import org.x4o.xml.lang.X4OLanguage;
|
|||
import org.x4o.xml.lang.X4OLanguageClassLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageConfiguration;
|
||||
import org.x4o.xml.lang.phase.DefaultX4OPhaseManager;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseLanguageInit;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseLanguageWrite;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseManager;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseType;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTask;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
|
|
@ -128,11 +126,6 @@ public final class X4ODriverManager {
|
|||
version = driver.getLanguageVersionDefault();
|
||||
}
|
||||
DefaultX4OLanguage result = new DefaultX4OLanguage(driver.buildLanguageConfiguration(), driver.buildPhaseManager(), driver.getLanguageName(), version);
|
||||
try {
|
||||
result.getPhaseManager().runPhases(result.createLanguageSession(), X4OPhaseType.INIT); // TODO: fix phase to interface T
|
||||
} catch (X4OPhaseException e) {
|
||||
throw new RuntimeException(e); // TODO: change layer
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,12 +75,13 @@ public class EldModuleLoader implements X4OLanguageModuleLoader {
|
|||
|
||||
/**
|
||||
* Loads the ELD language into the module.
|
||||
* @param language The langauge to load for.
|
||||
* @param languageModule The module to load it in.
|
||||
* @param session The session we run in.
|
||||
* @param language The local Language to load for.
|
||||
* @param module The language module to load it into.
|
||||
* @throws X4OLanguageModuleLoaderException When eld language could not be loaded.
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.lang.X4OLanguageLocal, org.x4o.xml.lang.X4OLanguageModuleLocal)
|
||||
*/
|
||||
public void loadLanguageModule(X4OLanguageLocal language, X4OLanguageModuleLocal languageModule) throws X4OLanguageModuleLoaderException {
|
||||
public void loadLanguageModule(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageModuleLocal module) throws X4OLanguageModuleLoaderException {
|
||||
logger.fine("Loading name eld file from resource: " + eldResource);
|
||||
try {
|
||||
X4ODriver<?> driver = null;
|
||||
|
|
@ -90,19 +91,11 @@ public class EldModuleLoader implements X4OLanguageModuleLoader {
|
|||
driver = X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
|
||||
}
|
||||
X4OReader<?> reader = driver.createReader();
|
||||
|
||||
//X4OLanguageSession eldLang = driver.createLanguageSession(driver.getLanguageVersionDefault());
|
||||
//X4OReader<?> reader = new DefaultX4OReader<Object>(eldLang);
|
||||
|
||||
reader.addELBeanInstance(EL_PARENT_LANGUAGE, language);
|
||||
reader.addELBeanInstance(EL_PARENT_LANGUAGE_MODULE, languageModule);
|
||||
|
||||
reader.setProperty(DefaultX4OReader.DEBUG_OUTPUT_HANDLER, null);
|
||||
|
||||
//TODO: if (language.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) {
|
||||
// eldLang.setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter());
|
||||
// }
|
||||
|
||||
reader.addELBeanInstance(EL_PARENT_LANGUAGE_MODULE, module);
|
||||
if (session.hasX4ODebugWriter()) {
|
||||
reader.setProperty(DefaultX4OReader.DEBUG_OUTPUT_HANDLER, session.getX4ODebugWriter().getContentWriter());
|
||||
}
|
||||
reader.readResource(eldResource);
|
||||
} catch (X4OConnectionException e) {
|
||||
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
|
||||
|
|
|
|||
|
|
@ -48,9 +48,11 @@ import org.x4o.xml.lang.X4OLanguageClassLoader;
|
|||
import org.x4o.xml.lang.X4OLanguageModuleLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageModuleLoaderException;
|
||||
import org.x4o.xml.lang.X4OLanguageModuleLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
/**
|
||||
* EldModuleLoaderCore provides a few basic elements for the core eld x4o language.
|
||||
* EldModuleLoaderCore provides a few basic elements for the core eld x4o
|
||||
* language.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 11, 2009
|
||||
|
|
@ -83,11 +85,15 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
|
|||
|
||||
/**
|
||||
* Loads the CEL language into the module.
|
||||
*
|
||||
* @param session The session to run in.
|
||||
* @param language The langauge to load for.
|
||||
* @param languageModule The module to load it in.
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.lang.X4OLanguageLocal, org.x4o.xml.lang.X4OLanguageModuleLocald)
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.lang.X4OLanguageLocal,
|
||||
* org.x4o.xml.lang.X4OLanguageModuleLocald)
|
||||
*/
|
||||
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModuleLocal languageModule) throws X4OLanguageModuleLoaderException {
|
||||
@Override
|
||||
public void loadLanguageModule(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageModuleLocal languageModule) throws X4OLanguageModuleLoaderException {
|
||||
|
||||
// Config module meta data
|
||||
configLanguageModule(languageModule);
|
||||
|
|
@ -116,6 +122,7 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
|
|||
|
||||
/**
|
||||
* Adds only Element class beans which need extra meta info for schema.
|
||||
*
|
||||
* @param namespace The namespace to config.
|
||||
* @param language The language to config for.
|
||||
* @throws X4OLanguageModuleLoaderException
|
||||
|
|
@ -215,13 +222,10 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
|
|||
throw new X4OLanguageModuleLoaderException(this, e.getMessage(), e);
|
||||
}
|
||||
try {
|
||||
namespace.setElementNamespaceInstanceProvider(
|
||||
X4OLanguageClassLoader.newInstance(ElementNamespaceInstanceProvider.class, language.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider())
|
||||
);
|
||||
namespace.setElementNamespaceInstanceProvider(X4OLanguageClassLoader.newInstance(ElementNamespaceInstanceProvider.class, language.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new X4OLanguageModuleLoaderException(this, e.getMessage(), e);
|
||||
}
|
||||
|
||||
namespace.setId(id);
|
||||
namespace.setUri(uri);
|
||||
namespace.setSchemaUri(schemaUri);
|
||||
|
|
@ -245,6 +249,7 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
|
|||
|
||||
/**
|
||||
* Creates new configed ElementClassAttribute instance.
|
||||
*
|
||||
* @param language The X4OLanguage to create from.
|
||||
* @param name The name of the attribute.
|
||||
* @param required Is the attribute required.
|
||||
|
|
@ -270,6 +275,7 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
|
|||
|
||||
/**
|
||||
* Adds binding handler to module.
|
||||
*
|
||||
* @param languageModule The language module.
|
||||
* @param handler The handler to add the the module.
|
||||
* @param id The handler id.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.io.OutputStream;
|
|||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
|
||||
import org.x4o.sax3.SAX3WriterXml;
|
||||
import org.x4o.sax3.io.ContentWriter;
|
||||
|
|
@ -36,6 +37,7 @@ import org.x4o.xml.lang.phase.X4OPhase;
|
|||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseLanguageWrite;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseListener;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
|
|
@ -48,52 +50,45 @@ import org.xml.sax.helpers.AttributesImpl;
|
|||
public abstract class AbstractX4OConnectionDebug implements X4OConnection {
|
||||
|
||||
private boolean debugStarted = false;
|
||||
private boolean debugAutoCloseOutputStream = true;
|
||||
private OutputStream debugCloseOutputStream = null;
|
||||
protected final static String ABSTRACT_DEBUG_OUTPUT_HANDLER = "debug/output-handler";
|
||||
protected final static String ABSTRACT_DEBUG_OUTPUT_STREAM = "debug/output-stream";
|
||||
protected final static String ABSTRACT_DEBUG_OUTPUT_STREAM_CLOSE = "debug/output-stream-close";
|
||||
|
||||
protected void debugStart(X4OLanguageSession languageSession,String debugHandlerKey,String debugStreamKey,String debugStreamCloseKey) throws UnsupportedEncodingException, SAXException {
|
||||
debugAutoCloseOutputStream = (Boolean)getProperty(debugStreamCloseKey);
|
||||
protected void debugStart(X4OLanguageSession languageSession, String debugHandlerKey, String debugStreamKey) throws UnsupportedEncodingException, SAXException {
|
||||
Object debugOutputHandler = getProperty(debugHandlerKey);
|
||||
Object debugOutputStream = getProperty(debugStreamKey);
|
||||
// init debug infra
|
||||
if (languageSession.getX4ODebugWriter() == null) {
|
||||
ContentWriter xmlDebugWriter = null;
|
||||
if (debugOutputHandler instanceof ContentWriter) {
|
||||
xmlDebugWriter = (ContentWriter) debugOutputHandler;
|
||||
} else if (debugOutputStream instanceof OutputStream) {
|
||||
debugCloseOutputStream = (OutputStream)debugOutputStream;
|
||||
xmlDebugWriter = new SAX3WriterXml(debugCloseOutputStream);
|
||||
xmlDebugWriter = new SAX3WriterXml((OutputStream) debugOutputStream);
|
||||
xmlDebugWriter.startDocument();
|
||||
xmlDebugWriter.startPrefixMapping(X4ODebugWriter.DEBUG_URI_NS, X4ODebugWriter.DEBUG_URI);
|
||||
// We only close if we started it, this is for recursief debugging AND debug output stream.
|
||||
debugStarted = true;
|
||||
}
|
||||
if (xmlDebugWriter != null) {
|
||||
xmlDebugWriter.startDocument();
|
||||
xmlDebugWriter.startPrefixMapping("debug", X4ODebugWriter.DEBUG_URI);
|
||||
X4ODebugWriter debugWriter = new X4ODebugWriter(xmlDebugWriter);
|
||||
X4OLanguageSessionLocal local = (X4OLanguageSessionLocal) languageSession;
|
||||
local.setX4ODebugWriter(debugWriter);
|
||||
|
||||
// We only close if we started it, this is for recursief debugging.
|
||||
debugStarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
// debug language
|
||||
// start debug language
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
try {
|
||||
languageSession.getX4ODebugWriter().debugConnectionStart(languageSession, this);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
|
||||
// Add debug phases for all phases
|
||||
X4OLanguageSessionLocal local = (X4OLanguageSessionLocal) languageSession;
|
||||
for (String key : languageSession.getLanguage().getPhaseManager().getPhaseKeys()) {
|
||||
X4OPhase p = languageSession.getLanguage().getPhaseManager().getPhase(key);
|
||||
|
||||
p.addPhaseListener(languageSession.getX4ODebugWriter().createDebugX4OPhaseListener());
|
||||
|
||||
List<X4OPhaseListener> listeners = local.storePhaseListeners(p.getId());
|
||||
listeners.add(languageSession.getX4ODebugWriter().createDebugX4OPhaseListener());
|
||||
if (shouldPrintTree(p)) {
|
||||
p.addPhaseListener(languageSession.getX4ODebugWriter().createDebugPrintTreePhaseListener());
|
||||
listeners.add(languageSession.getX4ODebugWriter().createDebugPrintTreePhaseListener());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -155,16 +150,8 @@ public abstract class AbstractX4OConnectionDebug implements X4OConnection {
|
|||
if (!debugStarted) {
|
||||
return; // not in this instance started so no stopping then.
|
||||
}
|
||||
languageSession.getX4ODebugWriter().getContentWriter().endPrefixMapping("debug");
|
||||
languageSession.getX4ODebugWriter().getContentWriter().endPrefixMapping(X4ODebugWriter.DEBUG_URI_NS);
|
||||
languageSession.getX4ODebugWriter().getContentWriter().endDocument();
|
||||
if (debugCloseOutputStream==null) {
|
||||
return; // we have handler
|
||||
}
|
||||
debugCloseOutputStream.flush();
|
||||
if (!debugAutoCloseOutputStream) {
|
||||
return; // no auto close
|
||||
}
|
||||
debugCloseOutputStream.close();
|
||||
} catch (SAXException ee) {
|
||||
throw new X4OConnectionException("Error while closing debug; " + ee.getMessage(), ee);
|
||||
} catch (IOException ee) {
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ abstract public class AbstractX4OReader<T> extends AbstractX4OReaderSession<T> i
|
|||
|
||||
/**
|
||||
* Reads the file fileName and reads it as an InputStream.
|
||||
*
|
||||
* @param fileName The file name to read.
|
||||
* @throws FileNotFoundException Is thrown is file is not found.
|
||||
* @throws X4OConnectionException Is thrown after x4o exception.
|
||||
|
|
@ -71,6 +72,7 @@ abstract public class AbstractX4OReader<T> extends AbstractX4OReaderSession<T> i
|
|||
|
||||
/**
|
||||
* Reads the file and reads it as an InputStream.
|
||||
*
|
||||
* @param file The file to read.
|
||||
* @throws FileNotFoundException Is thrown is file is not found.
|
||||
* @throws X4OConnectionException Is thrown after x4o exception.
|
||||
|
|
@ -87,6 +89,7 @@ abstract public class AbstractX4OReader<T> extends AbstractX4OReaderSession<T> i
|
|||
|
||||
/**
|
||||
* reads an resource locaction.
|
||||
*
|
||||
* @param resourceName The resource to readr.
|
||||
* @throws X4OConnectionException Is thrown after x4o exception.
|
||||
* @throws SAXException Is thrown after sax xml exception.
|
||||
|
|
@ -102,6 +105,7 @@ abstract public class AbstractX4OReader<T> extends AbstractX4OReaderSession<T> i
|
|||
|
||||
/**
|
||||
* Converts a String to a InputStream to is can me readd by SAX.
|
||||
*
|
||||
* @param xmlString The xml as String to read.
|
||||
* @throws X4OConnectionException Is thrown after x4o exception.
|
||||
* @throws SAXException Is thrown after sax xml exception.
|
||||
|
|
@ -116,7 +120,9 @@ abstract public class AbstractX4OReader<T> extends AbstractX4OReaderSession<T> i
|
|||
}
|
||||
|
||||
/**
|
||||
* Fetched the data direct from remote url to a InputStream to is can me readd by SAX.
|
||||
* Fetched the data direct from remote url to a InputStream to is can me readd
|
||||
* by SAX.
|
||||
*
|
||||
* @param url The url to read.
|
||||
* @throws X4OConnectionException Is thrown after x4o exception.
|
||||
* @throws SAXException Is thrown after sax xml exception.
|
||||
|
|
|
|||
|
|
@ -96,7 +96,9 @@ abstract public class AbstractX4OReaderSession<T> extends AbstractX4OConnection
|
|||
}
|
||||
URL basePath = new File(System.getProperty("user.dir")).toURI().toURL();
|
||||
String encoding = (String) getProperty(DefaultX4OReader.INPUT_ENCODING);
|
||||
readSession(session, new ByteArrayInputStream(xmlString.getBytes(encoding)),"inline-xml",basePath);
|
||||
try (InputStream inputStream = new ByteArrayInputStream(xmlString.getBytes(encoding))) {
|
||||
readSession(session, inputStream, "inline-xml", basePath);
|
||||
}
|
||||
}
|
||||
|
||||
public void readUrlSession(X4OLanguageSession session, URL url) throws X4OConnectionException, SAXException, IOException {
|
||||
|
|
@ -104,6 +106,8 @@ abstract public class AbstractX4OReaderSession<T> extends AbstractX4OConnection
|
|||
throw new NullPointerException("Can't read null url.");
|
||||
}
|
||||
URL basePath = new URL(url.toExternalForm().substring(0, url.toExternalForm().length() - url.getFile().length()));
|
||||
readSession(session, url.openStream(),url.toExternalForm(),basePath);
|
||||
try (InputStream inputStream = url.openStream()) {
|
||||
readSession(session, inputStream, url.toExternalForm(), basePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import org.x4o.sax3.io.SAX3PropertyConfig;
|
|||
import org.x4o.sax3.io.SAX3XMLConstants;
|
||||
import org.x4o.sax3.io.SAX3PropertyConfig.PropertyConfigItem;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
import org.x4o.xml.lang.X4OLanguageSessionLocal;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseType;
|
||||
|
|
@ -75,7 +76,6 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
public final static String VALIDATION_INPUT_SCHEMA = PROPERTY_CONTEXT_PREFIX + "validation/input-schema";
|
||||
public final static String DEBUG_OUTPUT_HANDLER = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_HANDLER;
|
||||
public final static String DEBUG_OUTPUT_STREAM = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_STREAM;
|
||||
public final static String DEBUG_OUTPUT_STREAM_CLOSE = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_STREAM_CLOSE;
|
||||
|
||||
static {
|
||||
DEFAULT_PROPERTY_CONFIG = new SAX3PropertyConfig(true, null, PROPERTY_CONTEXT_PREFIX,
|
||||
|
|
@ -93,8 +93,7 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
new PropertyConfigItem(VALIDATION_INPUT_DOC,Boolean.class,false),
|
||||
new PropertyConfigItem(VALIDATION_INPUT_SCHEMA,Boolean.class,false),
|
||||
new PropertyConfigItem(DEBUG_OUTPUT_HANDLER,ContentWriter.class),
|
||||
new PropertyConfigItem(DEBUG_OUTPUT_STREAM,OutputStream.class),
|
||||
new PropertyConfigItem(DEBUG_OUTPUT_STREAM_CLOSE,Boolean.class,true)
|
||||
new PropertyConfigItem(DEBUG_OUTPUT_STREAM,OutputStream.class)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -103,8 +102,11 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.AbstractX4OConnection#getPropertyConfig()
|
||||
*/
|
||||
@Override
|
||||
SAX3PropertyConfig getPropertyConfig() {
|
||||
public SAX3PropertyConfig getPropertyConfig() {
|
||||
return propertyConfig;
|
||||
}
|
||||
|
||||
|
|
@ -155,9 +157,12 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
}
|
||||
|
||||
// init debug
|
||||
debugStart(languageSession, DEBUG_OUTPUT_HANDLER, DEBUG_OUTPUT_STREAM, DEBUG_OUTPUT_STREAM_CLOSE);
|
||||
debugStart(languageSession, DEBUG_OUTPUT_HANDLER, DEBUG_OUTPUT_STREAM);
|
||||
|
||||
try {
|
||||
// Run init (auto once)
|
||||
X4OLanguageLocal.class.cast(languageSession.getLanguage()).init(languageSession);
|
||||
|
||||
// Run document parsing
|
||||
X4OContentParser parser = new X4OContentParser(propertyConfig);
|
||||
parser.parse(languageSession);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import org.x4o.xml.element.ElementInterface;
|
|||
import org.x4o.xml.element.ElementNamespace;
|
||||
import org.x4o.xml.element.ElementObjectPropertyValueException;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
|
|
@ -76,7 +77,6 @@ public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> {
|
|||
public final static String SCHEMA_ROOT_URI = PROPERTY_CONTEXT_PREFIX+"schema/root-uri";
|
||||
public final static String DEBUG_OUTPUT_HANDLER = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_HANDLER;
|
||||
public final static String DEBUG_OUTPUT_STREAM = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_STREAM;
|
||||
public final static String DEBUG_OUTPUT_STREAM_CLOSE = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_STREAM_CLOSE;
|
||||
|
||||
static {
|
||||
DEFAULT_PROPERTY_CONFIG = new SAX3PropertyConfig(true, SAX3WriterXml.DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX,
|
||||
|
|
@ -85,8 +85,7 @@ public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> {
|
|||
new PropertyConfigItem(SCHEMA_PRINT,Boolean.class,true),
|
||||
new PropertyConfigItem(SCHEMA_ROOT_URI,String.class),
|
||||
new PropertyConfigItem(DEBUG_OUTPUT_HANDLER,ContentWriter.class),
|
||||
new PropertyConfigItem(DEBUG_OUTPUT_STREAM,OutputStream.class),
|
||||
new PropertyConfigItem(DEBUG_OUTPUT_STREAM_CLOSE,Boolean.class,true)
|
||||
new PropertyConfigItem(DEBUG_OUTPUT_STREAM,OutputStream.class)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -112,8 +111,9 @@ public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> {
|
|||
public void writeSession(X4OLanguageSession languageSession, OutputStream output) throws X4OConnectionException,SAXException,IOException {
|
||||
setProperty(OUTPUT_STREAM, output);
|
||||
addPhaseSkip(X4OPhaseLanguageWrite.WRITE_RELEASE);
|
||||
debugStart(languageSession, DEBUG_OUTPUT_HANDLER, DEBUG_OUTPUT_STREAM, DEBUG_OUTPUT_STREAM_CLOSE);
|
||||
debugStart(languageSession, DEBUG_OUTPUT_HANDLER, DEBUG_OUTPUT_STREAM);
|
||||
try {
|
||||
X4OLanguageLocal.class.cast(languageSession.getLanguage()).init(languageSession);
|
||||
languageSession.getLanguage().getPhaseManager().runPhases(languageSession, X4OPhaseType.XML_WRITE);
|
||||
} catch (X4OPhaseException e) {
|
||||
throw new X4OConnectionException(e);
|
||||
|
|
@ -121,6 +121,7 @@ public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> {
|
|||
runWrite(languageSession);
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource") // caller closes the resource thus writerXML and writerXDBX are not closed
|
||||
private void runWrite(X4OLanguageSession languageSession) throws X4OConnectionException {
|
||||
OutputStream out = (OutputStream)getProperty(OUTPUT_STREAM);
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import java.util.Map;
|
|||
|
||||
import org.x4o.sax3.SAX3WriterEnum;
|
||||
import org.x4o.sax3.io.ContentWriter;
|
||||
import org.x4o.sax3.io.SAX3XMLConstants;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementNamespaceAttribute;
|
||||
|
|
@ -48,6 +47,7 @@ import org.x4o.xml.element.ElementNamespaceInstanceProvider;
|
|||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageModuleLoaderResult;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
import org.x4o.xml.lang.X4OLanguageSessionLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageConfiguration;
|
||||
import org.x4o.xml.lang.phase.X4OPhase;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
|
|
@ -64,11 +64,12 @@ import org.xml.sax.helpers.AttributesImpl;
|
|||
public class X4ODebugWriter {
|
||||
|
||||
static public final String DEBUG_URI = "http://language.x4o.org/xml/ns/debug-output";
|
||||
static public final String DEBUG_URI_NS = "debug";
|
||||
|
||||
protected SAX3WriterEnum<Tag,ContentWriter> contentWriter = null;
|
||||
|
||||
public X4ODebugWriter(ContentWriter debugWriter) {
|
||||
this.contentWriter=new SAX3WriterEnum<Tag,ContentWriter>(debugWriter,DEBUG_URI,SAX3XMLConstants.NULL_NS_URI);
|
||||
this.contentWriter = new SAX3WriterEnum<Tag,ContentWriter>(debugWriter, DEBUG_URI, DEBUG_URI_NS);
|
||||
}
|
||||
|
||||
public ContentWriter getContentWriter() {
|
||||
|
|
@ -83,6 +84,7 @@ public class X4ODebugWriter {
|
|||
X4OConnection,
|
||||
X4OLanguageSession,
|
||||
X4OLanguageSessionSkipPhase,
|
||||
X4OLanguageSessionPhaseListener,
|
||||
X4OConnectionProperties,
|
||||
X4OConnectionProperty,
|
||||
|
||||
|
|
@ -91,7 +93,6 @@ public class X4ODebugWriter {
|
|||
|
||||
phaseOrder,
|
||||
phase,
|
||||
X4OPhaseListener,
|
||||
X4OPhaseDependency,
|
||||
|
||||
ElementLanguageModules,
|
||||
|
|
@ -196,10 +197,24 @@ public class X4ODebugWriter {
|
|||
atts = new AttributesImpl();
|
||||
atts.addAttribute("", "phaseStop", "", "", languageSession.getPhaseStop());
|
||||
atts.addAttribute("", "className", "", "", languageSession.getClass().getName());
|
||||
//atts.addAttribute("", "listenersSize", "", "", phase.getPhaseListeners().size()+"");
|
||||
contentWriter.printTagStart(Tag.X4OLanguageSession, atts);
|
||||
for (String skipPhase:languageSession.getPhaseSkip()) {
|
||||
contentWriter.printTagCharacters(Tag.X4OLanguageSessionSkipPhase, skipPhase);
|
||||
}
|
||||
if (languageSession instanceof X4OLanguageSessionLocal) {
|
||||
X4OLanguageSessionLocal languageSessionLocal = X4OLanguageSessionLocal.class.cast(languageSession);
|
||||
for (String key : languageSession.getLanguage().getPhaseManager().getPhaseKeys()) {
|
||||
X4OPhase p = languageSession.getLanguage().getPhaseManager().getPhase(key);
|
||||
List<X4OPhaseListener> listeners = languageSessionLocal.storePhaseListeners(p.getId());
|
||||
for (X4OPhaseListener l : listeners) {
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute("", "phaseId", "", "", p.getId());
|
||||
atts.addAttribute("", "className", "", "", l.getClass().getName());
|
||||
contentWriter.printTagStartEnd(Tag.X4OLanguageSessionPhaseListener, atts);
|
||||
}
|
||||
}
|
||||
}
|
||||
contentWriter.printTagEnd(Tag.X4OLanguageSession);
|
||||
|
||||
atts = new AttributesImpl();
|
||||
|
|
@ -286,14 +301,8 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute("", "id", "", "", phase.getId());
|
||||
atts.addAttribute("", "type", "", "", phase.getType().name());
|
||||
atts.addAttribute("", "runOnce", "", "", phase.isRunOnce()+"");
|
||||
atts.addAttribute("", "listenersSize", "", "", phase.getPhaseListeners().size()+"");
|
||||
|
||||
contentWriter.printTagStart(Tag.phase, atts);
|
||||
for (X4OPhaseListener l:phase.getPhaseListeners()) {
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute("", "className", "", "", l.getClass().getName());
|
||||
contentWriter.printTagStartEnd(Tag.X4OPhaseListener, atts);
|
||||
}
|
||||
for (String dep:phase.getPhaseDependencies()) {
|
||||
contentWriter.printTagCharacters(Tag.X4OPhaseDependency, dep);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@
|
|||
package org.x4o.xml.lang;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.el.ELContext;
|
||||
|
|
@ -34,6 +36,7 @@ import org.x4o.xml.element.ElementAttributeValueParser;
|
|||
import org.x4o.xml.element.ElementObjectPropertyValue;
|
||||
import org.x4o.xml.io.X4ODebugWriter;
|
||||
import org.x4o.xml.lang.phase.X4OPhase;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseListener;
|
||||
|
||||
/**
|
||||
* AbstractX4OLanguageSession.
|
||||
|
|
@ -55,6 +58,7 @@ public abstract class AbstractX4OLanguageSession implements X4OLanguageSessionLo
|
|||
private X4OPhase phaseCurrent = null;
|
||||
private String phaseStop = null;
|
||||
private List<String> phaseSkip = null;
|
||||
private Map<String, List<X4OPhaseListener>> phaseListeners = null;
|
||||
|
||||
/**
|
||||
* Creates a new empty language context.
|
||||
|
|
@ -66,8 +70,9 @@ public abstract class AbstractX4OLanguageSession implements X4OLanguageSessionLo
|
|||
logger = Logger.getLogger(AbstractX4OLanguageSession.class.getName());
|
||||
logger.finest("Creating new ParsingContext");
|
||||
this.language=language;
|
||||
dirtyElements = new ArrayList<Element>(20);
|
||||
phaseSkip = new ArrayList<String>(5);
|
||||
dirtyElements = new ArrayList<>(20);
|
||||
phaseSkip = new ArrayList<>(5);
|
||||
phaseListeners = new HashMap<>(3);
|
||||
}
|
||||
|
||||
public X4OLanguage getLanguage() {
|
||||
|
|
@ -238,4 +243,18 @@ public abstract class AbstractX4OLanguageSession implements X4OLanguageSessionLo
|
|||
public void addPhaseSkip(String phaseId) {
|
||||
phaseSkip.add(phaseId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the phase listeners for a phase.
|
||||
* @param phaseId The phaseId of for the listeners.
|
||||
* @return The x4o phase listeners.
|
||||
*/
|
||||
public List<X4OPhaseListener> storePhaseListeners(String phaseId) {
|
||||
List<X4OPhaseListener> result = phaseListeners.get(phaseId);
|
||||
if (result == null) {
|
||||
result = new ArrayList<>(3);
|
||||
phaseListeners.put(phaseId, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ import org.x4o.xml.element.ElementInterface;
|
|||
import org.x4o.xml.element.ElementNamespace;
|
||||
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
|
||||
import org.x4o.xml.element.ElementObjectPropertyValue;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseManager;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseType;
|
||||
|
||||
/**
|
||||
* DefaultX4OLanguage holds all information about the x4o xml language.
|
||||
|
|
@ -55,6 +57,7 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
|
|||
private final String languageVersion;
|
||||
private final X4OPhaseManager phaseManager;
|
||||
private final Map<String, ElementNamespace> keyedNamespaceLookup;
|
||||
private boolean inited = false;
|
||||
|
||||
public DefaultX4OLanguage(X4OLanguageConfiguration languageConfiguration, X4OPhaseManager phaseManager, String languageName, String languageVersion) {
|
||||
if (languageName == null) {
|
||||
|
|
@ -72,6 +75,15 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
|
|||
this.phaseManager = phaseManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(X4OLanguageSession session) throws X4OPhaseException {
|
||||
if (inited) {
|
||||
return;
|
||||
}
|
||||
inited = true;
|
||||
getPhaseManager().runPhases(session, X4OPhaseType.INIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguage#getLanguageName()
|
||||
*/
|
||||
|
|
@ -139,16 +151,13 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
|
|||
languageSession.setExpressionLanguageFactory(X4OExpressionFactory.createExpressionFactory());
|
||||
}
|
||||
if (languageSession.getExpressionLanguageContext() == null) {
|
||||
languageSession.setExpressionLanguageContext(
|
||||
X4OExpressionFactory.createELContext(languageSession.getLanguage().getLanguageConfiguration().getDefaultExpressionLanguageContext()));
|
||||
languageSession.setExpressionLanguageContext(X4OExpressionFactory.createELContext(languageSession.getLanguage().getLanguageConfiguration().getDefaultExpressionLanguageContext()));
|
||||
}
|
||||
if (languageSession.getElementAttributeValueParser() == null) {
|
||||
languageSession.setElementAttributeValueParser(X4OLanguageClassLoader.newInstance(ElementAttributeValueParser.class,
|
||||
getLanguageConfiguration().getDefaultElementAttributeValueParser()));
|
||||
languageSession.setElementAttributeValueParser(X4OLanguageClassLoader.newInstance(ElementAttributeValueParser.class, getLanguageConfiguration().getDefaultElementAttributeValueParser()));
|
||||
}
|
||||
if (languageSession.getElementObjectPropertyValue() == null) {
|
||||
languageSession.setElementObjectPropertyValue(X4OLanguageClassLoader.newInstance(ElementObjectPropertyValue.class,
|
||||
getLanguageConfiguration().getDefaultElementObjectPropertyValue()));
|
||||
languageSession.setElementObjectPropertyValue(X4OLanguageClassLoader.newInstance(ElementObjectPropertyValue.class, getLanguageConfiguration().getDefaultElementObjectPropertyValue()));
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import javax.xml.parsers.SAXParserFactory;
|
|||
|
||||
import org.x4o.xml.eld.EldDriver;
|
||||
import org.x4o.xml.eld.EldModuleLoader;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseLanguageInit;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseLanguageInit.X4OPhaseInitLanguageSiblings;
|
||||
import org.xml.sax.Attributes;
|
||||
|
|
@ -67,25 +68,21 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
* @param language The X4O language we are loading.
|
||||
* @param message The message to log to the debug output.
|
||||
*/
|
||||
private void logMessage(X4OLanguage language,String message) {
|
||||
logger.finest(message+" from: "+language.getLanguageName());
|
||||
/*
|
||||
TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
|
||||
private void logMessage(X4OLanguageSession session, String message) {
|
||||
logger.finest(message + " from: " + session.getLanguage().getLanguageName());
|
||||
if (session.hasX4ODebugWriter()) {
|
||||
try {
|
||||
language.getLanguageConfiguration().getX4ODebugWriter().debugPhaseMessage(message, this.getClass());
|
||||
session.getX4ODebugWriter().debugPhaseMessage(message, this.getClass());
|
||||
} catch (ElementException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageLoader#loadLanguage(org.x4o.xml.lang.X4OLanguageLocal, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void loadLanguage(X4OLanguageLocal languageLocal, String language,String languageVersion) throws X4OLanguageLoaderException {
|
||||
@Override
|
||||
public void loadLanguage(X4OLanguageSession session, X4OLanguageLocal languageLocal, String language, String languageVersion) throws X4OLanguageLoaderException {
|
||||
logger.finer("Loading all modules for language: " + language);
|
||||
List<VersionedResources> modulesAll = loadLanguageModules(languageLocal,language);
|
||||
List<VersionedResources> modulesAll = loadLanguageModules(session, languageLocal, language);
|
||||
modulesAll = filterVersionModules(modulesAll, languageLocal, languageVersion);
|
||||
validateModules(modulesAll);
|
||||
|
||||
|
|
@ -100,7 +97,7 @@ TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
|
|||
} else {
|
||||
loader = new EldModuleLoader(resource,false); // load eld
|
||||
}
|
||||
loadModule(languageLocal,loader,value,versionedResources);
|
||||
loadModule(session, languageLocal, loader, value, versionedResources);
|
||||
}
|
||||
for (String value : versionedResources.moduleLoaders) {
|
||||
try {
|
||||
|
|
@ -108,7 +105,7 @@ TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
|
|||
} catch (Exception ee) {
|
||||
throw new X4OLanguageLoaderException("Could not load class: " + value + " error: " + ee.getMessage(),ee);
|
||||
}
|
||||
loadModule(languageLocal,loader,value,versionedResources);
|
||||
loadModule(session, languageLocal, loader, value, versionedResources);
|
||||
}
|
||||
for (String value : versionedResources.siblingLoaders) {
|
||||
try {
|
||||
|
|
@ -116,7 +113,7 @@ TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
|
|||
} catch (Exception ee) {
|
||||
throw new X4OLanguageLoaderException("Could not load class: " + value + " error: " + ee.getMessage(),ee);
|
||||
}
|
||||
loadModule(languageLocal,loader,value,versionedResources);
|
||||
loadModule(session, languageLocal, loader, value, versionedResources);
|
||||
if (loader instanceof X4OLanguageModuleLoaderSibling) {
|
||||
// mmm
|
||||
X4OPhaseInitLanguageSiblings sibPhase = (X4OPhaseInitLanguageSiblings)languageLocal.getPhaseManager().getPhase(X4OPhaseLanguageInit.INIT_LANG_SIB);
|
||||
|
|
@ -176,18 +173,18 @@ TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
|
|||
}
|
||||
}
|
||||
|
||||
private void loadModule(X4OLanguageLocal languageLocal,X4OLanguageModuleLoader loader,String resource,VersionedResources versionedResources) throws X4OLanguageLoaderException {
|
||||
private void loadModule(X4OLanguageSession session, X4OLanguageLocal languageLocal, X4OLanguageModuleLoader loader, String resource, VersionedResources versionedResources) throws X4OLanguageLoaderException {
|
||||
X4OLanguageModuleLocal module;
|
||||
try {
|
||||
module = X4OLanguageClassLoader.newInstance(X4OLanguageModuleLocal.class, languageLocal.getLanguageConfiguration().getDefaultElementLanguageModule());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new X4OLanguageLoaderException(e);
|
||||
}
|
||||
logMessage(languageLocal,"Created module: "+module);
|
||||
logMessage(session,"Created module: " + module);
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
logMessage(languageLocal,"Starting modules: "+module+" for language: "+languageLocal.getLanguageName());
|
||||
loader.loadLanguageModule(languageLocal, module);
|
||||
logMessage(session,"Starting modules: " + module + " for language: " + languageLocal.getLanguageName());
|
||||
loader.loadLanguageModule(session, languageLocal, module);
|
||||
} catch (X4OLanguageModuleLoaderException e) {
|
||||
throw new X4OLanguageLoaderException(e); // FIXME info
|
||||
}
|
||||
|
|
@ -209,7 +206,7 @@ TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
|
|||
* @param languageLocal The ElementLanguage to load for.
|
||||
* @param language The language to load.
|
||||
*/
|
||||
protected List<VersionedResources> loadLanguageModules(X4OLanguageLocal languageLocal,String language) throws X4OLanguageLoaderException {
|
||||
protected List<VersionedResources> loadLanguageModules(X4OLanguageSession session, X4OLanguageLocal languageLocal, String language) throws X4OLanguageLoaderException {
|
||||
List<VersionedResources> result = new ArrayList<VersionedResources>(15);
|
||||
StringBuilder buf = new StringBuilder(150);
|
||||
buf.append(languageLocal.getLanguageConfiguration().getLanguageResourcePathPrefix());
|
||||
|
|
@ -224,14 +221,14 @@ TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
|
|||
Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources(buf.toString());
|
||||
while (e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logMessage(languageLocal,"Loading relative modules: "+u+" for: "+language);
|
||||
logMessage(session, "Loading relative modules: " + u + " for: " + language);
|
||||
result.addAll(loadLanguageModulesXml(u.openStream(), u.toString()));
|
||||
}
|
||||
|
||||
e = Thread.currentThread().getContextClassLoader().getResources("/"+buf.toString());
|
||||
while (e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logMessage(languageLocal,"Loading root modules: "+u+" for: "+language);
|
||||
logMessage(session, "Loading root modules: " + u + " for: " + language);
|
||||
result.addAll(loadLanguageModulesXml(u.openStream(), u.toString()));
|
||||
}
|
||||
return result;
|
||||
|
|
@ -278,8 +275,7 @@ TODO: if (language.getLanguageConfiguration().hasX4ODebugWriter()) {
|
|||
this.result = new ArrayList<VersionedResources>(5);
|
||||
}
|
||||
|
||||
public List<VersionedResources> getResult()
|
||||
{
|
||||
public List<VersionedResources> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import org.x4o.xml.lang.phase.X4OPhaseException;
|
|||
public class DefaultX4OLanguageSession extends AbstractX4OLanguageSession {
|
||||
|
||||
/**
|
||||
* Creates a new empty language context.
|
||||
* Creates a new empty language session.
|
||||
*/
|
||||
public DefaultX4OLanguageSession(X4OLanguage language) {
|
||||
super(language);
|
||||
|
|
|
|||
|
|
@ -32,10 +32,11 @@ public interface X4OLanguageLoader {
|
|||
|
||||
/**
|
||||
* Loads the language modules.
|
||||
* @param languageLocal The elementLanguage to load the module in.
|
||||
* @param session The session we run in.
|
||||
* @param language The local Language to load for.
|
||||
* @param languageName The language name to load.
|
||||
* @param languageVersion The language version to load.
|
||||
* @throws X4OLanguageLoaderException When there is an error.
|
||||
*/
|
||||
void loadLanguage(X4OLanguageLocal languageLocal,String languageName,String languageVersion) throws X4OLanguageLoaderException;
|
||||
void loadLanguage(X4OLanguageSession session, X4OLanguageLocal language, String languageName, String languageVersion) throws X4OLanguageLoaderException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
|
||||
/**
|
||||
* X4OLanguageLocal exposes the add method to load the language.
|
||||
|
|
@ -31,11 +32,8 @@ package org.x4o.xml.lang;
|
|||
*/
|
||||
public interface X4OLanguageLocal extends X4OLanguage {
|
||||
|
||||
/*
|
||||
* @param parserConfiguration The parserConfiguration to set.
|
||||
|
||||
void setLanguageConfiguration(X4OLanguageConfiguration parserConfiguration);
|
||||
*/
|
||||
// TODO: refactor a bit more a this is now called manually on magic places
|
||||
void init(X4OLanguageSession session) throws X4OPhaseException;
|
||||
|
||||
/**
|
||||
* Adds an X4OLanguageModule to this language.
|
||||
|
|
|
|||
|
|
@ -33,9 +33,10 @@ public interface X4OLanguageModuleLoader {
|
|||
|
||||
/**
|
||||
* Starts the ElementProvider.
|
||||
* @param language The ElementLanguage to load for.
|
||||
* @param module The ElementLanguageModule to load it into.
|
||||
* @param session The session we run in.
|
||||
* @param language The local Language to load for.
|
||||
* @param module The language module to load it into.
|
||||
* @throws X4OLanguageModuleLoaderException Gets thrown when modules could not be correctly loaded.
|
||||
*/
|
||||
void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModuleLocal module) throws X4OLanguageModuleLoaderException;
|
||||
void loadLanguageModule(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageModuleLocal module) throws X4OLanguageModuleLoaderException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,10 @@ public interface X4OLanguageModuleLoaderSibling extends X4OLanguageModuleLoader
|
|||
|
||||
/**
|
||||
* Loads in the sibling language.
|
||||
* @param languageLocal The ElementLanguage for which we load an sibling.
|
||||
* @param languageLoader The loader to use to load the x4o languages.
|
||||
* @param session The session we run in.
|
||||
* @param language The local Language to load for.
|
||||
* @param loader The loader to use to load the x4o languages.
|
||||
* @throws X4OLanguageLoaderException Gets thrown when there is an error loading the sibling language.
|
||||
*/
|
||||
void loadLanguageSibling(X4OLanguageLocal languageLocal,X4OLanguageLoader languageLoader) throws X4OLanguageLoaderException;
|
||||
void loadLanguageSibling(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageLoader loader) throws X4OLanguageLoaderException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
*/
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ExpressionFactory;
|
||||
|
||||
|
|
@ -29,6 +31,7 @@ import org.x4o.xml.element.ElementAttributeValueParser;
|
|||
import org.x4o.xml.element.ElementObjectPropertyValue;
|
||||
import org.x4o.xml.io.X4ODebugWriter;
|
||||
import org.x4o.xml.lang.phase.X4OPhase;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseListener;
|
||||
|
||||
/**
|
||||
* X4OLanguageSessionLocal is the local set interface for X4OLanguageSession.
|
||||
|
|
@ -38,6 +41,14 @@ import org.x4o.xml.lang.phase.X4OPhase;
|
|||
*/
|
||||
public interface X4OLanguageSessionLocal extends X4OLanguageSession {
|
||||
|
||||
/**
|
||||
* Returns list of phase listeners which where added to it.
|
||||
* TODO: bad api here
|
||||
* @param phaseId The phaseId of for the listeners.
|
||||
* @return All X4OPhaseListeners.
|
||||
*/
|
||||
List<X4OPhaseListener> storePhaseListeners(String phaseId);
|
||||
|
||||
/**
|
||||
* Sets the EL Context.
|
||||
* @param context The ELContext to set.
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.x4o.xml.lang.X4OLanguageLoader;
|
|||
import org.x4o.xml.lang.X4OLanguageLoaderException;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageModuleLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
/**
|
||||
* MetaLanguageSiblingLoader loads the generic x4o meta language into defined language.
|
||||
|
|
@ -49,30 +50,16 @@ public class MetaLanguageSiblingLoader implements X4OLanguageModuleLoaderSibling
|
|||
/** Defines the identifier of the meta x4o language host. */
|
||||
public static final String META_LANGUAGE_DESCRIPTION = "X4O Meta XML Language Module.";
|
||||
|
||||
/**
|
||||
* Loads an ElementLanguageModule.
|
||||
* @param language The ElementLanguage to load for.
|
||||
* @param languageModule The ElementLanguageModule to load into.
|
||||
* @throws X4OLanguageModuleLoaderException Is thrown when meta language could not be loaded.
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.lang.X4OLanguageLocal, org.x4o.xml.lang.X4OLanguageModuleLocal)
|
||||
*/
|
||||
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModuleLocal languageModule) throws X4OLanguageModuleLoaderException {
|
||||
languageModule.setId(META_LANGUAGE);
|
||||
languageModule.setProviderHost(META_LANGUAGE_HOST);
|
||||
languageModule.setProviderName(MetaLanguageSiblingLoader.class.getSimpleName());
|
||||
languageModule.setDescription(META_LANGUAGE_DESCRIPTION);
|
||||
@Override
|
||||
public void loadLanguageModule(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageModuleLocal module) throws X4OLanguageModuleLoaderException {
|
||||
module.setId(META_LANGUAGE);
|
||||
module.setProviderHost(META_LANGUAGE_HOST);
|
||||
module.setProviderName(MetaLanguageSiblingLoader.class.getSimpleName());
|
||||
module.setDescription(META_LANGUAGE_DESCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an sibling language.
|
||||
* @param language The ElementLanguage to load for.
|
||||
* @param languageLoader The x4o language loader.
|
||||
* @throws X4OLanguageLoaderException
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLoaderSibling#loadLanguageSibling(org.x4o.xml.lang.X4OLanguageLocal, org.x4o.xml.lang.X4OLanguageLoader)
|
||||
*/
|
||||
public void loadLanguageSibling(X4OLanguageLocal language,X4OLanguageLoader languageLoader) throws X4OLanguageLoaderException {
|
||||
|
||||
// Load the meta language.
|
||||
languageLoader.loadLanguage(language, META_LANGUAGE, META_LANGUAGE_VERSION);
|
||||
@Override
|
||||
public void loadLanguageSibling(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageLoader loader) throws X4OLanguageLoaderException {
|
||||
loader.loadLanguage(session, language, META_LANGUAGE, META_LANGUAGE_VERSION);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@
|
|||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
|
||||
|
|
@ -37,13 +35,10 @@ import org.x4o.xml.lang.X4OLanguageSession;
|
|||
*/
|
||||
public abstract class AbstractX4OPhase implements X4OPhase {
|
||||
|
||||
protected List<X4OPhaseListener> phaseListeners = null;
|
||||
|
||||
/**
|
||||
* Creates the AbstractX4OPhaseHandler.
|
||||
*/
|
||||
public AbstractX4OPhase() {
|
||||
phaseListeners = new ArrayList<X4OPhaseListener>(3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,30 +48,6 @@ public abstract class AbstractX4OPhase implements X4OPhase {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the phase listeners.
|
||||
* @return The x4o phase listeners.
|
||||
*/
|
||||
public List<X4OPhaseListener> getPhaseListeners() {
|
||||
return phaseListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a phase listener.
|
||||
* @param listener The phase listener to add.
|
||||
*/
|
||||
public void addPhaseListener(X4OPhaseListener listener) {
|
||||
phaseListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed a phase listener.
|
||||
* @param listener The phase listener to remove.
|
||||
*/
|
||||
public void removePhaseListener(X4OPhaseListener listener) {
|
||||
phaseListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* If returns true then this handler will run on all elements.
|
||||
* @return defaults to true.
|
||||
|
|
@ -97,6 +68,17 @@ public abstract class AbstractX4OPhase implements X4OPhase {
|
|||
* @param elementLanguage The language to run phase for.
|
||||
* @throws X4OPhaseException when phase has error.
|
||||
*/
|
||||
public void runPhase(X4OLanguageSession elementLanguage) throws X4OPhaseException {
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
}
|
||||
|
||||
public void debugPhaseMessage(X4OLanguageSession languageSession, String message) throws X4OPhaseException {
|
||||
if (!languageSession.hasX4ODebugWriter()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
languageSession.getX4ODebugWriter().debugPhaseMessage(message,this.getClass());
|
||||
} catch (ElementException ee) {
|
||||
throw new X4OPhaseException(this, ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import org.x4o.xml.lang.X4OLanguageSessionLocal;
|
|||
public class DefaultX4OPhaseManager implements X4OPhaseManagerLocal {
|
||||
|
||||
/** The X4OPhaseHandler */
|
||||
private List<X4OPhase> x4oPhases = null;
|
||||
private final List<X4OPhase> x4oPhases;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -97,7 +97,6 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
// throw new IllegalStateException("Can't add new phases after first phase is completed.");
|
||||
//}
|
||||
x4oPhases.add(phase);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -128,6 +127,8 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
* @throws X4OPhaseException When a running handlers throws one.
|
||||
*/
|
||||
public void runPhases(X4OLanguageSession languageSession, X4OPhaseType type) throws X4OPhaseException {
|
||||
// convert to local for state changes
|
||||
X4OLanguageSessionLocal languageSessionLocal = X4OLanguageSessionLocal.class.cast(languageSession);
|
||||
|
||||
// sort for the order
|
||||
List<X4OPhase> x4oPhasesOrder = getOrderedPhases(type);
|
||||
|
|
@ -148,10 +149,10 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
}
|
||||
|
||||
// debug output
|
||||
((X4OLanguageSessionLocal)languageSession).setPhaseCurrent(phase);
|
||||
languageSessionLocal.setPhaseCurrent(phase);
|
||||
|
||||
// run listeners
|
||||
for (X4OPhaseListener l:phase.getPhaseListeners()) {
|
||||
for (X4OPhaseListener l : languageSessionLocal.storePhaseListeners(phase.getId())) {
|
||||
l.preRunPhase(phase, languageSession);
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +165,7 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
executePhaseRoot(languageSession, phase);
|
||||
} finally {
|
||||
// run the listeners again
|
||||
for (X4OPhaseListener l:phase.getPhaseListeners()) {
|
||||
for (X4OPhaseListener l : languageSessionLocal.storePhaseListeners(phase.getId())) {
|
||||
l.endRunPhase(phase, languageSession);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,9 @@
|
|||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhase is one small step in the read or write process of the language.
|
||||
*
|
||||
|
|
@ -59,24 +56,6 @@ public interface X4OPhase {
|
|||
*/
|
||||
void runPhase(X4OLanguageSession elementLanguage) throws X4OPhaseException;
|
||||
|
||||
/**
|
||||
* Returns all phase listeners which where added.
|
||||
* @return All X4OPhaseListeners.
|
||||
*/
|
||||
List<X4OPhaseListener> getPhaseListeners();
|
||||
|
||||
/**
|
||||
* Adds an X4OPhaseListener.
|
||||
* @param listener The listener to add.
|
||||
*/
|
||||
void addPhaseListener(X4OPhaseListener listener);
|
||||
|
||||
/**
|
||||
* Removes an X4OPhaseListener.
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
void removePhaseListener(X4OPhaseListener listener);
|
||||
|
||||
/**
|
||||
* runPhase is called but should do nothig.
|
||||
* When elementPhase is enables x4o tries to merge all element phases so
|
||||
|
|
|
|||
|
|
@ -102,9 +102,10 @@ public class X4OPhaseLanguageInit {
|
|||
}
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
try {
|
||||
//debugPhaseMessage("Loading main language: "+elementLanguage.getLanguage(),this,elementLanguage);
|
||||
debugPhaseMessage(languageSession, "Load main language: " + languageSession.getLanguage().getLanguageName());
|
||||
X4OLanguageLoader loader = X4OLanguageClassLoader.newInstance(X4OLanguageLoader.class, languageSession.getLanguage().getLanguageConfiguration().getDefaultLanguageLoader());
|
||||
loader.loadLanguage((X4OLanguageLocal)languageSession.getLanguage(),languageSession.getLanguage().getLanguageName(),languageSession.getLanguage().getLanguageVersion());
|
||||
X4OLanguageLocal language = (X4OLanguageLocal)languageSession.getLanguage();
|
||||
loader.loadLanguage(languageSession, language, language.getLanguageName(), language.getLanguageVersion());
|
||||
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
languageSession.getX4ODebugWriter().debugElementLanguageModules(languageSession);
|
||||
|
|
@ -142,9 +143,10 @@ public class X4OPhaseLanguageInit {
|
|||
try {
|
||||
if (siblingLoaders.isEmpty()==false) {
|
||||
X4OLanguageLoader loader = X4OLanguageClassLoader.newInstance(X4OLanguageLoader.class, languageSession.getLanguage().getLanguageConfiguration().getDefaultLanguageLoader());
|
||||
X4OLanguageLocal language = (X4OLanguageLocal)languageSession.getLanguage();
|
||||
for (X4OLanguageModuleLoaderSibling siblingLoader:siblingLoaders) {
|
||||
//debugPhaseMessage("Loading sibling langauge loader: "+siblingLoader,this,elementLanguage);
|
||||
siblingLoader.loadLanguageSibling((X4OLanguageLocal)languageSession.getLanguage(), loader);
|
||||
debugPhaseMessage(languageSession, "Loading sibling langauge loader: " + siblingLoader);
|
||||
siblingLoader.loadLanguageSibling(languageSession, language, loader);
|
||||
}
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
languageSession.getX4ODebugWriter().debugElementLanguageModules(languageSession);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import java.util.logging.Logger;
|
|||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementNamespaceAttribute;
|
||||
import org.x4o.xml.io.X4ODebugWriter;
|
||||
import org.x4o.xml.element.ElementAttributeValueParser;
|
||||
import org.x4o.xml.element.ElementBindingHandler;
|
||||
import org.x4o.xml.element.ElementClassAttribute;
|
||||
|
|
@ -44,8 +43,6 @@ import org.x4o.xml.element.ElementNamespace;
|
|||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
import org.x4o.xml.lang.X4OLanguageClassLoader;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
* Factory which can create X4OPhaseHandlers for all the predefined phases used in default x4o language parsing.
|
||||
|
|
@ -113,16 +110,6 @@ public class X4OPhaseLanguageRead {
|
|||
// We are done
|
||||
}
|
||||
|
||||
private void debugPhaseMessage(String message,X4OPhase phaseHandler,X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
try {
|
||||
languageSession.getX4ODebugWriter().debugPhaseMessage(message,phaseHandler.getClass());
|
||||
} catch (ElementException ee) {
|
||||
throw new X4OPhaseException(phaseHandler,ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the startX4OPhase which is a empty meta phase.
|
||||
*/
|
||||
|
|
@ -447,7 +434,7 @@ public class X4OPhaseLanguageRead {
|
|||
if (dirtyElements.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
debugPhaseMessage("Dirty elements: "+dirtyElements.size(), this,element.getLanguageSession());
|
||||
debugPhaseMessage(element.getLanguageSession(), "Dirty elements: " + dirtyElements.size());
|
||||
X4OPhase p = phaseManager.getPhase(READ_BEGIN);
|
||||
for (Element e : dirtyElements) {
|
||||
phaseManager.runPhasesForElement(e,getType(), p);
|
||||
|
|
@ -478,7 +465,7 @@ public class X4OPhaseLanguageRead {
|
|||
if (dirtyElements.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
debugPhaseMessage("Dirty elements last: "+dirtyElements.size(), this,element.getLanguageSession());
|
||||
debugPhaseMessage(element.getLanguageSession(), "Dirty elements last: " + dirtyElements.size());
|
||||
X4OPhase p = phaseManager.getPhase(READ_BEGIN);
|
||||
for (Element e : dirtyElements) {
|
||||
phaseManager.runPhasesForElement(e,getType(), p);
|
||||
|
|
@ -644,7 +631,6 @@ public class X4OPhaseLanguageRead {
|
|||
// print the properties and classes for this language/config
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
try {
|
||||
//languageSession.getX4ODebugWriter().debugLanguageProperties(languageSession);
|
||||
languageSession.getX4ODebugWriter().debugLanguageDefaultClasses(languageSession);
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
|
|
@ -659,18 +645,13 @@ public class X4OPhaseLanguageRead {
|
|||
*/
|
||||
public X4OPhase releasePhase() {
|
||||
|
||||
// for debug output
|
||||
// for debug output TODO: redo release counters
|
||||
/*
|
||||
class ReleasePhaseListener implements X4OPhaseListener {
|
||||
private int elementsReleased = 0;
|
||||
/**
|
||||
* @see org.x4o.xml.lang.phase.X4OPhaseListener#preRunPhase(org.x4o.xml.lang.phase.X4OPhase, org.x4o.xml.lang.X4OLanguageSession)
|
||||
*/
|
||||
public void preRunPhase(X4OPhase phase,X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
elementsReleased=0;
|
||||
}
|
||||
/**
|
||||
* @see org.x4o.xml.lang.phase.X4OPhaseListener#endRunPhase(org.x4o.xml.lang.phase.X4OPhase, org.x4o.xml.lang.X4OLanguageSession)
|
||||
*/
|
||||
public void endRunPhase(X4OPhase phase,X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
if (languageSession.hasX4ODebugWriter()==false) {
|
||||
return;
|
||||
|
|
@ -689,8 +670,9 @@ public class X4OPhaseLanguageRead {
|
|||
elementsReleased++;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
final ReleasePhaseListener releaseCounter = new ReleasePhaseListener();
|
||||
//final ReleasePhaseListener releaseCounter = new ReleasePhaseListener();
|
||||
X4OPhase result = new AbstractX4OPhase() {
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
|
|
@ -708,12 +690,12 @@ public class X4OPhaseLanguageRead {
|
|||
element.release();
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
} finally {
|
||||
releaseCounter.addReleasedElement();
|
||||
}
|
||||
}// finally {
|
||||
// releaseCounter.addReleasedElement();
|
||||
//}
|
||||
}
|
||||
};
|
||||
result.addPhaseListener(releaseCounter);
|
||||
//result.addPhaseListener(releaseCounter);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import org.x4o.xml.X4ODriverManager;
|
|||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTask;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTaskException;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTaskExecutor;
|
||||
|
||||
/**
|
||||
* X4OLanguageTaskCommandLine runs a language task from the command line.
|
||||
|
|
@ -87,9 +86,8 @@ public class X4OTaskCommandLine {
|
|||
}
|
||||
|
||||
private void executeLanguageTask() throws X4OLanguageTaskException {
|
||||
X4OLanguageTaskExecutor taskExecutor = task.createTaskExecutor(config);
|
||||
X4OLanguage language = driver.createLanguage();
|
||||
taskExecutor.execute(language);
|
||||
X4OLanguage language = driver.createLanguage(); // TODO: also add support for version select
|
||||
X4OTaskRunner.runTaskLanguage(task, language, config);
|
||||
}
|
||||
|
||||
private void systemErrExit(String message) {
|
||||
|
|
|
|||
|
|
@ -27,13 +27,18 @@ import java.util.List;
|
|||
import org.x4o.sax3.io.SAX3PropertyConfig;
|
||||
import org.x4o.xml.X4ODriver;
|
||||
import org.x4o.xml.X4ODriverManager;
|
||||
import org.x4o.xml.io.X4OConnectionException;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTask;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTaskException;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTaskExecutor;
|
||||
|
||||
/**
|
||||
* X4OTaskRunner finds all x4o objects and configs and then run the x4o langauge task.
|
||||
* X4OTaskRunner finds all x4o objects and configs and then run the x4o langauge
|
||||
* task.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 30, 2013
|
||||
|
|
@ -52,13 +57,23 @@ public final class X4OTaskRunner {
|
|||
String value = prop.getValue();
|
||||
config.setPropertyParsedValue(key, value);
|
||||
}
|
||||
X4OLanguageTaskExecutor taskExecutor = task.createTaskExecutor(config);
|
||||
X4OLanguage language = null;
|
||||
if (languageVersion == null) {
|
||||
language = driver.createLanguage();
|
||||
} else {
|
||||
language = driver.createLanguage(languageVersion);
|
||||
}
|
||||
runTaskLanguage(task, language, config);
|
||||
}
|
||||
|
||||
static public void runTaskLanguage(X4OLanguageTask task, X4OLanguage language, SAX3PropertyConfig config) throws X4OLanguageTaskException {
|
||||
X4OLanguageTaskExecutor taskExecutor = task.createTaskExecutor(config);
|
||||
// Run init to load the language, which is 'normally' in read or write for deep recursief debugging support.
|
||||
try (X4OLanguageSession session = language.createLanguageSession()) {
|
||||
X4OLanguageLocal.class.cast(language).init(session);
|
||||
} catch (X4OConnectionException | X4OPhaseException e) {
|
||||
throw new X4OLanguageTaskException(config, e.getMessage(), e);
|
||||
}
|
||||
taskExecutor.execute(language);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ import java.util.List;
|
|||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
import org.x4o.xml.lang.X4OLanguageSessionLocal;
|
||||
|
||||
/**
|
||||
* X4ODriverManager
|
||||
|
|
@ -86,12 +90,13 @@ public class X4ODriverManagerTest {
|
|||
|
||||
@Test
|
||||
public void testLanguageVersionNonExcisting() throws Exception {
|
||||
String language = "test";
|
||||
String version = "99.9";
|
||||
String languageTest = "test";
|
||||
String versionTest = "99.9";
|
||||
Throwable e = null;
|
||||
try {
|
||||
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(language);
|
||||
driver.createLanguage(version).createLanguageSession();
|
||||
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(languageTest);
|
||||
X4OLanguage language = driver.createLanguage(versionTest);
|
||||
X4OLanguageLocal.class.cast(language).init(language.createLanguageSession());
|
||||
} catch (Throwable catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,13 +28,18 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.x4o.sax3.SAX3WriterXml;
|
||||
import org.x4o.sax3.io.ContentCloseable;
|
||||
import org.x4o.sax3.io.ContentWriter;
|
||||
import org.x4o.xml.X4ODriver;
|
||||
import org.x4o.xml.io.DefaultX4OReader;
|
||||
import org.x4o.xml.io.DefaultX4OWriter;
|
||||
import org.x4o.xml.io.X4ODebugWriter;
|
||||
import org.x4o.xml.io.X4OReader;
|
||||
import org.x4o.xml.io.X4OWriter;
|
||||
import org.x4o.xml.test.TestDriver;
|
||||
|
|
@ -77,8 +82,13 @@ public class X4ODebugWriterTest {
|
|||
File debugFile = createDebugFile();
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
reader.setProperty(DefaultX4OReader.DEBUG_OUTPUT_STREAM, new FileOutputStream(debugFile));
|
||||
try (ContentWriter debugHandler = new SAX3WriterXml(new FileOutputStream(debugFile))) {
|
||||
try (ContentCloseable docClosure = debugHandler.startDocumentClosure()) {
|
||||
debugHandler.startPrefixMapping(X4ODebugWriter.DEBUG_URI_NS, X4ODebugWriter.DEBUG_URI);
|
||||
reader.setProperty(DefaultX4OReader.DEBUG_OUTPUT_HANDLER, debugHandler);
|
||||
reader.readResource("tests/attributes/test-bean.xml");
|
||||
}
|
||||
}
|
||||
|
||||
Assertions.assertTrue(debugFile.exists(), "Debug file does not exists.");
|
||||
String debug = readFile(debugFile);
|
||||
|
|
@ -86,8 +96,8 @@ public class X4ODebugWriterTest {
|
|||
Assertions.assertFalse(debug.length()==0, "no debug content");
|
||||
Assertions.assertTrue(debug.length()>20, "debug content to small");
|
||||
|
||||
System.out.println("=================== Reader Output ======================");
|
||||
System.out.println(debug);
|
||||
//System.out.println("=================== Reader Output ======================");
|
||||
//System.out.println(debug);
|
||||
debugFile.delete();
|
||||
}
|
||||
|
||||
|
|
@ -100,8 +110,10 @@ public class X4ODebugWriterTest {
|
|||
X4OWriter<TestObjectRoot> writer = driver.createWriter();
|
||||
TestObjectRoot object = reader.readResource("tests/attributes/test-bean.xml");
|
||||
|
||||
writer.setProperty(DefaultX4OWriter.DEBUG_OUTPUT_STREAM, new FileOutputStream(debugFile));
|
||||
try (OutputStream out = new FileOutputStream(debugFile)) {
|
||||
writer.setProperty(DefaultX4OWriter.DEBUG_OUTPUT_STREAM, out);
|
||||
writer.writeFile(object, writeFile);
|
||||
}
|
||||
|
||||
Assertions.assertTrue(debugFile.exists(), "Debug file does not exists.");
|
||||
String debug = readFile(debugFile);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import org.x4o.xml.X4ODriver;
|
|||
import org.x4o.xml.eld.CelDriver;
|
||||
import org.x4o.xml.io.DefaultX4OReader;
|
||||
import org.x4o.xml.io.X4OEntityResolver;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
import org.x4o.xml.test.TestDriver;
|
||||
import org.x4o.xml.test.models.TestObjectRoot;
|
||||
|
|
@ -62,14 +64,19 @@ public class X4OEntityResolverTest {
|
|||
@Test
|
||||
public void testResolve() throws Exception {
|
||||
X4ODriver<?> driver = new CelDriver();
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(driver.createLanguage().createLanguageSession(),DefaultX4OReader.DEFAULT_PROPERTY_CONFIG);
|
||||
X4OLanguage language = driver.createLanguage();
|
||||
try (X4OLanguageSession session = language.createLanguageSession()) {
|
||||
X4OLanguageLocal.class.cast(language).init(session);
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(session, DefaultX4OReader.DEFAULT_PROPERTY_CONFIG);
|
||||
InputSource input = resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd");
|
||||
Assertions.assertNotNull(input);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveMissing() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = new TestDriver();
|
||||
// NOTE: this session is not inited, see fix code above.
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(driver.createLanguage().createLanguageSession(),DefaultX4OReader.DEFAULT_PROPERTY_CONFIG);
|
||||
Exception e = null;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import org.x4o.xml.X4ODriverManager;
|
|||
import org.x4o.xml.eld.CelDriver;
|
||||
import org.x4o.xml.eld.EldDriver;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTask;
|
||||
import org.x4o.xml.lang.task.run.X4OTaskRunner;
|
||||
import org.x4o.xml.test.TestDriver;
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +57,7 @@ public class X4OWriteLanguageDocExecutorTest {
|
|||
SAX3PropertyConfig config = task.createTaskConfig();
|
||||
File outputPath = createOutputPath(outputPostfix);
|
||||
config.setProperty(EldDocWriter.OUTPUT_PATH,outputPath);
|
||||
task.createTaskExecutor(config).execute(driver.createLanguage());
|
||||
X4OTaskRunner.runTaskLanguage(task, driver.createLanguage(), config);
|
||||
Assertions.assertTrue(outputPath.exists());
|
||||
Assertions.assertTrue(outputPath.list()!=null);
|
||||
Assertions.assertTrue(outputPath.list().length>2);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import org.x4o.xml.eld.EldDriver;
|
|||
import org.x4o.xml.eld.EldModuleLoaderCore;
|
||||
import org.x4o.xml.io.X4OWriterTest;
|
||||
import org.x4o.xml.lang.task.X4OLanguageTask;
|
||||
import org.x4o.xml.lang.task.run.X4OTaskRunner;
|
||||
import org.x4o.xml.test.swixml.SwiXmlDriver;
|
||||
|
||||
/**
|
||||
|
|
@ -71,7 +72,7 @@ public class EldXsdLanguageTaskTest {
|
|||
config.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
task.createTaskExecutor(config).execute(driver.createLanguage());
|
||||
X4OTaskRunner.runTaskLanguage(task, driver.createLanguage(), config);
|
||||
Assertions.assertTrue(outputPath.exists());
|
||||
Assertions.assertTrue(outputPath.list()!=null);
|
||||
return outputPath;
|
||||
|
|
|
|||
|
|
@ -42,13 +42,16 @@ import org.x4o.xml.test.models.TestObjectRoot;
|
|||
public class DefaultX4OLanguageLoaderTest {
|
||||
|
||||
static X4ODriver<TestObjectRoot> driver;
|
||||
static X4OLanguage language;
|
||||
static X4OLanguageLocal language;
|
||||
static X4OLanguageSession session;
|
||||
static DefaultX4OLanguageLoader loader;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
driver = TestDriver.getInstance();
|
||||
language = driver.createLanguage();
|
||||
language = (X4OLanguageLocal)driver.createLanguage();
|
||||
session = language.createLanguageSession();
|
||||
language.init(session);
|
||||
loader = (DefaultX4OLanguageLoader)language.getLanguageConfiguration().getDefaultLanguageLoader().newInstance();
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +59,7 @@ public class DefaultX4OLanguageLoaderTest {
|
|||
public void testLoadingDuplicate() throws Exception {
|
||||
Exception e = null;
|
||||
try {
|
||||
loader.loadLanguage((X4OLanguageLocal)language, "test", "1.0");
|
||||
loader.loadLanguage(session, language, "test", "1.0");
|
||||
} catch (Exception ee) {
|
||||
e = ee;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
|||
|
||||
private final SAX3PropertyConfig propertyConfig;
|
||||
private final Writer out;
|
||||
private boolean started = false;
|
||||
private int indent = 0;
|
||||
private Map<String,String> prefixMapping = null;
|
||||
private List<String> printedMappings = null;
|
||||
|
|
@ -130,6 +131,10 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
|||
* @see org.xml.sax.ContentHandler#startDocument()
|
||||
*/
|
||||
public void startDocument() throws SAXException {
|
||||
if (started) {
|
||||
throw new SAXException("Can start document only once.");
|
||||
}
|
||||
started = true;
|
||||
indent = 0;
|
||||
write(SAX3XMLConstants.getDocumentDeclaration(getPropertyConfig().getPropertyString(OUTPUT_ENCODING)));
|
||||
prologWriteLicence();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
package org.x4o.sax3.io;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
|
|
@ -38,6 +39,23 @@ import org.xml.sax.ext.LexicalHandler;
|
|||
*/
|
||||
public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable {
|
||||
|
||||
/**
|
||||
* Wrap startDocument and endDocument in a body closable code block.
|
||||
*
|
||||
* @return An closable resource block reference.
|
||||
* @throws SAXException When IOException is thrown.
|
||||
*/
|
||||
default ContentCloseable startDocumentClosure() throws SAXException {
|
||||
startDocument();
|
||||
return () -> {
|
||||
try {
|
||||
endDocument();
|
||||
} catch (SAXException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts and ends an element in one call.
|
||||
* @param uri The uri of the element.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue