ohair@286: /*
alanb@368: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286: *
ohair@286: * This code is free software; you can redistribute it and/or modify it
ohair@286: * under the terms of the GNU General Public License version 2 only, as
ohair@286: * published by the Free Software Foundation. Oracle designates this
ohair@286: * particular file as subject to the "Classpath" exception as provided
ohair@286: * by Oracle in the LICENSE file that accompanied this code.
ohair@286: *
ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286: * version 2 for more details (a copy is included in the LICENSE file that
ohair@286: * accompanied this code).
ohair@286: *
ohair@286: * You should have received a copy of the GNU General Public License version
ohair@286: * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286: *
ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286: * or visit www.oracle.com if you need additional information or have any
ohair@286: * questions.
ohair@286: */
ohair@286:
ohair@286: package com.sun.xml.internal.messaging.saaj.util;
ohair@286:
ohair@286: import java.lang.reflect.*;
ohair@286: import javax.xml.transform.Source;
ohair@286: import javax.xml.transform.Result;
ohair@286: import java.io.InputStream;
ohair@286: import java.io.OutputStream;
ohair@286:
ohair@286: import org.w3c.dom.Document;
ohair@286: import org.w3c.dom.Node;
ohair@286:
ohair@286: /**
ohair@286: *
ohair@286: * @author Santiago.PericasGeertsen@sun.com
ohair@286: * @author Paul.Sandoz@sun.com
ohair@286: */
ohair@286: public class FastInfosetReflection {
ohair@286:
ohair@286: /**
ohair@286: * FI DOMDocumentParser constructor using reflection.
ohair@286: */
ohair@286: static Constructor fiDOMDocumentParser_new;
ohair@286:
ohair@286: /**
ohair@286: * FI DOMDocumentParser.parse()
method via reflection.
ohair@286: */
ohair@286: static Method fiDOMDocumentParser_parse;
ohair@286:
ohair@286: /**
ohair@286: * FI DOMDocumentSerializer constructor using reflection.
ohair@286: */
ohair@286: static Constructor fiDOMDocumentSerializer_new;
ohair@286:
ohair@286: /**
ohair@286: * FI FastInfosetSource.serialize(Document)
method via reflection.
ohair@286: */
ohair@286: static Method fiDOMDocumentSerializer_serialize;
ohair@286:
ohair@286: /**
ohair@286: * FI FastInfosetSource.setOutputStream(OutputStream)
method via reflection.
ohair@286: */
ohair@286: static Method fiDOMDocumentSerializer_setOutputStream;
ohair@286:
ohair@286: /**
ohair@286: * FI FastInfosetSource constructor using reflection.
ohair@286: */
ohair@286: static Class fiFastInfosetSource_class;
ohair@286:
ohair@286: /**
ohair@286: * FI FastInfosetSource constructor using reflection.
ohair@286: */
ohair@286: static Constructor fiFastInfosetSource_new;
ohair@286:
ohair@286: /**
ohair@286: * FI FastInfosetSource.getInputStream()
method via reflection.
ohair@286: */
ohair@286: static Method fiFastInfosetSource_getInputStream;
ohair@286:
ohair@286: /**
ohair@286: * FI FastInfosetSource.setInputSTream()
method via reflection.
ohair@286: */
ohair@286: static Method fiFastInfosetSource_setInputStream;
ohair@286:
ohair@286: /**
ohair@286: * FI FastInfosetResult constructor using reflection.
ohair@286: */
ohair@286: static Constructor fiFastInfosetResult_new;
ohair@286:
ohair@286: /**
ohair@286: * FI FastInfosetResult.getOutputSTream()
method via reflection.
ohair@286: */
ohair@286: static Method fiFastInfosetResult_getOutputStream;
ohair@286:
ohair@286: static {
ohair@286: try {
ohair@286: Class clazz = Class.forName("com.sun.xml.internal.fastinfoset.dom.DOMDocumentParser");
ohair@286: fiDOMDocumentParser_new = clazz.getConstructor((Class[]) null);
ohair@286: fiDOMDocumentParser_parse = clazz.getMethod("parse",
ohair@286: new Class[] { org.w3c.dom.Document.class, java.io.InputStream.class });
ohair@286:
ohair@286: clazz = Class.forName("com.sun.xml.internal.fastinfoset.dom.DOMDocumentSerializer");
ohair@286: fiDOMDocumentSerializer_new = clazz.getConstructor((Class[])null);
ohair@286: fiDOMDocumentSerializer_serialize = clazz.getMethod("serialize",
ohair@286: new Class[] { org.w3c.dom.Node.class });
ohair@286: fiDOMDocumentSerializer_setOutputStream = clazz.getMethod("setOutputStream",
ohair@286: new Class[] { java.io.OutputStream.class });
ohair@286:
ohair@286: fiFastInfosetSource_class = clazz = Class.forName("com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetSource");
ohair@286: fiFastInfosetSource_new = clazz.getConstructor(
ohair@286: new Class[] { java.io.InputStream.class });
ohair@286: fiFastInfosetSource_getInputStream = clazz.getMethod("getInputStream", (Class[]) null);
ohair@286: fiFastInfosetSource_setInputStream = clazz.getMethod("setInputStream",
ohair@286: new Class[] { java.io.InputStream.class });
ohair@286:
ohair@286: clazz = Class.forName("com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetResult");
ohair@286: fiFastInfosetResult_new = clazz.getConstructor(
ohair@286: new Class[] { java.io.OutputStream.class });
ohair@286: fiFastInfosetResult_getOutputStream = clazz.getMethod("getOutputStream", (Class[]) null);
ohair@286: }
ohair@286: catch (Exception e) {
ohair@286: // falls through
ohair@286: }
ohair@286: }
ohair@286:
ohair@286: // -- DOMDocumentParser ----------------------------------------------
ohair@286:
ohair@286: public static Object DOMDocumentParser_new() throws Exception {
ohair@286: if (fiDOMDocumentParser_new == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: return fiDOMDocumentParser_new.newInstance((Object[])null);
ohair@286: }
ohair@286:
ohair@286: public static void DOMDocumentParser_parse(Object parser,
ohair@286: Document d, InputStream s) throws Exception
ohair@286: {
ohair@286: if (fiDOMDocumentParser_parse == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: fiDOMDocumentParser_parse.invoke(parser, new Object[] { d, s });
ohair@286: }
ohair@286:
ohair@286: // -- DOMDocumentSerializer-------------------------------------------
ohair@286:
ohair@286: public static Object DOMDocumentSerializer_new() throws Exception {
ohair@286: if (fiDOMDocumentSerializer_new == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: return fiDOMDocumentSerializer_new.newInstance((Object[])null);
ohair@286: }
ohair@286:
ohair@286: public static void DOMDocumentSerializer_serialize(Object serializer, Node node)
ohair@286: throws Exception
ohair@286: {
ohair@286: if (fiDOMDocumentSerializer_serialize == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: fiDOMDocumentSerializer_serialize.invoke(serializer, new Object[] { node });
ohair@286: }
ohair@286:
ohair@286: public static void DOMDocumentSerializer_setOutputStream(Object serializer,
ohair@286: OutputStream os) throws Exception
ohair@286: {
ohair@286: if (fiDOMDocumentSerializer_setOutputStream == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: fiDOMDocumentSerializer_setOutputStream.invoke(serializer, new Object[] { os });
ohair@286: }
ohair@286:
ohair@286: // -- FastInfosetSource ----------------------------------------------
ohair@286:
ohair@286: public static boolean isFastInfosetSource(Source source) {
ohair@286: return source.getClass().getName().equals(
ohair@286: "com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetSource");
ohair@286: }
ohair@286:
ohair@286: public static Class getFastInfosetSource_class() {
ohair@286: if (fiFastInfosetSource_class == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286:
ohair@286: return fiFastInfosetSource_class;
ohair@286: }
ohair@286: public static Source FastInfosetSource_new(InputStream is)
ohair@286: throws Exception
ohair@286: {
ohair@286: if (fiFastInfosetSource_new == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: return (Source) fiFastInfosetSource_new.newInstance(new Object[] { is });
ohair@286: }
ohair@286:
ohair@286: public static InputStream FastInfosetSource_getInputStream(Source source)
ohair@286: throws Exception
ohair@286: {
ohair@286: if (fiFastInfosetSource_getInputStream == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: return (InputStream) fiFastInfosetSource_getInputStream.invoke(source, (Object[])null);
ohair@286: }
ohair@286:
ohair@286: public static void FastInfosetSource_setInputStream(Source source,
ohair@286: InputStream is) throws Exception
ohair@286: {
ohair@286: if (fiFastInfosetSource_setInputStream == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: fiFastInfosetSource_setInputStream.invoke(source, new Object[] { is });
ohair@286: }
ohair@286:
ohair@286: // -- FastInfosetResult ----------------------------------------------
ohair@286:
ohair@286: public static boolean isFastInfosetResult(Result result) {
ohair@286: return result.getClass().getName().equals(
ohair@286: "com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetResult");
ohair@286: }
ohair@286:
ohair@286: public static Result FastInfosetResult_new(OutputStream os)
ohair@286: throws Exception
ohair@286: {
ohair@286: if (fiFastInfosetResult_new == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: return (Result) fiFastInfosetResult_new.newInstance(new Object[] { os });
ohair@286: }
ohair@286:
ohair@286: public static OutputStream FastInfosetResult_getOutputStream(Result result)
ohair@286: throws Exception
ohair@286: {
ohair@286: if (fiFastInfosetResult_getOutputStream == null) {
ohair@286: throw new RuntimeException("Unable to locate Fast Infoset implementation");
ohair@286: }
ohair@286: return (OutputStream) fiFastInfosetResult_getOutputStream.invoke(result, (Object[])null);
ohair@286: }
ohair@286: }