if (mode.indexOf("pool") >= 0) {
builder = BuilderPool.GLOBAL_POOL.getBuilder(false);
}
if (mode.equals("xom-V")) {
builder = new Builder(new NodeFactory() {});
} else if (mode.equals("xom-V-pool")) {
builder = new BuilderFactory() {
protected Builder newBuilder(XMLReader parser, boolean validate) {
return new Builder(parser, false, new NodeFactory() {});
}
}.createBuilder(false);
}
if (mode.equals("xom-NNF")) {
builder = new Builder(XOMUtil.getNullNodeFactory());
} else if (mode.equals("xom-NNF-pool")) {
builder = new BuilderFactory() {
protected Builder newBuilder(XMLReader parser, boolean validate) {
return new Builder(parser, false, XOMUtil.getNullNodeFactory());
}
}.createBuilder(false);
}
// saxon
context = null;
saxonSerializer = null;
if (mode.equals("saxon")) {
context = new StaticQueryContext(new Configuration());
saxonSerializer = createIdentityTransform(
new String[] {"net.sf.saxon.TransformerFactoryImpl"});
}
// DOM
domBuilder = null;
domSerializer = null;
if (mode.equals("dom")) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
factory.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
} catch (IllegalArgumentException e) {
// crimson does not implement this attribute
}
domBuilder = factory.newDocumentBuilder();
domSerializer = createIdentityTransform(new String[] {
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl",
"org.apache.xalan.processor.TransformerFactoryImpl"});
System.err.println(domSerializer.getClass().getName());
}
// FastInfoSet
fiBuilder = null;
fiSerializer = null;
fiMethod = null;
if (mode.startsWith("fi")) {
NodeFactory factory = null;
if (mode.indexOf("NNF") >= 0) factory = XOMUtil.getNullNodeFactory();
XMLReader parser = (XMLReader) Class.forName("com.sun.xml.fastinfoset.sax.SAXDocumentParser").newInstance();
fiBuilder = new Builder(parser, false, factory);
if (mode.indexOf("stax") >= 0) {
fiSerializer = (XMLStreamWriter) Class.forName("com.sun.xml.fastinfoset.stax.StAXDocumentSerializer").newInstance();
} else {
fiSerializer = (ContentHandler) Class.forName("com.sun.xml.fastinfoset.sax.SAXDocumentSerializer").newInstance();
}
if (mode.startsWith("fi1")) { // enable "full indexing"
Method method;
method = fiSerializer.getClass().getMethod(
"setAttributeValueSizeLimit", new Class[] {Integer.TYPE});
method.invoke(fiSerializer, new Object[] {new Integer(Integer.MAX_VALUE)});
method = fiSerializer.getClass().getMethod(
"setCharacterContentChunkSizeLimit", new Class[] {Integer.TYPE});
method.invoke(fiSerializer, new Object[] {new Integer(Integer.MAX_VALUE)});
}
fiMethod = fiSerializer.getClass().getMethod(
"setOutputStream", new Class[] { OutputStream.class});
if (mode.indexOf("stax") >= 0) {
fistaxReader = (XMLStreamReader) Class.forName("com.sun.xml.fastinfoset.stax.StAXDocumentParser").newInstance();
fistaxMethod = fistaxReader.getClass().getMethod(
"setInputStream", new Class[] { InputStream.class});
}
}
// StAX
staxBuilder = null;
if (mode.indexOf("stax") >= 0) {
NodeFactory factory = null;
if (mode.indexOf("NNF") >= 0) factory = XOMUtil.getNullNodeFactory();
staxBuilder = StaxUtil.createBuilder(staxInputFactory, factory);
}
}