// Path: src/main/java/com/siemens/ct/exi/main/helpers/DefaultSchemaIdResolver.java
// public class DefaultSchemaIdResolver implements SchemaIdResolver {
// 
// 	// protected GrammarFactory gf;
// 
// 	public DefaultSchemaIdResolver() {
// 
// 	}
// 
// 	protected GrammarFactory getGrammarFactory() {
// 		return GrammarFactory.newInstance();
// 		// if (gf == null) {
// 		// gf = GrammarFactory.newInstance();
// 		// }
// 		// return gf;
// 	}
// 
// 	public Grammars resolveSchemaId(String schemaId) throws EXIException {
// 		if (schemaId == null) {
// 			return getGrammarFactory().createSchemaLessGrammars();
// 		} else if ("".equals(schemaId)) {
// 			return getGrammarFactory().createXSDTypesOnlyGrammars();
// 		} else {
// 			// interpret schemaId as location
// 			try {
// 				return getGrammarFactory().createGrammars(schemaId);
// 			} catch (Exception e) {
// 				throw new EXIException(this.getClass().getName()
// 						+ " failed to retrieve schemaId == " + schemaId, e);
// 			}
// 		}
// 	}
// 
// }


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import com.siemens.ct.exi.core.EXIBodyDecoder;
import com.siemens.ct.exi.core.EXIFactory;
import com.siemens.ct.exi.core.EXIStreamDecoder;
import com.siemens.ct.exi.core.FidelityOptions;
import com.siemens.ct.exi.core.container.DocType;
import com.siemens.ct.exi.core.container.NamespaceDeclaration;
import com.siemens.ct.exi.core.container.ProcessingInstruction;
import com.siemens.ct.exi.core.context.QNameContext;
import com.siemens.ct.exi.core.exceptions.EXIException;
import com.siemens.ct.exi.core.grammars.event.EventType;
import com.siemens.ct.exi.core.values.Value;
import com.siemens.ct.exi.main.helpers.DefaultSchemaIdResolver;

/*
 * Copyright (c) 2007-2018 Siemens AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 */

package com.siemens.ct.exi.main.api.stream;




/**
 * De-Serializes EXI to StAX
 * 
 * @author Daniel.Peintner.EXT@siemens.com
 * @author Richard.Kuntschke@siemens.com
 * 
 */

public class StAXDecoder implements XMLStreamReader
// XMLEventReader
{

	protected EXIFactory noOptionsFactory;
	protected EXIStreamDecoder exiStream;
	protected EXIBodyDecoder decoder;

	// protected XMLStreamReader xmlStream;

	protected boolean exiBodyOnly = false;

	protected QNameContext element;
	protected List<AttributeContainer> attributes;
	protected Value characters;
	protected DocType docType;
	protected char[] entityReference;
	protected char[] comment;
	protected ProcessingInstruction processingInstruction;
	protected boolean namespacePrefixes = false;

	/* current event */
	protected EventType eventType;

	/* pre-read event, e.g., for attribute count */
	protected EventType preReadEventType;

	/* namespace context */
	protected EXINamespaceContext nsContext;

	static class AttributeContainer {
		final QNameContext qname;
		final Value value;
		final String prefix;

		public AttributeContainer(QNameContext qname, Value value, String prefix) {
			this.qname = qname;
			this.value = value;
			this.prefix = prefix;
		}
	}

	public StAXDecoder(EXIFactory noOptionsFactory) throws EXIException {
		this.noOptionsFactory = noOptionsFactory;
		if (noOptionsFactory.getSchemaIdResolver() == null) {
			// set default schemaId resolver

// Path: src/main/java/com/siemens/ct/exi/main/helpers/DefaultSchemaIdResolver.java
// public class DefaultSchemaIdResolver implements SchemaIdResolver {
// 
// 	// protected GrammarFactory gf;
// 
// 	public DefaultSchemaIdResolver() {
// 
// 	}
// 
// 	protected GrammarFactory getGrammarFactory() {
// 		return GrammarFactory.newInstance();
// 		// if (gf == null) {
// 		// gf = GrammarFactory.newInstance();
// 		// }
// 		// return gf;
// 	}
// 
// 	public Grammars resolveSchemaId(String schemaId) throws EXIException {
// 		if (schemaId == null) {
// 			return getGrammarFactory().createSchemaLessGrammars();
// 		} else if ("".equals(schemaId)) {
// 			return getGrammarFactory().createXSDTypesOnlyGrammars();
// 		} else {
// 			// interpret schemaId as location
// 			try {
// 				return getGrammarFactory().createGrammars(schemaId);
// 			} catch (Exception e) {
// 				throw new EXIException(this.getClass().getName()
// 						+ " failed to retrieve schemaId == " + schemaId, e);
// 			}
// 		}
// 	}
// 
// }


// Path: src/main/java/com/siemens/ct/exi/main/api/stream/StAXDecoder.java
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import com.siemens.ct.exi.core.EXIBodyDecoder;
import com.siemens.ct.exi.core.EXIFactory;
import com.siemens.ct.exi.core.EXIStreamDecoder;
import com.siemens.ct.exi.core.FidelityOptions;
import com.siemens.ct.exi.core.container.DocType;
import com.siemens.ct.exi.core.container.NamespaceDeclaration;
import com.siemens.ct.exi.core.container.ProcessingInstruction;
import com.siemens.ct.exi.core.context.QNameContext;
import com.siemens.ct.exi.core.exceptions.EXIException;
import com.siemens.ct.exi.core.grammars.event.EventType;
import com.siemens.ct.exi.core.values.Value;
import com.siemens.ct.exi.main.helpers.DefaultSchemaIdResolver;

/*
 * Copyright (c) 2007-2018 Siemens AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 */

package com.siemens.ct.exi.main.api.stream;




/**
 * De-Serializes EXI to StAX
 * 
 * @author Daniel.Peintner.EXT@siemens.com
 * @author Richard.Kuntschke@siemens.com
 * 
 */

public class StAXDecoder implements XMLStreamReader
// XMLEventReader
{

	protected EXIFactory noOptionsFactory;
	protected EXIStreamDecoder exiStream;
	protected EXIBodyDecoder decoder;

	// protected XMLStreamReader xmlStream;

	protected boolean exiBodyOnly = false;

	protected QNameContext element;
	protected List<AttributeContainer> attributes;
	protected Value characters;
	protected DocType docType;
	protected char[] entityReference;
	protected char[] comment;
	protected ProcessingInstruction processingInstruction;
	protected boolean namespacePrefixes = false;

	/* current event */
	protected EventType eventType;

	/* pre-read event, e.g., for attribute count */
	protected EventType preReadEventType;

	/* namespace context */
	protected EXINamespaceContext nsContext;

	static class AttributeContainer {
		final QNameContext qname;
		final Value value;
		final String prefix;

		public AttributeContainer(QNameContext qname, Value value, String prefix) {
			this.qname = qname;
			this.value = value;
			this.prefix = prefix;
		}
	}

	public StAXDecoder(EXIFactory noOptionsFactory) throws EXIException {
		this.noOptionsFactory = noOptionsFactory;
		if (noOptionsFactory.getSchemaIdResolver() == null) {
			// set default schemaId resolver

			noOptionsFactory.setSchemaIdResolver(new DefaultSchemaIdResolver());
