/**
* This class was generated from a set of XML constraints
* by the Enhydra Zeus XML Data Binding Framework. All
* source code in this file is constructed specifically
* to work with other Zeus-generated classes. If you
* modify this file by hand, you run the risk of breaking
* this interoperation, as well as introducing errors in
* source code compilation.
*
* * * * * MODIFY THIS FILE AT YOUR OWN RISK * * * * *
*
* To find out more about the Enhydra Zeus framework, you
* can point your browser at <http://zeus.enhydra.org>
* where you can download releases, join and discuss Zeus
* on user and developer mailing lists, and access source
* code. Please report any bugs through that website.
*/
package javajaxb.generated.web;
// Global Implementation Import Statements
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
public class LoginConfigImpl extends DefaultHandler implements Unmarshallable, LexicalHandler, LoginConfig {
private String authMethod;
private boolean zeus_AuthMethodSet;
private String realmName;
private boolean zeus_RealmNameSet;
private FormLoginConfig formLoginConfig;
private String id;
private boolean zeus_IdSet;
/** Any DOCTYPE reference/statements. */
private String docTypeString;
/** The encoding for the output document */
private String outputEncoding;
/** The current node in unmarshalling */
private Unmarshallable zeus_currentUNode;
/** The parent node in unmarshalling */
private Unmarshallable zeus_parentUNode;
/** Whether this node has been handled */
private boolean zeus_thisNodeHandled = false;
/** Whether a DTD exists for an unmarshal call */
private boolean hasDTD;
/** Whether validation is occurring */
private boolean validate;
/** The namespace mappings on this element */
private Map namespaceMappings;
/** The EntityResolver for SAX parsing to use */
private static EntityResolver entityResolver;
/** The ErrorHandler for SAX parsing to use */
private static ErrorHandler errorHandler;
public LoginConfigImpl() {
zeus_AuthMethodSet = false;
zeus_RealmNameSet = false;
zeus_IdSet = false;
docTypeString = "";
hasDTD = false;
validate = false;
namespaceMappings = new HashMap();
}
public String getAuthMethod() {
return authMethod;
}
public void setAuthMethod(String authMethod) {
this.authMethod = authMethod;
zeus_AuthMethodSet = true;
}
public String getRealmName() {
return realmName;
}
public void setRealmName(String realmName) {
this.realmName = realmName;
zeus_RealmNameSet = true;
}
public FormLoginConfig getFormLoginConfig() {
return formLoginConfig;
}
public void setFormLoginConfig(FormLoginConfig formLoginConfig) {
this.formLoginConfig = formLoginConfig;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
zeus_IdSet = true;
}
public void setDocType(String name, String publicID, String systemID) {
try {
startDTD(name, publicID, systemID);
} catch (SAXException neverHappens) { }
}
public void setOutputEncoding(String outputEncoding) {
this.outputEncoding = outputEncoding;
}
public void marshal(File file) throws IOException {
// Delegate to the marshal(Writer) method
marshal(new FileWriter(file));
}
public void marshal(OutputStream outputStream) throws IOException {
// Delegate to the marshal(Writer) method
marshal(new OutputStreamWriter(outputStream));
}
public void marshal(Writer writer) throws IOException {
// Write out the XML declaration
writer.write("<?xml version=\"1.0\" ");
if (outputEncoding != null) {
writer.write("encoding=\"");
writer.write(outputEncoding);
writer.write("\"?>\n\n");
} else {
writer.write("encoding=\"UTF-8\"?>\n\n");
}
// Handle DOCTYPE declaration
writer.write(docTypeString);
writer.write("\n");
// Now start the recursive writing
writeXMLRepresentation(writer, "");
// Close up
writer.flush();
writer.close();
}
protected void writeXMLRepresentation(Writer writer,
String indent)
throws IOException {
writer.write(indent);
writer.write("<login-config");
// Handle namespace mappings (if needed)
for (Iterator i = namespaceMappings.keySet().iterator(); i.hasNext(); ) {
String prefix = (String)i.next();
String uri = (String)namespaceMappings.get(prefix);
writer.write(" xmlns");
if (!prefix.trim().equals("")) {
writer.write(":");
writer.write(prefix);
}
writer.write("=\"");
writer.write(uri);
writer.write("\"\n ");
}
// Handle attributes (if needed)
if (zeus_IdSet) {
writer.write(" id=\"");
writer.write(escapeAttributeValue(id));
writer.write("\"");
}
writer.write(">");
writer.write("\n");
// Handle child elements
if (authMethod != null) {
writer.write(new StringBuffer(indent).append(" ").toString());
writer.write("<auth-method>");
writer.write(this.authMethod);
writer.write("</auth-method>\n");
}
if (realmName != null) {
writer.write(new StringBuffer(indent).append(" ").toString());
writer.write("<realm-name>");
writer.write(this.realmName);
writer.write("</realm-name>\n");
}
if (formLoginConfig != null) {
((FormLoginConfigImpl)formLoginConfig).writeXMLRepresentation(writer,
new StringBuffer(indent).append(" ").toString());
}
writer.write(indent);
writer.write("</login-config>\n");
}
/** Indicates if we are in the authMethod element */
private boolean zeus_inAuthMethod = false;
/** Indicates if we are in the realmName element */
private boolean zeus_inRealmName = false;
private String escapeAttributeValue(String attributeValue) {
String returnValue = attributeValue;
for (int i = 0; i < returnValue.length(); i++) {
char ch = returnValue.charAt(i);
if (ch == '"') {
returnValue = new StringBuffer()
.append(returnValue.substring(0, i))
.append(""")
.append(returnValue.substring(i+1))
.toString();
}
}
return returnValue;
}
private String escapeTextValue(String textValue) {
String returnValue = textValue;
for (int i = 0; i < returnValue.length(); i++) {
char ch = returnValue.charAt(i);
if (ch == '<') {
returnValue = new StringBuffer()
.append(returnValue.substring(0, i))
.append("<")
.append(returnValue.substring(i+1))
.toString();
} else if (ch == '>') {
returnValue = new StringBuffer()
.append(returnValue.substring(0, i))
.append(">")
.append(returnValue.substring(i+1))
.toString();
}
}
return returnValue;
}
/**
* <p>
* This sets a SAX <code>EntityResolver</code> for this unmarshalling process.
* </p>
*
* @param resolver the entity resolver to use.
*/
public static void setEntityResolver(EntityResolver resolver) {
entityResolver = resolver;
}
/**
* <p>
* This sets a SAX <code>ErrorHandler</code> for this unmarshalling process.
* </p>
*
* @param handler the entity resolver to use.
*/
public static void setErrorHandler(ErrorHandler handler) {
errorHandler = handler;
}
public static LoginConfig unmarshal(File file) throws IOException {
// Delegate to the unmarshal(Reader) method
return unmarshal(new FileReader(file));
}
public static LoginConfig unmarshal(File file, boolean validate) throws IOException {
// Delegate to the unmarshal(Reader) method
return unmarshal(new FileReader(file), validate);
}
public static LoginConfig unmarshal(InputStream inputStream) throws IOException {
// Delegate to the unmarshal(Reader) method
return unmarshal(new InputStreamReader(inputStream));
}
public static LoginConfig unmarshal(InputStream inputStream, boolean validate) throws IOException {
// Delegate to the unmarshal(Reader) method
return unmarshal(new InputStreamReader(inputStream), validate);
}
public static LoginConfig unmarshal(Reader reader) throws IOException {
// Delegate with default validation value
return unmarshal(reader, false);
}
public static LoginConfig unmarshal(Reader reader, boolean validate) throws IOException {
LoginConfigImpl loginConfig = new LoginConfigImpl();
loginConfig.setValidating(validate);
loginConfig.setCurrentUNode(loginConfig);
loginConfig.setParentUNode(null);
// Load the XML parser
XMLReader parser = null;
String parserClass = System.getProperty("org.xml.sax.driver",
"org.apache.xerces.parsers.SAXParser");
try {
parser = XMLReaderFactory.createXMLReader(parserClass);
// Set entity resolver, if needed
if (entityResolver != null) {
parser.setEntityResolver(entityResolver);
}
// Set error handler
parser.setErrorHandler(loginConfig);
// Register lexical handler
parser.setProperty("http://xml.org/sax/properties/lexical-handler", loginConfig);
// Register content handler
parser.setContentHandler(loginConfig);
} catch (SAXException e) {
throw new IOException("Could not load XML parser: " +
e.getMessage());
}
InputSource inputSource = new InputSource(reader);
try {
parser.setFeature("http://xml.org/sax/features/validation", new Boolean(validate).booleanValue());
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
parser.parse(inputSource);
} catch (SAXException e) {
throw new IOException("Error parsing XML document: " +
e.getMessage());
}
// Return the resultant object
return loginConfig;
}
public Unmarshallable getParentUNode() {
return zeus_parentUNode;
}
public void setParentUNode(Unmarshallable parentUNode) {
this.zeus_parentUNode = parentUNode;
}
public Unmarshallable getCurrentUNode() {
return zeus_currentUNode;
}
public void setCurrentUNode(Unmarshallable currentUNode) {
this.zeus_currentUNode = currentUNode;
}
public void setValidating(boolean validate) {
this.validate = validate;
}
public void startDocument() throws SAXException {
// no-op
}
public void setDocumentLocator(Locator locator) {
// no-op
}
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
namespaceMappings.put(prefix, uri);
}
public void startElement(String namespaceURI, String localName,
String qName, org.xml.sax.Attributes atts)
throws SAXException {
// Feed this to the correct ContentHandler
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.startElement(namespaceURI, localName, qName, atts);
return;
}
// See if we handle, or we delegate
if ((localName.equals("login-config")) && (!zeus_thisNodeHandled)) {
// Handle ourselves
for (int i=0, len=atts.getLength(); i<len; i++) {
String attName= atts.getLocalName(i);
String attValue = atts.getValue(i);
if (attName.equals("id")) {
setId(attValue);
}
}
zeus_thisNodeHandled = true;
return;
} else {
// Delegate handling
if (localName.equals("auth-method")) {
this.zeus_inAuthMethod = true;
return;
}
if (localName.equals("realm-name")) {
this.zeus_inRealmName = true;
return;
}
if (localName.equals("form-login-config")) {
FormLoginConfigImpl formLoginConfig = new FormLoginConfigImpl();
current = getCurrentUNode();
formLoginConfig.setParentUNode(current);
formLoginConfig.setCurrentUNode(formLoginConfig);
this.setCurrentUNode(formLoginConfig);
formLoginConfig.startElement(namespaceURI, localName, qName, atts);
// Add this value in
this.formLoginConfig = formLoginConfig;
return;
}
}
}
public void endElement(String namespaceURI, String localName,
String qName)
throws SAXException {
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.endElement(namespaceURI, localName, qName);
return;
}
if (localName.equals("auth-method")) {
this.zeus_inAuthMethod = false;
return;
}
if (localName.equals("realm-name")) {
this.zeus_inRealmName = false;
return;
}
Unmarshallable parent = getCurrentUNode().getParentUNode();
if (parent != null) {
parent.setCurrentUNode(parent);
}
}
public void characters(char[] ch, int start, int len)
throws SAXException {
// Feed this to the correct ContentHandler
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.characters(ch, start, len);
return;
}
String text = new String(ch, start, len);
text = text.trim();
if (zeus_inAuthMethod) {
if (this.authMethod == null) {
this.authMethod = text;
} else {
this.authMethod = new StringBuffer(this.authMethod).append(text).toString();
}
return;
}
if (zeus_inRealmName) {
if (this.realmName == null) {
this.realmName = text;
} else {
this.realmName = new StringBuffer(this.realmName).append(text).toString();
}
return;
}
}
public void comment(char ch[], int start, int len) throws SAXException {
// Currently no-op
}
public void warning(SAXParseException e) throws SAXException {
if (errorHandler != null) {
errorHandler.warning(e);
}
}
public void error(SAXParseException e) throws SAXException {
if ((validate) && (!hasDTD)) {
throw new SAXException("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
}
if (errorHandler != null) {
errorHandler.error(e);
}
}
public void fatalError(SAXParseException e) throws SAXException {
if ((validate) && (!hasDTD)) {
throw new SAXException("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
}
if (errorHandler != null) {
errorHandler.fatalError(e);
}
}
public void startDTD(String name, String publicID, String systemID)
throws SAXException {
if ((name == null) || (name.equals(""))) {
docTypeString = "";
return;
}
hasDTD = true;
StringBuffer docTypeSB = new StringBuffer();
boolean hasPublic = false;
docTypeSB.append("<!DOCTYPE ")
.append(name);
if ((publicID != null) && (!publicID.equals(""))) {
docTypeSB.append(" PUBLIC \"")
.append(publicID)
.append("\"");
hasPublic = true;
}
if ((systemID != null) && (!systemID.equals(""))) {
if (!hasPublic) {
docTypeSB.append(" SYSTEM");
}
docTypeSB.append(" \"")
.append(systemID)
.append("\"");
}
docTypeSB.append(">");
docTypeString = docTypeSB.toString();
}
public void endDTD() throws SAXException {
// Currently no-op
}
public void startEntity(String name) throws SAXException {
// Currently no-op
}
public void endEntity(String name) throws SAXException {
// Currently no-op
}
public void startCDATA() throws SAXException {
// Currently no-op
}
public void endCDATA() throws SAXException {
// Currently no-op
}
}
|