// Path: src/main/java/com/siemens/ct/exi/main/api/sax/EXIResult.java
// public class EXIResult extends SAXResult {
// 
// 	protected SAXEncoder handler;
// 
// 	public EXIResult() throws IOException, EXIException {
// 		// use default exi-factory
// 		this(DefaultEXIFactory.newInstance());
// 	}
// 
// 	public EXIResult(EXIFactory exiFactory) throws EXIException {
// 		// DefaultHandler2 handler = exiFactory.createEXIWriter(os);
// 		handler = new SAXFactory(exiFactory).createEXIWriter();
// 		// set internal states
// 		setHandler(handler);
// 		setLexicalHandler(handler);
// 	}
// 
// 	public void setOutputStream(OutputStream os) throws EXIException,
// 			IOException {
// 		handler.setOutputStream(os);
// 	}
// 
// }
// 
// Path: src/main/java/com/siemens/ct/exi/main/api/sax/SAXFactory.java
// public class SAXFactory {
// 
// 	protected final EXIFactory exiFactory;
// 
// 	public SAXFactory(EXIFactory exiFactory) {
// 		this.exiFactory = exiFactory;
// 	}
// 
// 	/**
// 	 * Returns an <code>EXIReader</code>
// 	 * 
// 	 * @return reader using the previously set coding options.
// 	 * @throws EXIException
// 	 *             EXI exception
// 	 * 
// 	 */
// 	public XMLReader createEXIReader() throws EXIException {
// 		return new SAXDecoder(exiFactory);
// 	}
// 
// 	/**
// 	 * Returns a <code>SAXEncoder</code> that implements
// 	 * <code>DefaultHandler2</code>
// 	 * 
// 	 * <p>
// 	 * Note that the output stream MUST be set.
// 	 * </p>
// 	 * 
// 	 * @return writer using the previously set coding options.
// 	 * @throws EXIException
// 	 *             EXI exception
// 	 * 
// 	 */
// 	public SAXEncoder createEXIWriter() throws EXIException {
// 		final FidelityOptions fidelityOptions = exiFactory.getFidelityOptions();
// 		if (fidelityOptions.isFidelityEnabled(FidelityOptions.FEATURE_PREFIX)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_COMMENT)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_PI)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_DTD)) {
// 			return new SAXEncoderExtendedHandler(exiFactory);
// 		} else {
// 			return new SAXEncoder(exiFactory);
// 		}
// 	}
// 
// }


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import junit.framework.TestCase;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import com.siemens.ct.exi.core.CodingMode;
import com.siemens.ct.exi.core.Constants;
import com.siemens.ct.exi.core.EXIBodyDecoder;
import com.siemens.ct.exi.core.EXIBodyEncoder;
import com.siemens.ct.exi.core.EXIFactory;
import com.siemens.ct.exi.core.FidelityOptions;
import com.siemens.ct.exi.core.SelfContainedHandler;
import com.siemens.ct.exi.core.exceptions.EXIException;
import com.siemens.ct.exi.core.grammars.event.EventType;
import com.siemens.ct.exi.core.helpers.DefaultEXIFactory;
import com.siemens.ct.exi.core.io.channel.EncoderChannel;
import com.siemens.ct.exi.core.values.StringValue;
import com.siemens.ct.exi.core.values.Value;
import com.siemens.ct.exi.grammars.GrammarFactory;
import com.siemens.ct.exi.main.api.sax.EXIResult;
import com.siemens.ct.exi.main.api.sax.SAXFactory;

		}

	}

	protected void _testSelfContained2(boolean bytePacked) throws Exception {

		String xmlAsString = "<foo><foo>text</foo><bla>btext</bla></foo>";

		// boolean t1 = xmlAsString.matches("*");
		// boolean t2 = xmlAsString.matches(".*");

		EXIFactory factory = DefaultEXIFactory.newInstance();

		factory.setFidelityOptions(FidelityOptions.createDefault());
		// factory.setCodingMode(CodingMode.BIT_PACKED);
		if (bytePacked) {
			factory.setCodingMode(CodingMode.BYTE_PACKED);
		}
		FidelityOptions fo = factory.getFidelityOptions();
		fo.setFidelity(FidelityOptions.FEATURE_SC, true);

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		// QName sc = new QName("", "bla");
		QName sc = new QName(".*", ".*"); // any

		QName[] scElements = new QName[1];
		scElements[0] = sc;
		SelfContainedHandlerTracker scHandler = new SelfContainedHandlerTracker();
		factory.setSelfContainedElements(scElements, scHandler);


// Path: src/main/java/com/siemens/ct/exi/main/api/sax/EXIResult.java
// public class EXIResult extends SAXResult {
// 
// 	protected SAXEncoder handler;
// 
// 	public EXIResult() throws IOException, EXIException {
// 		// use default exi-factory
// 		this(DefaultEXIFactory.newInstance());
// 	}
// 
// 	public EXIResult(EXIFactory exiFactory) throws EXIException {
// 		// DefaultHandler2 handler = exiFactory.createEXIWriter(os);
// 		handler = new SAXFactory(exiFactory).createEXIWriter();
// 		// set internal states
// 		setHandler(handler);
// 		setLexicalHandler(handler);
// 	}
// 
// 	public void setOutputStream(OutputStream os) throws EXIException,
// 			IOException {
// 		handler.setOutputStream(os);
// 	}
// 
// }
// 
// Path: src/main/java/com/siemens/ct/exi/main/api/sax/SAXFactory.java
// public class SAXFactory {
// 
// 	protected final EXIFactory exiFactory;
// 
// 	public SAXFactory(EXIFactory exiFactory) {
// 		this.exiFactory = exiFactory;
// 	}
// 
// 	/**
// 	 * Returns an <code>EXIReader</code>
// 	 * 
// 	 * @return reader using the previously set coding options.
// 	 * @throws EXIException
// 	 *             EXI exception
// 	 * 
// 	 */
// 	public XMLReader createEXIReader() throws EXIException {
// 		return new SAXDecoder(exiFactory);
// 	}
// 
// 	/**
// 	 * Returns a <code>SAXEncoder</code> that implements
// 	 * <code>DefaultHandler2</code>
// 	 * 
// 	 * <p>
// 	 * Note that the output stream MUST be set.
// 	 * </p>
// 	 * 
// 	 * @return writer using the previously set coding options.
// 	 * @throws EXIException
// 	 *             EXI exception
// 	 * 
// 	 */
// 	public SAXEncoder createEXIWriter() throws EXIException {
// 		final FidelityOptions fidelityOptions = exiFactory.getFidelityOptions();
// 		if (fidelityOptions.isFidelityEnabled(FidelityOptions.FEATURE_PREFIX)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_COMMENT)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_PI)
// 				|| fidelityOptions
// 						.isFidelityEnabled(FidelityOptions.FEATURE_DTD)) {
// 			return new SAXEncoderExtendedHandler(exiFactory);
// 		} else {
// 			return new SAXEncoder(exiFactory);
// 		}
// 	}
// 
// }


// Path: src/test/java/com/siemens/ct/exi/main/core/SelfContainedTestCase.java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import junit.framework.TestCase;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import com.siemens.ct.exi.core.CodingMode;
import com.siemens.ct.exi.core.Constants;
import com.siemens.ct.exi.core.EXIBodyDecoder;
import com.siemens.ct.exi.core.EXIBodyEncoder;
import com.siemens.ct.exi.core.EXIFactory;
import com.siemens.ct.exi.core.FidelityOptions;
import com.siemens.ct.exi.core.SelfContainedHandler;
import com.siemens.ct.exi.core.exceptions.EXIException;
import com.siemens.ct.exi.core.grammars.event.EventType;
import com.siemens.ct.exi.core.helpers.DefaultEXIFactory;
import com.siemens.ct.exi.core.io.channel.EncoderChannel;
import com.siemens.ct.exi.core.values.StringValue;
import com.siemens.ct.exi.core.values.Value;
import com.siemens.ct.exi.grammars.GrammarFactory;
import com.siemens.ct.exi.main.api.sax.EXIResult;
import com.siemens.ct.exi.main.api.sax.SAXFactory;

		}

	}

	protected void _testSelfContained2(boolean bytePacked) throws Exception {

		String xmlAsString = "<foo><foo>text</foo><bla>btext</bla></foo>";

		// boolean t1 = xmlAsString.matches("*");
		// boolean t2 = xmlAsString.matches(".*");

		EXIFactory factory = DefaultEXIFactory.newInstance();

		factory.setFidelityOptions(FidelityOptions.createDefault());
		// factory.setCodingMode(CodingMode.BIT_PACKED);
		if (bytePacked) {
			factory.setCodingMode(CodingMode.BYTE_PACKED);
		}
		FidelityOptions fo = factory.getFidelityOptions();
		fo.setFidelity(FidelityOptions.FEATURE_SC, true);

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		// QName sc = new QName("", "bla");
		QName sc = new QName(".*", ".*"); // any

		QName[] scElements = new QName[1];
		scElements[0] = sc;
		SelfContainedHandlerTracker scHandler = new SelfContainedHandlerTracker();
		factory.setSelfContainedElements(scElements, scHandler);


		EXIResult exiResult = new EXIResult(factory);
