Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
1 /*
2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
26 */
28 package com.sun.xml.internal.fastinfoset.stax.factory;
30 import com.sun.xml.internal.fastinfoset.stax.*;
31 import com.sun.xml.internal.fastinfoset.stax.events.StAXEventWriter;
32 import javax.xml.transform.Result;
33 import javax.xml.stream.XMLOutputFactory ;
34 import javax.xml.stream.XMLEventWriter;
35 import javax.xml.stream.XMLStreamWriter;
36 import javax.xml.stream.XMLStreamException;
37 import javax.xml.transform.stream.StreamResult;
38 import java.io.File;
39 import java.io.FileWriter;
40 import java.io.IOException;
41 import java.io.OutputStream;
42 import java.io.Writer;
43 import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
45 public class StAXOutputFactory extends XMLOutputFactory {
47 //List of supported properties and default values.
48 private StAXManager _manager = null ;
50 /** Creates a new instance of StAXOutputFactory */
51 public StAXOutputFactory() {
52 _manager = new StAXManager(StAXManager.CONTEXT_WRITER);
53 }
55 public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException {
56 return new StAXEventWriter(createXMLStreamWriter(result));
57 }
59 public XMLEventWriter createXMLEventWriter(Writer writer) throws XMLStreamException {
60 return new StAXEventWriter(createXMLStreamWriter(writer));
61 }
63 public XMLEventWriter createXMLEventWriter(OutputStream outputStream) throws XMLStreamException {
64 return new StAXEventWriter(createXMLStreamWriter(outputStream));
65 }
67 public XMLEventWriter createXMLEventWriter(OutputStream outputStream, String encoding) throws XMLStreamException {
68 return new StAXEventWriter(createXMLStreamWriter(outputStream, encoding));
69 }
71 public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException {
72 if(result instanceof StreamResult){
73 StreamResult streamResult = (StreamResult)result;
74 if( streamResult.getWriter() != null){
75 return createXMLStreamWriter(streamResult.getWriter());
76 }else if(streamResult.getOutputStream() != null ){
77 return createXMLStreamWriter(streamResult.getOutputStream());
78 }else if(streamResult.getSystemId()!= null){
79 try{
80 FileWriter writer = new FileWriter(new File(streamResult.getSystemId()));
81 return createXMLStreamWriter(writer);
82 }catch(IOException ie){
83 throw new XMLStreamException(ie);
84 }
85 }
86 }
87 else {
88 try{
89 //xxx: should we be using FileOutputStream - nb.
90 FileWriter writer = new FileWriter(new File(result.getSystemId()));
91 return createXMLStreamWriter(writer);
92 }catch(IOException ie){
93 throw new XMLStreamException(ie);
94 }
95 }
96 throw new java.lang.UnsupportedOperationException();
97 }
99 /** this is assumed that user wants to write the file in xml format
100 *
101 */
102 public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException {
103 throw new java.lang.UnsupportedOperationException();
104 }
106 public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream) throws XMLStreamException {
107 return new StAXDocumentSerializer(outputStream, new StAXManager(_manager));
108 }
110 public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream, String encoding) throws XMLStreamException {
111 StAXDocumentSerializer serializer = new StAXDocumentSerializer(outputStream, new StAXManager(_manager));
112 serializer.setEncoding(encoding);
113 return serializer;
114 }
116 public Object getProperty(String name) throws java.lang.IllegalArgumentException {
117 if(name == null){
118 throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{null}));
119 }
120 if(_manager.containsProperty(name))
121 return _manager.getProperty(name);
122 throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
123 }
125 public boolean isPropertySupported(String name) {
126 if(name == null)
127 return false ;
128 else
129 return _manager.containsProperty(name);
130 }
132 public void setProperty(String name, Object value) throws java.lang.IllegalArgumentException {
133 _manager.setProperty(name,value);
135 }
137 }