Converted x4o debug writer to enum tagged writer.

This commit is contained in:
Willem Cazander 2014-03-14 20:02:56 +01:00
parent edde72a8fb
commit 7d14230745
2 changed files with 142 additions and 107 deletions

View file

@ -42,7 +42,9 @@ import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementNamespace; import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.element.ElementNamespaceInstanceProvider; import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.io.X4OConnection; import org.x4o.xml.io.X4OConnection;
import org.x4o.xml.io.XMLConstants;
import org.x4o.xml.io.sax.ext.ContentWriter; import org.x4o.xml.io.sax.ext.ContentWriter;
import org.x4o.xml.io.sax.ext.ContentWriterTagWrapper;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageModuleLoaderResult; import org.x4o.xml.lang.X4OLanguageModuleLoaderResult;
import org.x4o.xml.lang.X4OLanguageSession; import org.x4o.xml.lang.X4OLanguageSession;
@ -63,20 +65,74 @@ public class X4ODebugWriter {
static public final String DEBUG_URI = "http://language.x4o.org/xml/ns/debug-output"; static public final String DEBUG_URI = "http://language.x4o.org/xml/ns/debug-output";
protected ContentWriter contentWriter = null; protected ContentWriterTagWrapper<Tag,ContentWriter> contentWriter = null;
public X4ODebugWriter(ContentWriter debugWriter) { public X4ODebugWriter(ContentWriter debugWriter) {
this.contentWriter=debugWriter; this.contentWriter=new ContentWriterTagWrapper<Tag,ContentWriter>(debugWriter,DEBUG_URI,XMLConstants.NULL_NS_URI);
} }
public ContentWriter getContentWriter() { public ContentWriter getContentWriter() {
return contentWriter; return contentWriter.getContentWriterWrapped();
} }
enum X4ODebugTag { // TODO: rename most debug tags
execute222Phase, enum Tag {
testTasg, executePhase,
stekel executePhaseDone,
X4OConnection,
X4OLanguageSession,
X4OLanguageSessionSkipPhase,
X4OConnectionProperties,
X4OConnectionProperty,
X4OLanguageDefaultClasses,
X4OLanguageDefaultClass,
phaseOrder,
phase,
X4OPhaseListener,
X4OPhaseDependency,
ElementLanguageModules,
ElementLanguageModule,
ElementLanguageModuleResult,
elementInterface,
elementNamespace,
elementNamespaceAttribute,
nextAttribute,
ElementNamespaceInstanceProvider,
elementObject,
element,
elementClassAttribute,
attributeAlias,
SAXConfig,
SAXConfigProperty,
message,
runElementConfigurator,
doBind,
elementClass,
elementSkipPhase,
elementClassBase,
elementConfigurator,
elementConfiguratorGlobal,
objectConverter,
elementBindingHandler,
elementBindingHandlerChildClass,
printElementTree,
end
} }
public X4OPhaseListener createDebugX4OPhaseListener() { public X4OPhaseListener createDebugX4OPhaseListener() {
@ -84,7 +140,6 @@ public class X4ODebugWriter {
} }
class DebugX4OPhaseListener implements X4OPhaseListener { class DebugX4OPhaseListener implements X4OPhaseListener {
long startTime = 0; long startTime = 0;
/** /**
@ -99,7 +154,7 @@ public class X4ODebugWriter {
if (elementLanguage!=null) { if (elementLanguage!=null) {
atts.addAttribute("", "language","","", elementLanguage.getLanguage().getLanguageName()); atts.addAttribute("", "language","","", elementLanguage.getLanguage().getLanguageName());
} }
contentWriter.startElement (DEBUG_URI, X4ODebugTag.execute222Phase.name(), "", atts); contentWriter.printTagStart (Tag.executePhase, atts);
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
} }
@ -112,10 +167,9 @@ public class X4ODebugWriter {
atts.addAttribute ("", "phaseId", "", "", phase.getId()); atts.addAttribute ("", "phaseId", "", "", phase.getId());
atts.addAttribute ("", "time", "", "", (stopTime-startTime)+""); atts.addAttribute ("", "time", "", "", (stopTime-startTime)+"");
atts.addAttribute ("", "timeUnit", "", "", "ms"); atts.addAttribute ("", "timeUnit", "", "", "ms");
contentWriter.startElement (DEBUG_URI, "executePhaseDone", "", atts); contentWriter.printTagStartEnd (Tag.executePhaseDone, atts);
contentWriter.endElement (DEBUG_URI, "executePhaseDone" , "");
contentWriter.endElement (DEBUG_URI, X4ODebugTag.execute222Phase.name() , ""); contentWriter.printTagEnd (Tag.executePhase);
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
} }
@ -141,22 +195,19 @@ public class X4ODebugWriter {
atts.addAttribute ("", "languageVersion", "", "", languageSession.getLanguage().getLanguageVersion()); atts.addAttribute ("", "languageVersion", "", "", languageSession.getLanguage().getLanguageVersion());
atts.addAttribute ("", "className", "", "", ec.getClass().getName()); atts.addAttribute ("", "className", "", "", ec.getClass().getName());
atts.addAttribute ("", "currentTimeMillis", "", "", System.currentTimeMillis()+""); atts.addAttribute ("", "currentTimeMillis", "", "", System.currentTimeMillis()+"");
contentWriter.startElement(X4ODebugWriter.DEBUG_URI, "X4OConnection", "", atts); contentWriter.printTagStart(Tag.X4OConnection, atts);
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "phaseStop", "", "", languageSession.getPhaseStop()); atts.addAttribute ("", "phaseStop", "", "", languageSession.getPhaseStop());
atts.addAttribute ("", "className", "", "", languageSession.getClass().getName()); atts.addAttribute ("", "className", "", "", languageSession.getClass().getName());
contentWriter.startElement (DEBUG_URI, "X4OLanguageSession", "", atts); contentWriter.printTagStart (Tag.X4OLanguageSession, atts);
for (String skipPhase:languageSession.getPhaseSkip()) { for (String skipPhase:languageSession.getPhaseSkip()) {
atts = new AttributesImpl(); contentWriter.printTagCharacters(Tag.X4OLanguageSessionSkipPhase, skipPhase);
contentWriter.startElement (DEBUG_URI, "X4OLanguageSessionSkipPhase", "", atts);
contentWriter.characters(skipPhase);
contentWriter.endElement(DEBUG_URI, "X4OLanguageSessionSkipPhase", "");
} }
contentWriter.endElement(DEBUG_URI, "X4OLanguageSession", ""); contentWriter.printTagEnd(Tag.X4OLanguageSession);
atts = new AttributesImpl(); atts = new AttributesImpl();
contentWriter.startElement (DEBUG_URI, "X4OConnectionProperties", "", atts); contentWriter.printTagStart (Tag.X4OConnectionProperties, atts);
for (String key:ec.getPropertyKeys()) { for (String key:ec.getPropertyKeys()) {
Object value = ec.getProperty(key); Object value = ec.getProperty(key);
AttributesImpl atts2 = new AttributesImpl(); AttributesImpl atts2 = new AttributesImpl();
@ -169,22 +220,20 @@ public class X4ODebugWriter {
} }
atts2.addAttribute ("", "value", "", "", value.toString()); atts2.addAttribute ("", "value", "", "", value.toString());
} }
contentWriter.printTagStartEnd (Tag.X4OConnectionProperty, atts2);
contentWriter.startElement (DEBUG_URI, "X4OConnectionProperty", "", atts2);
contentWriter.endElement(DEBUG_URI, "X4OConnectionProperty", "");
} }
contentWriter.endElement(DEBUG_URI, "X4OConnectionProperties", ""); contentWriter.printTagEnd (Tag.X4OConnectionProperties);
} }
public void debugConnectionEnd() throws SAXException { public void debugConnectionEnd() throws SAXException {
contentWriter.endElement(X4ODebugWriter.DEBUG_URI, "X4OConnection", ""); contentWriter.printTagEnd (Tag.X4OConnection);
} }
public void debugLanguageDefaultClasses(X4OLanguageSession ec) throws ElementException { public void debugLanguageDefaultClasses(X4OLanguageSession ec) throws ElementException {
try { try {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
contentWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClasses", "", atts); contentWriter.printTagStart (Tag.X4OLanguageDefaultClasses,atts);
X4OLanguageConfiguration conf = ec.getLanguage().getLanguageConfiguration(); X4OLanguageConfiguration conf = ec.getLanguage().getLanguageConfiguration();
debugLanguageDefaultClass("defaultElementNamespace",conf.getDefaultElementNamespace()); debugLanguageDefaultClass("defaultElementNamespace",conf.getDefaultElementNamespace());
@ -201,7 +250,7 @@ public class X4ODebugWriter {
debugLanguageDefaultClass("defaultElementObjectPropertyValue",conf.getDefaultElementObjectPropertyValue()); debugLanguageDefaultClass("defaultElementObjectPropertyValue",conf.getDefaultElementObjectPropertyValue());
debugLanguageDefaultClass("defaultElementNamespaceAttributeComparator",conf.getDefaultElementNamespaceAttributeComparator()); debugLanguageDefaultClass("defaultElementNamespaceAttributeComparator",conf.getDefaultElementNamespaceAttributeComparator());
contentWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClasses", ""); contentWriter.printTagEnd(Tag.X4OLanguageDefaultClasses);
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -211,30 +260,28 @@ public class X4ODebugWriter {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", name); atts.addAttribute ("", "name", "", "", name);
atts.addAttribute ("", "className", "", "", clazz.getName()); atts.addAttribute ("", "className", "", "", clazz.getName());
contentWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClass", "", atts); contentWriter.printTagStartEnd (Tag.X4OLanguageDefaultClass, atts);
contentWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClass", "");
} }
public void debugPhaseOrder(List<X4OPhase> phases) throws X4OPhaseException { public void debugPhaseOrder(List<X4OPhase> phases) throws X4OPhaseException {
X4OPhase phase = null; X4OPhase phase = null;
try { try {
AttributesImpl atts = new AttributesImpl(); contentWriter.printTagStart (Tag.phaseOrder);
contentWriter.startElement (DEBUG_URI, "phaseOrder", "", atts);
for (X4OPhase phase2:phases) { for (X4OPhase phase2:phases) {
phase = phase2; phase = phase2;
debugPhase(phase2); debugPhase(phase2);
} }
contentWriter.endElement(DEBUG_URI, "phaseOrder", ""); contentWriter.printTagEnd(Tag.phaseOrder);
} catch (SAXException e) { } catch (SAXException e) {
// fall back... // fall back...
if (phase==null) { if (phase==null) {
if (phases.isEmpty()) { if (phases.isEmpty()) {
throw new X4OPhaseException(null,e); /// mmmm throw new X4OPhaseException(null,e); /// FIXME: mmmm phase in exception here ?
} }
phase = phases.get(0); phase = phases.get(0);
} }
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
} }
} }
private void debugPhase(X4OPhase phase) throws X4OPhaseException { private void debugPhase(X4OPhase phase) throws X4OPhaseException {
@ -245,21 +292,16 @@ public class X4ODebugWriter {
atts.addAttribute ("", "runOnce", "", "", phase.isRunOnce()+""); atts.addAttribute ("", "runOnce", "", "", phase.isRunOnce()+"");
atts.addAttribute ("", "listenersSize", "", "", phase.getPhaseListeners().size()+""); atts.addAttribute ("", "listenersSize", "", "", phase.getPhaseListeners().size()+"");
contentWriter.startElement (DEBUG_URI, "phase", "", atts); contentWriter.printTagStart (Tag.phase, atts);
for (X4OPhaseListener l:phase.getPhaseListeners()) { for (X4OPhaseListener l:phase.getPhaseListeners()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", l.getClass().getName()); atts.addAttribute ("", "className", "", "", l.getClass().getName());
contentWriter.startElement (DEBUG_URI, "X4OPhaseListener", "", atts); contentWriter.printTagStartEnd (Tag.X4OPhaseListener, atts);
contentWriter.endElement(DEBUG_URI, "X4OPhaseListener", "");
} }
for (String dep:phase.getPhaseDependencies()) { for (String dep:phase.getPhaseDependencies()) {
atts = new AttributesImpl(); contentWriter.printTagCharacters(Tag.X4OPhaseDependency, dep);
//atts.addAttribute ("", "dependency", "", "", dep);
contentWriter.startElement (DEBUG_URI, "X4OPhaseDependency", "", atts);
contentWriter.characters(dep);
contentWriter.endElement(DEBUG_URI, "X4OPhaseDependency", "");
} }
contentWriter.endElement(DEBUG_URI, "phase", ""); contentWriter.printTagEnd(Tag.phase);
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
} }
@ -267,8 +309,7 @@ public class X4ODebugWriter {
public void debugElementLanguageModules(X4OLanguageSession elementLanguage) throws ElementException { public void debugElementLanguageModules(X4OLanguageSession elementLanguage) throws ElementException {
try { try {
AttributesImpl attsEmpty = new AttributesImpl(); contentWriter.printTagStart (Tag.ElementLanguageModules);
contentWriter.startElement (DEBUG_URI, "ElementLanguageModules", "", attsEmpty);
for (X4OLanguageModule module:elementLanguage.getLanguage().getLanguageModules()) { for (X4OLanguageModule module:elementLanguage.getLanguage().getLanguageModules()) {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
@ -276,7 +317,7 @@ public class X4ODebugWriter {
atts.addAttribute ("", "id", "", "", module.getId()); atts.addAttribute ("", "id", "", "", module.getId());
atts.addAttribute ("", "providerName", "", "", module.getProviderName()); atts.addAttribute ("", "providerName", "", "", module.getProviderName());
atts.addAttribute ("", "providerHost", "", "", module.getProviderHost()); atts.addAttribute ("", "providerHost", "", "", module.getProviderHost());
contentWriter.startElement (DEBUG_URI, "ElementLanguageModule", "", atts); contentWriter.printTagStart (Tag.ElementLanguageModule, atts);
for (X4OLanguageModuleLoaderResult result:X4OLanguageModuleLoaderResult.values()) { for (X4OLanguageModuleLoaderResult result:X4OLanguageModuleLoaderResult.values()) {
String value = module.getLoaderResult(result); String value = module.getLoaderResult(result);
@ -286,8 +327,7 @@ public class X4ODebugWriter {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "resultKey", "", "", result.name()); atts.addAttribute ("", "resultKey", "", "", result.name());
atts.addAttribute ("", "resultValue", "", "", value); atts.addAttribute ("", "resultValue", "", "", value);
contentWriter.startElement (DEBUG_URI, "ElementLanguageModuleResult", "", atts); contentWriter.printTagStartEnd (Tag.ElementLanguageModuleResult, atts);
contentWriter.endElement(DEBUG_URI, "ElementLanguageModuleResult", "");
} }
debugElementConfiguratorGlobal(module.getElementConfiguratorGlobals()); debugElementConfiguratorGlobal(module.getElementConfiguratorGlobals());
@ -299,9 +339,9 @@ public class X4ODebugWriter {
atts.addAttribute ("", "description", "", "", elementInterface.getDescription()); atts.addAttribute ("", "description", "", "", elementInterface.getDescription());
atts.addAttribute ("", "interfaceClass", "", "", elementInterface.getInterfaceClass().getName()); atts.addAttribute ("", "interfaceClass", "", "", elementInterface.getInterfaceClass().getName());
contentWriter.startElement (DEBUG_URI, "elementInterface", "", atts); contentWriter.printTagStart (Tag.elementInterface, atts);
debugElementClassBase(elementInterface); debugElementClassBase(elementInterface);
contentWriter.endElement(DEBUG_URI, "elementInterface", ""); contentWriter.printTagEnd(Tag.elementInterface);
} }
for (ElementNamespace enc:module.getElementNamespaces()) { for (ElementNamespace enc:module.getElementNamespaces()) {
@ -312,21 +352,20 @@ public class X4ODebugWriter {
atts.addAttribute ("", "schemaResource", "", "", enc.getSchemaResource()); atts.addAttribute ("", "schemaResource", "", "", enc.getSchemaResource());
atts.addAttribute ("", "className", "", "", enc.getClass().getName()); atts.addAttribute ("", "className", "", "", enc.getClass().getName());
contentWriter.startElement (DEBUG_URI, ElementNamespace.class.getSimpleName(), "", atts); contentWriter.printTagStart (Tag.elementNamespace, atts);
for (ElementNamespaceAttribute p:enc.getElementNamespaceAttributes()) { for (ElementNamespaceAttribute p:enc.getElementNamespaceAttributes()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", p.getAttributeName()); atts.addAttribute ("", "attributeName", "", "", p.getAttributeName());
atts.addAttribute ("", "description", "", "", p.getDescription()); atts.addAttribute ("", "description", "", "", p.getDescription());
atts.addAttribute ("", "className", "", "", p.getClass().getName()); atts.addAttribute ("", "className", "", "", p.getClass().getName());
contentWriter.startElement (DEBUG_URI, "elementNamespaceAttribute", "", atts); contentWriter.printTagStart (Tag.elementNamespaceAttribute, atts);
for (String para:p.getNextAttributes()) { for (String para:p.getNextAttributes()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", para); atts.addAttribute ("", "attributeName", "", "", para);
contentWriter.startElement (DEBUG_URI, "nextAttribute", "", atts); contentWriter.printTagStartEnd (Tag.nextAttribute, atts);
contentWriter.endElement(DEBUG_URI, "nextAttribute", "");
} }
contentWriter.endElement(DEBUG_URI, "elementNamespaceAttribute", ""); contentWriter.printTagEnd(Tag.elementNamespaceAttribute);
} }
for (ElementClass ec:enc.getElementClasses()) { for (ElementClass ec:enc.getElementClasses()) {
debugElementClass(ec); debugElementClass(ec);
@ -335,16 +374,15 @@ public class X4ODebugWriter {
ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider(); ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider();
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", eip.getClass().getName()); atts.addAttribute ("", "className", "", "", eip.getClass().getName());
contentWriter.startElement (DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "", atts); contentWriter.printTagStartEnd (Tag.ElementNamespaceInstanceProvider, atts);
contentWriter.endElement(DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "");
contentWriter.endElement(DEBUG_URI, ElementNamespace.class.getSimpleName(), ""); contentWriter.printTagEnd(Tag.elementNamespace);
} }
contentWriter.endElement(DEBUG_URI, "ElementLanguageModule", ""); contentWriter.printTagEnd(Tag.ElementLanguageModule);
} }
contentWriter.endElement(DEBUG_URI, "ElementLanguageModules", ""); contentWriter.printTagEnd(Tag.ElementLanguageModules);
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -397,18 +435,18 @@ public class X4ODebugWriter {
atts.addAttribute ("", "exceptionWhileGetingBeanValues", "", "", e.getMessage()); atts.addAttribute ("", "exceptionWhileGetingBeanValues", "", "", e.getMessage());
} }
contentWriter.startElement (DEBUG_URI, "elementObject", "", atts2); contentWriter.printTagStartEnd (Tag.elementObject, atts2);
contentWriter.endElement(DEBUG_URI, "elementObject", "");
} }
StringBuilder elementPath = getElementPath(element,new StringBuilder()); StringBuilder elementPath = getElementPath(element,new StringBuilder());
atts.addAttribute ("", "elementPath", "", "", elementPath.toString()); atts.addAttribute ("", "elementPath", "", "", elementPath.toString());
contentWriter.startElement (DEBUG_URI, "element", "", atts); contentWriter.printTagStart(Tag.element, atts);
contentWriter.endElement(DEBUG_URI, "element", ""); // FIXME put elementObject herer ?
contentWriter.printTagEnd(Tag.element);
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
} }
/** /**
@ -430,30 +468,30 @@ public class X4ODebugWriter {
} }
public void debugSAXConfigStart() throws SAXException { public void debugSAXConfigStart() throws SAXException {
AttributesImpl atts = new AttributesImpl(); contentWriter.printTagStart (Tag.SAXConfig);
contentWriter.startElement (DEBUG_URI, "SAXConfig", "", atts);
} }
public void debugSAXConfigEnd() throws SAXException { public void debugSAXConfigEnd() throws SAXException {
contentWriter.endElement(DEBUG_URI, "SAXConfig", ""); contentWriter.printTagEnd (Tag.SAXConfig);
} }
public void debugSAXMessage(String type,String key,String value) throws SAXException { public void debugSAXMessage(String type,String key,String value) throws SAXException {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "key", "", "", key); atts.addAttribute ("", "key", "", "", key);
atts.addAttribute ("", "value", "", "", value); //atts.addAttribute ("", "value", "", "", value);
atts.addAttribute ("", "type", "", "", type); atts.addAttribute ("", "type", "", "", type);
contentWriter.startElement (DEBUG_URI, "SAXConfigProperty", "", atts); contentWriter.printTagStart (Tag.SAXConfigProperty, atts);
contentWriter.endElement(DEBUG_URI, "SAXConfigProperty", ""); contentWriter.printCharacters(value);
contentWriter.printTagEnd(Tag.SAXConfigProperty);
} }
public void debugPhaseMessage(String message,Class<?> clazz) throws ElementException { public void debugPhaseMessage(String message,Class<?> clazz) throws ElementException {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "class", "", "", clazz.getName()+""); atts.addAttribute ("", "fromClass", "", "", clazz.getName()+"");
try { try {
contentWriter.startElement (DEBUG_URI, "message", "", atts); contentWriter.printTagStart (Tag.message, atts);
contentWriter.characters(message); contentWriter.printCharacters(message);
contentWriter.endElement(DEBUG_URI, "message", ""); contentWriter.printTagEnd(Tag.message);
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -467,9 +505,9 @@ public class X4ODebugWriter {
atts.addAttribute ("", "description", "", "", ec.getDescription()); atts.addAttribute ("", "description", "", "", ec.getDescription());
atts.addAttribute ("", "className", "", "", ec.getClass().getName()); atts.addAttribute ("", "className", "", "", ec.getClass().getName());
contentWriter.startElement (DEBUG_URI, "runElementConfigurator", "", atts); contentWriter.printTagStart (Tag.runElementConfigurator, atts);
debugElement(element); debugElement(element);
contentWriter.endElement(DEBUG_URI, "runElementConfigurator", ""); contentWriter.printTagEnd(Tag.runElementConfigurator);
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -485,9 +523,9 @@ public class X4ODebugWriter {
atts.addAttribute ("", "parentClass", "", "", element.getParent().getElementObject().getClass()+""); atts.addAttribute ("", "parentClass", "", "", element.getParent().getElementObject().getClass()+"");
atts.addAttribute ("", "childClass", "", "", element.getElementObject().getClass()+""); atts.addAttribute ("", "childClass", "", "", element.getElementObject().getClass()+"");
contentWriter.startElement (DEBUG_URI, "doBind", "", atts); contentWriter.printTagStart (Tag.doBind, atts);
debugElement(element); debugElement(element);
contentWriter.endElement(DEBUG_URI, "doBind", ""); contentWriter.printTagEnd(Tag.doBind);
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -501,26 +539,25 @@ public class X4ODebugWriter {
atts.addAttribute ("", "description", "", "", elementClass.getDescription()); atts.addAttribute ("", "description", "", "", elementClass.getDescription());
atts.addAttribute ("", "objectClassName", "", "", ""+elementClass.getObjectClass()); atts.addAttribute ("", "objectClassName", "", "", ""+elementClass.getObjectClass());
atts.addAttribute ("", "className", "", "", elementClass.getClass().getName()); atts.addAttribute ("", "className", "", "", elementClass.getClass().getName());
contentWriter.startElement (DEBUG_URI, "elementClass", "", atts); contentWriter.printTagStart (Tag.elementClass, atts);
for (String phase:elementClass.getSkipPhases()) { for (String phase:elementClass.getSkipPhases()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "phase", "", "", ""+phase); atts.addAttribute ("", "phase", "", "", ""+phase);
contentWriter.startElement(DEBUG_URI, "elementSkipPhase", "", atts); contentWriter.printTagStartEnd(Tag.elementSkipPhase, atts);
contentWriter.endElement(DEBUG_URI, "elementSkipPhase", "");
} }
debugElementConfigurator(elementClass.getElementConfigurators()); debugElementConfigurator(elementClass.getElementConfigurators());
debugElementClassBase(elementClass); debugElementClassBase(elementClass);
contentWriter.endElement(DEBUG_URI, "elementClass", ""); contentWriter.printTagEnd(Tag.elementClass);
} }
private void debugElementClassBase(ElementClassBase elementClassBase) throws SAXException { private void debugElementClassBase(ElementClassBase elementClassBase) throws SAXException {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementClassBase.getDescription()); atts.addAttribute ("", "description", "", "", elementClassBase.getDescription());
atts.addAttribute ("", "className", "", "", elementClassBase.getClass().getName()); atts.addAttribute ("", "className", "", "", elementClassBase.getClass().getName());
contentWriter.startElement (DEBUG_URI, "elementClassBase", "", atts); contentWriter.printTagStart (Tag.elementClassBase, atts);
debugElementConfigurator(elementClassBase.getElementConfigurators()); debugElementConfigurator(elementClassBase.getElementConfigurators());
debugElementClassAttributes(elementClassBase.getElementClassAttributes()); debugElementClassAttributes(elementClassBase.getElementClassAttributes());
contentWriter.endElement(DEBUG_URI, "elementClassBase", ""); contentWriter.printTagEnd(Tag.elementClassBase);
} }
private void debugElementConfigurator(List<ElementConfigurator> elementConfigurators) throws SAXException { private void debugElementConfigurator(List<ElementConfigurator> elementConfigurators) throws SAXException {
@ -528,9 +565,8 @@ public class X4ODebugWriter {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription()); atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription());
atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName()); atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName());
contentWriter.startElement (DEBUG_URI, "elementConfigurator", "", atts); contentWriter.printTagStartEnd (Tag.elementConfigurator, atts);
contentWriter.endElement(DEBUG_URI, "elementConfigurator", ""); }
}
} }
private void debugElementConfiguratorGlobal(List<ElementConfiguratorGlobal> elementConfigurators) throws SAXException { private void debugElementConfiguratorGlobal(List<ElementConfiguratorGlobal> elementConfigurators) throws SAXException {
@ -538,9 +574,8 @@ public class X4ODebugWriter {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription()); atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription());
atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName()); atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName());
contentWriter.startElement (DEBUG_URI, "elementConfiguratorGlobal", "", atts); contentWriter.printTagStartEnd (Tag.elementConfiguratorGlobal, atts);
contentWriter.endElement(DEBUG_URI, "elementConfiguratorGlobal", ""); }
}
} }
private void debugElementClassAttributes(Collection<ElementClassAttribute> elementClassAttributes) throws SAXException { private void debugElementClassAttributes(Collection<ElementClassAttribute> elementClassAttributes) throws SAXException {
@ -554,17 +589,16 @@ public class X4ODebugWriter {
atts.addAttribute ("", "runConverters", "", "", ""+elementClassAttribute.getRunConverters()); atts.addAttribute ("", "runConverters", "", "", ""+elementClassAttribute.getRunConverters());
//atts.addAttribute ("", "runInterfaces", "", "", ""+elementClassAttribute.getRunInterfaces()); //atts.addAttribute ("", "runInterfaces", "", "", ""+elementClassAttribute.getRunInterfaces());
atts.addAttribute ("", "runResolveEL", "", "", ""+elementClassAttribute.getRunResolveEL()); atts.addAttribute ("", "runResolveEL", "", "", ""+elementClassAttribute.getRunResolveEL());
contentWriter.startElement(DEBUG_URI, "elementClassAttribute", "", atts); contentWriter.printTagStart(Tag.elementClassAttribute, atts);
if (elementClassAttribute.getObjectConverter()!=null) { if (elementClassAttribute.getObjectConverter()!=null) {
debugObjectConverter(elementClassAttribute.getObjectConverter()); debugObjectConverter(elementClassAttribute.getObjectConverter());
} }
for (String alias:elementClassAttribute.getAttributeAliases()) { for (String alias:elementClassAttribute.getAttributeAliases()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", ""+alias); atts.addAttribute ("", "name", "", "", ""+alias);
contentWriter.startElement(DEBUG_URI, "attributeAlias", "", atts); contentWriter.printTagStartEnd(Tag.attributeAlias, atts);
contentWriter.endElement(DEBUG_URI, "attributeAlias", "");
} }
contentWriter.endElement(DEBUG_URI, "elementClassAttribute", ""); contentWriter.printTagEnd(Tag.elementClassAttribute);
} }
} }
@ -573,8 +607,11 @@ public class X4ODebugWriter {
atts.addAttribute ("", "objectClassTo", "", "", objectConverter.getObjectClassTo().getName()); atts.addAttribute ("", "objectClassTo", "", "", objectConverter.getObjectClassTo().getName());
atts.addAttribute ("", "objectClassBack", "", "", objectConverter.getObjectClassBack().getName()); atts.addAttribute ("", "objectClassBack", "", "", objectConverter.getObjectClassBack().getName());
atts.addAttribute ("", "className", "", "", objectConverter.getClass().getName()); atts.addAttribute ("", "className", "", "", objectConverter.getClass().getName());
contentWriter.startElement (DEBUG_URI, "objectConverter", "", atts); contentWriter.printTagStart (Tag.objectConverter, atts);
contentWriter.endElement(DEBUG_URI, "objectConverter", ""); //for (ObjectConverter oc:objectConverter.getObjectConverters()) {
// debugObjectConverter(oc); // TODO: turn me on
//}
contentWriter.printTagEnd(Tag.objectConverter);
} }
private void debugElementBindingHandler(List<ElementBindingHandler> elementBindingHandlers) throws SAXException { private void debugElementBindingHandler(List<ElementBindingHandler> elementBindingHandlers) throws SAXException {
@ -583,16 +620,15 @@ public class X4ODebugWriter {
atts.addAttribute ("", "className", "", "", bind.getClass().getName()); atts.addAttribute ("", "className", "", "", bind.getClass().getName());
atts.addAttribute ("", "description", "", "", bind.getDescription()); atts.addAttribute ("", "description", "", "", bind.getDescription());
atts.addAttribute ("", "bindParentClass", "", "", bind.getBindParentClass().toString()); atts.addAttribute ("", "bindParentClass", "", "", bind.getBindParentClass().toString());
contentWriter.startElement (DEBUG_URI, "elementBindingHandler", "", atts); contentWriter.printTagStart (Tag.elementBindingHandler, atts);
for (Class<?> clazz:bind.getBindChildClasses()) { for (Class<?> clazz:bind.getBindChildClasses()) {
AttributesImpl atts2 = new AttributesImpl(); AttributesImpl atts2 = new AttributesImpl();
atts2.addAttribute ("", "className", "", "", clazz.getName()); atts2.addAttribute ("", "className", "", "", clazz.getName());
contentWriter.startElement (DEBUG_URI, "elementBindingHandlerChildClass", "", atts2); contentWriter.printTagStartEnd (Tag.elementBindingHandlerChildClass, atts2);
contentWriter.endElement (DEBUG_URI, "elementBindingHandlerChildClass", "");
} }
contentWriter.endElement(DEBUG_URI, "elementBindingHandler", ""); contentWriter.printTagEnd(Tag.elementBindingHandler);
} }
} }
@ -611,13 +647,13 @@ public class X4ODebugWriter {
} }
try { try {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
contentWriter.startElement (X4ODebugWriter.DEBUG_URI, "printElementTree", "", atts); contentWriter.printTagStart (Tag.printElementTree, atts);
startedPrefix.clear(); startedPrefix.clear();
printXML(languageSession.getRootElement()); printXML(languageSession.getRootElement());
for (String prefix:startedPrefix) { for (String prefix:startedPrefix) {
contentWriter.endPrefixMapping(prefix); contentWriter.getContentWriterWrapped().endPrefixMapping(prefix);
} }
contentWriter.endElement(X4ODebugWriter.DEBUG_URI, "printElementTree", ""); contentWriter.printTagEnd(Tag.printElementTree);
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
@ -641,7 +677,7 @@ public class X4ODebugWriter {
if (element==null) { if (element==null) {
throw new SAXException("Can't print debug xml of null element."); throw new SAXException("Can't print debug xml of null element.");
} }
ContentWriter handler = contentWriter; //element.getLanguageSession().getX4ODebugWriter().getContentWriter(); ContentWriter handler = getContentWriter();
if (element.getElementType().equals(Element.ElementType.comment)) { if (element.getElementType().equals(Element.ElementType.comment)) {
handler.comment((String)element.getElementObject()); handler.comment((String)element.getElementObject());
return; return;

View file

@ -45,7 +45,6 @@ import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler; import org.xml.sax.ContentHandler;
import org.xml.sax.Locator; import org.xml.sax.Locator;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/** /**
* AbstractContentWriterHandler writes SAX content handler events as XML. * AbstractContentWriterHandler writes SAX content handler events as XML.