com.gs.fw.common.mithra.cacheloader.xmlbinding.MithraCacheLoaderMarshallerAbstract Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reladomo Show documentation
Show all versions of reladomo Show documentation
Reladomo is an object-relational mapping framework.
package com.gs.fw.common.mithra.cacheloader.xmlbinding;
import java.io.*;
import java.text.SimpleDateFormat;
/**
* This file was automatically generated using FreyaXml 1.5.0. Please do not modify it.
* Add custom logic to its subclass instead.
*/
public abstract class MithraCacheLoaderMarshallerAbstract
{
private static ThreadLocal dateFormat = new ThreadLocal()
{
protected SimpleDateFormat initialValue()
{
return new SimpleDateFormat("yyyy-MM-dd");
}
}
;
private static ThreadLocal dateTimeFormatWithZone = new ThreadLocal()
{
protected SimpleDateFormat initialValue()
{
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
}
}
;
private EscapedAppendable appendable;
private Closeable toCloseAtEnd;
private int currentDepth;
private int indentWidth = 4;
private boolean tagIsOpen;
private boolean indent;
private boolean indentSafe;
public void setIndentWidth(int width)
{
this.indentWidth = width;
}
public void setIndent(boolean indent)
{
this.indent = indent;
}
protected void setAppendable(Appendable appendable)
{
this.appendable = new EscapedAppendable(appendable);
}
protected void openFile(String filename) throws IOException
{
FileWriter writer = new FileWriter(filename);
this.appendable = new EscapedAppendable(writer);
this.toCloseAtEnd = writer;
}
protected void close() throws IOException
{
if (this.appendable != null) this.appendable.flush();
this.appendable = null;
this.currentDepth = 0;
this.indentSafe = false;
this.tagIsOpen = false;
if (toCloseAtEnd != null)
{
this.toCloseAtEnd.close();
}
}
private void cleanThreadLocals()
{
dateFormat.remove();
dateTimeFormatWithZone.remove();
}
protected void toXml(CacheLoader cacheLoader) throws IOException
{
try
{
cacheLoader.toXml((MithraCacheLoaderMarshaller)this);
}
finally
{
cleanThreadLocals();
close();
}
}
public void marshall(String filename, CacheLoader cacheLoader) throws IOException
{
openFile(filename);
toXml(cacheLoader);
}
public void marshall(OutputStream stream, CacheLoader cacheLoader) throws IOException
{
this.appendable = new EscapedAppendable(new OutputStreamWriter(stream));
toXml(cacheLoader);
}
public void marshall(Appendable appendable, CacheLoader cacheLoader) throws IOException
{
this.appendable = new EscapedAppendable(appendable);
toXml(cacheLoader);
}
public void writeIndent(boolean startTag) throws IOException
{
if (indent && indentSafe)
{
if (currentDepth > 0 || !startTag) this.appendable.rawAppend("\n");
for(int i=0;i");
}
writeIndent(true);
this.currentDepth++;
this.appendable.rawAppend("<").rawAppend(tagName);
tagIsOpen = true;
indentSafe = true;
}
public void writeDateAttribute(String tagName, java.util.Date date) throws IOException
{
writeAttribute(tagName, dateFormat.get().format(date));
}
public void writeDateTimeAttribute(String tagName, java.util.Date date) throws IOException
{
String formatted = dateTimeFormatWithZone.get().format(date);
this.appendable.rawAppend(" ").rawAppend(tagName).rawAppend("=\"").rawAppend(formatted, 0, 26).rawAppend(":").rawAppend(formatted, 26, 28).rawAppend("\"");
}
public void writeDate(String tagName, java.util.Date date) throws IOException
{
writeSimpleTag(tagName, dateFormat.get().format(date));
}
public void writeDateTime(String tagName, java.util.Date date) throws IOException
{
writeStartTag(tagName);
this.appendable.rawAppend(">");
this.indentSafe = false;
this.tagIsOpen = false;
String formatted = dateTimeFormatWithZone.get().format(date);
this.appendable.rawAppend(formatted, 0, 26).rawAppend(":").rawAppend(formatted, 26, 28);
writeEndTag(tagName);
}
public void writeSimpleTag(String tagName, String value) throws IOException
{
writeStartTag(tagName);
writeContent(value);
writeEndTag(tagName);
}
public void writeSimpleTag(String tagName, boolean value) throws IOException
{
writeStartTag(tagName);
writeContent(Boolean.toString(value));
writeEndTag(tagName);
}
public void writeSimpleTag(String tagName, long value) throws IOException
{
writeStartTag(tagName);
writeContent(Long.toString(value));
writeEndTag(tagName);
}
public void writeSimpleTag(String tagName, int value) throws IOException
{
writeStartTag(tagName);
writeContent(Integer.toString(value));
writeEndTag(tagName);
}
public void writeSimpleTag(String tagName, double value) throws IOException
{
writeStartTag(tagName);
writeContent(Double.toString(value));
writeEndTag(tagName);
}
public void writeAttribute(String attributeName, String attributeValue) throws IOException
{
this.appendable.rawAppend(" ").rawAppend(attributeName).rawAppend("=\"").append(attributeValue).rawAppend("\"");
}
public void writeAttribute(String attributeName, boolean attributeValue) throws IOException
{
this.writeAttribute(attributeName, Boolean.toString(attributeValue));
}
public void writeAttribute(String attributeName, int attributeValue) throws IOException
{
this.writeAttribute(attributeName, Integer.toString(attributeValue));
}
public void writeAttribute(String attributeName, long attributeValue) throws IOException
{
this.writeAttribute(attributeName, Long.toString(attributeValue));
}
public void writeAttribute(String attributeName, double attributeValue) throws IOException
{
this.writeAttribute(attributeName, Double.toString(attributeValue));
}
public void writeEndTag(String tagName) throws IOException
{
this.currentDepth--;
if (tagIsOpen)
{
this.appendable.rawAppend("/>");
}
else
{
writeIndent(false);
this.appendable.rawAppend("").rawAppend(tagName).rawAppend(">");
}
tagIsOpen = false;
indentSafe = true;
}
public void writeContent(String content) throws IOException
{
this.indentSafe = false;
this.tagIsOpen = false;
this.appendable.rawAppend(">").appendDontEscapeLines(content);
}
private static class EscapedAppendable
{
private Appendable inner;
private EscapedAppendable(Appendable inner)
{
this.inner = inner;
}
public EscapedAppendable append(char c) throws IOException
{
return this.append(c, true);
}
public EscapedAppendable append(char c, boolean escapeLines) throws IOException
{
if (c == '<')
{
this.inner.append("<");
}
else if (c == '>')
{
this.inner.append(">");
}
else if (c == '&')
{
this.inner.append("&");
}
else if (c == '\'')
{
this.inner.append("'");
}
else if (c == '"')
{
this.inner.append(""");
}
else if (c == '\t')
{
this.inner.append(" ");
}
else if (c == '\n' && escapeLines)
{
this.inner.append("
");
}
else if (c > 127)
{
this.inner.append("").append(Integer.toString(c)).append(";");
}
else
{
this.inner.append(c);
}
return this;
}
public EscapedAppendable append(CharSequence csq) throws IOException
{
if (csq == null) return this;
for(int i=0;i