1 /* 2 * Copyright 2006 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.ws.server.endpoint; 18 19 import javax.xml.stream.XMLInputFactory; 20 import javax.xml.stream.XMLOutputFactory; 21 22 import org.springframework.xml.transform.TransformerObjectSupport; 23 24 /** 25 * Abstract base class for endpoints use StAX. Provides an <code>XMLInputFactory</code> and an 26 * <code>XMLOutputFactory</code>. 27 * 28 * @author Arjen Poutsma 29 * @see XMLInputFactory 30 * @see XMLOutputFactory 31 * @since 1.0.0 32 */ 33 public abstract class AbstractStaxPayloadEndpoint extends TransformerObjectSupport { 34 35 private XMLInputFactory inputFactory; 36 37 private XMLOutputFactory outputFactory; 38 39 /** Returns an <code>XMLInputFactory</code> to read XML from. */ 40 protected final XMLInputFactory getInputFactory() { 41 if (inputFactory == null) { 42 inputFactory = createXmlInputFactory(); 43 } 44 return inputFactory; 45 } 46 47 /** Returns an <code>XMLOutputFactory</code> to write XML to. */ 48 protected final XMLOutputFactory getOutputFactory() { 49 if (outputFactory == null) { 50 outputFactory = createXmlOutputFactory(); 51 } 52 return outputFactory; 53 } 54 55 /** 56 * Create a <code>XMLInputFactory</code> that this endpoint will use to create <code>XMLStreamReader</code>s or 57 * <code>XMLEventReader</code>. Can be overridden in subclasses, adding further initialization of the factory. The 58 * resulting <code>XMLInputFactory</code> is cached, so this method will only be called once. 59 * 60 * @return the created <code>XMLInputFactory</code> 61 */ 62 protected XMLInputFactory createXmlInputFactory() { 63 return XMLInputFactory.newInstance(); 64 } 65 66 /** 67 * Create a <code>XMLOutputFactory</code> that this endpoint will use to create <code>XMLStreamWriters</code>s or 68 * <code>XMLEventWriters</code>. Can be overridden in subclasses, adding further initialization of the factory. The 69 * resulting <code>XMLOutputFactory</code> is cached, so this method will only be called once. 70 * 71 * @return the created <code>XMLOutputFactory</code> 72 */ 73 protected XMLOutputFactory createXmlOutputFactory() { 74 return XMLOutputFactory.newInstance(); 75 } 76 }