View Javadoc
1   /*
2    * Copyright 2009 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  package org.openehealth.ipf.commons.ihe.ws.cxf.databinding.plainxml;
17  
18  import java.util.Collection;
19  
20  import javax.xml.namespace.QName;
21  import javax.xml.stream.XMLStreamException;
22  import javax.xml.stream.XMLStreamReader;
23  import javax.xml.validation.Schema;
24  
25  import org.apache.cxf.databinding.DataReader;
26  import org.apache.cxf.message.Attachment;
27  import org.apache.cxf.service.model.MessagePartInfo;
28  
29  /**
30   * Fake data reader which reads in the whole XML stream and returns 
31   * a <code>null</code> value instead of the expected POJO. 
32   * @author Dmytro Rud
33   */
34  public class PlainXmlReader implements DataReader<XMLStreamReader>{
35  
36      @Override
37      public Object read(XMLStreamReader reader) {
38          try {
39              while(reader.hasNext()) { 
40                  reader.next();
41              }
42          } catch (XMLStreamException e) {
43              throw new RuntimeException(e);
44          }
45          return null;
46      }
47  
48      @Override
49      public Object read(MessagePartInfo part, XMLStreamReader reader) {
50          return read(reader);
51      }
52  
53      @SuppressWarnings("unchecked")
54      @Override
55      public Object read(QName elementQName, XMLStreamReader reader, Class type) {
56          return read(reader);
57      }
58  
59      @Override
60      public void setAttachments(Collection<Attachment> attachments) {
61          // nop
62      }
63  
64      @Override
65      public void setProperty(String prop, Object value) {
66          // nop
67      }
68  
69      @Override
70      public void setSchema(Schema s) {
71          // nop
72      }
73  }