View Javadoc
1   /*
2    * Copyright 2013 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.platform.camel.cda.dataformat;
17  
18  import java.io.InputStream;
19  import java.io.OutputStream;
20  
21  import org.apache.camel.Exchange;
22  import org.apache.camel.spi.DataFormat;
23  import org.openehealth.ipf.modules.cda.CDAR2Parser;
24  import org.openehealth.ipf.modules.cda.CDAR2Renderer;
25  import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
26  
27  public class MdhtDataFormat implements DataFormat {
28  
29      private final CDAR2Renderer renderer;
30      private final CDAR2Parser parser;
31  
32      public MdhtDataFormat() {
33          renderer = new CDAR2Renderer();
34          parser = new CDAR2Parser();
35      }
36  
37      @Override
38      public void marshal(Exchange exchange, Object graph, OutputStream stream)
39              throws Exception {
40          renderer.render((ClinicalDocument) graph, stream,
41                  (Object[]) null);
42      }
43  
44      @Override
45      public Object unmarshal(Exchange exchange, InputStream stream)
46              throws Exception {
47          return parser.parse(stream, (Object[]) null);
48      }
49  
50  }