01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
34: TransformerObjectSupport {
35:
36: private XMLInputFactory inputFactory;
37:
38: private XMLOutputFactory outputFactory;
39:
40: /** Returns an <code>XMLInputFactory</code> to read XML from. */
41: protected final XMLInputFactory getInputFactory() {
42: if (inputFactory == null) {
43: inputFactory = createXmlInputFactory();
44: }
45: return inputFactory;
46: }
47:
48: /** Returns an <code>XMLOutputFactory</code> to write XML to. */
49: protected final XMLOutputFactory getOutputFactory() {
50: if (outputFactory == null) {
51: outputFactory = createXmlOutputFactory();
52: }
53: return outputFactory;
54: }
55:
56: /**
57: * Create a <code>XMLInputFactory</code> that this endpoint will use to create <code>XMLStreamReader</code>s or
58: * <code>XMLEventReader</code>. Can be overridden in subclasses, adding further initialization of the factory. The
59: * resulting <code>XMLInputFactory</code> is cached, so this method will only be called once.
60: *
61: * @return the created <code>XMLInputFactory</code>
62: */
63: protected XMLInputFactory createXmlInputFactory() {
64: return XMLInputFactory.newInstance();
65: }
66:
67: /**
68: * Create a <code>XMLOutputFactory</code> that this endpoint will use to create <code>XMLStreamWriters</code>s or
69: * <code>XMLEventWriters</code>. Can be overridden in subclasses, adding further initialization of the factory. The
70: * resulting <code>XMLOutputFactory</code> is cached, so this method will only be called once.
71: *
72: * @return the created <code>XMLOutputFactory</code>
73: */
74: protected XMLOutputFactory createXmlOutputFactory() {
75: return XMLOutputFactory.newInstance();
76: }
77: }
|