com.gs.fw.common.mithra.mithraruntime.MithraRuntimeUnmarshallerAbstract 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.mithraruntime;
import javax.xml.stream.Location;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* 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 MithraRuntimeUnmarshallerAbstract
{
private static final Map decode = new HashMap();
private static ThreadLocal dateFormat = new ThreadLocal()
{
protected SimpleDateFormat initialValue()
{
return new SimpleDateFormat("yyyy-MM-dd");
}
}
;
private static ThreadLocal dateTimeFormat = new ThreadLocal()
{
protected SimpleDateFormat initialValue()
{
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
}
}
;
private static ThreadLocal dateTimeFormatWithZone = new ThreadLocal()
{
protected SimpleDateFormat initialValue()
{
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
}
}
;
static
{
decode.put(XMLStreamConstants.ATTRIBUTE, "ATTRIBUTE");
decode.put(XMLStreamConstants.CDATA, "CDATA");
decode.put(XMLStreamConstants.CHARACTERS, "CHARACTERS");
decode.put(XMLStreamConstants.COMMENT, "COMMENT");
decode.put(XMLStreamConstants.DTD, "DTD");
decode.put(XMLStreamConstants.END_DOCUMENT, "END_DOCUMENT");
decode.put(XMLStreamConstants.END_ELEMENT, "END_ELEMENT");
decode.put(XMLStreamConstants.ENTITY_DECLARATION, "ENTITY_DECLARATION");
decode.put(XMLStreamConstants.ENTITY_REFERENCE, "ENTITY_REFERENCE");
decode.put(XMLStreamConstants.NAMESPACE, "NAMESPACE");
decode.put(XMLStreamConstants.NOTATION_DECLARATION, "NOTATION_DECLARATION");
decode.put(XMLStreamConstants.PROCESSING_INSTRUCTION, "PROCESSING_INSTRUCTION");
decode.put(XMLStreamConstants.SPACE, "SPACE");
decode.put(XMLStreamConstants.START_DOCUMENT, "START_DOCUMENT");
decode.put(XMLStreamConstants.START_ELEMENT, "START_ELEMENT");
}
private String diagnosticMessage;
private boolean validateAttributes = true;
private XMLStreamReader xmlStreamReader;
public static java.util.List emptyList()
{
return java.util.Collections.EMPTY_LIST;
}
public XMLStreamReader getXmlStreamReader()
{
return this.xmlStreamReader;
}
public void setValidateAttributes(boolean validateAttributes)
{
this.validateAttributes = validateAttributes;
}
public MithraRuntime parse(String filename) throws IOException
{
InputStream in = new FileInputStream(filename);
try
{
return parse(in, "in file "+filename);
}
finally
{
in.close();
}
}
public MithraRuntime parse(InputStream in, String diagnosticMessage) throws IOException
{
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
try
{
xmlStreamReader = inputFactory.createXMLStreamReader(in);
this.diagnosticMessage = diagnosticMessage;
return parse();
}
catch (XMLStreamException e)
{
throw new MithraRuntimeParserException(diagnosticMessage+" error in input stream", e);
}
}
public MithraRuntime parse() throws XMLStreamException
{
try
{
this.getNextByType(XMLStreamConstants.START_ELEMENT);
String elementName = xmlStreamReader.getLocalName();
if (elementName.equals("MithraRuntime"))
{
MithraRuntime result = new MithraRuntime();
result.parse((MithraRuntimeUnmarshaller) this, "MithraRuntime");
return result;
}
this.throwException("Unexpected top level element: "+elementName);
return null; //never gets here
}
finally
{
cleanThreadLocals();
}
}
private void cleanThreadLocals()
{
dateFormat.remove();
dateTimeFormat.remove();
dateTimeFormatWithZone.remove();
}
public void unknownAttribute(String attributeName, String attributeValue)
{
if (validateAttributes)
{
this.throwException("unexpected value '"+attributeValue+"' in '"+attributeName+"'");
}
else
{
Location location = xmlStreamReader.getLocation();
warn("unexpected value '"+attributeValue+"' in '"+attributeName+"' at location: "+location.toString()+(diagnosticMessage == null ? "": " "+diagnosticMessage));
}
}
protected void warn(String msg)
{
System.out.println("WARN: "+msg);
}
public java.util.List newList()
{
return new ArrayList();
}
public void throwException(String msg)
{
throw new MithraRuntimeParserException(msg, xmlStreamReader == null ? null : xmlStreamReader.getLocation(), diagnosticMessage);
}
public void getNextByType(int type) throws XMLStreamException
{
int event = xmlStreamReader.next();
while(event == XMLStreamConstants.COMMENT || event == XMLStreamConstants.SPACE || event == XMLStreamConstants.PROCESSING_INSTRUCTION ||
(event == XMLStreamConstants.CHARACTERS && xmlStreamReader.getText().trim().length() == 0) && xmlStreamReader.hasNext())
{
event = xmlStreamReader.next();
}
if (event != type)
{
throwException("Did not get xml event of type "+decode.get(type)+" but rather "+decode.get(event));
}
}
public int getNextStartOrEnd() throws XMLStreamException
{
int event = xmlStreamReader.next();
while(event == XMLStreamConstants.COMMENT || event == XMLStreamConstants.SPACE ||
(event == XMLStreamConstants.CHARACTERS && xmlStreamReader.getText().trim().length() == 0) && xmlStreamReader.hasNext())
{
event = xmlStreamReader.next();
}
if (event != XMLStreamConstants.START_ELEMENT && event != XMLStreamConstants.END_ELEMENT)
{
throwException("Did not get xml event of type start or end but rather "+decode.get(event));
}
return event;
}
public void skipToEndOfElement(String elementName) throws XMLStreamException
{
while(xmlStreamReader.hasNext())
{
int next = xmlStreamReader.next();
if (next == XMLStreamConstants.END_ELEMENT && xmlStreamReader.getLocalName().equals(elementName))
{
return;
}
}
}
public String parsePlainString(String name) throws XMLStreamException
{
int event = xmlStreamReader.next();
event = skipCommentsAndSpace(event);
String tokenString = "";
while (event == XMLStreamConstants.CHARACTERS)
{
tokenString = tokenString + xmlStreamReader.getText();
if (xmlStreamReader.hasNext())
{
event = xmlStreamReader.next();
event = skipCommentsAndSpace(event);
}
else
{
break;
}
}
if (event == XMLStreamConstants.END_ELEMENT && xmlStreamReader.getLocalName().equals(name))
{
return tokenString;
}
throwException("expecting end of "+name);
return null; //never gets here
}
public String parseTokenString(String name) throws XMLStreamException
{
int event = xmlStreamReader.next();
event = skipCommentsAndSpace(event);
String tokenString = "";
while (event == XMLStreamConstants.CHARACTERS)
{
tokenString = tokenString + xmlStreamReader.getText();
if (xmlStreamReader.hasNext())
{
event = xmlStreamReader.next();
event = skipCommentsAndSpace(event);
}
else
{
break;
}
}
if (event == XMLStreamConstants.END_ELEMENT && xmlStreamReader.getLocalName().equals(name))
{
return toToken(name, tokenString);
}
throwException("expecting end of "+name);
return null; //never gets here
}
private int skipCommentsAndSpace(int event) throws XMLStreamException
{
while((event == XMLStreamConstants.COMMENT || event == XMLStreamConstants.SPACE) && xmlStreamReader.hasNext())
{
event = xmlStreamReader.next();
}
return event;
}
public String toPlainString(String attributeName, String attributeValue)
{
return attributeValue;
}
public String toToken(String name, String value)
{
if (value.length() == 0) return "";
if (hasTokenWhiteSpace(value))
{
int start = 0;
while(start < value.length() && isWhiteSpace(value.charAt(start)))
{
start++;
}
if (start == value.length()) return "";
int end = value.length();
while(isWhiteSpace(value.charAt(end - 1)))
{
end--;
}
StringBuilder builder = new StringBuilder(end - start + 1);
boolean lastWasWhite = false;
for(int i=start;i 0)
{
throwException ("Unexpected value : " + attributeValue + " for " + attributeName + ". Expected type is nonPositiveInteger");
}
return value;
}
public int parseNegativeInt(String attributeName, String attributeValue)
{
int value = parseInt(attributeName, attributeValue);
if (value > -1)
{
throwException ("Unexpected value : " + attributeValue + " for " + attributeName + ". Expected type is negativeInteger");
}
return value;
}
public int parseInt(String elementName) throws XMLStreamException
{
return parseInt(elementName,getElementValue(elementName));
}
public long parseLong(String elementName) throws XMLStreamException
{
return parseLong(elementName,getElementValue(elementName));
}
public String getElementValue(String elementName) throws XMLStreamException
{
checkNoAttributes(elementName);
int event = xmlStreamReader.next();
event = skipCommentsAndSpace(event);
String tokenString = null;
while (event == XMLStreamConstants.CHARACTERS)
{
tokenString = tokenString == null ? xmlStreamReader.getText() : tokenString + xmlStreamReader.getText();
if (xmlStreamReader.hasNext())
{
event = xmlStreamReader.next();
event = skipCommentsAndSpace(event);
}
else
{
break;
}
}
if (event == XMLStreamConstants.END_ELEMENT && xmlStreamReader.getLocalName().equals(elementName))
{
return tokenString;
}
throwException("expecting end of " + elementName);
//never gets here
return null;
}
public double parseDecimal(String elementName) throws XMLStreamException
{
return parseDecimal(elementName,getElementValue(elementName));
}
public short parseShort (String elementName) throws XMLStreamException
{
return parseShort(elementName,getElementValue(elementName));
}
private void checkNoAttributes(String elementName)
{
if (xmlStreamReader.getAttributeCount() > 0 && this.validateAttributes)
{
throwException("Element "+elementName+" should not have any attributes");
}
}
public boolean isAtEnd(int eventType, String elementName)
{
return eventType == XMLStreamConstants.END_ELEMENT && xmlStreamReader.getLocalName().equals(elementName);
}
public void expectEnd(int eventType, String elementName)
{
if (!isAtEnd(eventType, elementName))
{
throwException("expecting end of element <" + elementName + ">");
}
}
public int getFractionDigits(String value)
{
int scale = 0;
int end = value.length();
while(end !=0 && value.charAt(end - 1) != '.')
{
scale++;
end --;
}
if (end == 0)
{
return 0;
}
return scale;
}
public int getTotalDigits(String value)
{
int scale = 0;
int end = value.length();
while(end !=0)
{
if ( value.charAt(end - 1) != '.' )
{
scale++;
}
end --;
}
return scale;
}
}