01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.databinding.source;
19:
20: import javax.xml.stream.XMLStreamReader;
21: import javax.xml.stream.XMLStreamWriter;
22:
23: import org.w3c.dom.Node;
24:
25: import org.apache.cxf.databinding.DataBinding;
26: import org.apache.cxf.databinding.DataReader;
27: import org.apache.cxf.databinding.DataWriter;
28: import org.apache.cxf.service.Service;
29:
30: /**
31: * A simple databinding implementation which reads and writes Source objects.
32: */
33: public class SourceDataBinding implements DataBinding {
34:
35: private XMLStreamDataReader xsrReader;
36: private XMLStreamDataWriter xswWriter;
37: private NodeDataWriter nodeWriter;
38: private NodeDataReader nodeReader;
39:
40: public SourceDataBinding() {
41: super ();
42: this .xsrReader = new XMLStreamDataReader();
43: this .xswWriter = new XMLStreamDataWriter();
44:
45: this .nodeReader = new NodeDataReader();
46: this .nodeWriter = new NodeDataWriter();
47: }
48:
49: public void initialize(Service service) {
50: // do nothing
51: }
52:
53: @SuppressWarnings("unchecked")
54: public <T> DataReader<T> createReader(Class<T> cls) {
55: if (cls == XMLStreamReader.class) {
56: return (DataReader<T>) xsrReader;
57: } else if (cls == Node.class) {
58: return (DataReader<T>) nodeReader;
59: } else {
60: throw new UnsupportedOperationException("The type "
61: + cls.getName() + " is not supported.");
62: }
63: }
64:
65: public Class<?>[] getSupportedReaderFormats() {
66: return new Class[] { XMLStreamReader.class, Node.class };
67: }
68:
69: @SuppressWarnings("unchecked")
70: public <T> DataWriter<T> createWriter(Class<T> cls) {
71: if (cls == XMLStreamWriter.class) {
72: return (DataWriter<T>) xswWriter;
73: } else if (cls == Node.class) {
74: return (DataWriter<T>) nodeWriter;
75: } else {
76: throw new UnsupportedOperationException("The type "
77: + cls.getName() + " is not supported.");
78: }
79: }
80:
81: public Class<?>[] getSupportedWriterFormats() {
82: return new Class[] { XMLStreamWriter.class, Node.class };
83: }
84:
85: }
|