View Javadoc
1   /*
2    * Copyright 2017 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.audit.marshal;
17  
18  
19  import org.openehealth.ipf.commons.audit.model.AuditMessage;
20  
21  import java.io.IOException;
22  import java.io.StringWriter;
23  import java.io.Writer;
24  
25  /**
26   * Strategy for marshalling an {@link AuditMessage} into a serialized format. The primary
27   * format is DICOM.
28   *
29   * @author Christian Ohr
30   * @since 3.5
31   */
32  public interface SerializationStrategy {
33  
34      void marshal(AuditMessage auditMessage, Writer writer, boolean pretty) throws IOException;
35  
36      default String marshal(AuditMessage auditMessage, boolean pretty) {
37          try {
38              StringWriter writer = new StringWriter();
39              marshal(auditMessage, writer, pretty);
40              return writer.toString();
41          } catch (IOException e) {
42              throw new RuntimeException(e);
43          }
44      }
45  
46  }